| 1 | #pragma once |
| 2 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 3 | |
| 4 | #include "verutil.h" |
| 5 | |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
| 10 | |
| 11 | #define ReleaseRegKey(h) if (h) { ::RegCloseKey(h); h = NULL; } |
| 12 | |
| 13 | typedef enum REG_KEY_BITNESS |
| 14 | { |
| 15 | REG_KEY_DEFAULT = 0, |
| 16 | REG_KEY_32BIT = 1, |
| 17 | REG_KEY_64BIT = 2 |
| 18 | } REG_KEY_BITNESS; |
| 19 | |
| 20 | typedef LSTATUS (APIENTRY *PFN_REGCREATEKEYEXW)( |
| 21 | __in HKEY hKey, |
| 22 | __in LPCWSTR lpSubKey, |
| 23 | __reserved DWORD Reserved, |
| 24 | __in_opt LPWSTR lpClass, |
| 25 | __in DWORD dwOptions, |
| 26 | __in REGSAM samDesired, |
| 27 | __in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, |
| 28 | __out PHKEY phkResult, |
| 29 | __out_opt LPDWORD lpdwDisposition |
| 30 | ); |
| 31 | typedef LSTATUS (APIENTRY *PFN_REGOPENKEYEXW)( |
| 32 | __in HKEY hKey, |
| 33 | __in_opt LPCWSTR lpSubKey, |
| 34 | __reserved DWORD ulOptions, |
| 35 | __in REGSAM samDesired, |
| 36 | __out PHKEY phkResult |
| 37 | ); |
| 38 | typedef LSTATUS (APIENTRY *PFN_REGDELETEKEYEXW)( |
| 39 | __in HKEY hKey, |
| 40 | __in LPCWSTR lpSubKey, |
| 41 | __in REGSAM samDesired, |
| 42 | __reserved DWORD Reserved |
| 43 | ); |
| 44 | typedef LSTATUS (APIENTRY *PFN_REGDELETEKEYW)( |
| 45 | __in HKEY hKey, |
| 46 | __in LPCWSTR lpSubKey |
| 47 | ); |
| 48 | typedef LSTATUS (APIENTRY *PFN_REGENUMKEYEXW)( |
| 49 | __in HKEY hKey, |
| 50 | __in DWORD dwIndex, |
| 51 | __out LPWSTR lpName, |
| 52 | __inout LPDWORD lpcName, |
| 53 | __reserved LPDWORD lpReserved, |
| 54 | __inout_opt LPWSTR lpClass, |
| 55 | __inout_opt LPDWORD lpcClass, |
| 56 | __out_opt PFILETIME lpftLastWriteTime |
| 57 | ); |
| 58 | typedef LSTATUS (APIENTRY *PFN_REGENUMVALUEW)( |
| 59 | __in HKEY hKey, |
| 60 | __in DWORD dwIndex, |
| 61 | __out LPWSTR lpValueName, |
| 62 | __inout LPDWORD lpcchValueName, |
| 63 | __reserved LPDWORD lpReserved, |
| 64 | __out_opt LPDWORD lpType, |
| 65 | __out_opt LPBYTE lpData, |
| 66 | __out_opt LPDWORD lpcbData |
| 67 | ); |
| 68 | typedef LSTATUS (APIENTRY *PFN_REGQUERYINFOKEYW)( |
| 69 | __in HKEY hKey, |
| 70 | __out_opt LPWSTR lpClass, |
| 71 | __inout_opt LPDWORD lpcClass, |
| 72 | __reserved LPDWORD lpReserved, |
| 73 | __out_opt LPDWORD lpcSubKeys, |
| 74 | __out_opt LPDWORD lpcMaxSubKeyLen, |
| 75 | __out_opt LPDWORD lpcMaxClassLen, |
| 76 | __out_opt LPDWORD lpcValues, |
| 77 | __out_opt LPDWORD lpcMaxValueNameLen, |
| 78 | __out_opt LPDWORD lpcMaxValueLen, |
| 79 | __out_opt LPDWORD lpcbSecurityDescriptor, |
| 80 | __out_opt PFILETIME lpftLastWriteTime |
| 81 | ); |
| 82 | typedef LSTATUS (APIENTRY *PFN_REGQUERYVALUEEXW)( |
| 83 | __in HKEY hKey, |
| 84 | __in_opt LPCWSTR lpValueName, |
| 85 | __reserved LPDWORD lpReserved, |
| 86 | __out_opt LPDWORD lpType, |
| 87 | __out_bcount_part_opt(*lpcbData, *lpcbData) __out_data_source(REGISTRY) LPBYTE lpData, |
| 88 | __inout_opt LPDWORD lpcbData |
| 89 | ); |
| 90 | typedef LSTATUS (APIENTRY *PFN_REGSETVALUEEXW)( |
| 91 | __in HKEY hKey, |
| 92 | __in_opt LPCWSTR lpValueName, |
| 93 | __reserved DWORD Reserved, |
| 94 | __in DWORD dwType, |
| 95 | __in_bcount_opt(cbData) CONST BYTE* lpData, |
| 96 | __in DWORD cbData |
| 97 | ); |
| 98 | typedef LSTATUS (APIENTRY *PFN_REGDELETEVALUEW)( |
| 99 | __in HKEY hKey, |
| 100 | __in_opt LPCWSTR lpValueName |
| 101 | ); |
| 102 | typedef LSTATUS(APIENTRY *PFN_REGGETVALUEW)( |
| 103 | __in HKEY hkey, |
| 104 | __in_opt LPCWSTR lpSubKey, |
| 105 | __in_opt LPCWSTR lpValue, |
| 106 | __in DWORD dwFlags, |
| 107 | __out_opt LPDWORD pdwType, |
| 108 | __out_bcount_part_opt(*pcbData, *pcbData) __out_data_source(REGISTRY) PVOID pvData, |
| 109 | __inout_opt LPDWORD pcbData |
| 110 | ); |
| 111 | |
| 112 | /******************************************************************** |
| 113 | RegInitialize - initializes regutil |
| 114 | |
| 115 | *********************************************************************/ |
| 116 | HRESULT DAPI RegInitialize(); |
| 117 | |
| 118 | /******************************************************************** |
| 119 | RegUninitialize - uninitializes regutil |
| 120 | |
| 121 | *********************************************************************/ |
| 122 | void DAPI RegUninitialize(); |
| 123 | |
| 124 | /******************************************************************** |
| 125 | RegFunctionOverride - overrides the registry functions. Typically used |
| 126 | for unit testing. |
| 127 | |
| 128 | *********************************************************************/ |
| 129 | void DAPI RegFunctionOverride( |
| 130 | __in_opt PFN_REGCREATEKEYEXW pfnRegCreateKeyExW, |
| 131 | __in_opt PFN_REGOPENKEYEXW pfnRegOpenKeyExW, |
| 132 | __in_opt PFN_REGDELETEKEYEXW pfnRegDeleteKeyExW, |
| 133 | __in_opt PFN_REGENUMKEYEXW pfnRegEnumKeyExW, |
| 134 | __in_opt PFN_REGENUMVALUEW pfnRegEnumValueW, |
| 135 | __in_opt PFN_REGQUERYINFOKEYW pfnRegQueryInfoKeyW, |
| 136 | __in_opt PFN_REGQUERYVALUEEXW pfnRegQueryValueExW, |
| 137 | __in_opt PFN_REGSETVALUEEXW pfnRegSetValueExW, |
| 138 | __in_opt PFN_REGDELETEVALUEW pfnRegDeleteValueW, |
| 139 | __in_opt PFN_REGGETVALUEW pfnRegGetValueW |
| 140 | ); |
| 141 | |
| 142 | /******************************************************************** |
| 143 | RegFunctionForceFallback - ignore functions only available in newer versions of Windows. |
| 144 | Typically used for unit testing. |
| 145 | |
| 146 | *********************************************************************/ |
| 147 | void DAPI RegFunctionForceFallback(); |
| 148 | |
| 149 | /******************************************************************** |
| 150 | RegCreate - creates a registry key. |
| 151 | |
| 152 | *********************************************************************/ |
| 153 | HRESULT DAPI RegCreate( |
| 154 | __in HKEY hkRoot, |
| 155 | __in_z LPCWSTR wzSubKey, |
| 156 | __in DWORD dwAccess, |
| 157 | __out HKEY* phk |
| 158 | ); |
| 159 | |
| 160 | /******************************************************************** |
| 161 | RegCreateEx - creates a registry key with extra options. |
| 162 | |
| 163 | *********************************************************************/ |
| 164 | HRESULT DAPI RegCreateEx( |
| 165 | __in HKEY hkRoot, |
| 166 | __in_z LPCWSTR wzSubKey, |
| 167 | __in DWORD dwAccess, |
| 168 | __in REG_KEY_BITNESS kbKeyBitness, |
| 169 | __in BOOL fVolatile, |
| 170 | __in_opt SECURITY_ATTRIBUTES* pSecurityAttributes, |
| 171 | __out HKEY* phk, |
| 172 | __out_opt BOOL* pfCreated |
| 173 | ); |
| 174 | |
| 175 | /******************************************************************** |
| 176 | RegOpen - opens a registry key. |
| 177 | |
| 178 | *********************************************************************/ |
| 179 | HRESULT DAPI RegOpen( |
| 180 | __in HKEY hkRoot, |
| 181 | __in_z LPCWSTR wzSubKey, |
| 182 | __in DWORD dwAccess, |
| 183 | __out HKEY* phk |
| 184 | ); |
| 185 | |
| 186 | /******************************************************************** |
| 187 | RegOpenEx - opens a registry key. |
| 188 | |
| 189 | *********************************************************************/ |
| 190 | HRESULT DAPI RegOpenEx( |
| 191 | __in HKEY hkRoot, |
| 192 | __in_z LPCWSTR wzSubKey, |
| 193 | __in DWORD dwAccess, |
| 194 | __in REG_KEY_BITNESS kbKeyBitness, |
| 195 | __out HKEY* phk |
| 196 | ); |
| 197 | |
| 198 | /******************************************************************** |
| 199 | RegDelete - deletes a registry key (and optionally it's whole tree). |
| 200 | |
| 201 | *********************************************************************/ |
| 202 | HRESULT DAPI RegDelete( |
| 203 | __in HKEY hkRoot, |
| 204 | __in_z LPCWSTR wzSubKey, |
| 205 | __in REG_KEY_BITNESS kbKeyBitness, |
| 206 | __in BOOL fDeleteTree |
| 207 | ); |
| 208 | |
| 209 | /******************************************************************** |
| 210 | RegKeyEnum - enumerates child registry keys. |
| 211 | |
| 212 | *********************************************************************/ |
| 213 | HRESULT DAPI RegKeyEnum( |
| 214 | __in HKEY hk, |
| 215 | __in DWORD dwIndex, |
| 216 | __deref_out_z LPWSTR* psczKey |
| 217 | ); |
| 218 | |
| 219 | /******************************************************************** |
| 220 | RegValueEnum - enumerates registry values. |
| 221 | |
| 222 | *********************************************************************/ |
| 223 | HRESULT DAPI RegValueEnum( |
| 224 | __in HKEY hk, |
| 225 | __in DWORD dwIndex, |
| 226 | __deref_out_z LPWSTR* psczName, |
| 227 | __out_opt DWORD *pdwType |
| 228 | ); |
| 229 | |
| 230 | /******************************************************************** |
| 231 | RegGetType - reads a registry key value type. |
| 232 | *********************************************************************/ |
| 233 | HRESULT DAPI RegGetType( |
| 234 | __in HKEY hk, |
| 235 | __in_z_opt LPCWSTR wzName, |
| 236 | __out DWORD *pdwType |
| 237 | ); |
| 238 | |
| 239 | /******************************************************************** |
| 240 | RegReadBinary - reads a registry key value. |
| 241 | If fExpand is TRUE and the value is REG_EXPAND_SZ then it will be expanded. |
| 242 | NOTE: caller is responsible for freeing *ppbBuffer |
| 243 | *********************************************************************/ |
| 244 | HRESULT DAPI RegReadValue( |
| 245 | __in HKEY hk, |
| 246 | __in_z_opt LPCWSTR wzName, |
| 247 | __in BOOL fExpand, |
| 248 | __deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer, |
| 249 | __inout SIZE_T* pcbBuffer, |
| 250 | __out DWORD* pdwType |
| 251 | ); |
| 252 | |
| 253 | /******************************************************************** |
| 254 | RegReadBinary - reads a registry key binary value. |
| 255 | NOTE: caller is responsible for freeing *ppbBuffer |
| 256 | *********************************************************************/ |
| 257 | HRESULT DAPI RegReadBinary( |
| 258 | __in HKEY hk, |
| 259 | __in_z_opt LPCWSTR wzName, |
| 260 | __deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer, |
| 261 | __out SIZE_T *pcbBuffer |
| 262 | ); |
| 263 | |
| 264 | /******************************************************************** |
| 265 | RegReadString - reads a registry key value as a string. |
| 266 | |
| 267 | *********************************************************************/ |
| 268 | HRESULT DAPI RegReadString( |
| 269 | __in HKEY hk, |
| 270 | __in_z_opt LPCWSTR wzName, |
| 271 | __deref_out_z LPWSTR* psczValue |
| 272 | ); |
| 273 | |
| 274 | /******************************************************************** |
| 275 | RegReadUnexpandedString - reads a registry key value as a string without expanding it. |
| 276 | |
| 277 | *********************************************************************/ |
| 278 | HRESULT DAPI RegReadUnexpandedString( |
| 279 | __in HKEY hk, |
| 280 | __in_z_opt LPCWSTR wzName, |
| 281 | __inout BOOL* pfNeedsExpansion, |
| 282 | __deref_out_z LPWSTR* psczValue |
| 283 | ); |
| 284 | |
| 285 | /******************************************************************** |
| 286 | RegReadStringArray - reads a registry key value REG_MULTI_SZ value as a string array. |
| 287 | |
| 288 | *********************************************************************/ |
| 289 | HRESULT DAPI RegReadStringArray( |
| 290 | __in HKEY hk, |
| 291 | __in_z_opt LPCWSTR wzName, |
| 292 | __deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings, |
| 293 | __out DWORD *pcStrings |
| 294 | ); |
| 295 | |
| 296 | /******************************************************************** |
| 297 | RegReadVersion - reads a registry key value as a version. |
| 298 | |
| 299 | *********************************************************************/ |
| 300 | HRESULT DAPI RegReadVersion( |
| 301 | __in HKEY hk, |
| 302 | __in_z_opt LPCWSTR wzName, |
| 303 | __out DWORD64* pdw64Version |
| 304 | ); |
| 305 | |
| 306 | /******************************************************************** |
| 307 | RegReadWixVersion - reads a registry key value as a WiX version. |
| 308 | |
| 309 | *********************************************************************/ |
| 310 | HRESULT DAPI RegReadWixVersion( |
| 311 | __in HKEY hk, |
| 312 | __in_z_opt LPCWSTR wzName, |
| 313 | __out VERUTIL_VERSION** ppVersion |
| 314 | ); |
| 315 | |
| 316 | /******************************************************************** |
| 317 | RegReadNone - reads a NONE registry key value. |
| 318 | |
| 319 | *********************************************************************/ |
| 320 | HRESULT DAPI RegReadNone( |
| 321 | __in HKEY hk, |
| 322 | __in_z_opt LPCWSTR wzName |
| 323 | ); |
| 324 | |
| 325 | /******************************************************************** |
| 326 | RegReadNumber - reads a DWORD registry key value as a number. |
| 327 | |
| 328 | *********************************************************************/ |
| 329 | HRESULT DAPI RegReadNumber( |
| 330 | __in HKEY hk, |
| 331 | __in_z_opt LPCWSTR wzName, |
| 332 | __out DWORD* pdwValue |
| 333 | ); |
| 334 | |
| 335 | /******************************************************************** |
| 336 | RegReadQword - reads a QWORD registry key value as a number. |
| 337 | |
| 338 | *********************************************************************/ |
| 339 | HRESULT DAPI RegReadQword( |
| 340 | __in HKEY hk, |
| 341 | __in_z_opt LPCWSTR wzName, |
| 342 | __out DWORD64* pqwValue |
| 343 | ); |
| 344 | |
| 345 | /******************************************************************** |
| 346 | RegWriteBinary - writes a registry key value as a binary. |
| 347 | |
| 348 | *********************************************************************/ |
| 349 | HRESULT DAPI RegWriteBinary( |
| 350 | __in HKEY hk, |
| 351 | __in_z_opt LPCWSTR wzName, |
| 352 | __in_bcount(cbBuffer) const BYTE *pbBuffer, |
| 353 | __in DWORD cbBuffer |
| 354 | ); |
| 355 | |
| 356 | /******************************************************************** |
| 357 | RegWriteExpandString - writes a registry key value as an expand string. |
| 358 | |
| 359 | Note: if wzValue is NULL the value will be removed. |
| 360 | *********************************************************************/ |
| 361 | HRESULT DAPI RegWriteExpandString( |
| 362 | __in HKEY hk, |
| 363 | __in_z_opt LPCWSTR wzName, |
| 364 | __in_z_opt LPCWSTR wzValue |
| 365 | ); |
| 366 | |
| 367 | /******************************************************************** |
| 368 | RegWriteString - writes a registry key value as a string. |
| 369 | |
| 370 | Note: if wzValue is NULL the value will be removed. |
| 371 | *********************************************************************/ |
| 372 | HRESULT DAPI RegWriteString( |
| 373 | __in HKEY hk, |
| 374 | __in_z_opt LPCWSTR wzName, |
| 375 | __in_z_opt LPCWSTR wzValue |
| 376 | ); |
| 377 | |
| 378 | /******************************************************************** |
| 379 | RegWriteStringFormatted - writes a registry key value as a formatted string. |
| 380 | |
| 381 | *********************************************************************/ |
| 382 | HRESULT DAPIV RegWriteStringFormatted( |
| 383 | __in HKEY hk, |
| 384 | __in_z_opt LPCWSTR wzName, |
| 385 | __in __format_string LPCWSTR szFormat, |
| 386 | ... |
| 387 | ); |
| 388 | |
| 389 | /******************************************************************** |
| 390 | RegWriteStringArray - writes an array of strings as a REG_MULTI_SZ value |
| 391 | |
| 392 | *********************************************************************/ |
| 393 | HRESULT DAPI RegWriteStringArray( |
| 394 | __in HKEY hk, |
| 395 | __in_z_opt LPCWSTR wzName, |
| 396 | __in_ecount(cStrings) LPWSTR* rgwzStrings, |
| 397 | __in DWORD cStrings |
| 398 | ); |
| 399 | |
| 400 | /******************************************************************** |
| 401 | RegWriteNone - writes a registry key value as none. |
| 402 | |
| 403 | *********************************************************************/ |
| 404 | HRESULT DAPI RegWriteNone( |
| 405 | __in HKEY hk, |
| 406 | __in_z_opt LPCWSTR wzName |
| 407 | ); |
| 408 | |
| 409 | /******************************************************************** |
| 410 | RegWriteNumber - writes a registry key value as a number. |
| 411 | |
| 412 | *********************************************************************/ |
| 413 | HRESULT DAPI RegWriteNumber( |
| 414 | __in HKEY hk, |
| 415 | __in_z_opt LPCWSTR wzName, |
| 416 | __in DWORD dwValue |
| 417 | ); |
| 418 | |
| 419 | /******************************************************************** |
| 420 | RegWriteQword - writes a registry key value as a Qword. |
| 421 | |
| 422 | *********************************************************************/ |
| 423 | HRESULT DAPI RegWriteQword( |
| 424 | __in HKEY hk, |
| 425 | __in_z_opt LPCWSTR wzName, |
| 426 | __in DWORD64 qwValue |
| 427 | ); |
| 428 | |
| 429 | /******************************************************************** |
| 430 | RegQueryKey - queries the key for the number of subkeys and values. |
| 431 | |
| 432 | *********************************************************************/ |
| 433 | HRESULT DAPI RegQueryKey( |
| 434 | __in HKEY hk, |
| 435 | __out_opt DWORD* pcSubKeys, |
| 436 | __out_opt DWORD* pcValues |
| 437 | ); |
| 438 | |
| 439 | /******************************************************************** |
| 440 | RegKeyReadNumber - reads a DWORD registry key value as a number from |
| 441 | a specified subkey. |
| 442 | |
| 443 | *********************************************************************/ |
| 444 | HRESULT DAPI RegKeyReadNumber( |
| 445 | __in HKEY hk, |
| 446 | __in_z LPCWSTR wzSubKey, |
| 447 | __in_z_opt LPCWSTR wzName, |
| 448 | __in REG_KEY_BITNESS kbKeyBitness, |
| 449 | __out DWORD* pdwValue |
| 450 | ); |
| 451 | |
| 452 | /******************************************************************** |
| 453 | RegValueExists - determines whether a named value exists in a |
| 454 | specified subkey. |
| 455 | |
| 456 | *********************************************************************/ |
| 457 | BOOL DAPI RegValueExists( |
| 458 | __in HKEY hk, |
| 459 | __in_z LPCWSTR wzSubKey, |
| 460 | __in_z_opt LPCWSTR wzName, |
| 461 | __in REG_KEY_BITNESS kbKeyBitness |
| 462 | ); |
| 463 | |
| 464 | /******************************************************************** |
| 465 | RegTranslateKeyBitness - Converts from REG_KEY_BITNESS values to |
| 466 | REGSAM-compatible values. |
| 467 | |
| 468 | *********************************************************************/ |
| 469 | REGSAM DAPI RegTranslateKeyBitness( |
| 470 | __in REG_KEY_BITNESS kbKeyBitness |
| 471 | ); |
| 472 | |
| 473 | #ifdef __cplusplus |
| 474 | } |
| 475 | #endif |
| 476 |