2009-12-03 50 views
0

我希望能夠做到相當於FormatMessage - 爲調試生成文本消息,甚至是可以報告一些常見HRESULT的運行時版本,甚至可以吐出嚴重程度,它是什麼設施,並可能包含對錯誤代碼的描述。爲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錯誤日誌輸出的合理設施?

回答

2

你使用Boost? boost :: system庫將自動查找HRESULT和Win32 API結果代碼。

3

如果您直接使用WIN32,FormatMessage()調用應該會幫助您。