我有以下问题:
我想通过使用 CreateToolhelp32Snapshot 和 Process32First/Next 来跟踪正在运行的进程。但是我想默认使用 Unicode 字符集。
bool active( const std::wstring& process_name )
{
HANDLE snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if ( snapshot == INVALID_HANDLE_VALUE )
return false;
PROCESSENTRY32 entry;
if ( Process32First( snapshot, &entry ) )
{
if ( process_name.compare( entry.szExeFile ) == 0 )
{
CloseHandle( snapshot );
return true;
}
}
while ( Process32Next( snapshot, &entry ) )
{
if ( process_name.compare( entry.szExeFile ) == 0 )
{
CloseHandle( snapshot );
return true;
}
}
CloseHandle( snapshot );
return false;
}
int main( )
{
SetConsoleTitle( L"Lel" );
if ( active( L"notepad++.exe" ) )
std::cout << "Hello" << std::endl;
else
std::cout << ":(" << std::endl;
}
但是,如果我使用多字节字符集,一切正常。