CComPtr<ICreateErrorInfo> pCreateError; CComPtr<IErrorInfo> pError; HRESULT result = CreateErrorInfo(&pCreateError); if(FAILED(result)) return E_NOTIMPL; result = pCreateError->QueryInterface(&pError); if(FAILED(result)) return E_NOTIMPL; result = pCreateError->SetDescription(message); if(FAILED(result)) return E_NOTIMPL; result = pCreateError->SetGUID(IID_IDispatch); if(FAILED(result)) return E_NOTIMPL; CComBSTR source(L"@mozilla.XPCDispatchTearOff"); result = pCreateError->SetSource(source); if(FAILED(result)) return E_NOTIMPL; result = SetErrorInfo(0, pError); if(FAILED(result)) return E_NOTIMPL; return hResult;
CComBSTR someText(message); return Error(hResult, someText);
static HRESULT Error(HRESULT hResult, const CComBSTR & message){    CComPtr<ICreateErrorInfo> pCreateError;    CComPtr<IErrorInfo> pError;    HRESULT result = CreateErrorInfo(&pCreateError);    if(FAILED(result))        return E_NOTIMPL;    result = pCreateError->QueryInterface(&pError);    if(FAILED(result))        return E_NOTIMPL;    result = pCreateError->SetDescription(message);    if(FAILED(result))        return E_NOTIMPL;    result = pCreateError->SetGUID(IID_IDispatch);    if(FAILED(result))        return E_NOTIMPL;    CComBSTR source(L"@mozilla.XPCDispatchTearOff");    result = pCreateError->SetSource(source);    if(FAILED(result))        return E_NOTIMPL;    result = SetErrorInfo(0, pError);    if(FAILED(result))        return E_NOTIMPL;    return hResult;}