LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

cdecl & stdcall calls mixed in one project

Solved!
Go to solution

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

 

 

0 Kudos
Message 1 of 6
(6,991 Views)

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, 

Rachel M.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(6,968 Views)

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

0 Kudos
Message 3 of 6
(6,937 Views)

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. 

Rachel M.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 6
(6,919 Views)
Solution
Accepted by topic author uriyal

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

Message 5 of 6
(6,909 Views)

rkm44,

Sorry for the long delay.

your solution works!

0 Kudos
Message 6 of 6
(6,787 Views)