Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to specify vc11 lambda calling convention

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
like image 861
andrew young Avatar asked Jan 05 '13 06:01

andrew young


1 Answers

Cast it:

WinApiFunc(static_cast<void(__stdcall *)()>(func));

Or store it into a local variable first:

void (__stdcall *funcp)() = func;
WinApiFunc(funcp);
like image 118
ildjarn Avatar answered Oct 01 '22 21:10

ildjarn