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.

413 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. REGKEY.HXX
  7. Win32 Configuration Registry Support
  8. This class provides the C++ interface to the Win32/NT Configuration
  9. Registry. Since the Registry is a tree of multi-valued keys, the
  10. basic class here represents a node in the tree.
  11. The Win32 Registry does not allow querying the name of a key, so
  12. the name of the key is preserved as part of each key object.
  13. Due to the number and variety of parameters used by Registry
  14. API functions, structures are used to contain sets of parameters
  15. to simplify the interface.
  16. FILE HISTORY:
  17. DavidHov 9/10/91 Created
  18. KeithMo 23-Oct-1991 Added forward references.
  19. DavidHov 28-Jan-92 Converted to Win32 Registry APIs
  20. DavidHov 18-Oct-92 Removed internal tree maintenance
  21. terryk 06-Nov-92 Added binary data support
  22. JonN 20-Jan-2002 Removed REG_ENUM, Copy and DeleteTree
  23. */
  24. #ifndef _REGKEY_HXX_
  25. #define _REGKEY_HXX_
  26. extern "C"
  27. {
  28. #include <winreg.h>
  29. }
  30. #define REG_VALUE_NOT_KNOWN (0xffffffff)
  31. #include "strlst.hxx"
  32. /***********************************************************************
  33. * Interface Support Structures *
  34. ***********************************************************************/
  35. // Support structure for key creation
  36. DLL_CLASS REG_KEY_CREATE_STRUCT : public BASE
  37. {
  38. public:
  39. REG_KEY_CREATE_STRUCT () ;
  40. ULONG dwTitleIndex ; // IN: Title index
  41. ULONG ulOptions ; // IN: options (TBD?)
  42. NLS_STR nlsClass ; // IN: class name
  43. REGSAM regSam ; // IN: SAM control
  44. LPSECURITY_ATTRIBUTES pSecAttr ; // IN: ACL
  45. ULONG ulDisposition ; // IN: disposition
  46. };
  47. // Support structure for QueryInfo
  48. DLL_CLASS REG_KEY_INFO_STRUCT : public BASE
  49. {
  50. public:
  51. REG_KEY_INFO_STRUCT () ;
  52. NLS_STR nlsName ; // OUT: name of subkey
  53. NLS_STR nlsClass ; // OUT: name of class
  54. ULONG ulTitleIndex ; // OUT: title index
  55. ULONG ulSubKeys ; // OUT: number of subkeys
  56. ULONG ulMaxSubKeyLen ; // OUT: length of longest subkey
  57. ULONG ulMaxClassLen ; // OUT: length of longest class name
  58. ULONG ulValues ; // OUT: number of values
  59. ULONG ulMaxValueIdLen ; // OUT: length of longest value name
  60. ULONG ulMaxValueLen ; // OUT: length of longest value data
  61. ULONG ulSecDescLen ; // OUT: length of security descriptor
  62. FILETIME ftLastWriteTime ; // OUT: date/time node was last written
  63. };
  64. // Structure for value query/set/add
  65. DLL_CLASS REG_VALUE_INFO_STRUCT : public BASE
  66. {
  67. public:
  68. REG_VALUE_INFO_STRUCT () ;
  69. NLS_STR nlsValueName ; // IN OUT: name of value
  70. ULONG ulTitle ; // IN OUT: title index
  71. ULONG ulType ; // IN OUT: type
  72. BYTE * pwcData ; // IN OUT: data buffer
  73. ULONG ulDataLength ; // IN : length of data buffer
  74. ULONG ulDataLengthOut ; // OUT : size of data required/stored
  75. };
  76. //
  77. // Forward references.
  78. //
  79. DLL_CLASS REG_KEY;
  80. DLL_CLASS REG_ENUM;
  81. /*************************************************************************
  82. NAME: REG_KEY
  83. SYNOPSIS: Win32 Registry Interface Class
  84. A REG_KEY represents a single node in the Registry.
  85. INTERFACE:
  86. PARENT: BASE
  87. USES: NLS_STR
  88. CAVEATS:
  89. NOTES:
  90. HISTORY:
  91. DavidHov 9/10/91 Created
  92. **************************************************************************/
  93. DLL_CLASS REG_KEY : public BASE
  94. {
  95. friend class REG_ENUM ;
  96. public:
  97. // Open a descendent sub-key by name using string
  98. REG_KEY ( REG_KEY & regNode,
  99. const NLS_STR & nlsSubKey,
  100. REGSAM amMask = MAXIMUM_ALLOWED ) ;
  101. // Create a descendent sub-key using string
  102. REG_KEY ( REG_KEY & regNode,
  103. const NLS_STR & nlsSubKey,
  104. REG_KEY_CREATE_STRUCT * prcCreate ) ;
  105. // Open a key on another machine
  106. REG_KEY ( HKEY hKey,
  107. const TCHAR * pszMachineName,
  108. REGSAM rsDesired = MAXIMUM_ALLOWED ) ;
  109. // Constructor using just an HKEY: only HKEY_LOCAL_MACHINE
  110. // or HKEY_CURRENT_USER are allowed.
  111. REG_KEY ( HKEY hKey,
  112. REGSAM rsDesired = MAXIMUM_ALLOWED ) ;
  113. // Open a key solely by name; name MUST have been obtained
  114. // from REG_KEY::QueryName().
  115. REG_KEY ( const NLS_STR & nlsKeyName,
  116. REGSAM amMask = MAXIMUM_ALLOWED ) ;
  117. // Copy constructor: clone a registry node
  118. REG_KEY ( REG_KEY & regNode ) ;
  119. // Destroy a node
  120. ~ REG_KEY () ;
  121. // Commit changes to the node
  122. APIERR Flush () ;
  123. // Delete a node; subkeys must be deleted first.
  124. APIERR Delete () ;
  125. // Query the node's information
  126. APIERR QueryInfo ( REG_KEY_INFO_STRUCT * pRegInfoStruct ) ;
  127. // Return info about the given value
  128. APIERR QueryValue ( REG_VALUE_INFO_STRUCT * pRegValueInfo ) ;
  129. // Change a value add a new one.
  130. APIERR SetValue ( REG_VALUE_INFO_STRUCT * pRegValueInfo ) ;
  131. // Delete a value by name (string)
  132. APIERR DeleteValue ( const NLS_STR & nlsValueName ) ;
  133. // Enhanced value manipulation operations
  134. // Query/Set single string values
  135. APIERR QueryValue (
  136. const TCHAR * pszValueName,
  137. NLS_STR * pnlsValue,
  138. ULONG cchMax = 0,
  139. DWORD * pdwTitle = NULL,
  140. BOOL fExpandSz = FALSE ) ;
  141. APIERR SetValue (
  142. const TCHAR * pszValueName,
  143. const NLS_STR * pnlsValue,
  144. const DWORD * pdwTitle = NULL,
  145. BOOL fExpandSz = FALSE ) ;
  146. // Query a value string; if cchMax==0, key is queried to
  147. // determine maximum size of any value.
  148. APIERR QueryValue (
  149. const TCHAR * pszValueName,
  150. TCHAR * * ppchValue,
  151. ULONG cchMax = 0,
  152. DWORD * pdwTitle = NULL,
  153. BOOL fExpandSz = FALSE ) ;
  154. // Set value string; if cchLen==0, string length is counted.
  155. APIERR SetValue (
  156. const TCHAR * pszValueName,
  157. const TCHAR * pchValue,
  158. ULONG cchLen = 0,
  159. const DWORD * pdwTitle = NULL,
  160. BOOL fExpandSz = FALSE ) ;
  161. // Query/Set numeric values
  162. APIERR QueryValue (
  163. const TCHAR * pszValueName,
  164. DWORD * pdwValue,
  165. DWORD * pdwTitle = NULL ) ;
  166. APIERR SetValue (
  167. const TCHAR * pszValueName,
  168. DWORD dwValue,
  169. const DWORD * pdwTitle = NULL ) ;
  170. // Query/Set Binary values
  171. APIERR QueryValue (
  172. const TCHAR * pszValueName,
  173. BYTE ** ppbByte,
  174. LONG *pcbSize,
  175. LONG cbMax = 0,
  176. DWORD * pdwTitle = NULL ) ;
  177. APIERR SetValue (
  178. const TCHAR * pszValueName,
  179. const BYTE * pByte,
  180. const LONG cbSize,
  181. const DWORD * pdwTitle = NULL ) ;
  182. // Query/Set Registry values of type REG_MULTI_SZ
  183. // use STRLIST (groups of strings)
  184. APIERR QueryValue (
  185. const TCHAR * pszValueName,
  186. STRLIST * * ppStrList,
  187. DWORD * pdwTitle = NULL ) ;
  188. APIERR SetValue (
  189. const TCHAR * pszValueName,
  190. const STRLIST * pStrList,
  191. const DWORD * pdwTitle = NULL ) ;
  192. // Obtain the full name up to the top HKEY
  193. APIERR QueryName ( NLS_STR * pnlsName, BOOL fComplete = TRUE ) const ;
  194. // Obtain the name of this key
  195. APIERR QueryKeyName ( NLS_STR * pnlsName ) const ;
  196. // Duplicate a key, including all subkeys and values. Argument
  197. // is source; receiver is destination.
  198. // JonN 1/21/02 Removed Copy since it depends on REG_ENUM
  199. // APIERR Copy ( REG_KEY & regNode ) ;
  200. // Delete a key and all its subordinate keys.
  201. // Warning: state is indeterminate after failure.
  202. // JonN 1/21/02 Removed DeleteTree since it depends on REG_ENUM
  203. // APIERR DeleteTree () ;
  204. // Return a new instance of REG_KEY representing a
  205. // standard Registry access point.
  206. static REG_KEY * QueryLocalMachine ( REGSAM rsDesired = MAXIMUM_ALLOWED ) ;
  207. static REG_KEY * QueryCurrentUser ( REGSAM rsDesired = MAXIMUM_ALLOWED ) ;
  208. // Conversion operator returning naked HKEY
  209. operator HKEY () const
  210. { return _hKey ; }
  211. private:
  212. LONG _lApiErr ; // Generic NT error code
  213. HKEY _hKey ; // Registry handle
  214. NLS_STR _nlsKeyName ; // Key name string
  215. REGSAM _amMask ; // Registry-specific access control
  216. // Open a child of this node,
  217. APIERR OpenChild ( REG_KEY * pRkChild,
  218. const NLS_STR & nlsSubKey,
  219. REGSAM rsDesired = MAXIMUM_ALLOWED,
  220. DWORD dwOptions = 0 ) ;
  221. // Open a key based on a string
  222. APIERR OpenByName ( const NLS_STR & nlsKeyName,
  223. REGSAM rsDesired = MAXIMUM_ALLOWED ) ;
  224. // Close the underlying handle
  225. APIERR Close () ;
  226. // Store the name of the child node into it.
  227. APIERR NameChild ( REG_KEY * prkChild,
  228. const NLS_STR & nlsSubKey ) const ;
  229. // Create a subkey to a REG_KEY; return resulting HKEY.
  230. APIERR CreateChild
  231. ( REG_KEY * pRkNew,
  232. const NLS_STR & nlsSubKey,
  233. REG_KEY_CREATE_STRUCT * prnStruct ) const ;
  234. // Open the parent of this key
  235. REG_KEY * OpenParent ( REGSAM rsDesired = MAXIMUM_ALLOWED ) ;
  236. // Return a pointer to the final segment of the key name
  237. const TCHAR * LeafKeyName () const ;
  238. // Extract the parent key name from this key's name.
  239. APIERR ParentName ( NLS_STR * pnlsParentName ) const ;
  240. static BOOL HandlePrefix ( const NLS_STR & nlsKeyName,
  241. HKEY * pHkey,
  242. NLS_STR * pnlsMachineName,
  243. NLS_STR * pnlsRemainder ) ;
  244. // Generic base QueryValue worker function for string data
  245. APIERR QueryKeyValueString
  246. ( const TCHAR * pszValueName,
  247. TCHAR * * ppszResult,
  248. NLS_STR * pnlsResult,
  249. DWORD * pdwTitle,
  250. LONG cchMaxSize,
  251. LONG * pcchSize,
  252. DWORD dwType ) ;
  253. APIERR SetKeyValueString
  254. ( const TCHAR * pszValueName,
  255. const TCHAR * pszValue,
  256. DWORD dwTitle,
  257. LONG lcbSize,
  258. DWORD dwType ) ;
  259. APIERR QueryKeyValueBinary
  260. ( const TCHAR * pszValueName,
  261. BYTE ** ppbByte,
  262. LONG * pcchSize,
  263. LONG cchMaxSize,
  264. DWORD * pdwTitle,
  265. DWORD dwType ) ;
  266. APIERR SetKeyValueBinary
  267. ( const TCHAR * pszValueName,
  268. const BYTE * pbValue,
  269. LONG lcbSize,
  270. DWORD dwTitle,
  271. DWORD dwType ) ;
  272. APIERR REG_KEY :: QueryKeyValueLong
  273. ( const TCHAR * pszValueName,
  274. LONG * pnResult,
  275. DWORD * pdwTitle ) ;
  276. APIERR REG_KEY :: SetKeyValueLong
  277. ( const TCHAR * pszValueName,
  278. LONG nNewValue,
  279. DWORD dwTitle ) ;
  280. };
  281. #if 0
  282. // removed 1/20/02 JonN
  283. /*************************************************************************
  284. NAME: REG_ENUM
  285. SYNOPSIS: REG_KEY Sub-key and Value Enumerator
  286. Objects of this class are used to enumerate the sub-keys
  287. or the values belonging to a REG_KEY.
  288. INTERFACE:
  289. PARENT: BASE
  290. USES: REG_KEY
  291. CAVEATS:
  292. NOTES: Only one type of enumeration can be done at a time.
  293. Switching is allowed, but will result in a restart
  294. from the zeroth element.
  295. HISTORY:
  296. DavidHov 9/12/91 Created
  297. **************************************************************************/
  298. DLL_CLASS REG_ENUM : public BASE
  299. {
  300. public:
  301. REG_ENUM ( REG_KEY & regNode ) ;
  302. ~ REG_ENUM () ;
  303. APIERR NextSubKey ( REG_KEY_INFO_STRUCT * pRegInfoStruct ) ;
  304. APIERR NextValue ( REG_VALUE_INFO_STRUCT * pRegValueInfo ) ;
  305. VOID Reset () ; // Reset the enumeration
  306. private:
  307. REG_KEY & _rnNode ; // Node being enumerated
  308. ULONG _ulIndex ; // Value index
  309. APIERR _usLastErr ; // Last error returned
  310. enum RENUM_TYPE { RENUM_NONE, RENUM_KEYS, RENUM_VALUES } _eType ;
  311. };
  312. #endif
  313. #endif /* _REGKEY_HXX_ */