Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: html dialog Pin
faroqtam31-Oct-04 10:44
faroqtam31-Oct-04 10:44 
GeneralRe: html dialog Pin
Christian Graus31-Oct-04 12:44
protectorChristian Graus31-Oct-04 12:44 
General_beginthreadex and WaitForSingleObject Pin
Bob Stanneveld31-Oct-04 3:50
Bob Stanneveld31-Oct-04 3:50 
GeneralRe: _beginthreadex and WaitForSingleObject Pin
valikac31-Oct-04 6:41
valikac31-Oct-04 6:41 
GeneralRe: _beginthreadex and WaitForSingleObject Pin
Bob Stanneveld31-Oct-04 6:45
Bob Stanneveld31-Oct-04 6:45 
GeneralRe: _beginthreadex and WaitForSingleObject Pin
valikac31-Oct-04 8:19
valikac31-Oct-04 8:19 
GeneralRe: _beginthreadex and WaitForSingleObject Pin
Michael Dunn31-Oct-04 8:59
sitebuilderMichael Dunn31-Oct-04 8:59 
GeneralRe: _beginthreadex and WaitForSingleObject Pin
Bob Stanneveld31-Oct-04 10:07
Bob Stanneveld31-Oct-04 10:07 
Hello,

I'm certain that I'm passing the handle returned by _beginthreadex to WaitForSingleObject.

I have to say a couple a things about the thread code:
1) It's a class
2) You can post messages to the thread function
3) The thread handle cannot be changed (it's not constant, but there is no statement that modifies the variable)
4) The thread functions returns after posting a TM_EXIT message

Anyhow, here's some code:
I create the thread like this:
<br />
m_hThread  = (HANDLE) _beginthreadex(NULL, 0, CThread::Run, this, 0, &m_nThreadID);<br />
<br />
	// was the thread created succesfully<br />
	if( m_hThread == 0 )<br />
	{<br />
		// error...<br />
	}<br />

The thread is terminated like this:
<br />
PostMessage(TM_EXIT);<br />
<br />
if( bWaitForTermination == TRUE)<br />
{<br />
	switch( ::WaitForSingleObject(m_hThread, INFINITE) )<br />
	{<br />
	case WAIT_FAILED:<br />
		{		<br />
			CStdString szError = "ERROR: Waiting for thread (0x%X, ThreadID: %d) termination failed. Reason:\n";<br />
			INTERNAL_LOCK();<br />
			szError.Format(szError, m_hThread, m_nThreadID);<br />
<br />
			GetLastErrorMessage(szError);<br />
<br />
			this->SetError(szError);<br />
<br />
			return TRC_UNKNOWNERROR;<br />
		}<br />
	case WAIT_TIMEOUT:<br />
		{<br />
			return TRC_WAITTIMEOUT;<br />
		}<br />
	} // switch( ::WaitForSingleObject(m_hThread, dwTimeOut) )<br />
} // if( bWaitForTermination == TRUE )<br />



Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.

GeneralSolved! Pin
Bob Stanneveld31-Oct-04 10:23
Bob Stanneveld31-Oct-04 10:23 
GeneralEval Logical Expression Pin
Mathias S.31-Oct-04 0:58
Mathias S.31-Oct-04 0:58 
GeneralBitBlt not working for printer Pin
Anorexic Tribble31-Oct-04 0:29
Anorexic Tribble31-Oct-04 0:29 
GeneralRe: BitBlt not working for printer Pin
faroqtam31-Oct-04 10:14
faroqtam31-Oct-04 10:14 
GeneralRe: BitBlt not working for printer Pin
Roger Allen1-Nov-04 3:06
Roger Allen1-Nov-04 3:06 
GeneralRe: BitBlt not working for printer Pin
Anorexic Tribble9-Nov-04 4:17
Anorexic Tribble9-Nov-04 4:17 
GeneralRe: BitBlt not working for printer Pin
Roger Allen9-Nov-04 4:25
Roger Allen9-Nov-04 4:25 
GeneralRe: BitBlt not working for printer Pin
Anorexic Tribble9-Nov-04 4:39
Anorexic Tribble9-Nov-04 4:39 
GeneralLinking C and C++ modules Pin
zelbazach30-Oct-04 21:56
zelbazach30-Oct-04 21:56 
GeneralRe: Linking C and C++ modules Pin
Christian Graus31-Oct-04 9:20
protectorChristian Graus31-Oct-04 9:20 
GeneralWindow Style Pin
Leyu30-Oct-04 20:57
Leyu30-Oct-04 20:57 
GeneralRe: Window Style Pin
kriaz31-Oct-04 20:12
kriaz31-Oct-04 20:12 
GeneralRe: Window Style Pin
Leyu3-Nov-04 6:05
Leyu3-Nov-04 6:05 
GeneralBuilding own String class Pin
KernKraft3330-Oct-04 18:53
KernKraft3330-Oct-04 18:53 
GeneralRe: Building own String class Pin
Andrew Peace31-Oct-04 3:18
Andrew Peace31-Oct-04 3:18 
QuestionHow to get the image from a clistctrl? Pin
shibble30-Oct-04 13:00
shibble30-Oct-04 13:00 
AnswerRe: How to get the image from a clistctrl? Pin
Ravi Bhavnani30-Oct-04 15:39
professionalRavi Bhavnani30-Oct-04 15:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.