Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1997-1998 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: iasexceptns.h
  6. //
  7. // Project: Everest
  8. //
  9. // Description: IAS Exceptions
  10. //
  11. // Author: TLP 1/20/98
  12. //
  13. ///////////////////////////////////////////////////////////////////////////
  14. #ifndef _IAS_EXCEPTIONS_H
  15. #define _IAS_EXCEPTIONS_H
  16. // Assume another include has #included ias.h
  17. // Exception Class for Win32 Errors
  18. class CWin32Error {
  19. LPTSTR m_lpMsgBuf;
  20. DWORD m_dwLastError;
  21. public:
  22. //////////////////////////////////////////////////////////////////////
  23. CWin32Error() throw()
  24. : m_lpMsgBuf(NULL)
  25. {
  26. m_dwLastError = GetLastError();
  27. }
  28. //////////////////////////////////////////////////////////////////////
  29. ~CWin32Error() throw()
  30. {
  31. if ( m_lpMsgBuf )
  32. {
  33. LocalFree( m_lpMsgBuf );
  34. }
  35. }
  36. //////////////////////////////////////////////////////////////////////
  37. DWORD Error()
  38. {
  39. return m_dwLastError;
  40. }
  41. //////////////////////////////////////////////////////////////////////
  42. LPCTSTR Reason() const throw()
  43. {
  44. DWORD dwCount;
  45. _ASSERTE ( NULL == m_lpMsgBuf );
  46. dwCount = FormatMessage(
  47. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  48. NULL,
  49. m_dwLastError,
  50. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  51. (LPTSTR) &m_lpMsgBuf,
  52. 0,
  53. NULL
  54. );
  55. if ( dwCount > 0 )
  56. {
  57. return m_lpMsgBuf;
  58. }
  59. else
  60. {
  61. return NULL;
  62. }
  63. }
  64. };
  65. #endif // __IAS_EXCEPTIONS_H