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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With