c++comidispatch

List of IDispatch errors and/or message texts


I am calling methods on WMI/WBEM interfaces that return HRESULTS. I want to display meaningful error messages for these error codes to the user. However, when I look up the HRESULT's error message I only get strings like "IDispatch error #3598".

Were can I find a list of these IDispatch error codes that explains their meaning?

Example code where errors may occur:

IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = NULL;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator);
if (FAILED(hr))
   return hr;

hr = pLocator->ConnectServer(wPath, NULL, NULL, NULL, 0, NULL, NULL, &pNamespace);
if(FAILED(hr))
   return hr;

Error lookup:

CString sMessage = _com_error(nError).ErrorMessage();

// sMessage now contains a string like "IDispatch error #3598"

Note: This does not help - it does not contain the HRESULTS I get. Neither are they contained in winerror.h.


Solution

  • COM servers can generate their own HRESULT error codes. The IErrorInfo interface helps a client to get a description of the error. You are not giving the _com_error class a chance to do that job, you don't pass the IErrorInfo interface pointer to the constructor.

    First QI the interface for ISupportErrorInfo and call its InterfaceSupportsErrorInfo() method to verify that error reporting is supported. Next call GetErrorInfo() to obtain the IErrorInfo interface pointer. MSDN docs are here.