Retrieving the exit code of CWinThread objects
Retrieving the Exit Code of a Thread
To get the exit code of either the worker or the user-interface thread, call the GetExitCodeThread function.
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:
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 because the framework will not automatically delete it for you. This is the preferred method.
Question: If the CWinThread was allocated by new I will call the destructor with delete. But how will I call the destructor if:
(1) CWinThread is allocated as a function variable?
(2) CWinThread is a global variable?