Tim*_*Tim 16 c++ error-handling winapi
我需要获取我从GetLastError函数获得的错误代码的文本.我看了几个例子,但我想要一个获取代码并返回字符串的函数.谢谢大家
hum*_*mba 46
我想你想要这样的东西:
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);
Run Code Online (Sandbox Code Playgroud)
另见:http://msdn.microsoft.com/en-us/library/ms679351(VS.85).aspx
| 归档时间: |
|
| 查看次数: |
18066 次 |
| 最近记录: |