且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从GetLastError()函数返回的错误代码中获取文本

更新时间:2023-02-16 20:43:43

我想你想要这样的东西:

  DWORD dwLastError = :: GetLastError(); 
TCHAR lpBuffer [256] = _T(?);
if(dwLastError!= 0)//不想看到操作成功完成错误;-)
:: FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,//它是系统错误
NULL,//不需要格式化的字符串
dwLastError,//嘿Windows:请解释这个错误!
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)//使用标准语言
lpBuffer ,//将消息放在这里
STR_ELEMS(lpBuffer)-1,//存储消息的字节数
NULL);

另请参阅: http://msdn.microsoft.com/en-us/library/ms679351(VS.85).aspx


I need to get the text of an error code that i got from the GetLastError function. I saw a few examples but i want a function that get the code and return the string. Thank's you all

I guess you want something like this:

DWORD   dwLastError = ::GetLastError();
TCHAR   lpBuffer[256] = _T("?");
if(dwLastError != 0)    // Don't want to see a "operation done successfully" error ;-)
    ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,                 // It´s a system error
                     NULL,                                      // No string to be formatted needed
                     dwLastError,                               // Hey Windows: Please explain this error!
                     MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),  // Do it in the standard language
                     lpBuffer,              // Put the message here
                     STR_ELEMS(lpBuffer)-1,                     // Number of bytes to store the message
                     NULL);

Also see: http://msdn.microsoft.com/en-us/library/ms679351(VS.85).aspx