IT tutorials
 
Windows
 

Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 4) - Creating a WDF Driver Object: DriverEntry

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/30/2013 8:23:21 PM

4. A Minimal KMDF Driver: The Simple Toaster

The Simple Toaster sample provided in toaster\func\simple is a minimal, software-only function driver. It creates a driver object, a device object, a device interface, and a single I\O queue. The driver handles read, write, and device I/O control requests that are targeted at its device.

This minimal driver includes the following functions:

  • A DriverEntry routine, which creates the driver object.

  • An EvtDriverDeviceAdd event callback, which creates the device object, a device interface, and a default I/O queue.

  • I/O callback functions for read, write, and device I/O control requests.

The driver does not manage any physical hardware, so no code to support Plug and Play or power management is required; the driver uses the WDF defaults.

4.1. Creating a WDF Driver Object: DriverEntry

Every KMDF driver must have a DriverEntry routine. The DriverEntry routine is the first driver function called when the driver is loaded. The KMDF DriverEntry routine has the same prototype as that of a WDM driver:

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
In PUNICODE_STRING RegistryPath
);

The DriverEntry routine performs the following tasks:

  • Creates a driver object (WDFDRIVER), which represents the loaded instance of the driver in memory. In effect, creating this object “registers” the driver with KMDF.

  • Registers the driver’s EvtDriverDeviceAdd callback. KMDF calls this function during device enumeration.

  • Optionally initializes event tracing for the driver.

  • Optionally allocates resources that are required on a driver-wide (rather than per-device) basis.

The following shows the DriverEntry function for the Simple Toaster sample:

NTSTATUS
DriverEntry(
IN PDRIVER_OBJ DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_DRIVER_CONFIG config;

KdPrint(("Toaster Function Driver Sample-"
Driver Framework Edition.\n));
KdPrint(("Built %s %s\n", __DATE__, __TIME__));
WDF_DRIVER_CONFIG_INIT(
&config,
ToasterEvtDeviceAdd
);

//
// Create a framework driver object.
//
Status = WdfDriverCreate(
DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES // Driver Attributes
&config, // Driver Config Info
WDF_NO_HANDLE
);

if ( !NT_SUCCESS(status)) {
KdPrint(("WdfDriverCreate failed with"
"status 0x%x\n", status));
}

return status;
}


Before creating the WDFDRIVER object, the driver must initialize a driver-object configuration structure (WDF_DRIVER_CONFIG) by using the WDF_DRIVER_CONFIG_INIT function. The function zeroes the structure and then initializes it with a pointer to the driver’s EvtDriverDeviceAdd callback function, which is named ToasterEvtDeviceAdd. KMDF calls this function during device enumeration, when it handles an add-device request that is targeted at the driver.

After setting up the configuration structure, DriverEntry calls WdfDriverCreate to create the WDFDRIVER object, passing as parameters the DriverObject and RegistryPath that were supplied to it, a pointer to the driver object attributes, and a pointer to the filled-in driver configuration structure. The framework’s default attributes are acceptable for the Simple Toaster’s WDFDRIVER object, so the sample specifies WDF_NO_OBJECT_ATTRIBUTES, which KMDF defines as NULL.

WdfDriverCreate can optionally return a handle to the created WDFDRIVER object. The Simple Toaster driver does not require a local copy of this handle, so instead of passing a location to receive the handle, it passes WDF_NO_HANDLE, which is a null pointer.

A WDM driver would typically save pointers to the DriverObject and RegistryPath, but a KMDF driver does not require them because KMDF maintains this information on behalf of the driver.

 
Others
 
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 3) - KMDF Driver Structure and Concepts - Object Context Area
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 2) - KMDF Driver Structure and Concepts - Object Creation
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 1)
- Windows Server 2008 : Creating and Running a PowerShell Script - Testing for the Existence of a File, Creating Output as HTML
- Windows Server 2008 : Creating and Running a PowerShell Script - Running PowerShell Scripts, Logging Processes with a get-process Script
- Windows Server 2008 : Creating and Running a PowerShell Script - Creating and Modifying the Global PowerShell Profile
- Windows Server 2008 : Creating and Running a PowerShell Script - Creating a PowerShell Profile
- Windows Server 2008 : Creating and Running a PowerShell Script - Setting the Security Context
- Windows 8 : Cloud Connections - Office 2013
- Windows 8 : Cloud Connections - SkyDrive (part 3) - To access SkyDrive from a browser
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us