C++ 错误C2664:MessageBoxW无法将参数2从';常量字符';至';LPCWSTR';
我一直收到以下错误消息: 状态错误C2664--int MessageBoxW(HWND、LPCWSTR、LPCWSTR、UINT)':无法将参数2从'const char*'转换为'LPCWSTR'”31 这是我下面的代码。我知道它与通过error类中的C++ 错误C2664:MessageBoxW无法将参数2从';常量字符';至';LPCWSTR';,c++,window,C++,Window,我一直收到以下错误消息: 状态错误C2664--int MessageBoxW(HWND、LPCWSTR、LPCWSTR、UINT)':无法将参数2从'const char*'转换为'LPCWSTR'”31 这是我下面的代码。我知道它与通过error类中的what()函数传递常量类型有关。出于某种原因,它不兼容。有什么想法吗 // on startup execute to determine exceptions try { // instantiate object app of c
what()
函数传递常量类型有关。出于某种原因,它不兼容。有什么想法吗
// 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;
返回const char*
,因此您应该使用MessageBoxA()
,而不是MessageBox()
或MessageBoxW()
MessageBoxA(nullptr,error.what(),“发生错误”,MB_OK);
另外,不要忘记从字符串文本中删除L
前缀。返回const char*
,因此应该使用MessageBoxA()
,而不是MessageBox()
或MessageBoxW()
MessageBoxA(nullptr,error.what(),“发生错误”,MB_OK);
也不要忘记从字符串文本中删除
L
前缀。您可以使用MessageBoxA()
并从标题字符串中删除L
前缀。或者将e.what()
转换为wchar\u t
字符串。您可以使用MessageBoxA()
并从标题字符串中删除L
前缀。或者转换e.what()
指向wchar\u t
字符串。一个LPCWSTR
是指向wchar\u t
元素数组的指针,每个元素都是16位而不是8位字符,并且,举个例子,许多重复项中的两个,是通过将错误消息粘贴到此站点的搜索字段中获得的。当消息包含窄字符s时trings,hard use MessageBoxA.LPCWSTR
是一个指向wchar\u t
元素数组的指针,每个元素都是16位而不是8位字符,并且,仅举其中的两个,通过将错误消息粘贴到此站点上的搜索字段中获得。当messageboxing窄字符串时,hard useMessageBoxA。