Is it possible to pass a class function to CreateThread in Windows? CreateThread works great with a function that isn''t a member of a class sent to it, but as soon as I try sending a class function it complains.
bool CThing::Start(int intPort)
{
HANDLE handle = NULL;
handle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Listen, 0, 0, 0);
if (!handle)
{
return false;
}
return true;
}
void CThing::Listen(LPVOID lpvParam)
{
...
}
the above fails, with the error:
error C2440: ''type cast'' : cannot convert from ''overloaded-function'' to ''LPTHREAD_START_ROUTINE''
Doesn''t matter if I type cast it to ''LPTHREAD_START_ROUTINE'' or not, it complains. Whereas if I make the Listen function not part of the class it works great:
void Listen(LPVOID lpvParam)
{
...
}
bool CThing::Start(int intPort)
{
HANDLE handle = NULL;
handle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Listen, 0, 0, 0);
if (!handle)
{
return false;
}
return true;
}
Is there any way to get a class function working with CreateThread? (This is VC7.0 btw)