Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I enter parameters into the AfxBeginThread-call ?

Status
Not open for further replies.

tcm1998

Programmer
Jul 17, 2001
1
NL
How can I use parameters in the AfxBeginThread-call used to start a CWintread derived class. I don't care if those parameter end up in the constructor or even in a derived 'operator new' function.

CThread : public CWinThread;

AfxBeginThread (RUNTIME_CLASS(CThread),Priority);

This calls both the new operator of my class as well as the constructor without any parameters.

Now I need to give some parameters to initialise my class.

CThread::CThread (HWND p_hPostWindow); // for example

or

void CThread::eek:perator new (size_t p_nSize, HWND p_hPostWindow);

Hope someone can help me ...
 
Try this way
AfxBeginThread((AFX_THREADPROC) <class/function name>, (LPVOID) this);

Second parameter is the current class itself, you can use it to pass other parameters too...

 

Don't forget this is a void pointer so you will need to type cast what ever paramater you pass. For example if you pass &quot;this&quot; from a CWnd do the following:


main{

myThread = AfxBeginThread(MyThread,this);

}


UINT MyThread(LPVOID pParam)
{
CWnd* pCWnd = (CWnd*)pParam;


return 0;

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top