如何指定vc11 lambda调用约定 [英] how to specify vc11 lambda calling convention
问题描述
我想通过一个lambda函数指针,它嵌套在一个班,对Windows API的回调函数。我发现没有地方可以指定 __ stdcall
关键字。我用nm命令有人告诉我,编译只支持 __ CDECL
,但经过转储obj的文件,我发现编译将产生三个辅助函数( __ stdcall
, __ cdecl
, __ fastcall
)。所以我的问题是,我怎么可以指定调用约定?
那些下面的代码是我的测试代码。
的#includestdafx.h中
INT _tmain(INT ARGC,_TCHAR *的argv [])
{
自动FUNC = [](){ };
return 0;
}
0000万吨< helper_func_cdecl> @< lambda_5738939ec88434c53e1a446c47cf2db6> @@ CAXXZ
0000万吨< helper_func_fastcall> @< lambda_5738939ec88434c53e1a446c47cf2db6> @@ CIXXZ
0000万吨< helper_func_stdcall> @< lambda_5738939ec88434c53e1a446c47cf2db6> @@ CGXXZ
0000万吨?? b< lambda_5738939ec88434c53e1a446c47cf2db6> @@ QBEP6AXXZXZ
0000万吨?? b< lambda_5738939ec88434c53e1a446c47cf2db6> @@ QBEP6GXXZXZ
0000万吨?? b< lambda_5738939ec88434c53e1a446c47cf2db6> @@ QBEP6IXXZXZ
0000万吨?? R< lambda_5738939ec88434c53e1a446c47cf2db6> @@ QBEXXZ
演员吧:
WinApiFunc(的static_cast<无效(__ STDCALL *)()>(FUNC));
或者先将其存储到本地变量中:
void(__stdcall * funcp)()= func;
WinApiFunc(funcp);
I want to pass a lambda function pointer, which nested in a class, to the Windows API callback function. I found there is no place for me to specify the __stdcall
keyword. Some people told me the compile only support __cdecl
, but after I used nm command to dump the obj file, I found the compile will generate three helper function (__stdcall
, __cdecl
, __fastcall
) concurrently. So my problem is, how can I specify the calling convention?
Those following code are my test code.
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
auto func = [](){};
return 0;
}
00000000 t ?<helper_func_cdecl>@<lambda_5738939ec88434c53e1a446c47cf2db6>@@CAXXZ
00000000 t ?<helper_func_fastcall>@<lambda_5738939ec88434c53e1a446c47cf2db6>@@CIXXZ
00000000 t ?<helper_func_stdcall>@<lambda_5738939ec88434c53e1a446c47cf2db6>@@CGXXZ
00000000 t ??B<lambda_5738939ec88434c53e1a446c47cf2db6>@@QBEP6AXXZXZ
00000000 t ??B<lambda_5738939ec88434c53e1a446c47cf2db6>@@QBEP6GXXZXZ
00000000 t ??B<lambda_5738939ec88434c53e1a446c47cf2db6>@@QBEP6IXXZXZ
00000000 t ??R<lambda_5738939ec88434c53e1a446c47cf2db6>@@QBEXXZ
Cast it:
WinApiFunc(static_cast<void(__stdcall *)()>(func));
Or store it into a local variable first:
void (__stdcall *funcp)() = func;
WinApiFunc(funcp);
这篇关于如何指定vc11 lambda调用约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!