CreateThread to function in class
Posted on 2004-10-04
I am building a class which will look something like this: (simplified, just to get the idea)
When start() is called, it creates a new thread which gets looped around in init();
The first code i used for start() was:
hC = CreateThread(0, 0, (LP_THREAD_START_ROUTINE) init, 0, 0, &tC);
This produced the error:
error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'LPTHREAD_START_ROUTINE'
So i changed the code to:
hC = CreateThread(0, 0, (void*)(void) init, 0, 0, &tC);
This appeared to work at first, but the code in init() never got called, and when i tried to call CloseHandle() on hC, it produced an exception saying invalid handle. So although it looked like it worked, it clearly did not work.
I would like to know how to achieve this
>> when start() is called, it creates a new thread which gets looped around in init();
any help would be appreciated,