简体   繁体   中英

Argument of type error in C++

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);
}

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

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

The signature of strcmp is

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

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. change ProcessName to a wide character string and use wcscmp to compare them.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM