我在VS2005下需要获取进程句柄信息。
通过
snap = CreateToolhelp32Snapshot()
Process32First()
OpenProcess()
Process32Next()
在2002的msdn描述CreateToolhelp32Snapshot()通过CloseHandle()释放,而在2005的MSDN上需要通过CloseToolhelp32Snapshot()释放。
我在2005编译器下好像没有CloseToolhelp32Snapshot();

解决方案 »

  1.   

    CloseToolhelp32Snapshot 似乎只在WINCE上有啊。
      

  2.   

    在2005的MSDN上需要通过CloseToolhelp32Snapshot()释放CreateToolhelp32Snapshot(),如果通过CloseToolhelp32Snapshot()释放会导致内存泄漏。请教大家有没有更好的办法获取进程句柄。
    通过CreateProcess,不太清楚dwCreationFlags参数该如何设置。
      

  3.   

    http://www.vckbase.com/document/viewdoc/?id=1482(如何用 Win32 APIs 枚举应用程序窗口和进程
    )
      

  4.   

    我用的就是VS2005啊,MSDN上根本就没有CloseToolhelp32Snapshot,应该就像上面大版所说的,这个是CE上的函数吧
      

  5.   

    //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&brvbar;   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 "); 

    Requirements   
        Windows   NT/2000   or   later:   Requires   Windows   NT   4.0   or   later. 
        Header:   Declared   in   Psapi.h. 
        Library:   Use   Psapi.lib. 
    You   can   not   use   it   under   win9x
      

  6.   

    在WINCE下用CreateToolhelp32Snapshot()创造或打开快照的句柄,但也不是用CloseToolhelp32Snapshot()来关闭,而是用CloseHandle()来关闭
      

  7.   

    http://blog.csdn.net/qsdnet/archive/2005/10/01/493312.aspx
    里面包含平台判断,不过没有读取16位进程的