STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
_com_error Class Reference

#include <comdef.h>

Public Member Functions

 _com_error (HRESULT hr, IErrorInfo *perrinfo=NULL, bool fAddRef=false) throw ()
 
 _com_error (const _com_error &that) throw ()
 
virtual ~_com_error () throw ()
 
_com_erroroperator= (const _com_error &that) throw ()
 
HRESULT Error () const throw ()
 
WORD WCode () const throw ()
 
IErrorInfo * ErrorInfo () const throw ()
 
_bstr_t Description () const
 
DWORD HelpContext () const throw ()
 
_bstr_t HelpFile () const
 
_bstr_t Source () const
 
GUID GUID () const throw ()
 
const TCHAR * ErrorMessage () const throw ()
 

Static Public Member Functions

static HRESULT WCodeToHRESULT (WORD wCode) throw ()
 
static WORD HRESULTToWCode (HRESULT hr) throw ()
 

Private Types

enum  { WCODE_HRESULT_FIRST = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x200), WCODE_HRESULT_LAST = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF+1, 0) - 1 }
 

Private Attributes

const HRESULT m_hresult
 
IErrorInfo * m_perrinfo
 
TCHAR * m_pszMsg
 

Member Enumeration Documentation

anonymous enum
private
Enumerator
WCODE_HRESULT_FIRST 
WCODE_HRESULT_LAST 
288  {
289  WCODE_HRESULT_FIRST = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x200),
290  WCODE_HRESULT_LAST = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF+1, 0) - 1
291  };
Definition: comdef.h:290
Definition: comdef.h:289

Constructor & Destructor Documentation

_com_error::_com_error ( HRESULT  hr,
IErrorInfo *  perrinfo = NULL,
bool  fAddRef = false 
)
throw (
)
inline
301 {
302  if (m_perrinfo != NULL && fAddRef) {
303  m_perrinfo->AddRef();
304  }
305 }
#define NULL
Definition: vcruntime.h:236
const HRESULT m_hresult
Definition: comdef.h:292
TCHAR * m_pszMsg
Definition: comdef.h:294
void IErrorInfo * perrinfo
Definition: comdef.h:221
IErrorInfo * m_perrinfo
Definition: comdef.h:293
_com_error::_com_error ( const _com_error that)
throw (
)
inline
309 {
310  if (m_perrinfo != NULL) {
311  m_perrinfo->AddRef();
312  }
313 }
#define NULL
Definition: vcruntime.h:236
const HRESULT m_hresult
Definition: comdef.h:292
TCHAR * m_pszMsg
Definition: comdef.h:294
IErrorInfo * m_perrinfo
Definition: comdef.h:293
_com_error::~_com_error ( )
throw (
)
inlinevirtual
316 {
317  if (m_perrinfo != NULL) {
318  m_perrinfo->Release();
319  }
320  if (m_pszMsg != NULL) {
321  LocalFree((HLOCAL)m_pszMsg);
322  }
323 }
#define NULL
Definition: vcruntime.h:236
TCHAR * m_pszMsg
Definition: comdef.h:294
IErrorInfo * m_perrinfo
Definition: comdef.h:293

Member Function Documentation

_bstr_t _com_error::Description ( ) const
inline
353 {
354  BSTR bstr = NULL;
355  if (m_perrinfo != NULL) {
356  if (FAILED(m_perrinfo->GetDescription(&bstr))) {
357  bstr = NULL;
358  }
359  }
360  return _bstr_t(bstr, false);
361 }
Definition: comutil.h:144
#define NULL
Definition: vcruntime.h:236
#define FAILED(hr)
Definition: comutil.h:71
IErrorInfo * m_perrinfo
Definition: comdef.h:293
HRESULT _com_error::Error ( ) const
throw (
)
inline
335 {
336  return m_hresult;
337 }
const HRESULT m_hresult
Definition: comdef.h:292
IErrorInfo * _com_error::ErrorInfo ( ) const
throw (
)
inline
345 {
346  if (m_perrinfo != NULL) {
347  m_perrinfo->AddRef();
348  }
349  return m_perrinfo;
350 }
#define NULL
Definition: vcruntime.h:236
IErrorInfo * m_perrinfo
Definition: comdef.h:293
const TCHAR * _com_error::ErrorMessage ( ) const
throw (
)
inline
408 {
409  if (m_pszMsg == NULL) {
410  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
411  FORMAT_MESSAGE_FROM_SYSTEM|
412  FORMAT_MESSAGE_IGNORE_INSERTS,
413  NULL,
414  m_hresult,
415  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
416  (LPTSTR)&m_pszMsg,
417  0,
418  NULL);
419  if (m_pszMsg != NULL) {
420  #ifdef UNICODE
421  size_t const nLen = wcslen(m_pszMsg);
422  #else
423  size_t const nLen = strlen(m_pszMsg);
424  #endif
425  if (nLen > 1 && m_pszMsg[nLen - 1] == '\n') {
426  m_pszMsg[nLen - 1] = 0;
427  if (m_pszMsg[nLen - 2] == '\r') {
428  m_pszMsg[nLen - 2] = 0;
429  }
430  }
431  }
432  else {
433  m_pszMsg = (LPTSTR)LocalAlloc(0, 32 * sizeof(TCHAR));
434  if (m_pszMsg != NULL) {
435  WORD wCode = WCode();
436  if (wCode != 0) {
437  _COM_PRINTF_S_1(m_pszMsg, 32, TEXT("IDispatch error #%d"), (int)wCode);
438  }
439  else {
440  _COM_PRINTF_S_1(m_pszMsg, 32, TEXT("Unknown error 0x%0lX"), m_hresult);
441  }
442  }
443  }
444  }
445  return m_pszMsg;
446 }
#define NULL
Definition: vcruntime.h:236
const HRESULT m_hresult
Definition: comdef.h:292
TCHAR * m_pszMsg
Definition: comdef.h:294
#define _COM_PRINTF_S_1(dest, destsize, format, arg1)
Definition: comutil.h:49
WORD WCode() const
Definition: comdef.h:339
_GUID _com_error::GUID ( ) const
throw (
)
inline
397 {
398  _GUID guid{};
399  if (m_perrinfo != NULL) {
400  if (FAILED(m_perrinfo->GetGUID(&guid))) {
401  guid = _GUID{};
402  }
403  }
404  return guid;
405 }
#define NULL
Definition: vcruntime.h:236
#define FAILED(hr)
Definition: comutil.h:71
IErrorInfo * m_perrinfo
Definition: comdef.h:293
DWORD _com_error::HelpContext ( ) const
throw (
)
inline
364 {
365  DWORD dwHelpContext = 0;
366  if (m_perrinfo != NULL) {
367  if (FAILED(m_perrinfo->GetHelpContext(&dwHelpContext))) {
368  dwHelpContext = 0;
369  }
370  }
371  return dwHelpContext;
372 }
#define NULL
Definition: vcruntime.h:236
#define FAILED(hr)
Definition: comutil.h:71
unsigned long DWORD
Definition: concrt.h:63
IErrorInfo * m_perrinfo
Definition: comdef.h:293
_bstr_t _com_error::HelpFile ( ) const
inline
375 {
376  BSTR bstr = NULL;
377  if (m_perrinfo != NULL) {
378  if (FAILED(m_perrinfo->GetHelpFile(&bstr))) {
379  bstr = NULL;
380  }
381  }
382  return _bstr_t(bstr, false);
383 }
Definition: comutil.h:144
#define NULL
Definition: vcruntime.h:236
#define FAILED(hr)
Definition: comutil.h:71
IErrorInfo * m_perrinfo
Definition: comdef.h:293
WORD _com_error::HRESULTToWCode ( HRESULT  hr)
throw (
)
inlinestatic
454 {
455  return (hr >= WCODE_HRESULT_FIRST && hr <= WCODE_HRESULT_LAST)
456  ? WORD(hr - WCODE_HRESULT_FIRST)
457  : 0;
458 }
Definition: comdef.h:290
Definition: comdef.h:289
_com_error & _com_error::operator= ( const _com_error that)
throw (
)
inline
326 {
327  if (this != &that) {
328  this->_com_error::~_com_error();
329  this->_com_error::_com_error(that);
330  }
331  return *this;
332 }
virtual ~_com_error()
Definition: comdef.h:315
_com_error(HRESULT hr, IErrorInfo *perrinfo=NULL, bool fAddRef=false)
Definition: comdef.h:297
_bstr_t _com_error::Source ( ) const
inline
386 {
387  BSTR bstr = NULL;
388  if (m_perrinfo != NULL) {
389  if (FAILED(m_perrinfo->GetSource(&bstr))) {
390  bstr = NULL;
391  }
392  }
393  return _bstr_t(bstr, false);
394 }
Definition: comutil.h:144
#define NULL
Definition: vcruntime.h:236
#define FAILED(hr)
Definition: comutil.h:71
IErrorInfo * m_perrinfo
Definition: comdef.h:293
WORD _com_error::WCode ( ) const
throw (
)
inline
340 {
341  return HRESULTToWCode(m_hresult);
342 }
const HRESULT m_hresult
Definition: comdef.h:292
static WORD HRESULTToWCode(HRESULT hr)
Definition: comdef.h:453
HRESULT _com_error::WCodeToHRESULT ( WORD  wCode)
throw (
)
inlinestatic
449 {
450  return wCode >= 0xFE00 ? WCODE_HRESULT_LAST : WCODE_HRESULT_FIRST + wCode;
451 }
Definition: comdef.h:290
Definition: comdef.h:289

Member Data Documentation

const HRESULT _com_error::m_hresult
private
IErrorInfo* _com_error::m_perrinfo
private
TCHAR* _com_error::m_pszMsg
mutableprivate

The documentation for this class was generated from the following file: