c++ - 混合调用约定会导致编译错误

标签 c++ compiler-errors stdcall cdecl

我有一个库 (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/

相关文章:

C++定义的?宏?在 header 中可见但在实现中丢失(链接器报告外部未解决)

c++ - 为什么不能正确解析显式析构函数调用中的限定类型名称?

c++ - 错误 C2440 : '=' : cannot convert from 'ListNode<T> *' to 'ListNode<T> *'

android - 错误: No resource identifier found for attribute 'popupTheme' in package “com.example…”

gcc - 从源代码编译miniupnpc

c - 在英特尔 x64 汇编中执行函数的最快(CPU 方式)方式?

c++ - 如何检查值是否在列表中

c++ - 没有参数列表的模板名称队列的无效使用

c++ - Linux中有STDCALL吗?

c++ - 链接器错误 LNK2019 追溯到 __stdcall 我想我得到了正确的库 - 我该怎么做才能解决这个问题?