I have a third party COM component with its c++ interface in VC++. I am getting a crash in the call below which is crashing my application. How can I recover gracefully from this function which is not really part of my application?
inline _RecordsetPtr IGLibMgr::GetLibInfo ( _bstr_t LibPath ) {
struct _Recordset * _result = 0;
HRESULT _hr = raw_GetLibInfo(LibPath, &_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _RecordsetPtr(_result, false);
}
It crashes in the last line. I don’t think I can modify this code since it’s third party COM stuff. What options do I really have? I just want to bring up message box to user and return gracefully.
If you’re not already doing this in your code, you need to be from the caller-side:
This is important on multiple levels. The most obvious being that not only can your
IGLibMgrmember throw an exception, so can thebstr_tallocation, etc. When using#importcode from a COM DLL, get used to this format if using generated smart-pointers from the comutil library of MSVC.Note: The
_com_errorclass provides several members for obtaining why the error happened, including the HRESULT, error description string, etc. It even provides access to theIErrorInfocreated by the error-returning object if it is so-nice as to provide that level of detail.