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.

204 lines
5.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: R E G I S T R Y . H
  7. //
  8. // Contents: Windows NT Registry Access Class
  9. //
  10. // Notes:
  11. //
  12. // Author: kumarp 14 April 97 (09:22:00 pm)
  13. //
  14. // Notes:
  15. // kumarp 1/16/97 most of the code in this file was originally in
  16. // net\ui\rhino\common\classes\common.h
  17. // extracted only that portion related to CRegKey & related classes
  18. // kumarp 3/27/97 the original code used MFC. converted the entire code
  19. // to make it use STL
  20. //----------------------------------------------------------------------------
  21. #pragma once
  22. #include "kkstl.h"
  23. #include "ncreg.h"
  24. //----------------------------------------------------------------------------
  25. // Forward declarations
  26. //----------------------------------------------------------------------------
  27. class CORegKey ;
  28. class CORegValueIter ;
  29. class CORegKeyIter ;
  30. typedef CORegKey *PCORegKey;
  31. //
  32. // Maximum size of a Registry class name
  33. //
  34. #define CORegKEY_MAX_CLASS_NAME MAX_PATH
  35. // ----------------------------------------------------------------------
  36. // Class CORegKey
  37. //
  38. // Inheritance:
  39. // none
  40. //
  41. // Purpose:
  42. // Provides a wrapper for NT registry access functions
  43. //
  44. // Hungarian: rk
  45. // ----------------------------------------------------------------------
  46. class CORegKey
  47. {
  48. protected:
  49. HKEY m_hKey ;
  50. DWORD m_dwDisposition ;
  51. BOOL m_fInherit;
  52. // Prepare to read a value by finding the value's size.
  53. LONG PrepareValue (PCWSTR pchValueName, DWORD * pdwType,
  54. DWORD * pcbSize, BYTE ** ppbData);
  55. // Convert a TStringList to the REG_MULTI_SZ format
  56. static LONG FlattenValue (TStringList & strList, DWORD * pcbSize,
  57. BYTE ** ppbData);
  58. // Convert a TByteArray to a REG_BINARY block
  59. static LONG FlattenValue (TByteArray & abData, DWORD * pcbSize,
  60. BYTE ** ppbData);
  61. public:
  62. //
  63. // Key information return structure
  64. //
  65. typedef struct
  66. {
  67. WCHAR chBuff [CORegKEY_MAX_CLASS_NAME] ;
  68. DWORD dwClassNameSize,
  69. dwNumSubKeys,
  70. dwMaxSubKey,
  71. dwMaxClass,
  72. dwMaxValues,
  73. dwMaxValueName,
  74. dwMaxValueData,
  75. dwSecDesc ;
  76. FILETIME ftKey ;
  77. } CORegKEY_KEY_INFO ;
  78. //
  79. // Standard constructor for an existing key
  80. //
  81. CORegKey (HKEY hKeyBase, PCWSTR pchSubKey = NULL,
  82. REGSAM regSam = KEY_READ_WRITE_DELETE, PCWSTR pchServerName = NULL);
  83. //
  84. // Constructor creating a new key.
  85. //
  86. CORegKey (PCWSTR pchSubKey, HKEY hKeyBase, DWORD dwOptions = 0,
  87. REGSAM regSam = KEY_READ_WRITE_DELETE, LPSECURITY_ATTRIBUTES pSecAttr = NULL,
  88. PCWSTR pchServerName = NULL);
  89. ~ CORegKey () ;
  90. //
  91. // Allow a CORegKey to be used anywhere an HKEY is required.
  92. //
  93. operator HKEY () { return m_hKey; }
  94. //
  95. // Also provide a function to get HKEY
  96. //
  97. HKEY HKey() { return m_hKey; }
  98. //
  99. // Fill a key information structure
  100. //
  101. LONG QueryKeyInfo ( CORegKEY_KEY_INFO * pRegKeyInfo ) ;
  102. //
  103. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  104. // if data exists but not in correct form to deliver into result object.
  105. //
  106. LONG QueryValue ( PCWSTR pchValueName, tstring & strResult ) ;
  107. LONG QueryValue ( PCWSTR pchValueName, TStringList & strList ) ;
  108. LONG QueryValue ( PCWSTR pchValueName, DWORD & dwResult ) ;
  109. LONG QueryValue ( PCWSTR pchValueName, TByteArray & abResult ) ;
  110. LONG QueryValue ( PCWSTR pchValueName, void * pvResult, DWORD cbSize );
  111. // Overloaded value setting members.
  112. LONG SetValue ( PCWSTR pchValueName, tstring & strResult ) ;
  113. LONG SetValue ( PCWSTR pchValueName, tstring & strResult , BOOL fRegExpand) ;
  114. LONG SetValue ( PCWSTR pchValueName, TStringList & strList ) ;
  115. LONG SetValue ( PCWSTR pchValueName, DWORD & dwResult ) ;
  116. LONG SetValue ( PCWSTR pchValueName, TByteArray & abResult ) ;
  117. LONG SetValue ( PCWSTR pchValueName, void * pvResult, DWORD cbSize );
  118. LONG DeleteValue ( PCWSTR pchValueName );
  119. };
  120. // ----------------------------------------------------------------------
  121. // Class CORegValueIter
  122. //
  123. // Inheritance:
  124. // none
  125. //
  126. // Purpose:
  127. // Iterate the values of a key, return the name and type of each
  128. //
  129. // Hungarian: rki
  130. // ----------------------------------------------------------------------
  131. class CORegValueIter
  132. {
  133. protected:
  134. CORegKey& m_rk_iter ;
  135. DWORD m_dw_index ;
  136. PWSTR m_p_buffer ;
  137. DWORD m_cb_buffer ;
  138. public:
  139. CORegValueIter ( CORegKey & regKey ) ;
  140. ~ CORegValueIter () ;
  141. //
  142. // Get the name (and optional last write time) of the next key.
  143. //
  144. LONG Next ( tstring * pstrName, DWORD * pdwType ) ;
  145. //
  146. // Reset the iterator
  147. //
  148. void Reset () { m_dw_index = 0 ; }
  149. };
  150. // ----------------------------------------------------------------------
  151. // Class CORegKeyIter
  152. //
  153. // Inheritance:
  154. // none
  155. //
  156. // Purpose:
  157. // Iterate the sub-key names of a key.
  158. //
  159. // Hungarian: rki
  160. // ----------------------------------------------------------------------
  161. class CORegKeyIter
  162. {
  163. protected:
  164. CORegKey & m_rk_iter ;
  165. DWORD m_dw_index ;
  166. PWSTR m_p_buffer ;
  167. DWORD m_cb_buffer ;
  168. public:
  169. CORegKeyIter (CORegKey & regKey) ;
  170. ~CORegKeyIter () ;
  171. LONG Next ( tstring * pstrName );
  172. // Reset the iterator
  173. void Reset () { m_dw_index = 0 ; }
  174. };