Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixed calling conventions make compilation errors

I have a library (C++) which has some API functions. One of them is declared as __cdecl, but gets a function poiner from __stdcall. Something like:

typedef  int (__stdcall *Func)(unsigned char* buffer);
//...
int ApiFunc(Func funcPtr); //This is __cdecl since it is an 'extern "C"' library and the calling convention is not specified

Then - I have a C++ executable project which uses this library, but doesn't call the above API or uses the Func type.

After changing the calling convention of Func to __stdcall, I get the following compilation error:

error C2995: 'std::pointer_to_unary_function<_Arg,_Result,_Result(__cdecl *)(_Arg)> std::ptr_fun(_Result (__cdecl *)(_Arg))' : function template has already been defined c:\program files\microsoft visual studio 8\vc\include\functional

Any idea what could it be?

Thanks in advance!!

like image 833
Allen L Avatar asked Sep 30 '26 09:09

Allen L


1 Answers

Err.. they're incompatible. You have to specify the same calling convention on both sides of the call. Otherwise attempting to call will blow up the machine stack.

like image 110
Billy ONeal Avatar answered Oct 01 '26 23:10

Billy ONeal