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.

185 lines
4.7 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994-1995 **
  4. //*********************************************************************
  5. //
  6. // CLSUTIL.H - header file for utility C++ classes
  7. //
  8. // HISTORY:
  9. //
  10. // 12/07/94 jeremys Borrowed from WNET common library
  11. //
  12. #ifndef _CLSUTIL_H_
  13. #define _CLSUTIL_H_
  14. /*************************************************************************
  15. NAME: BUFFER_BASE
  16. SYNOPSIS: Base class for transient buffer classes
  17. INTERFACE: BUFFER_BASE()
  18. Construct with optional size of buffer to allocate.
  19. Resize()
  20. Resize buffer to specified size. Returns TRUE if
  21. successful.
  22. QuerySize()
  23. Return the current size of the buffer in bytes.
  24. QueryPtr()
  25. Return a pointer to the buffer.
  26. PARENT: None
  27. USES: None
  28. CAVEATS: This is an abstract class, which unifies the interface
  29. of BUFFER, GLOBAL_BUFFER, etc.
  30. NOTES: In standard OOP fashion, the buffer is deallocated in
  31. the destructor.
  32. HISTORY:
  33. 03/24/93 gregj Created base class
  34. **************************************************************************/
  35. class BUFFER_BASE
  36. {
  37. protected:
  38. UINT _cb;
  39. virtual BOOL Alloc( UINT cbBuffer ) = 0;
  40. virtual BOOL Realloc( UINT cbBuffer ) = 0;
  41. public:
  42. BUFFER_BASE()
  43. { _cb = 0; } // buffer not allocated yet
  44. ~BUFFER_BASE()
  45. { _cb = 0; } // buffer size no longer valid
  46. BOOL Resize( UINT cbNew );
  47. UINT QuerySize() const { return _cb; };
  48. };
  49. #define GLOBAL_BUFFER BUFFER
  50. /*************************************************************************
  51. NAME: BUFFER
  52. SYNOPSIS: Wrapper class for new and delete
  53. INTERFACE: BUFFER()
  54. Construct with optional size of buffer to allocate.
  55. Resize()
  56. Resize buffer to specified size. Only works if the
  57. buffer hasn't been allocated yet.
  58. QuerySize()
  59. Return the current size of the buffer in bytes.
  60. QueryPtr()
  61. Return a pointer to the buffer.
  62. PARENT: BUFFER_BASE
  63. USES: operator new, operator delete
  64. CAVEATS:
  65. NOTES: In standard OOP fashion, the buffer is deallocated in
  66. the destructor.
  67. HISTORY:
  68. 03/24/93 gregj Created
  69. **************************************************************************/
  70. class BUFFER : public BUFFER_BASE
  71. {
  72. protected:
  73. TCHAR *_lpBuffer;
  74. virtual BOOL Alloc( UINT cbBuffer );
  75. virtual BOOL Realloc( UINT cbBuffer );
  76. public:
  77. BUFFER( UINT cbInitial=0 );
  78. ~BUFFER();
  79. BOOL Resize( UINT cbNew );
  80. TCHAR * QueryPtr() const { return (TCHAR *)_lpBuffer; }
  81. operator TCHAR *() const { return (TCHAR *)_lpBuffer; }
  82. };
  83. class RegEntry
  84. {
  85. public:
  86. RegEntry(const TCHAR *pszSubKey, HKEY hkey = HKEY_CURRENT_USER);
  87. ~RegEntry();
  88. long GetError() { return _error; }
  89. long SetValue(const TCHAR *pszValue, const TCHAR *string);
  90. long SetValue(const TCHAR *pszValue, unsigned long dwNumber);
  91. TCHAR * GetString(const TCHAR *pszValue, TCHAR *string, unsigned long length);
  92. long GetNumber(const TCHAR *pszValue, long dwDefault = 0);
  93. long DeleteValue(const TCHAR *pszValue);
  94. long FlushKey();
  95. long MoveToSubKey(const TCHAR *pszSubKeyName);
  96. HKEY GetKey() { return _hkey; }
  97. private:
  98. HKEY _hkey;
  99. long _error;
  100. BOOL bhkeyValid;
  101. };
  102. class RegEnumValues
  103. {
  104. public:
  105. RegEnumValues(RegEntry *pRegEntry);
  106. ~RegEnumValues();
  107. long Next();
  108. TCHAR * GetName() {return pchName;}
  109. DWORD GetType() {return dwType;}
  110. LPBYTE GetData() {return pbValue;}
  111. DWORD GetDataLength() {return dwDataLength;}
  112. long GetError() { return _error; }
  113. private:
  114. RegEntry * pRegEntry;
  115. DWORD iEnum;
  116. DWORD cEntries;
  117. TCHAR * pchName;
  118. LPBYTE pbValue;
  119. DWORD dwType;
  120. DWORD dwDataLength;
  121. DWORD cMaxValueName;
  122. DWORD cMaxData;
  123. LONG _error;
  124. };
  125. /*************************************************************************
  126. NAME: WAITCURSOR
  127. SYNOPSIS: Sets the cursor to an hourclass until object is destructed
  128. **************************************************************************/
  129. class WAITCURSOR
  130. {
  131. private:
  132. HCURSOR m_curOld;
  133. HCURSOR m_curNew;
  134. public:
  135. WAITCURSOR() { m_curNew = ::LoadCursor( NULL, IDC_WAIT ); m_curOld = ::SetCursor( m_curNew ); }
  136. ~WAITCURSOR() { ::SetCursor( m_curOld ); }
  137. };
  138. #endif // _CLSUTIL_H_