PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to create a worker thread to use with GapiDraw?

joke_Playwiz · 05 Apr 2004, 06:24 UTC
I want to use communication module and show graphic surface in the same time(like a using more one thread).
Thank you.
You can create the worker thread in InitInstance, like:

Code:

// Note: If your compiler cannot find "_beginthreadex" you are probably using the single-threaded
// version of the run-time library. Change this in your project settings to "Multithreaded".
// (Hint: "Project" -> "Settings" -> "C/C++" -> "Code Generation" -> "Use run-time library")
#ifdef _WIN32_WCE
DWORD dwThreadID;
m_hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) CMyClass::StaticFunction, (void*)this, CREATE_SUSPENDED, &dwThreadID);
#else
unsigned int nThreadID;
m_hThread = (void*) ::_beginthreadex(NULL, 0, &CMyClass::StaticFunction, (void*)this, CREATE_SUSPENDED, &nThreadID);
#endif
if (NULL == m_hThread)
{
SetError(TEXT("Could not create primary thread."), ::GetLastError());
CloseDisplay();
DestroyMainWindow();
return E_FAIL;
}

// Start thread
::ResumeThread(m_hThread);


Please note that you need to include <process.h> if your application runs on stationary PCs. In the example above it is assumed that you have a class CMyClass with a static member function called "StaticFunction". Callbacks can be used since a pointer to the CMyApplication class is sent as a parameter ("this").
Do I have to create a CMyClass object like a CMyApplication?
What're necessary things in CMyClass::StaticFunction()?


I believe you should post questions related to how you write multithreaded programs in the "General Developer" forum. I can help you out with how to integrate a multithreaded program with GapiDraw, but not with how you should write the code itself.