C++ Argument of type "const wchar_t" * incompatible with parameter of type "wchar_t"


Сan't call "GetProcessByExeName"

DWORD GetProcessByExeName(wchar_t* ExeName)
pe32.dwSize = sizeof(PROCESSENTRY32W);

HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
if (hProcessSnap == INVALID_HANDLE_VALUE)
    MessageBoxW(NULL, L"Error CreateToolhelp32Snapshot", L"error", MB_OK);
    return false;

if (Process32FirstW(hProcessSnap, &pe32))
        if (_wcsicmp(pe32.szExeFile, ExeName) == 0)
            return pe32.th32ProcessID;
    } while (Process32NextW(hProcessSnap, &pe32));

   return 0;

By calling GetProcessByExeName(L"chrome.exe"); writes -> Argument of type "const wchar_t" * is incompatible with parameter of type "wchar_t"


You are attempting to pass a wide character string literal which is not modifiable and should be a const wchar_t* to a function that is declared to take a wchar_t* which is not a const. Since you don't want to modify the string in your function you should change the signature of your function from

DWORD GetProcessByExeName(wchar_t* ExeName)


DWORD GetProcessByExeName(const wchar_t* ExeName)

This question should add some information on why string literals must be const: Why are string literals const?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment


Cannot convert parameter 1 from 'const wchar_t *' to 'LPCTSTR' in MFC / C++ project

Convert const char* to const wchar_t*

cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}'

Poco::Path compiles with const wchar_t* but behaves unexpectedly

How to make concatenations at const wchar_t* parameters?

How to convert int variable and append to const wchar_t*

Unordered_map find const wchar_t*

Error: argument of type "const wchar_t *" is incompatible with parameter of type "WCHAR *"

How to fix " State Error (active) E0513 a value of type “const wchar_t *” cannot be assigned to an entity of type “wchar_t *”"

How to transform const wchar_t type to LPTSTR (C++)

String conversion from System::String ^ to const wchar_t *

how wchar_t data type working c?

Check whether type is char or wchar_t in compile time

Understanding wchar_t type in c++

C++ wifstream: Incompatible type char const*, wchar_t const*

Convert LOWORD(wParam) to const wchar_t*

Casting std::wstring to const wchar_t x[]

Convert const wchar_t* into a WCHAR*

Make a condition on const wchar_t*

String parameter const char* and const wchar_t*

Visual Studio 2017; argument of type "const wchar_t *" is incompatible with parameter of type "PWSTR" when /permissive is enabled

How to delete a file that has a name of type wchar_t in C++ in a portable way?

GLUT Problem: error redeclaration of c++ built-in type 'wchar_t'

Type conversion from string to const wchar_t* . Type does not match

g++ wchar_t string litteral is not of expected type

How could I assign the value from lua_tostring() to a variable in type of wstring or const wchar_t* in utf-8

C++ Builder 10.3 can not assign to const wchar_t* from const char[18]

Convert const wchar_t* to LPWSTR

format wstring with fmt fails: no matching function for call to 'format(const wchar_t [17], int)'