IOCTL_GET_HCD_DRIVERKEY_NAME IOCTL (usbioctl.h)

IOCTL_GET_HCD_DRIVERKEY_NAME I/O 控制请求检索 USB 主机控制器驱动程序注册表中的驱动程序密钥名称。

IOCTL_GET_HCD_DRIVERKEY_NAME 是用户模式 I/O 控制请求。 此请求面向 USB 主机控制器(GUID_DEVINTERFACE_USB_HOST_CONTROLLER)。

主要代码

IRP_MJ_DEVICE_CONTROL

输入缓冲区

没有。

输入缓冲区长度

没有。

输出缓冲区

AssociatedIrp.SystemBuffer 成员指定包含 USB_HCD_DRIVERKEY_NAME 结构的调用方分配缓冲区的地址。 在输出中,此结构保存驱动程序密钥名称。 有关详细信息,请参阅“备注”。

输出缓冲区长度

此缓冲区的大小在 Parameters.DeviceIoControl.OutputBufferLength 成员中指定。

状态块

USB 堆栈 Irp->IoStatus.Status 设置为STATUS_SUCCESS(如果请求成功)。 否则,USB 堆栈会将 状态 设置为适当的错误条件,例如STATUS_INVALID_PARAMETER或STATUS_INSUFFICIENT_RESOURCES。

言论

若要在注册表中获取驱动程序密钥名称,必须执行以下任务:

  1. 声明类型 USB_HCD_DRIVERKEY_NAME变量。
  2. 通过在输出参数中指定变量的地址和大小来发送 IOCTL_GET_HCD_DRIVERKEY_NAME 请求。 返回时,ActualLength 成员 USB_HCD_DRIVERKEY_NAME 包含分配缓冲区以保存用驱动程序密钥名称填充的 USB_HCD_DRIVERKEY_NAME 所需的长度。
  3. 为缓冲区分配内存以保存 USB_HCD_DRIVERKEY_NAME 结构。 缓冲区的大小必须是接收 ActualLength 值。
  4. 通过将指针传递给分配的缓冲区及其大小,在输出参数中发送 IOCTL_GET_HCD_DRIVERKEY_NAME 请求。 返回时,USB_HCD_DRIVERKEY_NAMEDriverKeyName 成员是一个以 null 结尾的 Unicode 字符串,其中包含与主机控制器驱动程序关联的驱动程序密钥的名称。
以下示例代码演示如何发送 IOCTL_GET_HCD_DRIVERKEY_NAME I/O 控制请求。

/*++

Routine Description:

This routine prints the name of the driver key associated with
the specified host controller driver.

Arguments:

HCD - Handle for host controller driver.

Return Value: Boolean that indicates success or failure.

--*/

BOOL GetHCDDriverKeyName (HANDLE  HCD)
{
    BOOL                    success;
    ULONG                   nBytes;
    USB_HCD_DRIVERKEY_NAME  driverKeyName;
    PUSB_HCD_DRIVERKEY_NAME driverKeyNameW;

    driverKeyNameW = NULL;

    // 1. Get the length of the name of the driver key.
    success = DeviceIoControl(HCD,
        IOCTL_GET_HCD_DRIVERKEY_NAME,
        NULL,
        0,
        &driverKeyName,
        sizeof(driverKeyName),
        &nBytes,
        NULL);

    if (!success) 
    {
        printf("First IOCTL_GET_HCD_DRIVERKEY_NAME request failed\n");
        goto GetHCDDriverKeyNameDone;
    }

    //2. Get the length of the driver key name.
    nBytes = driverKeyName.ActualLength;

    if (nBytes <= sizeof(driverKeyName)) 
    {
        printf("Incorrect length received by IOCTL_GET_HCD_DRIVERKEY_NAME.\n");
        goto GetHCDDriverKeyNameDone;
    }

    // 3. Allocate memory for a USB_HCD_DRIVERKEY_NAME
    //    to hold the driver key name.
    driverKeyNameW = (PUSB_HCD_DRIVERKEY_NAME) malloc(nBytes);

    if (driverKeyNameW == NULL) 
    {
        printf("Failed to allocate memory.\n");
        goto GetHCDDriverKeyNameDone;
    }

    // Get the name of the driver key of the device attached to
    // the specified port.
    success = DeviceIoControl(HCD,
        IOCTL_GET_HCD_DRIVERKEY_NAME,
        NULL,
        0,
        driverKeyNameW,
        nBytes,
        &nBytes,
        NULL);

    if (!success) 
    {
        printf("Second IOCTL_GET_HCD_DRIVERKEY_NAME request failed.\n");
        goto GetHCDDriverKeyNameDone;
    }

    // print the driver key name. 
    printf("Driver Key Name: %s.\n", driverKeyNameW->DriverKeyName);


GetHCDDriverKeyNameDone:

    // Cleanup.
    // Free the allocated memory for USB_HCD_DRIVERKEY_NAME.

    if (driverKeyNameW != NULL) 
    {
        free(driverKeyNameW);
        driverKeyNameW = NULL;
    }

    return success;
}


要求

要求 价值
标头 usbioctl.h (包括 Usbioctl.h)

另请参阅

USB_HCD_DRIVERKEY_NAME