What I usually do in this situation is as Richard mentioned. I use a static thread interface method as the thread procedure. A make another non-static method that creates the thread and passes this as its argument. Then it calls another non-static method that does the actual work. Here is a brief example with just the relevant bits :
class CMyObject
{
int ThreadMethod();
static int ThreadProcedure( pvoid * p )
{
CMyObject * pthis = (CMyObject *)p;
return pthis->ThreadMethod();
}
void StartWorkThread()
{
BeginThread( ThreadProcedure, this ); }
};
Sometimes the thread method needs some additional arguments so I make a little class or structure to hold the arguments along with the this pointer since you can pass only one thing to the thread procedure. Here's an example of that :
typedef struct
{
int arg1;
double arg2;
CSomethingElse * pse;
CMyObject * pthis;
} ThreadData;
int CMyObject::ThreadMethod( ThreadData *ptd )
{
ThreadData td;
memcpy( &td, ptd, sizeof( ThreadData ) );
}
void CMyObject::StartWorkThread()
{
ThreadData td;
td.arg1 = 42;
td.arg2 = 3.1416;
td.pse = nullptr;
td.pthis = this;
BeginThread( ThreadProcedure, &td ); }
int CMyObject::ThreadProcedure( pvoid *p )
{
ThreadData * ptd = (ThreadData *)p;
return ptd->pthis->ThreadMethod( ptd );
}
You can pass the thread data to the ThreadMethod also. The copy is made because the thread data will be invalid when StartWorkThread returns.