Source code of Windows XP (NT5)
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.

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