void ListProcessThreads(DWORD dwOwnerPID) { HANDLE hThreadSnap = INVALID_HANDLE_VALUE; THREADENTRY32 te32; hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); if (hThreadSnap == INVALID_HANDLE_VALUE) return; te32.dwSize = sizeof(THREADENTRY32); if (!Thread32First(hThreadSnap, &te32)) { CloseHandle(hThreadSnap); return; } DWORD result = 0; do { if (te32.th32OwnerProcessID == dwOwnerPID) { printf("\n THREAD ID = 0x%08X", te32.th32ThreadID); HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID); PTEB pTeb = GetTeb(hThread); printf("\n TEB = %p\n", pTeb); CloseHandle(hThread); } } while (Thread32Next(hThreadSnap, &te32)); printf("\n"); CloseHandle(hThreadSnap); }
/* * @implemented */ DWORD WINAPI GetCurrentProcessId(VOID) { return HandleToUlong(GetTeb()->ClientId.UniqueProcess); }