本文介绍了为HRESULT代码生成诊断消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想能够做相当于FormatMessage - 生成一个文本消息的调试,甚至运行时生成,可以报告一些常见的HRESULTs,甚至吐出的东西,例如严重性,什么设施



我发现,但是它太简单了,而且大多数似乎生成未知错误。



我可以这样做:

  CComPtr< IErrorInfo> iei; 
if(S_OK == GetErrorInfo(0,& iei)& iei)
{
//从IErrorInfo获取错误描述
BSTR bstr = NULL;
if(SUCCEEDED(iei-> GetDescription(& bstr)))
{
//将描述附加到我们的标签
Append

//用BSTR完成,手动清理
SysFreeString(bstr);
}
}
else if(HRESULT_FACILITY(hr)== FACILITY_WIN32)
{
//将描述附加到我们的标签
Append(CErrorMessage HRESULT_CODE(hr))。c_str());
}

但是,我不知道我是否比_com_error完成任何事。 p>

有没有人知道为HRESULT生成错误日志输出的合理的设备?

解决方案

随着您的使用,应该做的。



如果你得到未知错误,那么你得到的HRESULT不知道窗口。对于这些邮件,请尝试转储HRESULT值,然后。



一些可用的宏可帮助您拆分HRESULT的位。


I'd like to be able to do the equivalent of FormatMessage - generate a text message for debug and even runtime builds that can report some of the common HRESULTs, or even spit out things like what the severity is, what facility it was, and possibly a description of the error code.

I found this simple function, but its too simple, and mostly seems to generate "unknown error". But so far I haven't found anything that looks more promising.

I can do something like the following:

CComPtr<IErrorInfo> iei;
if (S_OK == GetErrorInfo(0, &iei) && iei)
{
	// get the error description from the IErrorInfo 
	BSTR bstr = NULL;
	if (SUCCEEDED(iei->GetDescription(&bstr)))
	{
		// append the description to our label
		Append(bstr);

		// done with BSTR, do manual cleanup
		SysFreeString(bstr);
	}
}
else if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
{
	// append the description to our label
	Append(CErrorMessage(HRESULT_CODE(hr)).c_str());
}

However, I wonder if I'm accomplishing anything more than _com_error.

Does anyone know of a reasonably fleshed out facility for generating error log output for HRESULTs?

解决方案

As you muse, _com_error::ErrorMessage() should do the trick.

If you are getting "Unknown Error", then the HRESULTs you are getting are probably not known to windows. For those messages, try dumping the HRESULT value and figuring out if they actually map to win32 error codes.

There are some com macros available to help you split out the bits of the HRESULT.

这篇关于为HRESULT代码生成诊断消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 15:17