Felix Snow
Felix Snow

Reputation: 3

no instance of overloaded function "" matches the argument list error

I'm Getting the following errors in my cpp and I'm not quite sure how to fix them (I'm new to C++)

Errors:

Severity    Code    Description Project File    Line    Suppression State
Error (active)      no instance of overloaded function "std::basic_string<_Elem, _Traits, _Alloc>::compare [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" matches the argument list    KernelHop   c:\Users\Root\Downloads\KernelHop-master (1)\KernelHop-master\KernelHop\KernelHop.cpp   102 


Severity    Code    Description Project File    Line    Suppression State
Error (active)      no instance of overloaded function "std::basic_string<_Elem, _Traits, _Alloc>::compare [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" matches the argument list    KernelHop   c:\Users\Root\Downloads\KernelHop-master (1)\KernelHop-master\KernelHop\KernelHop.cpp   110 

My Code:

DWORD FindProcessId(const std::string processName)
{
    PROCESSENTRY32 processInfo;
    processInfo.dwSize = sizeof(processInfo);

    HANDLE processSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
    if (processSnapshot == INVALID_HANDLE_VALUE)
        return 0;

    Process32First(processSnapshot, &processInfo);
    if (!processName.compare(processInfo.szExeFile))
    {
        CloseHandle(processSnapshot);
        return processInfo.th32ProcessID;
    }

    while (Process32Next(processSnapshot, &processInfo))
    {
        if (!processName.compare(processInfo.szExeFile))
        {
            CloseHandle(processSnapshot);
            return processInfo.th32ProcessID;
        }
    }

    CloseHandle(processSnapshot);
    return 0;
}

Anyone know what I'm doing wrong?

Upvotes: 0

Views: 5646

Answers (1)

user1610015
user1610015

Reputation: 6678

You are probably compiling as Unicode, in which case PROCESSENTRY32::szExeFile will be a wide string (wchar_t[]), but std::string::compare() expects a byte string (char[]). So try using std::wstring instead.

Upvotes: 1

Related Questions