混合调用约定会导致编译错误
我有一个库(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
后,出现以下编译错误:
错误 C2995: 'std::pointer_to_unary_function<_Arg,_Result,_Result(__cdecl *)(_Arg)>; std::ptr_fun(_Result (__cdecl *)(_Arg))' :函数 模板已经有了 定义 c:\program files\microsoft Visual Studio 8\vc\include\功能
知道它是什么吗?
提前致谢!!
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!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
呃..他们不兼容。您必须在调用双方指定相同的调用约定。否则尝试调用将炸毁机器堆栈。
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.
它们是兼容的,至少在 Windows 中(并且在 Linux 中根本没有 __stdcall...)
问题是,库错误地重新定义了 __stdcall 以与 Linux 兼容,如下所示:
exe 项目包含此定义,而 __MYLIB_WIN32 未在其中定义,而仅在库中定义。
将上面的定义更改为:
一切正常。
谢谢大家。
They ARE compatible, in Windows at least (and in Linux there isn't __stdcall at all...)
The problem was that by mistake, the library re-defined __stdcall for compatibility with Linux, as:
The exe project includes this definition, and __MYLIB_WIN32 was not defined in it, but in the library only.
Changing the above definition to:
and everything works fine.
Thank you all.