int _tmain(int argc, _TCHAR* argv[])
{
std::string strName = "QQ.exe";
std::string strFind;
HANDLE hProcessSnap = NULL;
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( !hProcessSnap ) return 0;
PROCESSENTRY32 pe32={0};
pe32.dwSize = sizeof( PROCESSENTRY32 );
if(Process32First(hProcessSnap,&pe32))
{
char temp[256] = {0};
do
{
int num = WideCharToMultiByte( CP_ACP, 0, pe32.szExeFile, wcslen( pe32.szExeFile ), 0, 0, NULL, NULL );
if( num == 0 ) continue;
char *szmultibyte = new char[num + 1];
memset( szmultibyte, 0, num+1 );
WideCharToMultiByte( CP_ACP, 0, pe32.szExeFile, wcslen( pe32.szExeFile ), szmultibyte, num, NULL, NULL );
szmultibyte[num] = '\0';
if( strcmp( strName.c_str(), szmultibyte ) == 0 )
{
strFind = szmultibyte;
break;
}else
{
std::string strTemp = szmultibyte;
if( strTemp.find( strName.c_str() ) != strTemp.npos )
{
strFind = szmultibyte;
break;
}
}
delete szmultibyte;
}
while(Process32Next(hProcessSnap,&pe32));
}
if( strFind.size() ) printf( "find: %s\n", strFind.c_str() );
getchar();
return 0;
}
感覺這記憶力是越來越差了。 之前搞過,忘記了。這次寫的時候又糾結了。 寫到日誌裏來當筆記了。