L o a d i n g . . .
主打一个C++
文章详情

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

作者近期文章
提示
×
确定
数据库执行: 7次 总耗时: 0.01s
页面加载耗时: 



wechat +447752296473
wechat cpp-blog