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
- A narrow string is passed to a Unicode Windows function. With Character Set set to Unicode,
MessageBoxisMessageBoxWand expects wide strings: writeL"Hello", callMessageBoxA, or useTEXT("Hello"). - A temporary is passed to a non-const reference. A parameter
std::string&does not accept a literal or a temporary: takeconst std::string&when the function does not change it. - A const object is passed to a non-const parameter. Make the parameter
const, or pass a copy. - 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.
Related errors: C2440. See all guides.