错误C2664:MessageBoxW无法将参数2从'const char'转换为'LPCWSTR'

科迪

我不断收到此错误消息:

状态错误C2664-int MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT)':无法将参数2从'const char *'转换为'LPCWSTR'“ 31

这是我的下面的代码。我知道这与通过what()错误类中函数传递const类型有关由于某种原因,它是不兼容的。有任何想法吗?

// on startup execute to determine exceptions
try
{
    // instantiate object app of class AppWindow
    AppWindow app;

    // if(initialize function in class app is executed, and while the app is running, broadcast app)
    if (app.init())
    {
        while (app.isRun())
        {
            app.broadcast();
        }
    }
}

// if the following error is found, execute MessageBox function with following parameters
catch (const std::runtime_error& error)
{
    // parameters(has no owner window so displays independently)
    MessageBox(nullptr,  error.what(), L"An error has occured", MB_OK);
}

return 0;
迈克猫

std::runtime_error::what()返回const char*,因此您应该使用MessageBoxA(),而MessageBox()不是MessageBoxW()

MessageBoxA(nullptr,  error.what(), "An error has occured", MB_OK);

同样不要忘记L从字符串文字中删除前缀。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将const char **转换为void *?

C ++-错误C2664:'int scanf(const char *,...)':无法将参数1从'int'转换为'const char *'

无法将'const char *'转换为'LPCWSTR {aka const wchar_t *}'

将wstringstream转换为LPCWSTR

在C ++中将char *转换为const char *

错误:无法将“ const value_type”转换为“ char”

类型“ const char *”的参数与类型“ LPCWSTR”的参数不兼容

无法从const char *转换为const char *&

C2440:“ =”:无法从“ const char [9]”转换为“ char *”

错误:无法将“ const char **”转换为“ const char(*)[64]”

将const char **转换为std :: vector <const char *>

错误C2664'HRESULT IUnknown :: QueryInterface(const IID&,void **)':无法将参数1从'const winrt :: guid'转换为'const IID&'

将const Char *转换为Char数组

将(const)char *转换为LPCWSTR

从char转换为LPCWSTR

将const char *转换为QString

无法将“ TCHAR *”转换为“ const char *”

错误C2664:“ errno_t strcpy_s(char *,rsize_t,const char *)”:无法将参数2从“ char [512]”转换为“ rsize_t”

无法从DWORD转换为const char *

无法将参数1从char转换为strcmp的const char

将表格CString转换为const char *

在C ++中将wstring转换为const * char

无法将参数1从'const char [11]'转换为'LPCWSTR'

在视觉工作室中获取错误:错误C2664:'_chmod':无法将参数1从'wchar_t [260]'转换为'const char *'

无法将 QString 转换为 Const Char*

如何将 const char* 转换为 const unsigned char*

错误 C2440:“=”:无法从“const char *”转换为“LPCWSTR”

将 QString 转换为 const char*

将 const char * 转换为小写 char *