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.

167 lines
5.5 KiB

  1. /***************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Dot4Usb.sys - Lower Filter Driver for Dot4.sys for USB connected
  5. IEEE 1284.4 devices.
  6. File Name:
  7. Registry.c
  8. Abstract:
  9. Registry access utility functions
  10. Environment:
  11. Kernel mode only
  12. Notes:
  13. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  14. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  16. PURPOSE.
  17. Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
  18. Revision History:
  19. 01/18/2000 : created
  20. Author(s):
  21. Doug Fritz (DFritz)
  22. Joby Lafky (JobyL)
  23. ****************************************************************************/
  24. #include "pch.h"
  25. /************************************************************************/
  26. /* RegGetDword */
  27. /************************************************************************/
  28. //
  29. // Routine Description:
  30. //
  31. // - Read a DWORD value from the registry (with caller specified
  32. // default value) given an absolute KeyPath.
  33. //
  34. // - If we are unable to read the value from the registry for any
  35. // reason (e.g., no ValueName entry exists) then return the
  36. // default value passed into the function in *Value.
  37. //
  38. // Arguments:
  39. //
  40. // KeyPath - absolute path to registry key
  41. // ValueName - name of the value to retrieve
  42. // Value - in - points to a default value
  43. // - out - points to the location for returned value
  44. // Return Value:
  45. //
  46. // NTSTATUS
  47. //
  48. /************************************************************************/
  49. NTSTATUS
  50. RegGetDword(
  51. IN PCWSTR KeyPath,
  52. IN PCWSTR ValueName,
  53. IN OUT PULONG Value
  54. )
  55. {
  56. NTSTATUS status;
  57. RTL_QUERY_REGISTRY_TABLE paramTable[2];
  58. D4UAssert( KeyPath && ValueName && Value );
  59. RtlZeroMemory( &paramTable[0], sizeof(paramTable) );
  60. paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
  61. paramTable[0].Name = (PWSTR)ValueName; // cast away const
  62. paramTable[0].EntryContext = Value;
  63. paramTable[0].DefaultType = REG_DWORD;
  64. paramTable[0].DefaultData = Value;
  65. paramTable[0].DefaultLength = sizeof(ULONG);
  66. // leave paramTable[1] as all zeros - this terminates the table
  67. status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL,
  68. KeyPath,
  69. &paramTable[0],
  70. NULL,
  71. NULL );
  72. TR_VERBOSE(("registry::RegGetDword - status = %x , *Value = %x\n", status, *Value));
  73. return status;
  74. }
  75. /************************************************************************/
  76. /* RegGetDeviceParameterDword */
  77. /************************************************************************/
  78. //
  79. // Routine Description:
  80. //
  81. // - Read a DWORD value from the registry (with caller specified
  82. // default value) given a PDO.
  83. //
  84. // - If we are unable to read the value from the registry for any
  85. // reason (e.g., no ValueName entry exists) then return the
  86. // default value passed into the function in *Value.
  87. //
  88. // Arguments:
  89. //
  90. // Pdo - PDO for which we want to read the device parameter
  91. // ValueName - name of the value to retrieve
  92. // Value - in - points to a default value
  93. // - out - points to the location for returned value
  94. // Return Value:
  95. //
  96. // NTSTATUS
  97. //
  98. /************************************************************************/
  99. NTSTATUS
  100. RegGetDeviceParameterDword(
  101. IN PDEVICE_OBJECT Pdo,
  102. IN PCWSTR ValueName,
  103. IN OUT PULONG Value
  104. )
  105. {
  106. NTSTATUS status;
  107. HANDLE hKey;
  108. D4UAssert( Pdo && ValueName && Value );
  109. status = IoOpenDeviceRegistryKey( Pdo, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &hKey );
  110. if( NT_SUCCESS(status) ) {
  111. RTL_QUERY_REGISTRY_TABLE queryTable[2];
  112. RtlZeroMemory(&queryTable, sizeof(queryTable));
  113. queryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
  114. queryTable[0].Name = (PWSTR)ValueName; // cast away const
  115. queryTable[0].EntryContext = Value;
  116. queryTable[0].DefaultType = REG_DWORD;
  117. queryTable[0].DefaultData = Value;
  118. queryTable[0].DefaultLength = sizeof(ULONG);
  119. status = RtlQueryRegistryValues( RTL_REGISTRY_HANDLE | RTL_REGISTRY_OPTIONAL,
  120. hKey,
  121. queryTable,
  122. NULL,
  123. NULL );
  124. ZwClose(hKey);
  125. TR_VERBOSE(("registry::RegGetDeviceParameterDword - status = %x , *Value = %x\n", status, *Value));
  126. }
  127. return status;
  128. }