0

Instead of

CreateThread(NULL, NULL, function, NULL, NULL, NULL);

I was interested in trying

CreateThread(NULL, NULL, [](LPTHREAD_START_ROUTINE){ int x = 0; return x;}, NULL, NULL, NULL);

I get ERROR: No suitable conversion function from lambda []int (LPTHREAD_START_ROUTINE)->int to LPTHREAD_START_ROUTINE exists.

2c2c
  • 4,694
  • 7
  • 22
  • 33

1 Answers1

2

The signature on your lambda function is incorrect. It needs to accept void* and return DWORD. Try the following

LPTHREAD_START_ROUTINE pStart = [](void* pValue) -> DWORD { int x = 0; return x; };
::CreateThread(NULL, NULL, pStart, NULL, NULL, NULL);

Note: I believe this will only work on Visual Studio 2012 and higher. I do not believe lambda to function pointer conversions were implemented before then

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454