关于获取进程名

qq_27691569 2015-09-05 12:19:16
#include<tlhelp32.h>
#include"windows.h"
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);
HANDLE hp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
bool find = Process32First(hp,&pe32);
while (find)
{
if (lstrcmp(pe32.szExeFile,L"QQ.exe")==0)
{
printf("%d",pe32.th32ProcessID);
break;
}
find = Process32Next(hp,&pe32);
}


头文件都包含了,为什么说不行呢
...全文
92 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
paschen 版主 2015-09-06
  • 打赏
  • 举报
回复
你代码没问题啊,你要把他写在main函数或者其他函数里啊,你写在全局区什么意思
赵4老师 2015-09-06
  • 打赏
  • 举报
回复
PROCESSENTRY32 Describes an entry from a list that enumerates the processes residing in the system address space when a snapshot was taken. typedef struct tagPROCESSENTRY32 { DWORD dwSize; DWORD cntUsage; DWORD th32ProcessID; DWORD th32DefaultHeapID; DWORD th32ModuleID; DWORD cntThreads; DWORD th32ParentProcessID; LONG pcPriClassBase; DWORD dwFlags; char szExeFile[MAX_PATH]; } PROCESSENTRY32; typedef PROCESSENTRY32 * PPROCESSENTRY32; typedef PROCESSENTRY32 * LPPROCESSENTRY32; Members dwSize Specifies the length, in bytes, of the structure. Before calling the Process32First function, set this member to sizeof(PROCESSENTRY32). If you do not initialize dwSize, Process32First will fail. cntUsage Number of references to the process. A process exists as long as its usage count is nonzero. As soon as its usage count becomes zero, a process terminates. th32ProcessID Identifier of the process. The contents of this member can be used by Win32 API elements. th32DefaultHeapID Identifier of the default heap for the process. The contents of this member has meaning only to the tool help functions. It is not a handle, nor is it usable by Win32 API elements. th32ModuleID Module identifier of the process. The contents of this member has meaning only to the tool help functions. It is not a handle, nor is it usable by Win32 API elements. cntThreads Number of execution threads started by the process. th32ParentProcessID Identifier of the process that created the process being examined. The contents of this member can be used by Win32 API elements. pcPriClassBase Base priority of any threads created by this process. dwFlags Reserved; do not use. szExeFile Path and filename of the executable file for the process. QuickInfo Windows NT: Requires version 5.0 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in tlhelp32.h. See Also Tool Help Library Overview, Tool Help Structures
zeloas 2015-09-05
  • 打赏
  • 举报
回复
没搞过windows编程, 64位的机器上编32位的程序吧,可以看看头文件,有宏是表示的32位的,但是64位编译是未定义的

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧