Enumerating threads in a process
Posted: Thu Dec 20, 2007 6:16 am
Source: http://blogs.msdn.com/oldnewthing/archi ... 37856.aspx
I love PureBasic. 
Can someone confirm if 'Process 0' and 'Thread 0' is not an error?
MSDN wrote:To identify the threads that belong to a specific process, compare its process identifier to the th32OwnerProcessID member of the THREADENTRY32 structure when enumerating the threads.
Code: Select all
Define te.THREADENTRY32
h=CreateToolhelp32Snapshot_(#TH32CS_SNAPTHREAD,0);
If (h<>#INVALID_HANDLE_VALUE)
te\dwSize=SizeOf(te)
If (Thread32First_(h,@te))
Repeat
If (te\dwSize>=OffsetOf(THREADENTRY32\th32OwnerProcessID)+SizeOf(te\th32OwnerProcessID))
Debug "Process "+RSet(Hex(te\th32OwnerProcessID),4,"0")+" Thread "+RSet(Hex(te\th32ThreadID),4,"0")
EndIf
te\dwSize=SizeOf(te);
Until Not (Thread32Next_(h,@te));
EndIf
CloseHandle_(h);
EndIf

Can someone confirm if 'Process 0' and 'Thread 0' is not an error?