CppPilot

MSVC build errors > C2664

C2664: cannot convert argument

error C2664: 'int MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT)': cannot convert argument 2 from 'const char [6]' to 'LPCWSTR'

An argument of a function call cannot be converted to the type of its parameter.

Causes and fixes

  1. A narrow string is passed to a Unicode Windows function. With Character Set set to Unicode, MessageBox is MessageBoxW and expects wide strings: write L"Hello", call MessageBoxA, or use TEXT("Hello").
  2. A temporary is passed to a non-const reference. A parameter std::string& does not accept a literal or a temporary: take const std::string& when the function does not change it.
  3. A const object is passed to a non-const parameter. Make the parameter const, or pass a copy.
  4. The arguments are in the wrong order. Compare the call with the declaration the message shows; another overload may be the one you meant.

Fix C2664 with CppPilot

CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.

Let the AI fix it in Visual Studio

CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.

Get CppPilot free Get started

Related errors: C2440. See all guides.