When I try to compile the following on MinGW 4.6.2
EnumChildWindows(hwnd, [](HWND, LPARAM) -> BOOL { return TRUE; }, 0);
I get
error: cannot convert '<lambda(HWND, LPARAM)>'
to 'ENUMWINDOWSPROC {aka int (*)(HWND__*,long int)}'
for argument '2' to 'BOOL EnumChildWindows(HWND, ENUMWINDOWSPROC, LPARAM)'
Am I declaring the lambda incorrectly, or is this simply not going to work? The MS definition of the callback is
BOOL CALLBACK EnumChildProc(
__in HWND hwnd,
__in LPARAM lParam
);
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633493%28v=vs.85%29.aspx
Is the calling convention causing the issue?
BOOL CALLBACK EnumChildProc(...)
That's the problem, the CALLBACK macro applies the __stdcall attribute to the function to change the calling convention from the default setting. Which is __cdecl in most programs. You cannot control the calling convention for your lambda, other than by changing the global setting (/Gz compile option). That can have a lot more side-effects than you'd care about, give up on this lamda.
Not a problem in 64-bit code btw.
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