Click here to Skip to main content
15,906,106 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Setting minimum and maximum value for a editbox control in mfc Pin
Mark Salsbery5-Dec-06 20:48
Mark Salsbery5-Dec-06 20:48 
Questioncopying string from CString to BYTE*. How ? Pin
Sakthiu5-Dec-06 18:19
Sakthiu5-Dec-06 18:19 
AnswerRe: copying string from CString to BYTE*. How ? Pin
Hamid_RT5-Dec-06 18:29
Hamid_RT5-Dec-06 18:29 
AnswerRe: copying string from CString to BYTE*. How ? Pin
kanduripavan5-Dec-06 18:30
kanduripavan5-Dec-06 18:30 
GeneralRe: copying string from CString to BYTE*. How ? Pin
ThatsAlok5-Dec-06 22:06
ThatsAlok5-Dec-06 22:06 
AnswerRe: copying string from CString to BYTE*. How ? Pin
Mark Salsbery5-Dec-06 20:56
Mark Salsbery5-Dec-06 20:56 
AnswerRe: copying string from CString to BYTE*. How ? Pin
Mark Salsbery5-Dec-06 21:01
Mark Salsbery5-Dec-06 21:01 
QuestionHow to stop a thread from a primary thread Pin
cy163@hotmail.com5-Dec-06 17:51
cy163@hotmail.com5-Dec-06 17:51 
How to stop a thread from a primary thread

In My project, a SDI CFormView application, I start a worker thread to accompolish a lengthy task by clicking a botton 'btnStart' on the form. I want stop the running work in the thread by clicking another button 'btnStop'. I cannot figure out why the following scheme cannot stop the thread.

handler for 'btnStop'
<br />
	m_CEvent_StopThread.SetEvent();<br />
         WaitForSingleObject(pMyTheadProc->m_hThread, INFINITE);<br />
	delete pMyTheadProc;<br />
<br />



in the thread, an instance of class MyClass is running. The thread is started by the following lines (handler for btnStart)

<br />
	MyClass * objMyClass = new MyClass(this);	<br />
	<br />
	UpdateData(true);<br />
<br />
	objMyClass->m_EditBox10Weight1Itemset = m_EditBox10Weight1Itemset;<br />
	objMyClass->m_EditBox11Weight2Itemset = m_EditBox11Weight2Itemset;<br />
	objMyClass->m_EditBox12Weight3Itemset = m_EditBox12Weight3Itemset;<br />
	objMyClass->m_EditBox13SimiThreshold = m_EditBox13SimiThreshold;<br />
	objMyClass->m_EditBox14HRmin = m_EditBox14HRmin;<br />
	objMyClass->m_EditBox15Excel = m_EditBox15Excel;<br />
<br />
	objMyClass->m_Radio = m_Radio;<br />
	objMyClass->m_Radio3 = m_Radio3;<br />
	<br />
	objMyClass->m_CheckVerb = m_CheckVerb;<br />
	objMyClass->m_CheckNoun = m_CheckNoun;<br />
	objMyClass->m_CheckAbbr = m_CheckAbbr;<br />
	objMyClass->m_CheckIdiom = m_CheckIdiom;<br />
	objMyClass->m_CheckVg = m_CheckVg;<br />
	objMyClass->m_CheckNg = m_CheckNg;<br />
<br />
	objMyClass->m_EditBox6 = m_EditBox6;<br />
	<br />
	objMyClass->m_DebugMode = m_DebugMode;<br />
<br />
	test_globalvariable = FALSE;<br />
	pMyTheadProc = AfxBeginThread(MyThreadProc, objMyClass);<br />
	pMyTheadProc->m_bAutoDelete=FALSE;<br />
<br />

The worker thread is coded as follows

<br />
UINT MyThreadProc(LPVOID pParam)<br />
{<br />
	MyClass* pObject = (MyClass*)pParam;<br />
    if (pObject == NULL) <br />
	{<br />
		return -1;    <br />
	}<br />
	else<br />
	{<br />
		<br />
		<br />
		pObject->SubFunc();<br />
		<br />
		return 0;   <br />
	}<br />
	<br />
}<br />
<br />
<br />



In the SubFunc(), the following code is used to response the stop-thread signal generated when clicking on btnStop.
<br />
		if(WAIT_OBJECT_0==::WaitForSingleObject(m_TerminateThread.m_hObject,0))<br />
		{<br />
			AfxMessageBox("Exit Thread\n");<br />
			::AfxEndThread( 0, FALSE ); <br />
<br />
		}<br />
<br />
<br />


In addition, I wonder if the dynamically allocated mem in the thread can be automatically deallocated in the above scheme. Or I have to use additional code to release the allocated mem myself.
AnswerRe: How to stop a thread from a primary thread Pin
Hamid_RT5-Dec-06 18:06
Hamid_RT5-Dec-06 18:06 
GeneralRe: How to stop a thread from a primary thread Pin
Stephen Hewitt5-Dec-06 20:14
Stephen Hewitt5-Dec-06 20:14 
GeneralRe: How to stop a thread from a primary thread Pin
cy163@hotmail.com5-Dec-06 23:52
cy163@hotmail.com5-Dec-06 23:52 
AnswerRe: How to stop a thread from a primary thread Pin
Stephen Hewitt5-Dec-06 20:18
Stephen Hewitt5-Dec-06 20:18 
AnswerRe: How to stop a thread from a primary thread Pin
Roger Stoltz5-Dec-06 20:34
Roger Stoltz5-Dec-06 20:34 
Questionshell programming Pin
sanwalz5-Dec-06 17:46
sanwalz5-Dec-06 17:46 
AnswerRe: shell programming Pin
Joe Woodbury5-Dec-06 17:51
professionalJoe Woodbury5-Dec-06 17:51 
QuestionHow to LPCTSTR Convert to char * Pin
rxgmoral5-Dec-06 15:23
rxgmoral5-Dec-06 15:23 
QuestionRe: How to LPCTSTR Convert to char * Pin
David Crow5-Dec-06 16:29
David Crow5-Dec-06 16:29 
AnswerRe: How to LPCTSTR Convert to char * Pin
ThatsAlok5-Dec-06 22:07
ThatsAlok5-Dec-06 22:07 
AnswerRe: How to LPCTSTR Convert to char * Pin
Stephen Hewitt5-Dec-06 17:06
Stephen Hewitt5-Dec-06 17:06 
GeneralRe: How to LPCTSTR Convert to char * Pin
rxgmoral5-Dec-06 17:55
rxgmoral5-Dec-06 17:55 
AnswerRe: How to LPCTSTR Convert to char * Pin
Hamid_RT5-Dec-06 17:50
Hamid_RT5-Dec-06 17:50 
QuestionOnCancel problem Pin
celllllllll5-Dec-06 13:45
celllllllll5-Dec-06 13:45 
AnswerRe: OnCancel problem Pin
Leah_Garrett5-Dec-06 14:01
Leah_Garrett5-Dec-06 14:01 
GeneralRe: OnCancel problem Pin
celllllllll5-Dec-06 14:10
celllllllll5-Dec-06 14:10 
GeneralRe: OnCancel problem Pin
Leah_Garrett5-Dec-06 14:13
Leah_Garrett5-Dec-06 14:13 

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.