|
void dump_com_error(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TCHAR szTemp[1024];
CString csMsg = "COM error!\n";
wsprintf(szTemp, _T("Code = %08lx\n"), e.Error());
csMsg += szTemp;
wsprintf(szTemp, _T("Code meaning = %s\n"), e.ErrorMessage());
csMsg += szTemp;
wsprintf(szTemp, _T("Source = %s\n"), bstrSource.length() ?
(LPCTSTR)bstrSource : _T("null"));
csMsg += szTemp;
wsprintf(szTemp, _T("Description = %s\n"), bstrDescription.length() ?
(LPCTSTR)bstrDescription : _T("null"));
csMsg += szTemp;
AfxMessageBox(csMsg);
}
void com_error_test()
{
try {
// to do
// ......
}
catch(_com_error& e) {
dump_com_error(e);
}
} |
|