📄 subject_66562.htm
字号:
<p>
序号:66562 发表者:李强-01 发表日期:2003-12-25 11:28:25
<br>主题:关于线程的问题
<br>内容:我这里有一个线程的程序:<BR><BR>void CSmsclientDlg::OnButton6() <BR>{<BR> UINT ret;<BR><BR> ....<BR><BR> AfxBeginTread(SendSmsProc, this, THREAD_PRIORITY_NORMAL);<BR><BR> ....<BR>}<BR><BR>UINT SendSmsProc(LPVOID pParam)<BR>{<BR> ....<BR><BR> if(....)<BR> return 0;<BR> else<BR> return 1;<BR>}<BR><BR>请问我如何将SendSmsProc中返回的结果也就是return的0或1赋值给ret.
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:BigJames 回复日期:2003-12-25 13:02:48
<br>内容:Retrieving the Exit Code of a Thread<BR>To get the exit code of either the worker or the user-interface thread, call the GetExitCodeThread function. For information about this function, see the Platform SDK. This function takes the handle to the thread (stored in the m_hThread data member of CWinThread objects) and the address of a DWORD.<BR><BR>If the thread is still active, GetExitCodeThread will place STILL_ACTIVE in the supplied DWORD address; otherwise, the exit code is placed in this address.<BR><BR>Retrieving the exit code of CWinThread objects takes an extra step. By default, when a CWinThread thread terminates, the thread object is deleted. This means you cannot access the m_hThread data member because the CWinThread object no longer exists. To avoid this situation, do one of the following two things: <BR><BR>Set the m_bAutoDelete data member to FALSE. This allows the CWinThread object to survive after the thread has been terminated. You can then access the m_hThread data member after the thread has been terminated. If you use this technique, however, you are responsible for destroying the CWinThread object as the framework will not automatically delete it for you. This is the preferred method. <BR>-or- <BR><BR>Store the thread's handle separately. After the thread is created, copy its m_hThread data member (using ::DuplicateHandle) to another variable and access it through that variable. This way the object is deleted automatically upon termination and you can still find out why the thread terminated. Be careful that the thread does not terminate before you can duplicate the handle. The safest way to do this is to pass CREATE_SUSPENDED to AfxBeginThread, store the handle, and then resume the thread by calling ResumeThread. <BR>Either method allows you to determine why a CWinThread object terminated. <BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:李强-01 回复日期:2003-12-25 23:13:58
<br>内容:哈哈,我有研究出来了,其实增加一个全局变量就行了.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -