home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / common / lasterr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  2.2 KB  |  86 lines

  1. /////////////////////////////////////////////////////////////////
  2. //  LASTERR.H
  3. //
  4. // Copyright 1986-1996 Microsoft Corporation. All Rights Reserved.
  5. //
  6. //
  7. // last err support object.
  8. //
  9.  
  10. //There should be no global objects of this class
  11. // because by the time the dectructor of a global CLastError
  12. // is called, MAPIFreeBuffer does not work.
  13.  
  14. #ifndef __LASTERR_H__
  15. #define __LASTERR_H__
  16.  
  17. class CLastError
  18. {
  19. public:
  20.     CLastError(LPSTR);
  21.     ~CLastError(void);
  22.  
  23.     // standard OLE or MAPI errors.
  24.     HRESULT     HrSetLastError(HRESULT hr);
  25.  
  26.     // our internal extended error codes or a non-standard string for OLE or MAPI errors
  27.     // scFORM is one of the errors defined by MAKE_FORM_X_SCODE macro family
  28.     HRESULT     HrSetLastError(HRESULT hr, SCODE scFORM, ...);
  29.  
  30.     // errors returned from underlying objects.
  31.     HRESULT     HrSetLastError(HRESULT hr, IUnknown* punk);
  32.  
  33.     // our implementation of GetLastError
  34.     HRESULT     HrGetLastError(HRESULT hr, DWORD dwFlags,
  35.                                LPMAPIERROR * lppMAPIError);
  36.     
  37.     //displays the last error info
  38.     int         ShowError(HWND);
  39.  
  40.  
  41. private:
  42.     // we have three possible error types: our internal errors which
  43.     //  we signify by MAPI_E_EXTENDED to the user, standard errors
  44.     //  defined by MAPI and errors returned by objects we keep and utilize.
  45.  
  46.     enum {eNoError, eExtended, eMAPI, eObject} m_eLastErr;
  47.  
  48.     HRESULT     m_hrLast;
  49.  
  50.     HRESULT     m_hrGLE;  // what GetLastError on the object returned; mostly 0
  51.     LPMAPIERROR m_pmapierr;
  52.     LPSTR m_szComponent;
  53. };
  54.  
  55.  
  56. inline CLastError::CLastError(LPSTR szComponent)
  57. {
  58.     m_eLastErr = eNoError;
  59.     m_hrLast = 0;
  60.     m_hrGLE = 0;
  61.     m_pmapierr = 0;
  62.  
  63.     m_szComponent = NULL;
  64.     
  65.     if(!MAPIAllocateBuffer(lstrlen(szComponent) +1,
  66.                         (LPVOID *) &m_szComponent))
  67.     {
  68.         lstrcpy(m_szComponent, szComponent);
  69.     }
  70.     
  71. }
  72.  
  73. inline CLastError::~CLastError()
  74. {
  75.     if (m_pmapierr != NULL)
  76.     {
  77.         MAPIFreeBuffer(m_pmapierr);
  78.     }
  79.     if(m_szComponent != NULL)
  80.     {
  81.         MAPIFreeBuffer(m_szComponent);
  82.     }
  83. }
  84.  
  85. #endif // __LASTERR_H__
  86.