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.

425 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. registry.h
  5. Abstract:
  6. Registry classes definitions
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. #ifndef _REGISTRY_H
  14. #define _REGISTRY_H
  15. //
  16. // Forward declarations
  17. //
  18. class CRMCRegKey;
  19. class CRMCRegValueIter;
  20. class CRMCRegKeyIter;
  21. //
  22. // Maximum size of a Registry class name
  23. //
  24. #define CREGKEY_MAX_CLASS_NAME MAX_PATH
  25. //
  26. // Parameter helper
  27. //
  28. #define EXPANSION_ON (TRUE)
  29. #define EXPANSION_OFF (FALSE)
  30. class COMDLL CRMCRegKey : public CObject
  31. /*++
  32. Class Description:
  33. Registry key class.
  34. Public Interface:
  35. CRMCRegKey : Registry key object constructor
  36. ~CRMCRegKey : Registry key object destructor
  37. operator HKEY : cast to HKEY handle
  38. GetHandle : Get HKEY handle
  39. Ok : TRUE if the key was initialized OK, FALSE otherwise.
  40. IsLocal : TRUE if the key was opened on the local machine
  41. QueryKeyInfo : Fill a key information structure
  42. QueryValue : Overloaded value query members
  43. SetValue : Overloaded set value members
  44. AssertValid : Assert the object is in a valid state (debug only)
  45. Dump : Dump to the debug context (debug only)
  46. --*/
  47. {
  48. public:
  49. //
  50. // Key information return structure
  51. //
  52. typedef struct
  53. {
  54. TCHAR chBuff[CREGKEY_MAX_CLASS_NAME];
  55. DWORD dwClassNameSize,
  56. dwNumSubKeys,
  57. dwMaxSubKey,
  58. dwMaxClass,
  59. dwMaxValues,
  60. dwMaxValueName,
  61. dwMaxValueData,
  62. dwSecDesc;
  63. FILETIME ftKey;
  64. } CREGKEY_KEY_INFO;
  65. //
  66. // Constructor/Destructor
  67. //
  68. public:
  69. //
  70. // Standard constructor for an existing key
  71. //
  72. CRMCRegKey(
  73. IN HKEY hKeyBase,
  74. IN LPCTSTR lpszSubKey = NULL,
  75. IN REGSAM regSam = KEY_ALL_ACCESS,
  76. IN LPCTSTR lpszServerName = NULL
  77. );
  78. //
  79. // Constructor creating a new key.
  80. //
  81. CRMCRegKey(
  82. OUT BOOL * pfNewKeyCreated,
  83. IN HKEY hKeyBase,
  84. IN LPCTSTR lpszSubKey = NULL,
  85. IN DWORD dwOptions = REG_OPTION_NON_VOLATILE,
  86. IN REGSAM regSam = KEY_ALL_ACCESS,
  87. IN LPSECURITY_ATTRIBUTES pSecAttr = NULL,
  88. IN LPCTSTR lpszServerName = NULL
  89. );
  90. ~CRMCRegKey();
  91. //
  92. // Interface
  93. //
  94. public:
  95. //
  96. // Allow a CRMCRegKey to be used anywhere an HKEY is required.
  97. //
  98. operator HKEY() const;
  99. HKEY GetHandle() const;
  100. BOOL Ok() const;
  101. BOOL IsLocal() const;
  102. //
  103. // Fill a key information structure
  104. //
  105. DWORD QueryKeyInfo(
  106. OUT CREGKEY_KEY_INFO * pRegKeyInfo
  107. );
  108. //
  109. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  110. // if data exists but not in correct form to deliver into result object.
  111. //
  112. public:
  113. //
  114. // Autoexpand will automatically expand REG_EXPAND_SZ items on the
  115. // local computer.
  116. //
  117. DWORD QueryValue(
  118. IN LPCTSTR lpszValueName,
  119. OUT CString & strResult,
  120. IN BOOL fAutoExpand = EXPANSION_OFF,
  121. OUT BOOL * pfExpanded = NULL
  122. );
  123. DWORD QueryValue(
  124. IN LPCTSTR lpszValueName,
  125. OUT CStringListEx & strList
  126. );
  127. DWORD QueryValue(
  128. IN LPCTSTR lpszValueName,
  129. OUT DWORD & dwResult
  130. );
  131. DWORD QueryValue(
  132. IN LPCTSTR lpszValueName,
  133. OUT CByteArray & abResult
  134. );
  135. DWORD QueryValue(
  136. IN LPCTSTR lpszValueName,
  137. OUT void * pvResult,
  138. OUT DWORD cbSize
  139. );
  140. //
  141. // Overloaded value setting members.
  142. //
  143. public:
  144. //
  145. // AutoDeflate will attempt to use %SystemRoot% in the path
  146. // and write it as REG_EXPAND_SZ. if *pfDeflate = TRUE
  147. // upon entry, REG_EXPAND_SZ will be set as well, but
  148. // not automatic environment substitution will be performed.
  149. //
  150. // Otherwise, this will set as REG_SZ.
  151. //
  152. DWORD SetValue(
  153. IN LPCTSTR lpszValueName,
  154. IN CString & strResult,
  155. IN BOOL fAutoDeflate = EXPANSION_OFF,
  156. OUT BOOL * pfDeflate = NULL
  157. );
  158. DWORD SetValue(
  159. IN LPCTSTR lpszValueName,
  160. IN CStringListEx & strList
  161. );
  162. DWORD SetValue(
  163. IN LPCTSTR lpszValueName,
  164. IN DWORD & dwResult
  165. );
  166. DWORD SetValue(
  167. IN LPCTSTR lpszValueName,
  168. IN CByteArray & abResult
  169. );
  170. DWORD SetValue(
  171. IN LPCTSTR lpszValueName,
  172. IN void * pvResult,
  173. IN DWORD cbSize
  174. );
  175. //
  176. // Delete Key/Value
  177. //
  178. public:
  179. DWORD DeleteValue(LPCTSTR lpszValueName);
  180. DWORD DeleteKey(LPCTSTR lpszSubKey);
  181. #ifdef _DEBUG
  182. virtual void AssertValid() const;
  183. virtual void Dump(
  184. IN OUT CDumpContext& dc
  185. ) const;
  186. #endif // _DEBUG
  187. protected:
  188. //
  189. // Convert a CStringListEx to the REG_MULTI_SZ format
  190. //
  191. static DWORD FlattenValue(
  192. IN CStringListEx & strList,
  193. OUT DWORD * pcbSize,
  194. OUT BYTE ** ppbData
  195. );
  196. //
  197. // Convert a CByteArray to a REG_BINARY block
  198. //
  199. static DWORD FlattenValue(
  200. IN CByteArray & abData,
  201. OUT DWORD * pcbSize,
  202. OUT BYTE ** ppbData
  203. );
  204. protected:
  205. //
  206. // Prepare to read a value by finding the value's size.
  207. //
  208. DWORD PrepareValue(
  209. LPCTSTR lpszValueName,
  210. DWORD * pdwType,
  211. DWORD * pcbSize,
  212. BYTE ** ppbData
  213. );
  214. private:
  215. BOOL m_fLocal;
  216. HKEY m_hKey;
  217. DWORD m_dwDisposition;
  218. };
  219. class COMDLL CRMCRegValueIter : public CObject
  220. /*++
  221. Class Description:
  222. Registry value iteration class
  223. Public Interface:
  224. CRMCRegValueIter : Iteration class constructor
  225. ~CRMCRegValueIter : Iteration class destructor
  226. Next : Get the name of the next key
  227. Reset : Reset the iterator
  228. --*/
  229. {
  230. //
  231. // Constructor/Destructor
  232. //
  233. public:
  234. CRMCRegValueIter(
  235. IN CRMCRegKey & regKey
  236. );
  237. ~CRMCRegValueIter();
  238. //
  239. // Interface
  240. //
  241. public:
  242. //
  243. // Get the name (and optional last write time) of the next key.
  244. //
  245. DWORD Next(
  246. OUT CString * pstrName,
  247. OUT DWORD * pdwType
  248. );
  249. //
  250. // Reset the iterator
  251. //
  252. void Reset();
  253. protected:
  254. CRMCRegKey & m_rkIter;
  255. DWORD m_dwIndex;
  256. TCHAR * m_pBuffer;
  257. DWORD m_cbBuffer;
  258. };
  259. class COMDLL CRMCRegKeyIter : public CObject
  260. /*++
  261. Class Description:
  262. Iterate the sub-key names of a key
  263. Public Interface:
  264. CRMCRegKeyIter : Iteration class constructor
  265. ~CRMCRegKeyIter : Iteration class destructor
  266. Next : Get the name of the next key
  267. Reset : Reset the iterator
  268. --*/
  269. {
  270. public:
  271. CRMCRegKeyIter(
  272. IN CRMCRegKey & regKey
  273. );
  274. ~CRMCRegKeyIter();
  275. //
  276. // Interface
  277. //
  278. public:
  279. //
  280. // Get the name (and optional last write time) of the next key.
  281. //
  282. DWORD Next(
  283. OUT CString * pstrName,
  284. OUT CTime * pTime = NULL
  285. );
  286. //
  287. // Reset the iterator
  288. //
  289. void Reset();
  290. private:
  291. CRMCRegKey & m_rkIter;
  292. DWORD m_dwIndex;
  293. TCHAR * m_pBuffer;
  294. DWORD m_cbBuffer;
  295. };
  296. //
  297. // Inline Expansion
  298. //
  299. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  300. inline CRMCRegKey::operator HKEY() const
  301. {
  302. return m_hKey;
  303. }
  304. inline HKEY CRMCRegKey::GetHandle() const
  305. {
  306. return m_hKey;
  307. }
  308. inline BOOL CRMCRegKey::Ok() const
  309. {
  310. return m_hKey != NULL;
  311. }
  312. inline BOOL CRMCRegKey::IsLocal() const
  313. {
  314. return m_fLocal;
  315. }
  316. inline DWORD CRMCRegKey::DeleteValue(
  317. IN LPCTSTR lpszValueName
  318. )
  319. {
  320. return ::RegDeleteValue(*this, lpszValueName);
  321. }
  322. inline DWORD CRMCRegKey::DeleteKey(
  323. IN LPCTSTR lpszSubKey
  324. )
  325. {
  326. return ::RegDeleteKey(*this, lpszSubKey);
  327. }
  328. inline void CRMCRegValueIter::Reset()
  329. {
  330. m_dwIndex = 0L;
  331. }
  332. inline void CRMCRegKeyIter::Reset()
  333. {
  334. m_dwIndex = 0L;
  335. }
  336. #endif // _REGISTRY_H