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.

226 lines
5.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: registry.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INC_CSCVIEW_REGISTRY_H
  11. #define _INC_CSCVIEW_REGISTRY_H
  12. #ifndef _WINDOWS_
  13. # include <windows.h>
  14. #endif
  15. //
  16. // Represents a single registry key. Provides basic functions for
  17. // opening and closing the key as well as setting and querying for
  18. // values in that key. Closure of the key handle is ensured through
  19. // the destructor.
  20. //
  21. class RegKey
  22. {
  23. public:
  24. //
  25. // Class for iterating values in the key.
  26. //
  27. class ValueIterator
  28. {
  29. public:
  30. explicit ValueIterator(RegKey& key);
  31. HRESULT Next(LPTSTR pszName, UINT cchName, LPDWORD pdwType, LPBYTE pbData, LPDWORD pcbData);
  32. private:
  33. RegKey& m_key;
  34. int m_iValue;
  35. int m_cchValueName;
  36. };
  37. //
  38. // Flags used by QueryInfo().
  39. //
  40. enum
  41. {
  42. QIM_SUBKEYCNT = 0x00000001,
  43. QIM_SUBKEYMAXCHARCNT = 0x00000002,
  44. QIM_CLASSMAXCHARCNT = 0x00000004,
  45. QIM_VALUECNT = 0x00000008,
  46. QIM_VALUENAMEMAXCHARCNT = 0x00000010,
  47. QIM_VALUEMAXBYTECNT = 0x00000020,
  48. QIM_LASTWRITETIME = 0x00000040,
  49. QIM_SECURITYBYTECNT = 0x00000080,
  50. QIM_ALL = 0xFFFFFFFF
  51. };
  52. //
  53. // Data returned by QueryInfo().
  54. //
  55. struct KEYINFO
  56. {
  57. DWORD cSubKeys;
  58. DWORD cchSubKeyMax;
  59. DWORD cchClassMax;
  60. DWORD cValues;
  61. DWORD cchValueNameMax;
  62. DWORD cbValueMax;
  63. DWORD cbSecurityDesc;
  64. FILETIME LastWriteTime;
  65. };
  66. RegKey(void);
  67. RegKey(HKEY hkeyRoot, LPCTSTR pszSubKey);
  68. virtual ~RegKey(void);
  69. operator HKEY(void) const
  70. { return m_hkey; }
  71. HKEY GetHandle(void) const
  72. { return m_hkey; }
  73. bool IsOpen(void) const
  74. { return NULL != m_hkey; }
  75. HRESULT Open(REGSAM samDesired, bool bCreate = false) const;
  76. void Attach(HKEY hkey);
  77. void Detach(void);
  78. void Close(void) const;
  79. LPCTSTR SubKeyName(void) const
  80. { return m_szSubKey; }
  81. int GetValueBufferSize(
  82. LPCTSTR pszValueName) const;
  83. HRESULT ValueExists(
  84. LPCTSTR pszValueName) const;
  85. //
  86. // Retrieve REG_DWORD
  87. //
  88. HRESULT GetValue(
  89. LPCTSTR pszValueName,
  90. DWORD *pdwDataOut) const;
  91. //
  92. // Retrieve REG_BINARY
  93. //
  94. HRESULT GetValue(
  95. LPCTSTR pszValueName,
  96. LPBYTE pbDataOut,
  97. int cbDataOut) const;
  98. //
  99. // Retrieve REG_SZ
  100. //
  101. HRESULT GetValue(
  102. LPCTSTR pszValueName,
  103. LPTSTR pszData,
  104. UINT cchData) const;
  105. //
  106. // Retrieve REG_MULTI_SZ
  107. //
  108. HRESULT GetValue(
  109. LPCTSTR pszValueName,
  110. HDPA hdpaStringsOut) const;
  111. //
  112. // Set REG_DWORD
  113. //
  114. HRESULT SetValue(
  115. LPCTSTR pszValueName,
  116. DWORD dwData);
  117. //
  118. // Set REG_BINARY
  119. //
  120. HRESULT SetValue(
  121. LPCTSTR pszValueName,
  122. const LPBYTE pbData,
  123. int cbData);
  124. //
  125. // Set REG_SZ
  126. //
  127. HRESULT SetValue(
  128. LPCTSTR pszValueName,
  129. LPCTSTR pszData);
  130. //
  131. // Set REG_MULTI_SZ
  132. //
  133. HRESULT SetValue(
  134. LPCTSTR pszValueName,
  135. HDPA dpaStrings);
  136. HRESULT DeleteValue(
  137. LPCTSTR pszValue);
  138. HRESULT DeleteAllValues(
  139. int *pcNotDeleted);
  140. HRESULT QueryInfo(RegKey::KEYINFO *pInfo, DWORD fMask) const;
  141. RegKey::ValueIterator CreateValueIterator(void)
  142. { return ValueIterator(*this); }
  143. private:
  144. HKEY m_hkeyRoot;
  145. mutable HKEY m_hkey;
  146. TCHAR m_szSubKey[MAX_PATH];
  147. HRESULT SetValue(
  148. LPCTSTR pszValueName,
  149. DWORD dwValueType,
  150. const LPBYTE pbData,
  151. int cbData);
  152. HRESULT GetValue(
  153. LPCTSTR pszValueName,
  154. DWORD dwTypeExpected,
  155. LPBYTE pbData,
  156. int cbData) const;
  157. LPTSTR CreateDoubleNulTermList(
  158. HDPA hdpaStrings) const;
  159. //
  160. // Prevent copy.
  161. //
  162. RegKey(const RegKey& rhs);
  163. RegKey& operator = (const RegKey& rhs);
  164. };
  165. //
  166. // Use this object when you can't trust HKEY_CURRENT_USER to be correct.
  167. // It uses the new NT5 API RegOpenCurrentUser to open the key.
  168. //
  169. class RegKeyCU
  170. {
  171. public:
  172. RegKeyCU(REGSAM samDesired);
  173. ~RegKeyCU(void);
  174. operator HKEY(void) const
  175. { return m_hkey; }
  176. private:
  177. HKEY m_hkey;
  178. };
  179. LONG
  180. _RegEnumValueExp(
  181. HKEY hKey,
  182. DWORD dwIndex,
  183. LPTSTR lpValueName,
  184. LPDWORD lpcbValueName,
  185. LPDWORD lpReserved,
  186. LPDWORD lpType,
  187. LPBYTE lpData,
  188. LPDWORD lpcbData);
  189. #endif // _INC_CSCVIEW_REGISTRY_H