01-08-2015 01:13 AM
Hi,
I have a dll project that its call convention set to stdcall.
It calls other dlls (3rd party), some of them using stdcall call convention and some are using cdecl.
It seems that I can't have both!, if I switch my project call convention to stdcall Im getting linking error (undefined symbole...) on the cdecl functions and vice versa.
I've checked, searched, googled and didn't find any practical solutions.
The only thing that I've found close to a solution is to wrap the dlls that are different from my project call conention. is this the only way?
Any help will be greatly appreciated 🙂
Best Regards,
Uriya
Solved! Go to Solution.
01-08-2015 06:28 PM
Hi uriyal,
Could you post a screenshot of the error you are receiving? I think that will help us understand what is going on better.
Thank you,
01-12-2015 03:00 AM - edited 01-12-2015 03:16 AM
Hi rkm44,
My project's call conventions setup is cdecl and when trying building the project Im getting Link error that says: Undefined symbol '_CalcCenterOfGravity' referenced in "service.c".
I've service.c file which within it, it calls:
status = CalcCenterOfGravity(5);
CalcCenterOfGravity - is a 3rd party dll that compiled under stdcall call convetion.
its header goes like this:
#ifdef CALCCENTEROFGRAVITY_EXPORTS
#define CALCCENTEROFGRAVITY_API extern "C" __declspec(dllexport)
#else
#define CALCCENTEROFGRAVITY_API extern "C" __declspec(dllimport)
#endif
CALCCENTEROFGRAVITY_API int CalcCenterOfGravity (int x)
P.S. I don't use compiler flag CALCCENTEROFGRAVITY_EXPORTS.
Best Regards,
Uriya
01-13-2015 01:11 PM
Hi uriyal,
Unfortunately you can only use one call convention at a time with CVI. Both cdecl and stdcall are supported, but not together. Since the calling conventions are set in the Build Options of CVI, you can only select one or the other. Here is a document about calling conventions in CVI: http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/programmerref/callingconventions/
Ultimately you will want all dlls to use the same calling convention. So it sounds like your previous suggestion of wrapping the different dlls will be your best bet.
01-14-2015 03:47 AM - edited 01-14-2015 03:48 AM
Hi Uriya,
The setting in Build Option is the calling convention used if no calling convention is specified. But you can change the calling convention of a function by specifying _stdcall or _cdecl and you can mix them.
The problem in your case is the declarations in dll header don't specify a calling convention and the default calling convention is assumed. To fix it you should add the calling convention in the function declaration.
Example: CALCCENTEROFGRAVITY_API int _cdecl CalcCenterOfGravity (int x)
I hope this helps.
Constantin
01-27-2015 06:52 AM