I'm using CodeBlocks with mingw, gcc version 5.1.0.
I have a code that looks like this:
unsigned int __stdcall doWork(void* data)
{
if (napolniDrevo())
{
return 0;
}
else
{
return 1;
}
}
Then somewhere else in other function:
HANDLE m_hThread = (HANDLE)_beginthreadex(0, 0, &doWork, 0, 0, 0);
The code works fine. Today I learned about lambda expressions, and wanted to try it.
So I deleted function doWork()
and tried to do the same with:
auto lambda = [](void* data) WINAPI -> unsigned int {if (napolniDrevo()) return 0; else return 1;};
HANDLE m_hThread = (HANDLE)_beginthreadex(0, 0, lambda, 0, 0, 0);
But I get error:
||=== Build: Release in CtrlData (compiler: GNU GCC Compiler) ===|
||warning: ./wx_pch.h.gch/Debug_wx_pch_h_gch: not used because `__WXDEBUG__' not defined [-Winvalid-pch]|
C:\Users\M0097932\Desktop\CtrlData\CtrlDataMain.cpp||In member function 'void DataGetterFrame::OnButton2Click(wxCommandEvent&)':|
C:\Users\M0097932\Desktop\CtrlData\CtrlDataMain.cpp|551|error: invalid user-defined conversion from 'DataGetterFrame::OnButton2Click(wxCommandEvent&)::<lambda(void*)>' to 'unsigned int (__attribute__((__stdcall__)) *)(void*)' [-fpermissive]|
C:\Users\M0097932\Desktop\CtrlData\CtrlDataMain.cpp|550|note: candidate is: DataGetterFrame::OnButton2Click(wxCommandEvent&)::<lambda(void*)>::operator unsigned int (*)(void*)() const <near match>|
C:\Users\M0097932\Desktop\CtrlData\CtrlDataMain.cpp|550|note: no known conversion from 'unsigned int (*)(void*)' to 'unsigned int (__attribute__((__stdcall__)) *)(void*)'|
C:\Program Files (x86)\CodeBlocks\MinGW\include\process.h|100|note: initializing argument 3 of 'long unsigned int _beginthreadex(void*, unsigned int, unsigned int (__attribute__((__stdcall__)) *)(void*), void*, unsigned int, unsigned int*)'|
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
I guess I have to put __stdcall somewhere. I didn't find anything by googling yet.