|
#include "stdafx.h"
#include "Tools\Exception.h"
namespace Tools
{
Exception::Exception(const CLSID& clsId, UINT resourceId, ...)
{
_ASSERTE ((resourceId > 0x0200) && (resourceId < 0xFFFF));
m_hr = MAKE_HRESULT (3/*error*/, FACILITY_ITF, resourceId);
_bstr_t component = GetProgId (clsId);
va_list argList;
va_start (argList, resourceId);
_bstr_t description (LoadString (resourceId, &argList));
va_end (argList);
ICreateErrorInfoPtr iCreateErrorInfo;
if (SUCCEEDED (CreateErrorInfo (&iCreateErrorInfo)))
{
iCreateErrorInfo->SetGUID (GUID_NULL);
iCreateErrorInfo->SetSource (component);
iCreateErrorInfo->SetDescription (description);
IErrorInfoPtr iErrorInfo (iCreateErrorInfo);
SetErrorInfo (0, iErrorInfo);
}
}
HRESULT Exception::GetException() const
{
return m_hr;
}
_bstr_t Exception::LoadString (UINT resourceId, va_list *argList)
{
_bstr_t description;
WCHAR format[256];
int length = ::LoadString(::GetModuleInstance(), resourceId, format, ArraySize(format));
if (length == 0)
{
description = L"Unkown message";
}
else
{
LPWSTR buffer = NULL;
::FormatMessage (FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
format, 0, 0, (LPWSTR) &buffer, 0, argList);
if (buffer != NULL)
{
description = buffer;
LocalFree (buffer);
}
}
return description;
}
_bstr_t Exception::GetProgId (const CLSID& clsId)
{
_bstr_t progId (L"Unknown");
LPOLESTR progIdOle;
ProgIDFromCLSID (clsId, &progIdOle);
if (progIdOle != NULL)
{
progId = progIdOle;
CoTaskMemFree (progIdOle);
}
return progId;
}
} // namespace Tools
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.