Enumerating Threads

The toolhelp functions can be used to list all the threads running on a device. The code in Listing 5.12 takes a snapshot of all threads by calling CreateToolhelp32Snapshot and passing the TH32CS_SNAPTHREAD constant. The second parameter is a process identifier, and 0 specifies that threads for all processes should be enumerated. The functions Thread32First and Thread32Next are used to enumerate the threads in the snapshot, and data on each thread is placed in a THREADENTRY32 structure. As usual, CloseToolhelp32Snapshot should be called to close the snapshot.

Listing 5.12. Lists running threads
 void Listing5_12() { HANDLE hThreadSnap; THREADENTRY32 th32; hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); if (hThreadSnap ...

Get Windows® CE 3.0 Application Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.