文章详情
C++获取GetLastError的详细错误信息文本提示
Posted on 2019-04-30 10:00:40 by 主打一个C++
函数代码:
void GetErrorMessage(DWORD _errorCode, BOOL _popMsg = TRUE, std::string* _out = nullptr) {
LPVOID lpMsgBuf;
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
_errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpMsgBuf,
0, NULL);
if (_popMsg) {
MessageBoxA(GetForegroundWindow(), (LPCSTR)lpMsgBuf, "错误", MB_ICONERROR);
}
if (_out) {
*_out = (const char*)&lpMsgBuf;
}
// 释放分配的缓冲区
LocalFree(lpMsgBuf);
}
*转载请注明出处:原文链接:https://cpp.vin/page/79.html