Leaked source code of windows server 2003
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.

1001 lines
22 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "sfilter.h"
  4. #include "proto.h"
  5. #include "macros.h"
  6. //+---------------------------------------------------------------------------
  7. //
  8. // Member: HrRegOpenAdapterKey
  9. //
  10. // Purpose: This creates or opens the Adapters subkey to a component
  11. //
  12. // Arguments:
  13. // pszComponentName [in] The name of the component being
  14. // fCreate [in] TRUE if the directory is to be created
  15. // phkey [out] The handle to the Adapters subkey
  16. //
  17. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  18. //
  19. //
  20. // Notes: The handle has to be released by the calling app on SUCCESS
  21. //
  22. HRESULT
  23. HrRegOpenAdapterKey (
  24. IN PCWSTR pszComponentName,
  25. IN BOOL fCreate,
  26. OUT HKEY* phkey)
  27. {
  28. HRESULT hr = S_OK;
  29. DWORD dwDisposition = 0x0;
  30. tstring strKey;
  31. TraceMsg (L"--> HrRegOpenAdapterKey \n");
  32. // Build the registry path
  33. strKey = c_szRegParamAdapter;
  34. //
  35. // Now do the operation on the registry
  36. //
  37. hr = HrRegOpenAString (strKey.c_str(), fCreate, phkey);
  38. if (hr != S_OK)
  39. {
  40. phkey = NULL;
  41. }
  42. TraceMsg (L"<-- HrRegOpenAdapterKey \n");
  43. return hr;
  44. }
  45. //
  46. // Basic utility function
  47. //
  48. ULONG
  49. CbOfSzAndTermSafe (
  50. IN PCWSTR psz)
  51. {
  52. if (psz)
  53. {
  54. return (wcslen (psz) + 1) * sizeof(WCHAR);
  55. }
  56. else
  57. {
  58. return 0;
  59. }
  60. }
  61. //+---------------------------------------------------------------------------
  62. //
  63. // Member: HrRegOpenAdapterGuid
  64. //
  65. // Purpose: This creates and entry under the adapter key. The entry contains
  66. // Guid of the underlying adapter.
  67. //
  68. // Arguments:
  69. // IN HKEY phkeyAdapters - key - Service-><Protocol>->Parameters\Adapters entry,
  70. // IN PGUID pAdapterGuid - Guid of the underlying adapter
  71. // OUT PHKEY phGuidKey - The key to be used to access the new entry
  72. //
  73. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  74. // Appropriate KEy if successful
  75. //
  76. //
  77. // Notes: The handle has to be released by the calling app on SUCCESS
  78. //
  79. HRESULT
  80. HrRegOpenAdapterGuid(
  81. IN HKEY phkeyAdapters,
  82. IN PGUID pAdapterGuid,
  83. IN BOOL fCreate,
  84. OUT HKEY *phGuidKey
  85. )
  86. {
  87. HRESULT hr = S_OK;
  88. DWORD dwDisposition = 0x0;
  89. tstring strKey;
  90. WCHAR szGuid[64];
  91. ULONG lr = 0;
  92. TraceMsg (L"--> HrRegCreateAdapterGuid \n");
  93. // Build the registry path
  94. strKey = c_szRegParamAdapter;
  95. strKey.append(c_szBackslash);
  96. //
  97. // Convert the Guid to a string
  98. //
  99. StringFromGUID2(
  100. *pAdapterGuid,
  101. szGuid,
  102. (sizeof(szGuid) / sizeof(szGuid[0])));
  103. //
  104. // Append it to Services\<Protocl>\Parameters\Adapters\
  105. //
  106. strKey.append(szGuid);
  107. TraceMsg(L"Check String of Adapter Guid %s \n", strKey.wcharptr());
  108. BREAKPOINT();
  109. //
  110. // Now do the operation on the registry
  111. //
  112. hr = HrRegOpenAString (strKey.c_str(), fCreate, phGuidKey);
  113. if (hr != S_OK)
  114. {
  115. phGuidKey = NULL;
  116. }
  117. //
  118. // return the hr error code
  119. //
  120. TraceMsg (L"<-- HrRegCreateAdapterGuid \n");
  121. return hr;
  122. }
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Member: HrRegOpenAdapterKey
  126. //
  127. // Purpose: This creates and entry under the adapter Guid key. The entry is
  128. // the KeyWord "Upperbindings" and it contains the Guid of the IM
  129. // IM Miniport.
  130. //
  131. // Arguments:
  132. // IN HKEY phkeyAdapterGuid - The key to <Protocol>->Paramaters->Adapters->Guid,
  133. // IN PGUID pIMMiniportGuid, - The Guid of the IM miniport
  134. // OUT HKEY *phImMiniportKey - Key for the IMminiport key
  135. //
  136. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  137. // Appropriate KEy if successful
  138. //
  139. //
  140. // Notes: The handle has to be released by the calling app on SUCCESS
  141. //
  142. HRESULT
  143. HrRegOpenIMMiniportGuid(
  144. IN HKEY phkeyAdapterGuid,
  145. IN PGUID pIMMiniportGuid,
  146. IN BOOL fCreate,
  147. OUT PHKEY phImMiniportKey
  148. )
  149. {
  150. HRESULT hr = ERROR_INVALID_PARAMETER;
  151. tstring strDevice;
  152. WCHAR szGuid[GUID_LENGTH];
  153. DWORD dwDisposition = 0x0;
  154. HKEY hImMiniportKey = NULL;
  155. do
  156. {
  157. //
  158. // If the key, Guid is NULL Return
  159. //
  160. if ((phkeyAdapterGuid == NULL) ||
  161. (pIMMiniportGuid == NULL) )
  162. {
  163. TraceBreak (L"HrRegSetIMMiniportGuid Bad arguments\n");
  164. break;
  165. }
  166. strDevice = c_szDevice;
  167. //
  168. // Convert the Guid to a string.
  169. // Insert '\Device\' at the beginning of the string
  170. //
  171. //
  172. StringFromGUID2(
  173. *pIMMiniportGuid,
  174. szGuid,
  175. (sizeof(szGuid) / sizeof(szGuid[0])));
  176. strDevice.append(szGuid);
  177. //
  178. // Now do the operation on the registry
  179. //
  180. hr = HrRegOpenAString (strDevice.c_str(), fCreate, &hImMiniportKey);
  181. }while (FALSE);
  182. //
  183. // update the output variable
  184. //
  185. if (hr == S_OK && phImMiniportKey != NULL)
  186. {
  187. *phImMiniportKey = hImMiniportKey;
  188. }
  189. //
  190. // return the hr error code
  191. //
  192. TraceMsg (L"<-- HrRegOpenIMMiniportGuid \n");
  193. return hr;
  194. }
  195. //---------------------------------------------------------------------------
  196. // Basic Functions accessed only by the routines above
  197. //----------------------------------------------------------------------------
  198. //+---------------------------------------------------------------------------
  199. //
  200. // Function: HrRegCreateKeyEx
  201. //
  202. // Purpose: Creates a registry key by calling RegCreateKeyEx.
  203. //
  204. // Arguments:
  205. // hkey [in]
  206. // pszSubkey [in]
  207. // dwOptions [in] See the Win32 documentation for the
  208. // samDesired [in] RegCreateKeyEx function.
  209. // lpSecurityAttributes [in]
  210. // phkResult [out]
  211. // pdwDisposition [out]
  212. //
  213. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  214. //
  215. //
  216. // Notes:
  217. //
  218. HRESULT
  219. HrRegCreateKeyEx (
  220. IN HKEY hkey,
  221. IN PCWSTR pszSubkey,
  222. IN DWORD dwOptions,
  223. IN REGSAM samDesired,
  224. IN LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  225. OUT PHKEY phkResult,
  226. OUT LPDWORD pdwDisposition)
  227. {
  228. LONG lr = RegCreateKeyExW (hkey, pszSubkey, 0, NULL, dwOptions, samDesired,
  229. lpSecurityAttributes, phkResult, pdwDisposition);
  230. HRESULT hr = HRESULT_FROM_WIN32 (lr);
  231. if (FAILED(hr))
  232. {
  233. *phkResult = NULL;
  234. }
  235. TraceMsg(L"HrRegCreateKeyEx %x SubKey %s\n", hr, pszSubkey);
  236. return hr;
  237. }
  238. //+---------------------------------------------------------------------------
  239. //
  240. // Function: HrRegOpenKeyEx
  241. //
  242. // Purpose: Opens a registry key by calling RegOpenKeyEx.
  243. //
  244. // Arguments:
  245. // hkey [in]
  246. // pszSubkey [in] See the Win32 documentation for the
  247. // samDesired [in] RegOpenKeyEx function.
  248. // phkResult [out]
  249. //
  250. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  251. //
  252. //
  253. // Notes:
  254. //
  255. HRESULT
  256. HrRegOpenKeyEx (
  257. IN HKEY hkey,
  258. IN PCWSTR pszSubkey,
  259. IN REGSAM samDesired,
  260. OUT PHKEY phkResult)
  261. {
  262. HRESULT hr = ERROR_INVALID_PARAMETER;
  263. long lr = ERROR_INVALID_PARAMETER;
  264. do
  265. {
  266. if (hkey == NULL ||
  267. pszSubkey == NULL )
  268. {
  269. TraceBreak(L"HrRegOpenKey - Invalid Parameters \n");
  270. break;
  271. }
  272. lr = RegOpenKeyExW (hkey,
  273. pszSubkey,
  274. 0,
  275. samDesired,
  276. phkResult);
  277. hr = HRESULT_FROM_WIN32(lr);
  278. if (FAILED(hr))
  279. {
  280. *phkResult = NULL;
  281. }
  282. } while (FALSE);
  283. TraceMsg (L"HrRegOpenKeyEx %x, %x", hr, (ERROR_FILE_NOT_FOUND == lr));
  284. return hr;
  285. }
  286. //+---------------------------------------------------------------------------
  287. //
  288. // Function: HrRegSetValue
  289. //
  290. // Purpose: Sets the data for the given registry value by calling the
  291. // appropriate WinReg function.
  292. //
  293. // Arguments:
  294. // hkey [in]
  295. // pszValueName [in]
  296. // dwType [in] See the Win32 documentation for the RegSetValueEx
  297. // pbData [in] function.
  298. // cbData [in]
  299. //
  300. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  301. //
  302. //
  303. // Notes:
  304. //
  305. HRESULT
  306. HrRegSetSz (
  307. HKEY hkey,
  308. PCWSTR pszValueName,
  309. PCWSTR pszValue
  310. )
  311. {
  312. TraceMsg (L"--> HrHrRegSetSz \n");
  313. LONG lr = RegSetValueExW(hkey,
  314. pszValueName,
  315. 0,
  316. REG_SZ,
  317. (LPBYTE)pszValue,
  318. CbOfSzAndTermSafe (pszValue) );;
  319. HRESULT hr = HRESULT_FROM_WIN32 (lr);
  320. TraceMsg (L"<-- HrRegSetValue hr %x\n", hr);
  321. return hr;
  322. }
  323. //+---------------------------------------------------------------------------
  324. //
  325. // Function: HrRegDeleteKeyTree
  326. //
  327. // Purpose: Deletes an entire registry hive.
  328. //
  329. // Arguments:
  330. // hkeyParent [in] Handle to open key where the desired key resides.
  331. // pszRemoveKey [in] Name of key to delete.
  332. //
  333. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  334. //
  335. //
  336. // Notes:
  337. //
  338. HRESULT
  339. HrRegDeleteKeyTree (
  340. IN HKEY hkeyParent,
  341. IN PCWSTR pszRemoveKey)
  342. {
  343. // Open the key we want to remove
  344. HKEY hkeyRemove;
  345. HRESULT hr = ERROR_INVALID_PARAMETER;
  346. WCHAR szValueName [MAX_PATH];
  347. DWORD cchBuffSize = MAX_PATH;
  348. FILETIME ft;
  349. LONG lr;
  350. TraceMsg(L"-->HrRegDeleteKeyTree \n");
  351. do
  352. {
  353. hr = HrRegOpenKeyEx(hkeyParent,
  354. pszRemoveKey,
  355. KEY_ALL_ACCESS,
  356. &hkeyRemove);
  357. if (S_OK != hr)
  358. {
  359. TraceBreak(L"HrRegDeleteKeyTree->HrRegOpenKeyEx Failed\n");
  360. break;
  361. }
  362. // Enum the keys children, and remove those sub-trees
  363. while (ERROR_SUCCESS == (lr = RegEnumKeyExW (hkeyRemove,
  364. 0,
  365. szValueName,
  366. &cchBuffSize,
  367. NULL,
  368. NULL,
  369. NULL,
  370. &ft)))
  371. {
  372. HrRegDeleteKeyTree (hkeyRemove, szValueName);
  373. cchBuffSize = MAX_PATH;
  374. }
  375. RegCloseKey (hkeyRemove);
  376. if ((ERROR_SUCCESS == lr) || (ERROR_NO_MORE_ITEMS == lr))
  377. {
  378. lr = RegDeleteKeyW (hkeyParent, pszRemoveKey);
  379. }
  380. hr = HRESULT_FROM_WIN32 (lr);
  381. } while (FALSE);
  382. TraceMsg(L"<--HrRegDeleteKeyTree %x\n", hr);
  383. return hr;
  384. }
  385. //+---------------------------------------------------------------------------
  386. //
  387. // Member: HrRegOpenAString
  388. //
  389. // Purpose: This creates and entry under the adapter key. The entry contains
  390. // Guid of the underlying adapter.
  391. //
  392. // Arguments:
  393. // IN WCHAR_T *pcszStr - A string
  394. // IN BOOL fCreate - Create Or Open,
  395. // OUT PHKEY phKey - The key to be used to access the new entry
  396. //
  397. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  398. // Appropriate KEy if successful
  399. //
  400. //
  401. // Notes: The handle has to be released by the calling app on SUCCESS
  402. //
  403. HRESULT
  404. HrRegOpenAString(
  405. IN CONST WCHAR *pcszStr ,
  406. IN BOOL fCreate,
  407. OUT PHKEY phKey
  408. )
  409. {
  410. HRESULT hr = S_OK;
  411. DWORD dwDisposition = 0x0;
  412. ULONG lr = 0;
  413. TraceMsg (L"--> HrRegOpenAString\n");
  414. TraceMsg(L" String opened %s \n", pcszStr);
  415. if (fCreate)
  416. {
  417. //
  418. // Create the entry
  419. //
  420. hr = HrRegCreateKeyEx(HKEY_LOCAL_MACHINE,
  421. pcszStr,
  422. REG_OPTION_NON_VOLATILE,
  423. KEY_ALL_ACCESS,
  424. NULL ,
  425. phKey,
  426. &dwDisposition);
  427. }
  428. else
  429. {
  430. //
  431. // Open the entry
  432. //
  433. hr = HrRegOpenKeyEx( HKEY_LOCAL_MACHINE,
  434. pcszStr,
  435. KEY_READ,
  436. phKey);
  437. }
  438. if (hr != S_OK)
  439. {
  440. phKey = NULL;
  441. }
  442. //
  443. // return the hr error code
  444. //
  445. TraceMsg (L"<-- HrRegOpenAString\n");
  446. return hr;
  447. }
  448. //+---------------------------------------------------------------------------
  449. //
  450. // Function: HrRegSetValueEx
  451. //
  452. // Purpose: Sets the data for the given registry value by calling the
  453. // RegSetValueEx function.
  454. //
  455. // Arguments:
  456. // hkey [in]
  457. // pszValueName [in]
  458. // dwType [in] See the Win32 documentation for the RegSetValueEx
  459. // pbData [in] function.
  460. // cbData [in]
  461. //
  462. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  463. //
  464. //
  465. // Notes:
  466. //
  467. HRESULT
  468. HrRegSetValueEx (
  469. IN HKEY hkey,
  470. IN PCWSTR pszValueName,
  471. IN DWORD dwType,
  472. IN const BYTE *pbData,
  473. IN DWORD cbData)
  474. {
  475. LONG lr = RegSetValueExW(hkey,
  476. pszValueName,
  477. 0,
  478. dwType,
  479. pbData,
  480. cbData);
  481. HRESULT hr = HRESULT_FROM_WIN32 (lr);
  482. TraceMsg(L"--HrRegSetValue ValueName %s, Data %s, hr %x \n", pszValueName, pbData, hr);
  483. return hr;
  484. }
  485. //+---------------------------------------------------------------------------
  486. //
  487. // Function: HrRegDeleteValue
  488. //
  489. // Purpose: Deletes the given registry value.
  490. //
  491. // Arguments:
  492. // hkey [in] See the Win32 documentation for the RegDeleteValue
  493. // pszValueName [in] function.
  494. //
  495. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  496. //
  497. //
  498. // Notes:
  499. //
  500. HRESULT
  501. HrRegDeleteValue (
  502. IN HKEY hkey,
  503. IN PCWSTR pszValueName)
  504. {
  505. LONG lr = RegDeleteValueW (hkey,
  506. pszValueName);
  507. HRESULT hr = HRESULT_FROM_WIN32(lr);
  508. TraceMsg(L"--HrRegDeleteValue ValueName %s, hr %x \n", pszValueName, hr);
  509. return hr;
  510. }
  511. //+---------------------------------------------------------------------------
  512. //
  513. // Function: HrRegEnumKeyEx
  514. //
  515. // Purpose: Enumerates subkeys of the specified open registry key.
  516. //
  517. // Arguments:
  518. // hkey [in]
  519. // dwIndex [in] See the Win32 documentation for the
  520. // pszSubkeyName [out] RegEnumKeyEx function.
  521. // pcchSubkeyName [inout]
  522. // pszClass [out]
  523. // pcchClass [inout]
  524. // pftLastWriteTime [out]
  525. //
  526. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  527. //
  528. //
  529. // Notes:
  530. //
  531. HRESULT
  532. HrRegEnumKeyEx (
  533. IN HKEY hkey,
  534. IN DWORD dwIndex,
  535. OUT PWSTR pszSubkeyName,
  536. IN OUT LPDWORD pcchSubkeyName,
  537. OUT PWSTR pszClass,
  538. IN OUT LPDWORD pcchClass,
  539. OUT FILETIME* pftLastWriteTime)
  540. {
  541. LONG lr = RegEnumKeyExW (hkey, dwIndex, pszSubkeyName, pcchSubkeyName,
  542. NULL, pszClass, pcchClass, pftLastWriteTime);
  543. HRESULT hr = HRESULT_FROM_WIN32(lr);
  544. TraceMsg(L" -- HrRegEnumKeyEx");
  545. return hr;
  546. }
  547. //+---------------------------------------------------------------------------
  548. //
  549. // Function: HrRegQueryTypeWithAlloc
  550. //
  551. // Purpose: Retrieves a type'd value from the registry and returns a
  552. // pre-allocated buffer with the data and optionally the size of
  553. // the returned buffer.
  554. //
  555. // Arguments:
  556. // hkey [in] Handle of parent key
  557. // pszValueName [in] Name of value to query
  558. // ppbValue [out] Buffer with binary data
  559. // pcbValue [out] Size of buffer in bytes. If NULL, size is not
  560. // returned.
  561. //
  562. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  563. //
  564. //
  565. // Notes: Free the returned buffer with MemFree.
  566. //
  567. HRESULT
  568. HrRegQueryTypeWithAlloc (
  569. HKEY hkey,
  570. PCWSTR pszValueName,
  571. DWORD dwType,
  572. LPBYTE* ppbValue,
  573. DWORD* pcbValue)
  574. {
  575. HRESULT hr;
  576. DWORD dwTypeRet;
  577. LPBYTE pbData;
  578. DWORD cbData;
  579. // Get the value.
  580. //
  581. hr = HrRegQueryValueWithAlloc(hkey, pszValueName, &dwTypeRet,
  582. &pbData, &cbData);
  583. // It's type should be REG_BINARY. (duh).
  584. //
  585. if ((S_OK == hr) && (dwTypeRet != dwType))
  586. {
  587. MemFree(pbData);
  588. pbData = NULL;
  589. hr = HRESULT_FROM_WIN32 (ERROR_INVALID_DATATYPE);
  590. }
  591. // Assign the output parameters.
  592. if (S_OK == hr)
  593. {
  594. *ppbValue = pbData;
  595. if (pcbValue)
  596. {
  597. *pcbValue = cbData;
  598. }
  599. }
  600. else
  601. {
  602. *ppbValue = NULL;
  603. if (pcbValue)
  604. {
  605. *pcbValue = 0;
  606. }
  607. }
  608. TraceMsg (L" -- HrRegQueryTypeWithAlloc hr %x\n", hr);
  609. return hr;
  610. }
  611. //+---------------------------------------------------------------------------
  612. //
  613. // Function: HrRegQueryValueWithAlloc
  614. //
  615. // Purpose: Retrieve a registry value in a buffer allocated by this
  616. // function. This goes through the mess of checking the value
  617. // size, allocating the buffer, and then calling back to get the
  618. // actual value. Returns the buffer to the user.
  619. //
  620. // Arguments:
  621. // hkey [in] An open HKEY (the one that contains the value
  622. // to be read)
  623. // pszValueName [in] Name of the registry value
  624. // pdwType [in/out] The REG_ type that we plan to be reading
  625. // ppbBuffer [out] Pointer to an LPBYTE buffer that will contain
  626. // the registry value
  627. // pdwSize [out] Pointer to a DWORD that will contain the size
  628. // of the ppbBuffer.
  629. //
  630. //
  631. //
  632. HRESULT
  633. HrRegQueryValueWithAlloc (
  634. IN HKEY hkey,
  635. IN PCWSTR pszValueName,
  636. LPDWORD pdwType,
  637. LPBYTE* ppbBuffer,
  638. LPDWORD pdwSize)
  639. {
  640. HRESULT hr;
  641. BYTE abData [256];
  642. DWORD cbData;
  643. BOOL fReQuery = FALSE;
  644. // Initialize the output parameters.
  645. //
  646. *ppbBuffer = NULL;
  647. if (pdwSize)
  648. {
  649. *pdwSize = 0;
  650. }
  651. // Get the size of the data, and if it will fit, the data too.
  652. //
  653. cbData = sizeof(abData);
  654. hr = HrRegQueryValueEx (
  655. hkey,
  656. pszValueName,
  657. pdwType,
  658. abData,
  659. &cbData);
  660. if (HRESULT_FROM_WIN32(ERROR_MORE_DATA) == hr)
  661. {
  662. // The data didn't fit, so we'll have to requery for it after
  663. // we allocate our buffer.
  664. //
  665. fReQuery = TRUE;
  666. hr = S_OK;
  667. }
  668. if (S_OK == hr)
  669. {
  670. // Allocate the buffer for the required size.
  671. //
  672. BYTE* pbBuffer = (BYTE*)MemAlloc (cbData);
  673. if (pbBuffer)
  674. {
  675. if (fReQuery)
  676. {
  677. hr = HrRegQueryValueEx (
  678. hkey,
  679. pszValueName,
  680. pdwType,
  681. pbBuffer,
  682. &cbData);
  683. }
  684. else
  685. {
  686. CopyMemory (pbBuffer, abData, cbData);
  687. }
  688. if (S_OK == hr)
  689. {
  690. // Fill in the return values.
  691. //
  692. *ppbBuffer = pbBuffer;
  693. if (pdwSize)
  694. {
  695. *pdwSize = cbData;
  696. }
  697. }
  698. else
  699. {
  700. MemFree (pbBuffer);
  701. }
  702. }
  703. else
  704. {
  705. hr = E_OUTOFMEMORY;
  706. }
  707. }
  708. TraceMsg (L" -- HrRegQueryValueWithAlloc hr %x\n", hr);
  709. return hr;
  710. }
  711. //+---------------------------------------------------------------------------
  712. //
  713. // Function: HrRegQueryValueEx
  714. //
  715. // Purpose: Retrieves the data from the given registry value by calling
  716. // RegQueryValueEx.
  717. //
  718. // Arguments:
  719. // hkey [in]
  720. // pszValueName [in]
  721. // pdwType [out] See the Win32 documentation for the
  722. // pbData [out] RegQueryValueEx function.
  723. // pcbData [in,out]
  724. //
  725. // Returns: S_OK or an HRESULT_FROM_WIN32 error code.
  726. //
  727. //
  728. // Notes: Note that pcbData is an *in/out* param. Set this to the size
  729. // of the buffer pointed to by pbData *before* calling this
  730. // function!
  731. //
  732. HRESULT
  733. HrRegQueryValueEx (
  734. IN HKEY hkey,
  735. IN PCWSTR pszValueName,
  736. OUT LPDWORD pdwType,
  737. OUT LPBYTE pbData,
  738. OUT LPDWORD pcbData)
  739. {
  740. LONG lr = RegQueryValueExW (hkey, pszValueName, NULL, pdwType,
  741. pbData, pcbData);
  742. HRESULT hr = HRESULT_FROM_WIN32 (lr);
  743. TraceMsg (L" -- HrRegQueryValueEx hr %x\n", hr);
  744. return hr;
  745. }
  746. HRESULT
  747. HrRegQuerySzWithAlloc (
  748. HKEY hkey,
  749. PCWSTR pszValueName,
  750. PWSTR* pszValue)
  751. {
  752. return HrRegQueryTypeWithAlloc (hkey, pszValueName, REG_SZ,
  753. (LPBYTE*)pszValue, NULL);
  754. }
  755. HRESULT
  756. HrRegQueryMultiSzWithAlloc (
  757. HKEY hkey,
  758. PCWSTR pszValueName,
  759. PWSTR* pszValue)
  760. {
  761. TraceMsg (L" -- HrRegQueryMultiSzWithAlloc pszValueName %s\n",pszValueName );
  762. return HrRegQueryTypeWithAlloc (hkey,
  763. pszValueName,
  764. REG_MULTI_SZ,
  765. (LPBYTE*)pszValue,
  766. NULL);
  767. }