How do I create a thread routine of a static member function
class Blah
{
static void WINAPI Start();
};
// ..
// ...
// ....
hThread = (HANDLE)_beginthre
class Blah
{
static unsigned int __stdcall Start(void*); // void* should be here, because _beginthreadex requires it.
};
The routine passed to _beginthreadex
must use the __stdcall
calling convention and must return a thread exit code.
Implementation of Blah::Start:
unsigned int __stdcall Blah::Start(void*)
{
// ... some code
return 0; // some exit code. 0 will be OK.
}
Later in your code you could write any of the following:
hThread = (HANDLE)_beginthreadex(NULL, 0, CBlah::Start, NULL, NULL, NULL);
// or
hThread = (HANDLE)_beginthreadex(NULL, 0, &CBlah::Start, NULL, NULL, NULL);
In first case Function-to-pointer conversion
will be applied according to C++ Standard 4.3/1. In second case you'll pass pointer to function implicitly.