#include <TlHelp32.h> int get_thread_amount() { int i = 0; char Buff[9]; PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); int processid = GetCurrentProcessId(); HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE) { printf("CreateToolhelp32Snapshot() failed. error code:%d.\n", GetLastError()); return 0; } BOOL bMore = ::Process32First(hProcessSnap, &pe32); HANDLE hProcess; while (bMore) { if (pe32.th32ProcessID == processid) { return pe32.cntThreads; } bMore = Process32Next(hProcessSnap, &pe32); i++; } return 0; }
windows 下获取当前进程的线程数量
时间: 2024-10-13 01:35:30