我正在使用 Visual Studio 2013。错误显示““WCHAR *”类型的参数与“const char *”类型的参数不兼容。
while (!processId)
{
system("CLS");
cout << "Searching for game" << ProcessName << "..." << endl;
cout << "Make sure your game is running" << endl;
hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(hProcSnap, &pe32))
{
do
{
if (!strcmp(pe32.szExeFile, ProcessName))
{
processId = pe32.th32ProcessID;
break;
}
} while (Process32Next(hProcSnap, &pe32));
}
Sleep(1000);
}
错误位于以下行。在我的IDE上它位于“pe32”上
if (!strcmp(pe32.szExeFile, ProcessName))
的签名strcmp
is
int strcmp ( const char * str1, const char * str2 );
Whereas pe32.szExeFile
is a TCHAR[]
,这是wchar_t[]
or char[]
取决于是否UNICODE
被定义为。在您的情况下,它已定义,因此您需要:
change ProcessName
到宽字符串并使用wcscmp
来比较它们。
use _tcscmp()
,并确保ProcessName
是宽还是窄基于UNICODE
.
使用 ANSI 版本的 API,其大写字母A
附加在他们的名字后面(例如,Process32FirstA()
and Process32NextA()
).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)