ThreadMessages() must be a static method of the c++ class or a global function outside any class. I prefer using CreateThread() because it does not require linking to special multi-threading libraries like _beginthread().
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Most of the parameters to CreateThread are 0 (NULL). The only required parameters are the name of the thread proc and the last one -- pointer to DWORD threadID. I leave all others 0.
The parameter immediately following the thread proc is a parameter you want to pass to the thread -- it can be a pointer to any object or a simple integer. Sometimes I pass the "this" pointer so that the thread will have access to c++ class instance.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
This is the minimum required -- all parameters but two are optional and left 0. On W2K and XP the last parameter can be 0 too, but it comes in useful sometimes.
#include <windows.h>
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
return 0;
}
int main()
{
DWORD dwThreadID;
HANDLE hThread = CreateThread(0, //lpThreadAttributes
0, //dwStackSize
ThreadProc,//lpStartAddress
0, // lpParameter
0, // dwCreationFlags
&dwThreadID);//lpThreadId
return 0;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Just think about it -- its is nothing more than like passing a variable to any other function
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
// typecast lpParameter back to desired c++ class
CIlikerpsChatClientDlg* pDlg = (CIlikerpsChatClientDlg*)lpParameter;
pDlg->DoSomething();
// blabla
return 0;
}
void CIlikerpsChatClientDlg::foo()
{
DWORD dwThreadID;
HANDLE hThread = CreateThread(0, //lpThreadAttributes
0, //dwStackSize
ThreadProc,//lpStartAddress
this, // lpParameter
0, // dwCreationFlags
&dwThreadID);//lpThreadId
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343