5. ActivateDeviceEx loads the driver DLL registered in the DLL value located in the driver's subkey, and then creates a subkey for the driver under the HKEY_LOCAL_MACHINE\Drivers\Active registry key to keep track of all currently loaded drivers.
Figure 6-4 shows a typical registration under the HKEY_LOCAL_MACHINE\Drivers\BuiltIn registry key for an audio device driver.
Figure 6-4 An audio device driver registration
Registry Settings to Load Device Drivers
If you use ActivateDeviceEx to load your driver dynamically, you are not required to place the driver's registry settings in a subkey under HKEY_LOCAL_MACHINE\Drivers\BuiltIn. You can use an arbitrary path, such as HKEY_LOCAL_MACHINE\SampleDriver. However, the registry values for the driver are the same in both cases. Table 6-3 lists general registry entries that you can specify for a device driver in the driver's registry subkey (see Figure 6-4 for sample values).
Table 6-3 General registry entries for device drivers
Registry Entry | Type | Description |
---|---|---|
Prefix | REG_SZ | A string value that contains the driver's three-letter name. This is the value that replaces XXX in the stream interface functions. Applications also use this prefix to open a context of the driver through CreateFile. |
Dll | REG_SZ | This is the name of the DLL that Device Manager loads to load the driver. Note that this is the only mandatory registry entry for a driver. |
Index | REG_DWORD | This is the number appended to the driver prefix to create the driver's file name. For example, if this value is 1, applications can access this driver through a call to CreateFile(L"XXX1:"…) or CreateFile(L"\$device\XXX1"…). Note that this value is optional. If you do not define it, Device Manager assigns the next available index value to the driver. |
Order | REG_DWORD | This is the order in which Device Manger loads the driver. If this value is not specified, the driver will be loaded last, at the same time as other drivers with no order specified. Drivers with the same Order value start concurrently. You should only configure this value to enforce a sequential load order. For example, a Global Positioning System (GPS) driver might require a Universal Asynchronous Receiver/Transmitter (UART) driver to get access to the GPS data through a serial port. In this case, it is important to assign the UART driver a lower Order value than the GPS driver so that the UART driver starts first. This will enable the GPS driver to access the UART driver during its initialization. |
IClass | REG_MULTI_SZ | This value can specify predefined device interface globally unique identifiers (GUIDs). To advertise an interface to Device Manager, such as to support the Plug and Play notification system and power management capabilities, add the corresponding interface GUIDs to the IClass value or call AdvertiseInterface in the driver. |
Flags | REG_DWORD | This value can contain the following flags: |
■ DEVFLAGS_UNLOAD (0x0000 0001) The driver unloads after a call to XXX_Init. | ||
■ DEVFLAGS_NOLOAD (0x0000 0004) The driver cannot be loaded. | ||
■ DEVFLAGS_NAKEDENTRIES (0x0000 0008) The entry points of the driver are Init, Open, IOControl, and so forth, without any prefixes. | ||
■ DEVFLAGS_BOOTPHASE_1 (0x0000 1000) The driver is loaded during system phase 1 for systems with multiple boot phases. This prevents the driver from being loaded more than one time during the boot process. | ||
■ DEVFLAGS_IRQ_EXCLUSIVE (0x0000 0100) The bus driver loads this driver only when it has exclusive access to the interrupt request (IRQ) specified by the IRQ value. | ||
■ DEVFLAGS_LOAD_AS_USERPROC (0x0000 0010) Loads the driver in user mode. | ||
UserProcGroup | REG_DWORD | Associates a driver marked with the DEVFLAGS_LOAD_AS_USERPROC (0x0000 0010) flag to load in user mode with a user-mode driver host process group. User-mode drivers that belong to the same group are loaded by Device Manager in the same host process instance. If this registry entry does not exist, Device Manager loads the user-mode driver into a new host process instance. |
For details about the Flags registry value, see the section "ActivateDeviceEx" in the Windows Embedded CE 6.0 Documentation, available on the Microsoft MSDN Web site at http://msdn2.microsoft.com/en-us/library/aa929596.aspx.
Registry Keys Related to Loaded Device Drivers
Apart from configurable registry entries in driver-specific subkeys, Device Manager also maintains dynamic registry information in subkeys for loaded drivers under the HKEY_LOCAL_MACHINE\Drivers\Active key. The subkeys correspond to numerical values that the operating system assigns dynamically and increments for each driver until the system is restarted. The number does not signify a particular driver. For example, if you unload and reload a device driver, the operating system assigns the next number to the driver and does not reuse the previous subkey. Because you cannot ensure a reliable association between the subkey number and a particular device driver, you should not edit the driver entries in the HKEY_LOCAL_MACHINE\Drivers\Active key manually. However, you can create, read, and write driver-specific registry keys at load time in a driver's XXX_Init function because Device Manager passes the path to the current Drivers\Active subkey to the stream driver as the first parameter. The driver can open this registry key using OpenDeviceKey.
Table 6-4 lists typical entries that the subkeys under Drivers\Active can contain.
Table 6-4 Registry entries for device drivers under the HKEY_LOCAL_MACHINE\Drivers\Active key
Registry Entry | Type | Description |
---|---|---|
Hnd | REG_DWORD | The handle value for the loaded device driver. You can obtain this DWORD value from the registry and pass it in a call to DeactivateDevice in order to unload the driver. |
BusDriver | REG_SZ | The name of the driver's bus. |
BusName | REG_SZ | The name of the device's bus. |
DevID | A unique device identifier from Device Manager. | |
FullName | REG_SZ | The name of the device if used with the $device namespace. |
Name | REG_SZ | The driver's legacy device file name including index, if a prefix is specified (not present for drivers that do not specify a prefix). |
Order | REG_DWORD | The same order value as in the driver's registry key. |
Key | REG_SZ | The registry path to the driver's registry key. |
PnpId | REG_SZ | The Plug and Play identifier string for PCMCIA drivers. |
Sckt | REG_DWORD | For PCMCIA drivers, describes the current socket and function of the PC card. |