BOOL FindProcess()
{
int i = 0;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
i += 0;
}
BOOL bMore = ::Process32First(hProcessSnap, &pe32);
while (bMore)
{
//printf(" 行程名稱:%s \n", pe32.szExeFile);
if (stricmp("TExt", pe32.szExeFile) == 0)
{
//printf("行程運行中");
i += 1;
}
bMore = ::Process32Next(hProcessSnap, &pe32);
}
if (i > 1) { //大于1,排除自身
return true;
}
else {
return false;
}
}
原始碼是這樣的,但是在pe32.szExeFile這個位置一直提示我:WCHAR *”型別的實參與"const char *"型別的形參不兼容;
想請教一下在不改字符集的情況下怎么解決這個問題呀?
uj5u.com熱心網友回復:
#include <atlconv.h>
using namespace std;
BOOL FindProcess()
{
int i = 0;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
i += 0;
}
BOOL bMore = ::Process32First(hProcessSnap, &pe32);
while (bMore)
{
USES_CONVERSION;
//printf(" 行程名稱:%s \n", pe32.szExeFile);
if (_stricmp("TExt", W2A(pe32.szExeFile)) == 0)
{
//printf("行程運行中");
i += 1;
}
bMore = ::Process32Next(hProcessSnap, &pe32);
}
if (i > 1) { //大于1,排除自身
return true;
}
else {
return false;
}
}
uj5u.com熱心網友回復:
_tcsicmp(TEXT("TExt"), pe32.szExeFile)轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/269213.html
標籤:C++ 語言
