【问题标题】:Argument of type error in C++C++ 中的类型错误参数
【发布时间】:2015-02-06 19:28:33
【问题描述】:

我正在使用 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);
}

错误在下一行。在我看来,它在“pe32”上

          if (!strcmp(pe32.szExeFile, ProcessName))

【问题讨论】:

标签: c++ winapi visual-c++


【解决方案1】:

strcmp的签名是

int strcmp ( const char * str1, const char * str2 );

pe32.szExeFileTCHAR[],它是wchar_t[]char[],具体取决于是否定义了UNICODE。在您的情况下,它已定义,因此您需要:

  1. ProcessName更改为宽字符串,并使用wcscmp进行比较。

  2. 使用_tcscmp(),并根据UNICODE确定ProcessName是宽还是窄。

  3. 使用 API 的 ANSI 版本,其名称后附有大写的 A(例如,Process32FirstA()Process32NextA())。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-03
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 2016-02-11
    • 2014-03-28
    相关资源
    最近更新 更多