I want to use c++ lambda expression as a window procedure in WinApi.
I've seen it on many pages, this one for example.
The code won't compile tho:
WNDPROC x = [](HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT {
return 0;
};
Error I'm getting:
invalid user-defined conversion from 'main()::<lambda(HWND, UINT, WPARAM, LPARAM)>' to 'WNDPROC {aka long int (__attribute__((__stdcall__)) *)(HWND__*, unsigned int, unsigned int, long int)}' [-fpermissive]|
The problem seems to lay in __stdcall convention, but when I'm trying to add it:
WNDPROC x = [](HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -> CALLBACK LRESULT {
return 0;
};
The complier says:
warning: 'stdcall' attribute only applies to function types [-Wattributes]|
So how are people using lambda as wndproc then?
Is it a compiler thing? (Does not work in CodeBlocks standard compiler, nor Visual Studio 2015)