“类型为WCHAR *的参数与"const char *"不兼容" [英] 'The argument of type WCHAR* is not compatible with "const char*"'
问题描述
DWORD ProcMem::Module(LPSTR ModuleName){
HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
MODULEENTRY32 mEntry;
mEntry.dwSize = sizeof(mEntry);
do
if (!strcmp(mEntry.szModule, ModuleName))
{
CloseHandle(hModule);
return (DWORD)mEntry.modBaseAddr;
}
while (Module32Next(hModule, &mEntry));
cout << "\nMODULE: Process Platform Invalid\n";
return 0;
}
WCHAR *类型的参数与"const char *"`不兼容. 同时将光标放在mEntry上.
the argument of type WCHAR* is not compatible with "const char*"`. while holding my cursor on mEntry.
推荐答案
您的项目在启用Unicode的情况下进行了编译,因此CreateToolhelp32Snapshot()
映射到CreateToolhelp32SnapshotW()
,PROCESSENTRY32
映射到PROCESSENTRY32W
,并且Process32Next()
映射到Process32NextW()
.因此,ProcEntry.szExeFile
字段是一个WCHAR[]
数组.
Your project is compiled with Unicode enabled, so CreateToolhelp32Snapshot()
maps to CreateToolhelp32SnapshotW()
, PROCESSENTRY32
maps to PROCESSENTRY32W
, and Process32Next()
maps to Process32NextW()
. Thus, ProcEntry.szExeFile
field is a WCHAR[]
array.
您要将szExeFile
传递给strcmp()
,它不支持wchar_t*
字符串,仅支持char*
字符串.您需要:
You are passing szExeFile
to strcmp()
, which does not support wchar_t*
strings, only char*
strings. You need to either:
-
使用
WideCharToMultiByte()
将szExeFile
转换为char[]
数组,以便将其传递给strcmp()
.
use
WideCharToMultiByte()
to convertszExeFile
to achar[]
array so you can then pass that tostrcmp()
.
将您的ProcessName
参数更改为wchar_t*
,或使用MultiByteToWideChar()
将ProcessName
转换为wchar_t[]
数组,然后将其传递给wcscmp()
或lstrcmpW()
而不是strcmp()
.
change your ProcessName
parameter to wchar_t*
, or use MultiByteToWideChar()
to convert ProcessName
to a wchar_t[]
array, and pass that to wcscmp()
or lstrcmpW()
instead of strcmp()
.
如果要继续使用基于TCHAR
的API,请将ProcessName
参数更改为LPTSTR
,然后使用_tcscmp()
或lstrcmp()
代替strcmp()
.
if you want to continue using TCHAR
-based APIs, change your ProcessName
parameter to LPTSTR
and then use _tcscmp()
or lstrcmp()
instead of strcmp()
.
这篇关于“类型为WCHAR *的参数与"const char *"不兼容"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!