Standard Driver Routine Requirements
Keep the following points in mind when designing a kernel-mode driver:
- Each driver must have a DriverEntry routine, which initializes driver-wide data structures and resources. The I/O Manager calls the DriverEntry routine when it loads the driver.
- Every driver must have at least one dispatch routine, and it must place a dispatch routine's entry point in its DRIVER_OBJECT structure for each IRP_MJ_XXX function code it handles. A driver can have a separate dispatch routine for each of the IRP_MJ_XXX function codes the driver handles.
- Every driver must have an Unload routine, and must place the Unload routine's entry point in its driver object, if the driver can be replaced while the system is running. An Unload routine is responsible for releasing any system resources, such as system-defined objects or driver-allocated memory, that the driver is using before the driver itself is unloaded from the system.
- Every PnP driver must have an AddDevice routine and define its entry point in the driver extension of the driver object. An AddDevice routine is responsible for creating and initializing device objects for each PnP device the driver controls.
- A driver can have a StartIo routine and place its entry point in the driver object. Any lowest-level driver that does not have a StartIo routine must set up and manage internal queues of the IRPs sent to its dispatch routines, unless it can complete every IRP it gets within its dispatch routines. Higher-level drivers can have a StartIo routine, but seldom do because higher-level drivers usually pass IRPs on to lower-level drivers directly from their dispatch routines.
- Certain miniport drivers are exceptions to the preceding requirements. See the device-type-specific documentation in this DDK for information about the requirements for miniport drivers.
- Whether a driver has any other kind of standard routine depends on its functionality and on how that driver fits into the system (for example, whether it interoperates with system-supplied drivers). See the device-type specific documentation in this DDK for details.