#include Psapi.h#include vectorBOOL TraversalProcess2(OUT std::vectorDWORD vec){vec.clear();try{BYTE *pbt = 0;DWORD dwSize = 0, dw = 0x1000;BOOL b = 0;for (; dw INT_MAX !b; dw *= 2){if ...
#include <Psapi.h>
#include <vector>
BOOL TraversalProcess2(OUT std::vector<DWORD> &vec)
{
vec.clear();
try
{
BYTE *pbt = 0;
DWORD dwSize = 0, dw = 0x1000;
BOOL b = 0;
for (; dw < INT_MAX && !b; dw *= 2)
{
if (pbt)
{
delete pbt;
pbt = 0;
}
pbt = new BYTE[dw];
if (pbt)
{
b = EnumProcesses((DWORD*)pbt, dw, &dwSize);
}
}
if (pbt && b)
{
DWORD *pdw = (DWORD*)pbt;
for (DWORD i = 0; i < dwSize / sizeof(DWORD); ++i)
{
vec.push_back(pdw[i]);
}
delete pbt;
pbt = 0;
}
}
catch (...)
{
OutputDebugStringA(__FUNCTION__);
return 0;
}
return vec.size() > 0;
}
int main()
{
std::vector<DWORD> vec;
std::cout << TraversalProcess2(vec) << endl;
for each (DWORD var in vec)
{
printf("%d\t", var);
printf("\r\n");
}
return 0;
}
沃梦达教程
本文标题为:C++.进程2
基础教程推荐
猜你喜欢
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26
- C++中的atoi 函数简介 2023-01-05
- C利用语言实现数据结构之队列 2022-11-22
- 一文带你了解C++中的字符替换方法 2023-07-20
- C/C++编程中const的使用详解 2023-03-26
- C++详细实现完整图书管理功能 2023-04-04
- C语言 structural body结构体详解用法 2022-12-06
- 详解c# Emit技术 2023-03-25
- 如何C++使用模板特化功能 2023-03-05
- C语言基础全局变量与局部变量教程详解 2022-12-31