From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with DLL import library function names

I am trying to use a 3rd party DLL written using VC++6.0, and use it in CVI6.0 under XP. The .h file declares functions as
extern __declspec(dllimport) int WINAPI FnName(void);
and CVI then tries to link to _FnName@0
However it cannot because the .lib file has entries like __imp_?FnName@@YGHXZ. I have tried generating a new import library from the .h file but run into other problems.

Any ideas?

Thanks
0 Kudos
Message 1 of 6
(4,205 Views)
Hello

In order to use the library from a C compiler, the library author has to disable name mangling by using the extern "C" directive with the function definitions. C++ compilers will always mangle names otherwise. You might try to check with the 3rd party provider to see if they have a dll you can use with a C compiler.

Hope this helps

Bilal Durrani
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(4,205 Views)
Hi,

Here is a document that explains this a bit further, it was written for object file, however it also applies to DLLs.

The only drawback of using extern C is that you can't overlod functions (same fucntion name, different parameters).

I hope this helps.

Juan Carlos
N.I.
0 Kudos
Message 3 of 6
(4,205 Views)
Thanks for the assistance.

They do not have another DLL, however, in the meantime I have discovered that they do have a VB "header" that said it was for the same DLL. I therefore took that header and reduced it to the likes of

extern int FnName(int);

after which I was able to generate an import library. On the little testing I have done so far this seems to be working. What I do not know is whether in my ignorance I have done something daft that will blow up in my face later! Does what I have done seem reasonable?

Thanks

Adrian Davidson
0 Kudos
Message 4 of 6
(4,205 Views)
Perhaps the dll might not have had the names mangled. You can check this by using Dependency Walker to actaully view the names of the functions exported by the dll. If the names look readable, then you should be fine. I doubt the VB header would have worked if the function names in the dll were mangled.

Make sure you verify the calling convention in the headers and explicitly mention it (usually a good practice) . If someone changes the default calling convention for CVI, you might start getting linking errors. WINAPI is __stdcall

Hope this helps

Bilal
Bilal Durrani
NI
0 Kudos
Message 5 of 6
(4,205 Views)
Thanks for pointing me to Dependency Walker. You are correct, the names appear in the export section as C exports, and without any mangling.

Have included the __stdcall as suggested. I would normally have had CVI default convention as __cdecl, but had changed it while trying to solve my problem.

Thanks again
0 Kudos
Message 6 of 6
(4,205 Views)