USB Device Driver Installation

The HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients registry key must be set up correctly so that the USBD module can load the appropriate driver for a device when a device is attached to the bus. Each installed USB device driver must have a subkey within the LoadClients key for the USBD module to load it.

For a USB device driver supplied by an OEM, the OEM should configure the LoadClients registry key in a platform’s .reg file to include keys for the driver. For third-party peripherals, however, the driver does not have appropriate registry keys when first connected to the platform. In this case, the USBD module fails to locate an appropriate USB device driver when the peripheral is attached to the bus. The USBD module instead displays a dialog box prompting the user to enter the name of the appropriate USB device driver dynamic-link library (DLL). The USBD then loads the specified driver to control the peripheral and calls the driver’s USBInstallDriver function.

The USB device driver’s USBInstallDriver function sets up the driver’s subkey correctly within the LoadClients\ registry key so that the USBD module can load the driver the next time that the peripheral is attached to the bus. The driver does this by creating a USB_driver_SETTINGS structure and passing it to the RegisterClientSettings function. The format of the USB_DRIVER_SETTINGS structure parallels that of the LoadClients registry key. If all the fields in a group have USB_NO_INFO value, the corresponding GroupX_ID is set to Default in the registry. For example, the following example shows the USB_DRIVER_SETTINGS for the HID class sample driver.

USB_DRIVER_SETTINGS DriverSettings;
DriverSettings->dwVendorId          = USB_NO_INFO;
DriverSettings->dwProductId         = USB_NO_INFO;
DriverSettings->dwReleaseNumber     = USB_NO_INFO;

DriverSettings->dwDeviceClass       = USB_NO_INFO;
DriverSettings->dwDeviceSubClass    = USB_NO_INFO;
DriverSettings->dwDeviceProtocol    = USB_NO_INFO;

DriverSettings->dwInterfaceClass    = USB_DEVICE_CLASS_HUMAN_INTERFACE;
DriverSettings->dwInterfaceSubClass = USB_NO_INFO;
DriverSettings->dwInterfaceProtocol = USB_NO_INFO;

The following example shows how calling RegisterClientSettings with this DriverSettings structure is equivalent to having set up this registry key.

[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients]
  [Default]
    [Default]
      [3]
         [Generic_Sample_Hid_Class_Driver]
           “DLL”=“USBHID.dll”

In general, the client driver performs the following operations in USBInstallDriver:

This location for driver-specific keys may change in future versions of Windows CE, so USB device drivers should always use OpenClientRegistryKey to manipulate the settings, rather than opening the registry key directly.

After USBInstallDriver completes these actions, it returns control to the USBD module. The USBD module once again attempts to load a client driver for the device, using the algorithm described in USB Device Driver Load Process. At this time, the USBD module calls the USB device driver’s attach routine.