Redigera

Dela via


Writing a DriverEntry Routine

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.

In a driver that supports Plug and Play (PnP), as all drivers should, the DriverEntry routine is responsible for driver initialization, while the AddDevice routine (and, possibly, the dispatch routine that handles a PnP IRP_MN_START_DEVICE request) is responsible for device initialization. Driver initialization includes exporting the driver's other entry points, initializing certain objects the driver uses, and setting up various per-driver system resources. (Non-PnP drivers have significantly different requirements, as described in the Driver Development Kit [DDK] for Microsoft Windows NT 4.0 and earlier.)

DriverEntry routines are called in the context of a system thread at IRQL = PASSIVE_LEVEL.

A DriverEntry routine can be pageable and should be in an INIT segment so it will be discarded. Use an alloc_text pragma directive, as illustrated in the sample drivers that are provided with the Windows Driver Kit (WDK).

This section contains the following topics:

DriverEntry's Required Responsibilities

DriverEntry's Optional Responsibilities

DriverEntry Return Values