Shurik
Shurik

Reputation: 67

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

Upvotes: 1

Views: 2043

Answers (1)

wakjah
wakjah

Reputation: 4551

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 (e.g., Process32FirstA() and Process32NextA()).

Upvotes: 4

Related Questions