//-----------------------------------------------------------------------------
// 程序说明:获取系统中当前所有进程PID、进程名称
//
//-----------------------------------------------------------------------------
#include<Windows.h>
#include<iostream>
#include<TlHelp32.h>
#include<vector>
#include<algorithm>
using namespace std;
//定义结构:进程PID、进程名称
struct ProcessInfo
{
DWORD PID;
string PName;
ProcessInfo(DWORD PID, string PNmae) : PID(PID), PName(PNmae) {}
//排序条件:PID 从小到大降序
bool operator < (const ProcessInfo & rhs) const {
return (PID < rhs.PID) ;
}
};
// WCHAR 转换为 std::string
string WCHAR2String(LPCWSTR pwszSrc)
{
int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL);
if (nLen <= 0)
return std::string("");
char* pszDst = new char[nLen];
if (NULL == pszDst)
return string("");
WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL);
pszDst[nLen - 1] = 0;
std::
【C++】代码实现:获取 Windows 操作系统当前所有进程PID、进程名称
最新推荐文章于 2025-06-12 11:10:23 发布