“类型为WCHAR *的参数与"const char *"不兼容" [英] 'The argument of type WCHAR* is not compatible with "const char*"'

查看:349
本文介绍了“类型为WCHAR *的参数与"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:

  1. 使用WideCharToMultiByte()szExeFile转换为char[]数组,以便将其传递给strcmp().

  1. use WideCharToMultiByte() to convert szExeFile to a char[] array so you can then pass that to strcmp().

将您的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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆