Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A number of useful API functions of this type are under the (of course!) <a href="http://msdn.microsoft.com/en-us/library/ms686832%28VS.85%29.aspx" rel="nofollow noreferrer">Tool Help</a> suite. The <a href="http://msdn.microsoft.com/en-us/library/ms682489%28VS.85%29.aspx" rel="nofollow noreferrer"><code>CreateToolhelp32Snapshot()</code></a> API will take a snapshot of the running threads for a specified process. </p> <pre><code>// Take a snapshot of all running threads hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); if( hThreadSnap == INVALID_HANDLE_VALUE ) return( FALSE ); </code></pre> <p>Full example code <a href="http://msdn.microsoft.com/en-us/library/ms686852%28VS.85%29.aspx" rel="nofollow noreferrer">here.</a></p> <p>The struct returned does not differentiate the primary thread from the others. I do not know a mechanism to do so; while some versions of the C runtime will all ExitProcess() at the end of the primary thread, in all recent versions the process continues to run until the last thread exits.</p> <p>Interjay's recommendation to use GetThreadTimes may be the best bet. If you can <a href="http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx" rel="nofollow noreferrer"><code>CreateProcess()</code></a> the target process, the hThread member of the <a href="http://msdn.microsoft.com/en-us/library/ms684873%28VS.85%29.aspx" rel="nofollow noreferrer"><code>PROCESS_INFORMATION</code></a> block contains the tid for the primary thread. Welcome any ideas from others. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload