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.

359 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. reg.h
  5. Abstract:
  6. Implements macros to simplify the registry APIs and to track
  7. the resource allocations.
  8. Author:
  9. Jim Schmidt (jimschm) 24-Mar-1997
  10. Revision History:
  11. jimschm 09-Apr-1997 Expanded Get functionality
  12. --*/
  13. #pragma once
  14. //
  15. // Reg API simplification routines
  16. //
  17. typedef struct {
  18. HKEY KeyHandle;
  19. BOOL OpenedByEnum;
  20. DWORD Index;
  21. WCHAR SubKeyName[MAX_PATH];
  22. } REGKEY_ENUMW, *PREGKEY_ENUMW;
  23. typedef struct {
  24. HKEY KeyHandle;
  25. DWORD Index;
  26. WCHAR ValueName[MAX_PATH];
  27. DWORD Type;
  28. DWORD DataSize;
  29. } REGVALUE_ENUMW, *PREGVALUE_ENUMW;
  30. typedef struct _tagREGKEYINFOW {
  31. WCHAR KeyName[MAX_PATH];
  32. HKEY KeyHandle;
  33. REGKEY_ENUMW KeyEnum;
  34. UINT BaseKeyBytes;
  35. struct _tagREGKEYINFOW *Parent, *Child;
  36. } REGKEYINFOW, *PREGKEYINFOW;
  37. typedef enum {
  38. ENUMERATE_SUBKEY_BEGIN,
  39. ENUMERATE_SUBKEY_RETURN,
  40. ENUMERATE_SUBKEY_NEXT,
  41. ENUMERATE_SUBKEY_DONE,
  42. NO_MORE_ITEMS
  43. } REGTREESTATE;
  44. typedef struct {
  45. WCHAR FullKeyName[MAX_PATH];
  46. UINT FullKeyNameBytes;
  47. UINT EnumBaseBytes;
  48. PREGKEYINFOW CurrentKey;
  49. POOLHANDLE EnumPool;
  50. REGTREESTATE State;
  51. BOOL FirstEnumerated;
  52. } REGTREE_ENUMW, *PREGTREE_ENUMW;
  53. //
  54. // Enum functions
  55. //
  56. BOOL
  57. EnumFirstRegKeyW (
  58. OUT PREGKEY_ENUMW EnumPtr,
  59. IN HKEY hKey
  60. );
  61. BOOL
  62. RealEnumFirstRegKeyStrW (
  63. OUT PREGKEY_ENUMW EnumPtr,
  64. IN PCWSTR RegKey
  65. );
  66. #define EnumFirstRegKeyStrA RealEnumFirstRegKeyStrA
  67. #define EnumFirstRegKeyStrW RealEnumFirstRegKeyStrW
  68. BOOL
  69. EnumNextRegKeyW (
  70. IN OUT PREGKEY_ENUMW EnumPtr
  71. );
  72. VOID
  73. AbortRegKeyEnumW (
  74. IN OUT PREGKEY_ENUMW EnumPtr
  75. );
  76. BOOL
  77. RealEnumFirstRegKeyInTreeW (
  78. OUT PREGTREE_ENUMW EnumPtr,
  79. IN PCWSTR BaseKeyStr
  80. );
  81. #define EnumFirstRegKeyInTreeW(e,base) RealEnumFirstRegKeyInTreeW(e,base)
  82. BOOL
  83. RealEnumNextRegKeyInTreeW (
  84. IN OUT PREGTREE_ENUMW EnumPtr
  85. );
  86. #define EnumNextRegKeyInTreeW(e) RealEnumNextRegKeyInTreeW(e)
  87. VOID
  88. AbortRegKeyTreeEnumW (
  89. IN OUT PREGTREE_ENUMW EnumPtr
  90. );
  91. BOOL
  92. EnumFirstRegValueW (
  93. OUT PREGVALUE_ENUMW EnumPtr,
  94. IN HKEY hKey
  95. );
  96. BOOL
  97. EnumNextRegValueW (
  98. IN OUT PREGVALUE_ENUMW EnumPtr
  99. );
  100. //
  101. // Versions that allow caller to specify allocator, and macro that uses
  102. // MemAllocWrapper
  103. //
  104. typedef PVOID (ALLOCATOR_PROTOTYPE)(DWORD Size);
  105. typedef ALLOCATOR_PROTOTYPE * ALLOCATOR;
  106. ALLOCATOR_PROTOTYPE MemAllocWrapper;
  107. typedef VOID (DEALLOCATOR_PROTOTYPE)(PVOID Mem);
  108. typedef DEALLOCATOR_PROTOTYPE * DEALLOCATOR;
  109. DEALLOCATOR_PROTOTYPE MemFreeWrapper;
  110. BOOL
  111. GetRegValueTypeAndSizeW (
  112. IN HKEY Key,
  113. IN PCWSTR ValueName,
  114. OUT PDWORD OutType, OPTIONAL
  115. OUT PDWORD Size OPTIONAL
  116. );
  117. PBYTE
  118. GetRegValueData2W (
  119. IN HKEY hKey,
  120. IN PCWSTR Value,
  121. IN ALLOCATOR Allocator,
  122. IN DEALLOCATOR Deallocator
  123. );
  124. #define GetRegValueDataW(key,valuename) GetRegValueData2W((key),(valuename),MemAllocWrapper,MemFreeWrapper)\
  125. PBYTE
  126. GetRegValueDataOfType2W (
  127. IN HKEY hKey,
  128. IN PCWSTR Value,
  129. IN DWORD MustBeType,
  130. IN ALLOCATOR Allocator,
  131. IN DEALLOCATOR Deallocator
  132. );
  133. #define GetRegValueDataOfTypeW(key,valuename,type) GetRegValueDataOfType2W((key),(valuename),(type),MemAllocWrapper,MemFreeWrapper)
  134. PBYTE
  135. GetRegKeyData2W (
  136. IN HKEY hKey,
  137. IN PCWSTR SubKey,
  138. IN ALLOCATOR Allocator,
  139. IN DEALLOCATOR Deallocator
  140. );
  141. #define GetRegKeyDataW(key,subkey) GetRegKeyData2W((key),(subkey),MemAllocWrapper,MemFreeWrapper)
  142. PBYTE
  143. GetRegData2W (
  144. IN PCWSTR KeyString,
  145. IN PCWSTR ValueName,
  146. IN ALLOCATOR Allocator,
  147. IN DEALLOCATOR Deallocator
  148. );
  149. #define GetRegDataW(keystr,value) GetRegData2W((keystr),(value),MemAllocWrapper,MemFreeWrapper)
  150. BOOL
  151. GetRegSubkeysCount (
  152. IN HKEY ParentKey,
  153. OUT PDWORD SubKeyCount, OPTIONAL
  154. OUT PDWORD MaxSubKeyLen OPTIONAL
  155. );
  156. //
  157. // Reg key create & open
  158. //
  159. HKEY
  160. RealCreateRegKeyW (
  161. IN HKEY ParentKey,
  162. IN PCWSTR NewKeyName
  163. );
  164. HKEY
  165. RealCreateRegKeyStrW (
  166. IN PCWSTR NewKeyName
  167. );
  168. HKEY
  169. RealOpenRegKeyStrW (
  170. IN PCWSTR RegKey
  171. );
  172. HKEY
  173. RealOpenRegKeyW (
  174. IN HKEY ParentKey,
  175. IN PCWSTR KeyToOpen
  176. );
  177. LONG
  178. RealCloseRegKey (
  179. IN HKEY Key
  180. );
  181. #define CloseRegKey RealCloseRegKey
  182. #define CreateRegKeyW RealCreateRegKeyW
  183. #define CreateRegKeyStrW RealCreateRegKeyStrW
  184. #define OpenRegKeyStrW RealOpenRegKeyStrW
  185. #define OpenRegKeyW RealOpenRegKeyW
  186. //
  187. // Registry root functions
  188. //
  189. VOID
  190. SetRegRoot (
  191. IN HKEY Root
  192. );
  193. HKEY
  194. GetRegRoot (
  195. VOID
  196. );
  197. // Returns non-zero array offset to root, or zero if no root matches
  198. INT GetOffsetOfRootStringW (PCWSTR RootString, PDWORD LengthPtr OPTIONAL);
  199. // Returns non-zero array offset to root, or zero if no root matches
  200. INT GetOffsetOfRootKey (HKEY RootKey);
  201. // Given non-zero array offset to root, returns string or NULL if element
  202. // is out of bounds
  203. PCWSTR GetRootStringFromOffsetW (INT i);
  204. // Given non-zero array offset to root, returns registry handle or NULL if
  205. // element is out of bounds
  206. HKEY GetRootKeyFromOffset (INT i);
  207. // Converts the root at the head of RegPath to an HKEY and gives the number
  208. // of characters occupied by the root string (including optional wack)
  209. HKEY ConvertRootStringToKeyW (PCWSTR RegPath, PDWORD LengthPtr OPTIONAL);
  210. // Returns a pointer to a static string for the matching root, or NULL if
  211. // RegRoot does not point to a valid root
  212. PCWSTR ConvertKeyToRootStringW (HKEY RegRoot);
  213. //
  214. // Macros
  215. //
  216. #define GetRegValueStringW(key,valuename) (PWSTR) GetRegValueDataOfTypeW((key),(valuename),REG_SZ)
  217. #define GetRegValueBinaryW(key,valuename) (PBYTE) GetRegValueDataOfTypeW((key),(valuename),REG_BINARY)
  218. #define GetRegValueMultiSzW(key,valuename) (PWSTR) GetRegValueDataOfTypeW((key),(valuename),REG_MULTISZ)
  219. #define GetRegValueDwordW(key,valuename) (PDWORD) GetRegValueDataOfTypeW((key),(valuename),REG_DWORD)
  220. #define GetRegValueString2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_SZ,alloc,free)
  221. #define GetRegValueBinary2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_BINARY,alloc,free)
  222. #define GetRegValueMultiSz2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_MULTISZ,alloc,free)
  223. #define GetRegValueDword2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_DWORD,alloc,free)
  224. #ifdef UNICODE
  225. #define REGKEY_ENUM REGKEY_ENUMW
  226. #define PREGKEY_ENUM PREGKEY_ENUMW
  227. #define REGVALUE_ENUM REGVALUE_ENUMW
  228. #define PREGVALUE_ENUM PREGVALUE_ENUMW
  229. #define REGTREE_ENUM REGTREE_ENUMW
  230. #define PREGTREE_ENUM PREGTREE_ENUMW
  231. #define EnumFirstRegKey EnumFirstRegKeyW
  232. #define EnumFirstRegKeyStr EnumFirstRegKeyStrW
  233. #define EnumNextRegKey EnumNextRegKeyW
  234. #define AbortRegKeyEnum AbortRegKeyEnumW
  235. #define EnumFirstRegKeyInTree EnumFirstRegKeyInTreeW
  236. #define EnumNextRegKeyInTree EnumNextRegKeyInTreeW
  237. #define AbortRegKeyTreeEnum AbortRegKeyTreeEnumW
  238. #define EnumFirstRegValue EnumFirstRegValueW
  239. #define EnumNextRegValue EnumNextRegValueW
  240. #define GetRegValueTypeAndSize GetRegValueTypeAndSizeW
  241. #define GetRegValueData GetRegValueDataW
  242. #define GetRegValueDataOfType GetRegValueDataOfTypeW
  243. #define GetRegKeyData GetRegKeyDataW
  244. #define GetRegValueData2 GetRegValueData2W
  245. #define GetRegValueDataOfType2 GetRegValueDataOfType2W
  246. #define GetRegKeyData2 GetRegKeyData2W
  247. #define GetRegValueString GetRegValueStringW
  248. #define GetRegValueBinary GetRegValueBinaryW
  249. #define GetRegValueMultiSz GetRegValueMultiSzW
  250. #define GetRegValueDword GetRegValueDwordW
  251. #define GetRegValueString2 GetRegValueString2W
  252. #define GetRegValueBinary2 GetRegValueBinary2W
  253. #define GetRegValueMultiSz2 GetRegValueMultiSz2W
  254. #define GetRegValueDword2 GetRegValueDword2W
  255. #define GetRegData2 GetRegData2W
  256. #define GetRegData GetRegDataW
  257. #define CreateRegKey CreateRegKeyW
  258. #define CreateRegKeyStr CreateRegKeyStrW
  259. #define OpenRegKey OpenRegKeyW
  260. #define OpenRegKeyStr OpenRegKeyStrW
  261. #define GetOffsetOfRootString GetOffsetOfRootStringW
  262. #define GetRootStringFromOffset GetRootStringFromOffsetW
  263. #define ConvertRootStringToKey ConvertRootStringToKeyW
  264. #define ConvertKeyToRootString ConvertKeyToRootStringW
  265. #define CreateEncodedRegistryString CreateEncodedRegistryStringW
  266. #define CreateEncodedRegistryStringEx CreateEncodedRegistryStringExW
  267. #define FreeEncodedRegistryString FreeEncodedRegistryStringW
  268. #endif
  269. VOID
  270. RegistrySearchAndReplaceW (
  271. IN PCWSTR Root,
  272. IN PCWSTR Search,
  273. IN PCWSTR Replace
  274. );