LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Implicit .dll linking help

Solved!
Go to solution

Hi,

 

I have a .dll that I'm trying to link implicitly (I've tried explicitly linking too), but I just wanted to check with people more knowledgeable before I complain to the developer of the .dll.  I've looked at the examples in the NI Example Finder, read a couple webpages including this one http://zone.ni.com/devzone/cda/tut/p/id/3341 so I'm coming with a little bit of knowledge but not a whole lot on .dlls.

 

I have the .lib, the .h file and the .dll and there all located in the same folder as my project.  So all I've done is add the .h and the .lib files to my project, and written #include "LEDdriver.h" in my source code.  I compile and this should work right? It shouldn't give me any errors, since I haven't written any code in myself other than the include statement but it does.

 

The errors I get come from the .h file where it doesn't recognize the declaration SDK_API that sits before the export functions in the .h file, saying "Warning: Empty declaration."

 

This is the code from the top of the .h file where I think is the problem since it's where SDK_API is defined, but I think it looks fine to me, so I don't know why it isn't working.

 

 

typedef int SDK_RETURN_CODE;

 

#ifdef SDK_EXPORTS

#define SDK_API extern "C" __declspec(dllexport) SDK_RETURN_CODE _cdecl

#else

#define SDK_API extern "C" __declspec(dllimport) SDK_RETURN_CODE _cdecl

#endif 

 

Any help would be greatly appreciated, thanks. 

0 Kudos
Message 1 of 6
(4,769 Views)
Solution
Accepted by topic author Obscura

Its the old chestnut of using extern "C" with a non-C++ compiler. There are elegant ways of handling this situation, but a quick and dirty option for CVI is simply to delete the phrase.

 

(If you search the forum posts, you will find more descriptive discussions on the topic.)

 

JR

Message 2 of 6
(4,753 Views)

this has been discussed not long ago in this forum.

 

the extern "C" is a C++ declaration stating that the following code is indeed C and not C++. CVI does not know how to handle such a declaration. also, __declspec( dllexport/dllimport ) is a private extension to the language, targetted mainly at Visual C++ (although other compilers might be using it too): this extension is to avoid the DLL developper to write a definition (.def) file. this also is not understood by CVI. 

 

i think you can safely remove those declaration and let SDK_APIS be empty.

Message 3 of 6
(4,752 Views)

Actually, CVI does support:

 

__declspec(dllimport) / __declspec(dllexport)

__import / __export

_import / _export

 

as well as definining DLLEXPORT and DLLIMPORT macros that are portable accross external compilers. See the help topic "Import and Export Qualifiers" for more details.

 

Mert A.

National Instruments

Message 4 of 6
(4,735 Views)

I didn't know this problem was such old hat, apologies for not being able to dig up the solution in the forums, but I want to thank everyone for their help.  The issue was successfully resolved by removing extern "C", and it turns out CVI does indeed support the __declspec(dllimport/dllexport) commands.

 

 Now I can finally start using the hardware I bought, so a round of beer to all of you.

0 Kudos
Message 5 of 6
(4,730 Views)

ho sorry, i didn't know CVI did support __declspec(...) and all the stuff. my bad for not having verified my claim.

 

anyway, cheers Obscura ! and thanks for the beer !

0 Kudos
Message 6 of 6
(4,712 Views)