用EnumProcesses()之类应该加什么头文件?

qiuanhong 2002-04-01 08:18:46
用EnumProcesses()之类应该加什么头文件?在MSDN里也没有看到提示呀,但运行却出错:
error C2065: 'EnumProcesses' : undeclared identifier
还有OpenProcess()、EnumProcessModules()等.
...全文
1290 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjp009 2002-04-01
  • 打赏
  • 举报
回复
多看看MSDN吧, 对于API应有尽有。
比如定义:
The EnumProcesses function retrieves the process identifier for each process object in the system.

BOOL EnumProcesses(
DWORD * lpidProcess, // array to receive the process identifiers
DWORD cb, // size of the array
DWORD * cbNeeded // receives the number of bytes returned
);

另外看看See Also啊就知道包含在什么.H中了。
捕鲸叉 2002-04-01
  • 打赏
  • 举报
回复
试试动态加载该dll吧:
LoadLibrary();

//获取函数指针
typedef UINT pFunc ...
...

FreeLibrary()
ahao 2002-04-01
  • 打赏
  • 举报
回复
你的sdk太老了
qiuanhong 2002-04-01
  • 打赏
  • 举报
回复
对了,在Win2000下运行调试
qiuanhong 2002-04-01
  • 打赏
  • 举报
回复
我把代码给大家参考一下(这是一位大哥的),帮我调试一下看看(如何在一个程序中得知另一个指定的程序是否运行?):
#include "psapi.h"

//enum process to find a certain module
void CPtbView::IsAppRun(CString modulename)
{
DWORD buf[4096];
DWORD num;
TCHAR filenamebuf[_MAX_PATH+1];
HMODULE hModule;
DWORD cbReturned;
BOOL bret=EnumProcesses(buf,4095,&num);
bool bfound=false;
CString msg;

if(!bret)
{
AfxMessageBox("Error EnumProcesses");
return;
}

for(int i=0;i<(int)num;i++)
{
HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION¦ PROCESS_VM_READ,false,buf[i]);
if(hProcess ==NULL)
continue;
bret=EnumProcessModules(hProcess ,&hModule, sizeof(hModule), &cbReturned );
if(bret)
{
DWORD dwret=GetModuleFileNameEx(hProcess ,hModule,filenamebuf,_MAX_PATH);
CloseHandle( hProcess ) ;
if(dwret==0)
{
msg.Format("%d",GetLastError());
AfxMessageBox(msg);
break;
}
else
{
TCHAR* pfind=_tcsstr(filenamebuf,modulename);
if(pfind)
{
bfound=true;
break;
}
}
}
}
if(bfound)
AfxMessageBox("Found it");
else
AfxMessageBox("Not found");
}

void CPtbView::OnViewCheckrun()
{
IsAppRun("notepad.exe");
}


qiuanhong 2002-04-01
  • 打赏
  • 举报
回复
啊??不会吧,会出现这种情况,我是真的没有看到哟,要不就不会这样了,我再看看

EnumProcesses
The EnumProcesses function retrieves the process identifier for each process object in the system.

BOOL EnumProcesses(
DWORD * lpidProcess, // array to receive the process identifiers
DWORD cb, // size of the array
DWORD * cbNeeded // receives the number of bytes returned
);

Parameters
lpidProcess
Pointer to an array that receives the list of process identifiers.
cb
Specifies the size, in bytes, of the lpidProcess array.
cbNeeded
Receives the number of bytes returned in the lpidProcess array.
Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
It is a good idea to give EnumProcesses a large array of DWORD values, because it is hard to predict how many processes there will be at the time you call EnumProcesses. To determine how many processes were enumerated by the call to EnumProcesses, divide the resulting value in the cbNeeded parameter by sizeof(DWORD).

To obtain process handles for the processes whose identifiers you have just obtained, call the OpenProcess function.

See Also
Process Status Helper Overview, PSAPI Functions, OpenProcess

没有吧,是什么原因?

对了,加了后(psapi.h、psapi.lib)
又出错:
fatal error C1083: Cannot open include file: 'psapi.h': No such file or directory
Error executing cl.exe.
error0 2002-04-01
  • 打赏
  • 举报
回复
谁说MSDN里没有看最下面


EnumProcesses
The EnumProcesses function retrieves the process identifier for each process object in the system.

BOOL EnumProcesses(
DWORD *lpidProcess, // array of process identifiers
DWORD cb, // size of array
DWORD *cbNeeded // number of bytes returned
);
Parameters
lpidProcess
[out] Pointer to an array that receives the list of process identifiers.
cb
[in] Specifies the size, in bytes, of the lpidProcess array.
cbNeeded
[out] Receives the number of bytes returned in the lpidProcess array.
Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
It is a good idea to give EnumProcesses a large array of DWORD values, because it is hard to predict how many processes there will be at the time you call EnumProcesses. To determine how many processes were enumerated by the call to EnumProcesses, divide the resulting value in the cbNeeded parameter by sizeof(DWORD). There is no indication given when the buffer is too small to store all process identifiers.

To obtain process handles for the processes whose identifiers you have just obtained, call the OpenProcess function.

Requirements
Windows NT/2000/XP: Included in Windows NT 4.0 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Psapi.h.
Library: Use Psapi.lib.

error0 2002-04-01
  • 打赏
  • 举报
回复
psapi.h
ahao 2002-04-01
  • 打赏
  • 举报
回复
psapi.h

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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