tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

取得内存中的实例数

Posted on 2005-10-22 10:47 Tommy Liang 阅读(422) 评论(0)  编辑 收藏 引用 所属分类: 进程与线程
this is the content:
#include <Tlhelp32.h>

//取得内存中的实例数
int GetMemoryProcessCount(LPCSTR peFileName)
{
    
int result = 0;

    HANDLE hSnapshot;
    PROCESSENTRY32 pe;
    pe.dwSize
=sizeof(pe);
    BOOL blExist
=FALSE;
    
char sPath[MAX_PATH] = "";
    strcpy(sPath,peFileName);

    size_t len 
= strlen(sPath);    
    hSnapshot
=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    
if(hSnapshot<0goto L1;

    
if(::Process32First(hSnapshot,&pe)==FALSE)
    
{
        ::CloseHandle(hSnapshot); 
goto L1;
    }

    
if(_strnicmp(sPath,pe.szExeFile,len)==0)
    
{        
        
++ result;
    }


    
while(::Process32Next(hSnapshot,&pe))
    
{
        
if(_strnicmp(sPath,pe.szExeFile,len)==0)
        
{
            
++ result;
        }
 
    }


L1: 
    ::CloseHandle(hSnapshot);
    
return result;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理