如下:
PROCESSENTRY32 processListStr;
HANDLE hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hSnapShot==NULL)
AfxMessageBox("createtool help32 snapshot failed");
// ZeroMemory(&processListStr,sizeof(PROCESSENTRY32));
BOOL bReturnValue=Process32First(hSnapShot,&processListStr);
if(!bReturnValue)
AfxMessageBox("process32 first fun failed");
这样的代码在debug下可以通过,但是在release下却总是返回0,不知为什么呢?
我将processListStr清零之后,debug和release版本Process32First均出错,返回0.
是哪里出错了呢?
我用的是winxp.

解决方案 »

  1.   

    用GetLastError()得到的结果为24.
      

  2.   

    参照下面的代码 PROCESSENTRY32 pe;
    pe.dwSize=sizeof(PROCESSENTRY32);
    HANDLE hProcess=NULL;
    HANDLE hSnapShot;
    hSnapShot=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(hSnapShot==NULL)
    {
    return FALSE;//cannot get the snapshot handle
    } ::Process32First(hSnapShot, &pe);注意 pe.dwSize=sizeof(PROCESSENTRY32);这句话,当时我出的问题是没有这句话在release下就出错,有什么问题再探讨
      

  3.   

    谢谢!
    我将processListStr.dwSize=1024,编译了一下就可以了,
    但我将这名改为processListStr.dwSize=sizeof(PROCESSENTRY32)),居然也可以了.
    现在怎么弄也都可以了.
    真是莫名其妙.