C++ 如何使用常规Windows C/C++;原料药
有没有办法使用标准的Windows C/C++API查询特定进程当前运行的线程数 我已经浏览了MSDN文档,但唯一接近的是C++ 如何使用常规Windows C/C++;原料药,c++,c,winapi,C++,C,Winapi,有没有办法使用标准的Windows C/C++API查询特定进程当前运行的线程数 我已经浏览了MSDN文档,但唯一接近的是 BOOL WINAPI GetProcessHandleCount( __in HANDLE hProcess, __inout PDWORD pdwHandleCount ); 它查询给定进程当前使用的系统句柄数,其中包括线程句柄,但不限于线程句柄 如有任何见解,将不胜感激 提前谢谢 Bjoern参见此示例:这里是一些基于代码示例的示例代码,可以在接受
BOOL WINAPI GetProcessHandleCount(
__in HANDLE hProcess,
__inout PDWORD pdwHandleCount
);
它查询给定进程当前使用的系统句柄数,其中包括线程句柄,但不限于线程句柄
如有任何见解,将不胜感激
提前谢谢
Bjoern参见此示例:这里是一些基于代码示例的示例代码,可以在接受答案的注释部分中的链接下找到:
#if defined(_WIN32)
#include <windows.h>
#include <tlhelp32.h>
/**
Returns the thread copunt of the current process or -1 in case of failure.
*/
int GetCurrentThreadCount()
{
// first determine the id of the current process
DWORD const id = GetCurrentProcessId();
// then get a process list snapshot.
HANDLE const snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPALL, 0 );
// initialize the process entry structure.
PROCESSENTRY32 entry = { 0 };
entry.dwSize = sizeof( entry );
// get the first process info.
BOOL ret = true;
ret = Process32First( snapshot, &entry );
while( ret && entry.th32ProcessID != id ) {
ret = Process32Next( snapshot, &entry );
}
CloseHandle( snapshot );
return ret
? entry.cntThreads
: -1;
}
#endif // _WIN32
#如果已定义(_WIN32)
#包括
#包括
/**
返回当前进程的线程计数,如果失败,返回-1。
*/
int GetCurrentThreadCount()
{
//首先确定当前进程的id
DWORD const id=GetCurrentProcessId();
//然后获取进程列表快照。
HANDLE const snapshot=CreateToolhelp32Snapshot(TH32CS\u SNAPALL,0);
//初始化进程条目结构。
PROCESSENTRY32条目={0};
entry.dwSize=sizeof(条目);
//获取第一个进程信息。
BOOL-ret=真;
ret=Process32First(快照和条目);
while(ret&&entry.th32ProcessID!=id){
ret=Process32Next(快照和条目);
}
CloseHandle(快照);
回程网
?entry.cnt线程
: -1;
}
#endif/\u WIN32
谢谢你的提示,它给了我正确的方向。事实上,这个样本更符合我的需要:很高兴能提供帮助,很高兴你也能给出答案。