中的类型错误参数

中的类型错误参数

本文介绍了C ++中的类型错误参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio2013.错误显示类型为"WCHAR *"的参数与类型为"const char *"的参数不兼容.

I am using Visual Studio 2013. The error says "argument of type "WCHAR *" is incompatible with parameter of type "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"上

The error is on the following line. On my ide it is on "pe32"

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

推荐答案

strcmp 的签名是

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

pe32.szExeFile TCHAR [] ,可以是 wchar_t [] char [] >,取决于是否定义了 UNICODE .在您的情况下,它已定义,因此您需要:

Whereas pe32.szExeFile is a TCHAR[], which is either wchar_t[] or char[] depending on whether UNICODE is defined. In your case, it is defined, so you need to either:

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

  1. change ProcessName to a wide character string and use wcscmp to compare them.

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

use _tcscmp(), and make sure ProcessName is wide or narrow based on UNICODE.

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

use the ANSI versions of the APIs, which have a capital A appended to their names (e.g., Process32FirstA() and Process32NextA()).

这篇关于C ++中的类型错误参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:28