Many COM objects simply use setErrorInfo and expect to call getErrorInfo to retrieve the detail error message. However, .Net would not call getErrorInfo unless the COM object implements the ISupportErrorInfo interface. There are the steps:
1. In the .h file, make the COM object implements the ISupportErrorInfo interface, e.g.:
class
ATL_NO_VTABLE CMyObject : ..., public ISupportErrorInfo, ...
2. In COM MAP, add:
BEGIN_COM_MAP(CMyObject)
...
COM_INTERFACE_ENTRY(ISupportErrorInfo)
...
END_COM_MAP()
3. Add the method declaration:
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
4. Implement the method in the .cpp file:
/////////////////////////////////////////////////////////////////////////////
// ISupportsErrorInfo
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP CMyObject::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IMyObject,
&IID_IMyObject2,
&IID_IMyObject3,
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}