HRESULT StatisticScreen::StartScreen();
DWORD StatisticScreen::PrintingThread(void);
HRESULT StatisticScreen::StartScreen()
{
// ?????????????? Is this legal ????????????????
// Start PrintingThread(void) on another thread
DWORD dwThreadID1;
HANDLE Handle1 = CreateThread (NULL, 0, PrintingThread, NULL, 0, &dwThreadID1);
return S_OK;
}
Running a member method on a worker thread...
Is it possible to launch a member method on a worker thread from another member method of the same class?
Say I have the following two methods that belong to the StatisticScreen class.
If this is not the correct method, is there anyway to achieve this?
Please don't flame me for not trying it out first, I'm just trying to save myself time and effort!
Kind regards,
Mark Coleman
The classical solution is to use the LPVOID parameter to pass a pointer to this to a static method:
When you create a new thread, it knows to which instance it belongs; he static function is then able to call a member function of this instance.
HTH,
class Thread{ static LRESULT static_threadfunc(LPVOID param); LRESULT threadfunc(); DWORD mThreadId; HANDLE mHThread;public: Thread();};Thread::Thread(){ mHThread = CreateThread(NULL, 0, static_threadfunc, (LPVOID)this, 0, &mThreadId);}LRESULT Thread::static_threadfunc(LPVOID param){ Thread *thread = (Thread*)param; return thread->threadfunc();}LRESULT Thread::threadfunc(){ // ...}
When you create a new thread, it knows to which instance it belongs; he static function is then able to call a member function of this instance.
HTH,
Quote:Original post by mrmrcoleman
It isn't in the DirectX forum.
It probably was before he moved it :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement