Registry Enumerator

The Registry Enumerator (RegEnum.dll) exports the Init and Deinit functions. It finds new devices by reading entries from the registry. It is re-entrant; the Device Manager can call it again while a previous invocation is still active, and supports hierarchical usage so it can load itself over a different registry key. When the Registry Enumerator gets unloaded, it unloads anything it directly loaded.

The Device Manager loads the Registry Enumerator by checking HKEY_LOCAL_MACHINE\Drivers\RootKey to determine the key where to start the driver loading process. The default value of RootKey is Drivers. The Device Manager loads the driver indicated by that key, which is typically RegEnum.dll.

The Registry Enumerator examines its root key, which is the registry key passed to it, by looking for subkeys that describe drivers to load. The following list shows what subkeys these keys contain:

  • Built-in or native devices.
  • ISA devices.
  • The PCI bus.
  • Virtual devices such as the Network Driver Interface Specification (NDIS).
  • Optional protocol elements such as Simple Network Management Protocol (SNMP) or Point-to-Point Protocol (PPP).
  • Other non-enumerable operating system (OS) components.

RegEnum.dll examines the first level of keys just below the key passed to it, according to the Order registry subkey. It invokes ActivateDeviceEx on each subkey it finds. The Registry Enumerator generally runs with the DEVFLAGS_UNLOAD flag.

Each subkey can have any values typically interpreted by ActivateDeviceEx or by the driver ultimately getting loaded. Additionally, each subkey can have an Order value between 0 and 255. The smallest Order value gets loaded first. If there is no Order value, the driver gets loaded after drivers with defined Order values.

The entry point of the driver is constructed from the Prefix value if the driver exposes a stream interface, or is Init if no Prefix value exists. For example, a serial driver with Prefix equal to COM has an entry point of COM_Init. If there is no Prefix value, then the entry point is Init. The Registry Enumerator driver does all of its work in its Init entry point and the Device Manager can unload it once Init returns.

As the Registry Enumerator initializes the system, it traverses the subkeys of HKEY_LOCAL_MACHINE\Drivers\BuiltIn, or where ever the HKEY_LOCAL_MACHINE\Drivers\RootKey value points, one by one, and initializes a driver for each entry. It loads the DLL indicated by the DLL value, and then creates a subkey for the driver under HKEY_LOCAL_MACHINE\Drivers\Active. Then it calls the Init function or the driver's entry point and passes in a string containing that subkey.

Using the string it gets, the XXX_Init routine can call RegOpenKeyEx to get a handle for this key, and then call RegQueryValueEx to look up the key value, which contains the string corresponding to the registry key that Device Manager originally encountered under HKEY_LOCAL_MACHINE\Drivers\BuiltIn.

It is common for device driver writers to include other values in their registry key. These values can indicate other things such as the I/O port address, the IRQ setting, the DMA settings, or any other type of additional information needed.

The following is an example of a registry key for a device called SAMPLE; you can find other examples in the Platform.reg file for your platform.

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Sample]
    "Dll" = "sampledev.Dll"
    "Prefix" = "SMP"
    "Index" = dword:1
    "Order" = dword:0
    "FriendlyName" = "Sample Controller"
    "Ioctl" = dword:0

Using the above registry settings, the Device Manager creates a new key. Then it calls SAMPLE_Init, and passes in a pointer to the new key. SAMPLE_Init then calls RegOpenKeyEx to get a handle for the key. Then it calls RegQueryValueEx to get the string "\Drivers\BuiltIn\Sample". XXX_Init can then use this string to open that key and get at other information placed there. For non-stream drivers, if there is no Prefix value, Init is the assumed entry point.

See Also

Driver Loading Model | Device Interface Classes | Device Interface Notifications

 Last updated on Tuesday, May 18, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.