我试图在 MessageBox 中显示由 GetLastError() 提供给我并由 FormatMessage() 格式化的代码表示的错误消息。(使用 C++/CLI)
但是由于某种原因,我无法匹配 MessageBox::Show 的参数列表。
我正在尝试复制 Doron Moraz 在此论坛主题中提供的解决方案:
http://forums.codeguru.com/showthread.php?478858-GetLastError ()-in-a-MessageBox()
但是,当我尝试编译我的代码时,我得到:
'System::Windows::Forms::MessageBox::Show' : none of the 21 overloads could convert all the argument types
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\system.windows.forms.dll: could be 'System::Windows::Forms::DialogResult System::Windows::Forms::MessageBox::Show(System::String ^,System::String ^,System::Windows::Forms::MessageBoxButtons,System::Windows::Forms::MessageBoxIcon)'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\system.windows.forms.dll: or 'System::Windows::Forms::DialogResult System::Windows::Forms::MessageBox::Show(System::Windows::Forms::IWin32Window ^,System::String ^,System::String ^,System::Windows::Forms::MessageBoxButtons)'
1> while trying to match the argument list '(int, LPCTSTR, const wchar_t [6], long)'
正如您在下面看到的,我的代码与链接中提供的解决方案非常相似。只有我得到上述错误。问题是,为什么?(见下面我的代码)。
if((m_hglrc = wglCreateContext(m_hDC)) == NULL)//if the creation of a wgl context fails
{
MessageBox::Show("wglCreateContext Failed");//let us know
void* lpBuffer; //create a buffer to hold our error message
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, // It´s a system error
NULL, // No string to be formatted needed
::GetLastError(), // Hey Windows: Please explain this error!
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), // Do it in the standard language
(LPTSTR)&lpBuffer, // Put the message here
0, // Number of bytes to store the message
NULL);
System::Windows::Forms::MessageBox::Show( NULL, (LPCTSTR)lpBuffer, _T("Error"),MB_OK|MB_ICONWARNING);
// Free the buffer.
if(lpBuffer)LocalFree(lpBuffer);
return 0;
}
如果它是相关的,我的包括:
#pragma once
#include <Windows.h>
#include <GL/gl.h>
#include<tchar.h>
using namespace System::Windows::Forms;
在此先感谢,
盖伊