std::deque<DWORD> dqThreads; HANDLE hThreadSnap = NULL; BOOL bRet = FALSE; THREAD_INFORMATION_EX tie; DWORD dwThisThread = ::GetCurrentThreadId(); // used for not killing ourself // Take a snapshot of all threads currently in the system. DWORD dwProcessID=GetCurrentProcessId(); hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID); if (hThreadSnap == INVALID_HANDLE_VALUE) return false; // Fill in the size of the structure before using it. tie.te32.dwSize = sizeof(THREADENTRY32); // Walk the thread snapshot to find all threads of the process. // If the thread belongs to the process, add its information // to the display list. if (Thread32First(hThreadSnap, &tie.te32)) { do { if (tie.te32.th32OwnerProcessID == dwProcessID) { dqThreads.push_back(tie.te32.th32ThreadID); ZeroMemory(&tie, sizeof(THREAD_INFORMATION_EX)); tie.te32.dwSize = sizeof(THREADENTRY32); } } while (Thread32Next(hThreadSnap, &tie.te32)); bRet = TRUE; } //else // return false; // could not walk the list of threads CloseHandle (hThreadSnap);
HANDLE hThreadSnap = NULL;
BOOL bRet = FALSE;
THREAD_INFORMATION_EX tie;
DWORD dwThisThread = ::GetCurrentThreadId(); // used for not killing ourself // Take a snapshot of all threads currently in the system.
DWORD dwProcessID=GetCurrentProcessId();
hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID);
if (hThreadSnap == INVALID_HANDLE_VALUE)
return false;
// Fill in the size of the structure before using it.
tie.te32.dwSize = sizeof(THREADENTRY32);
// Walk the thread snapshot to find all threads of the process.
// If the thread belongs to the process, add its information
// to the display list.
if (Thread32First(hThreadSnap, &tie.te32))
{
do
{
if (tie.te32.th32OwnerProcessID == dwProcessID)
{
dqThreads.push_back(tie.te32.th32ThreadID);
ZeroMemory(&tie, sizeof(THREAD_INFORMATION_EX));
tie.te32.dwSize = sizeof(THREADENTRY32);
}
}
while (Thread32Next(hThreadSnap, &tie.te32));
bRet = TRUE;
}
//else
// return false; // could not walk the list of threads
CloseHandle (hThreadSnap);