Is there any way to specify a class member function as the thread procedure in calls such as beginthreadex() or CreateThread()?
Printable View
Is there any way to specify a class member function as the thread procedure in calls such as beginthreadex() or CreateThread()?
Yes, but they must be static member functions............Quote:
Originally posted by johnnie2
Is there any way to specify a class member function as the thread procedure in calls such as beginthreadex() or CreateThread()?
Code:#include <iostream>
#include <string>
#include <windows.h>
class foobar{
public:
static DWORD WINAPI ThreadProc(LPVOID);
};
DWORD WINAPI foobar::ThreadProc(LPVOID lpv){
std::cout << static_cast<char*>(lpv);
return 0;
}
int main(void){
DWORD dwDummy;
HANDLE hHand;
char str[] = "Hello World";
hHand = CreateThread(0,0,&foobar::ThreadProc,
static_cast<LPVOID>(str),0,&dwDummy);
WaitForSingleObject(hHand,INFINITE);
};
Thanks for the response. I'm guessing there is absolutely no way to accomplish this with non-static member functions?
Right.