/*---------------------------------------------------------------------------------------------- Creates an error object and then sets a description from a resource id. Also sets a full help URL as required by HtmlHelp. Uses ierr as an index for both resource id and help URL. @param ierr Index to a set of htm help files (second part of full help URL) and matching resource strings for Message Box text. @param pei [out] Error info object ----------------------------------------------------------------------------------------------*/ void LgKeymanHandler::ThrowErrorWithInfo(HRESULT hrErr, int stidDescription) { IErrorInfoPtr qei; ICreateErrorInfoPtr qcei; // Create error info object. CheckHr(CreateErrorInfo(&qcei)); StrUni stu(stidDescription); CheckHr(qcei->SetDescription((wchar *)stu.Chars())); // Now get the IErrorInfo interface of the error object and set it for the current thread. CheckHr(qcei->QueryInterface(IID_IErrorInfo, (void **)&qei)); SetErrorInfo(0, qei); ThrowHr(hrErr, stu.Chars(), -1, qei); // An error object exists. }
virtual void ProcessAttach(void) { HRESULT hr; if (FAILED(hr = ::CreateErrorInfo(&s_qcerrinfoMem))) ThrowInternalError(hr); if (FAILED(hr = s_qcerrinfoMem->QueryInterface(IID_IErrorInfo, (LPVOID FAR*) &s_qerrinfoMem))) { // We should have plenty of memory as we start up components! ThrowInternalError(hr); } StrUni stuDesc(kstidOutOfMemory); s_qcerrinfoMem->SetDescription(stuDesc.Bstr()); // We can't set the IID or source yet. s_qcerrinfoMem->SetHelpFile(const_cast<OLECHAR *>(GetModuleHelpFilePath().Chars())); s_qcerrinfoMem->SetHelpContext(khcidHelpOutOfMemory); }
/*---------------------------------------------------------------------------------------------- General purpose method to set up and store an error, rather than throw an exception in the normal way. ----------------------------------------------------------------------------------------------*/ HRESULT StackDumper::RecordError(REFGUID iid, StrUni stuDescr, StrUni stuSource, int hcidHelpId, StrUni stuHelpFile) { // We are going to make a new error info object. ICreateErrorInfoPtr qcerrinfo; IErrorInfoPtr qerrinfo; HRESULT hr; // If we can't get a new error object, the only documented cause is E_OUTOFMEMORY. if (FAILED(hr = ::CreateErrorInfo(&qcerrinfo))) { return E_OUTOFMEMORY; } if (FAILED(hr = qcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID FAR*) &qerrinfo))) { return E_UNEXPECTED; } hr = qcerrinfo->SetDescription(const_cast<OLECHAR *>(stuDescr.Chars())); if (FAILED(hr)) return hr; hr = qcerrinfo->SetGUID(iid); if (FAILED(hr)) return hr; hr = qcerrinfo->SetSource(const_cast<OLECHAR *>(stuSource.Chars())); if (FAILED(hr)) return hr; hr = qcerrinfo->SetHelpFile(const_cast<OLECHAR *>(stuHelpFile.Chars())); if (FAILED(hr)) return hr; if (!hcidHelpId) hcidHelpId = khcidNoHelpAvailable; hr = qcerrinfo->SetHelpContext(hcidHelpId); if (FAILED(hr)) return hr; ::SetErrorInfo(0, qerrinfo); return hr; }