WdfRegistryQueryValue function

[Applies to KMDF and UMDF]

The WdfRegistryQueryValue method retrieves the data that is currently assigned to a specified registry value.

Syntax

NTSTATUS WdfRegistryQueryValue(
  WDFKEY           Key,
  PCUNICODE_STRING ValueName,
  ULONG            ValueLength,
  PVOID            Value,
  PULONG           ValueLengthQueried,
  PULONG           ValueType
);

Parameters

Key

A handle to a registry-key object that represents an opened registry key.

ValueName

A pointer to a UNICODE_STRING structure that contains a value name.

ValueLength

The length, in bytes, of the buffer that Value points to.

Value

A pointer to a driver-allocated buffer that receives the registry value's data. If this pointer is NULL, WdfRegistryQueryValue retrieves the data length but not the data.

ValueLengthQueried

A pointer to a location that receives the registry value's data length. This pointer is optional and can be NULL.

ValueType

A pointer to a location that receives the registry value's data type. For a list of data type values, see the Type member of KEY_VALUE_BASIC_INFORMATION. This pointer is optional and can be NULL.

Return Value

WdfRegistryQueryValue returns STATUS_SUCCESS if the operation succeeds. Otherwise, the method might return one of the following values:

Return code Description
STATUS_INVALID_DEVICE_REQUEST
WdfRegistryQueryValue was not called at IRQL = PASSIVE_LEVEL.
STATUS_INVALID_PARAMETER
An invalid parameter was specified.
STATUS_ACCESS_DENIED
The driver did not open the registry key with KEY_QUERY_VALUE, KEY_READ, or KEY_ALL_ACCESS access.
STATUS_BUFFER_OVERFLOW
The buffer that the Value parameter points to is too small, and only partial data has been written to the buffer.
STATUS_BUFFER_OVERFLOW
The Value buffer is too small, and no data has been written to the buffer.
STATUS_OBJECT_NAME_NOT_FOUND
The registry value was not available.

This method also might return other NTSTATUS values.

A bug check occurs if the driver supplies an invalid object handle.

Remarks

For more information about registry-key objects, see Using the Registry in Framework-Based Drivers.

Examples

The following code example opens a device's hardware key and retrieves the data that is assigned to the NumberOfToasters value, which is stored under the device's hardware key.

WCHAR  comPort[FM_COM_PORT_STRING_LENGTH];
ULONG  length;
NTSTATUS  status;
ULONG  length, valueType, value;
DECLARE_CONST_UNICODE_STRING(valueName, L"NumberOfToasters");
WDFKEY  hKey;

status = WdfDeviceOpenRegistryKey(
                                  Device,
                                  PLUGPLAY_REGKEY_DEVICE,
                                  KEY_QUERY_VALUE,
                                  NULL, 
                                  &hKey
                                  );
if (!NT_SUCCESS (status)) {
    goto Error;
}
status = WdfRegistryQueryValue(
                               hKey,
                               &valueName,
                               sizeof(ULONG),
                               &value,
                               &length,
                               &valueType
                               );

Requirements

   
Target Platform Universal
Minimum KMDF version 1.0
Minimum UMDF version 2.0
Header wdfregistry.h (include Wdf.h)
Library Wdf01000.sys (KMDF); WUDFx02000.dll (UMDF)
IRQL PASSIVE_LEVEL
DDI compliance rules DriverCreate, KmdfIrql, KmdfIrql2

See Also

KEY_VALUE_BASIC_INFORMATION

UNICODE_STRING

WdfDeviceOpenRegistryKey

WdfRegistryQueryMemory

WdfRegistryQueryMultiString

WdfRegistryQueryString

WdfRegistryQueryULong

WdfRegistryQueryUnicodeString