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.

104 lines
1.7 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. ErrorStr
  5. Abstract:
  6. This header file describes the error string services of the common Library.
  7. Author:
  8. Doug Barlow (dbarlow) 7/16/1996
  9. Environment:
  10. Win32, C++ w/ Exceptions
  11. Notes:
  12. --*/
  13. #ifndef _ERRORSTR_H_
  14. #define _ERRORSTR_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. extern LPCTSTR
  19. ErrorString( // Convert an error code into a string.
  20. DWORD dwErrorCode);
  21. extern void
  22. FreeErrorString( // Free the string returned from ErrorString.
  23. LPCTSTR szErrorString);
  24. inline LPCTSTR
  25. LastErrorString(
  26. void)
  27. {
  28. return ErrorString(GetLastError());
  29. }
  30. #ifdef __cplusplus
  31. }
  32. //
  33. //==============================================================================
  34. //
  35. // CErrorString
  36. //
  37. // A trivial class to simplify the use of the ErrorString service.
  38. //
  39. class CErrorString
  40. {
  41. public:
  42. // Constructors & Destructor
  43. CErrorString(DWORD dwError = 0)
  44. {
  45. m_szErrorString = NULL;
  46. SetError(dwError);
  47. };
  48. ~CErrorString()
  49. {
  50. FreeErrorString(m_szErrorString);
  51. };
  52. // Properties
  53. // Methods
  54. void SetError(DWORD dwError)
  55. {
  56. m_dwError = dwError;
  57. };
  58. LPCTSTR Value(void)
  59. {
  60. FreeErrorString(m_szErrorString);
  61. m_szErrorString = ErrorString(m_dwError);
  62. return m_szErrorString;
  63. };
  64. // Operators
  65. operator LPCTSTR(void)
  66. {
  67. return Value();
  68. };
  69. protected:
  70. // Properties
  71. DWORD m_dwError;
  72. LPCTSTR m_szErrorString;
  73. // Methods
  74. };
  75. #endif // __cplusplus
  76. #endif // _ERRORSTR_H_