static void test_thread(DWORD curr_pid, DWORD sub_pcs_pid) { HANDLE hSnapshot; THREADENTRY32 te; MODULEENTRY32 me; int num = 0; unsigned curr_found = 0; unsigned sub_found = 0; hSnapshot = pCreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); ok(hSnapshot != NULL, "Cannot create snapshot\n"); /* check that this current process is enumerated */ te.dwSize = sizeof(te); if (pThread32First( hSnapshot, &te )) { do { if (te.th32OwnerProcessID == curr_pid) curr_found++; if (te.th32OwnerProcessID == sub_pcs_pid) sub_found++; if (winetest_debug > 1) trace("PID=%x TID=%x %d\n", te.th32OwnerProcessID, te.th32ThreadID, te.tpBasePri); num++; } while (pThread32Next( hSnapshot, &te )); } ok(curr_found == 1, "couldn't find self in thread list\n"); ok(sub_found == 2, "couldn't find sub-process thread's in thread list\n"); /* check that first really resets enumeration */ curr_found = 0; sub_found = 0; if (pThread32First( hSnapshot, &te )) { do { if (te.th32OwnerProcessID == curr_pid) curr_found++; if (te.th32OwnerProcessID == sub_pcs_pid) sub_found++; if (winetest_debug > 1) trace("PID=%x TID=%x %d\n", te.th32OwnerProcessID, te.th32ThreadID, te.tpBasePri); num--; } while (pThread32Next( hSnapshot, &te )); } ok(curr_found == 1, "couldn't find self in thread list\n"); ok(sub_found == 2, "couldn't find sub-process thread's in thread list\n"); me.dwSize = sizeof(me); ok(!pModule32First( hSnapshot, &me ), "shouldn't return a module\n"); CloseHandle(hSnapshot); ok(!pThread32First( hSnapshot, &te ), "shouldn't return a thread\n"); }
static int count_threads(void) { THREADENTRY32 te; int threads; HANDLE h; h = pCreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); te.dwSize = sizeof(te); if (h == INVALID_HANDLE_VALUE) return -1; pThread32First(h, &te); if (te.th32OwnerProcessID == GetCurrentProcessId()) threads = 1; else threads = 0; while (pThread32Next(h, &te)) if (te.th32OwnerProcessID == GetCurrentProcessId()) ++threads; CloseHandle(h); return threads; }