【发布时间】:2009-12-03 22:48:48
【问题描述】:
我希望能够执行与 FormatMessage 等效的操作 - 生成用于调试甚至运行时构建的文本消息,可以报告一些常见的 HRESULT,甚至吐出诸如严重性是什么、它是什么设施等信息是,并且可能是错误代码的描述。
我找到了this simple function,但它太简单了,而且似乎大多会产生“未知错误”。但到目前为止,我还没有发现任何看起来更有希望的东西。
我可以执行以下操作:
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());
}
但是,我想知道我是否完成了比 _com_error 更多的事情。
有没有人知道为 HRESULT 生成错误日志输出的合理充实的工具?
【问题讨论】: