我有一个库 (C++),其中包含一些 API 函数。其中之一被声明为 __cdecl,但从 __stdcall 获取函数指针。像这样的东西:
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
然后 - 我有一个使用此库的 C++ 可执行项目,但不调用上述 API 或使用 Func
类型。
将 Func
的调用约定更改为 __stdcall
后,出现以下编译错误:
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
知道它会是什么吗?
提前致谢!
最佳答案
呃……他们不相容。您必须在调用的两侧指定相同的调用约定。否则尝试调用会炸毁机器堆栈。
关于c++ - 混合调用约定会导致编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3141232/