MessageBoxW cannot convert

2019-09-04 11:43发布

问题:

I am using wxWidgets 2.9.4 in Visual Studio 2012 and I keep getting these two error messages:

Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'

IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR"

My code is:

#ifdef _WIN32
    std::string msg;
    StringFromFormatV(&msg, format, args);
    retval = IDYES == MessageBox(0, msg.c_str(), "ERROR! Continue?", MB_ICONQUESTION | MB_YESNO);

回答1:

You are compiling your project using multi-byte characters as default. You can change that in your project's properties, or you can use msg.wc_str(), or even enforce the use of MessageBoxA instead of using the macro MessageBox.