
Common C++ Multithreading class
I'm trying to create a Common Worker thread class, where I can derive from
it, creating my own function that implements the functionality and hey
presto. Perfect world??? But I'm having real trouble due the function
needing to be static. Here's what I've got so far
// CThread allows the user to override the RunThread() function and insert
the processing
class CThread {
public:
virtual DWORD RunThread();
inline static DWORD WINAPI ThreadProc(LPVOID parameter) {
return ((CThread*)parameter)->RunThread();
}
Quote:
};
// CWorkerThread - Implements the Worker Thread creation and control, used
in conjunction
// with an instance of CThread.
class CWorkerThread : public CObject {
public:
HANDLE hThread;
DWORD dwThreadID;
CThread *pThread;
inline CWorkerThread() {
hThread = ::CreateThread(NULL, 0, CThread::ThreadProc, &pThread, 0,
&dwThreadID);
}
Quote:
};
Then... if i did
// TESTING
class CMyThread : public CThread {
DWORD RunThread();
Quote:
};
class CListener : public CWorkerThread {
public:
Quote:
};
DWORD CMyThread::RunThread()
{
return (0);
Quote:
}
and create an instance of CMyThread everything would work------NOT!. My
inexperience is showing but I would really appreciate an answer.
MarkM