IT tutorials
 
Windows
 

Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 5) - Creating the Device Object, Device Interface

- 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:59 PM

4.2. Creating the Device Object, Device Interface, and I/O Queue: EvtDriverDeviceAdd

Every KMDF driver that supports Plug and Play must have an EvtDriverDeviceAdd callback function, which is called each time the system enumerates a device that belongs to the driver. This callback performs actions required at device enumeration, such as the following:

  • Creates and initializes a device object (WDFDEVICE) and corresponding context areas.

  • Sets entry points for the driver’s Plug and Play and power management callbacks.

  • Creates a device interface.

  • Configures and creates one or more I/O queues.

  • Creates an interrupt object, if the device controls physical hardware that generates interrupts.

The EvtDriverDeviceAdd function is called with two parameters: a handle to the WDFDRIVER object that the driver created during DriverEntry and a handle to a WDFDEVICE_INIT object.

The Simple Toaster does not control hardware, so it does not set Plug and Play or power management callbacks, nor does it create an interrupt object. Its EvtDriverDeviceAdd callback creates the device object and context area, device interface, and a single default I/O queue. The following shows the source code for this function:

NTSTATUS
ToasterEvtDeviceAdd(
IN WDFDRIVER Driver,
IN PWDFDEVICE_INIT DeviceInit
)
{
NTSTATUS status = STATUS_SUCCESS;
PFDO_DATA fdoData;
WDF_IO_QUEUE_CONFIG queueConfig;
WDF_OBJECT_ATTRIBUTES fdoAttributes;
WDFDEVICE hDevice;
WDFQUEUE queue;
UNREFERENCED_PARAMETER(Driver);

PAGED_CODE();
KdPrint(("ToasterEvtDEviceAdd called\n"));
//
// Initialize attributes and a context area for the
// device object.
//
//
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE
(&fdoAttributes, FDO_DATA);

//
// Create a framework device object.
status = WdfDEviceCreate(&DeviceInit, &fdoAttributes,
&hDevice);
if(!NT_SUCCESS(status)) {
KdPrint(("WdfDeviceCreate failed with status code"
"0x%x\n", status));
return status;
}

// Get the device context by using the accessor function
// specified in the WDF_DECLARE_CONTEXT_TYPE_WITH_NAME
// macro for FDO_DATA.
//
fdoData = ToasterFdoGetData(hDevice);

//
// Create device interface.
//
status = WdfDEviceCreateDeviceInterface(
hDevice,
(LPUID) &GUID)DEVINTERFACE_TOASTER,
NULL // Reference String
);

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

//
// Configure the default I/O queue.
//
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig,
WdfIoQueueDispatchParallel);

// Register I/O callbacks for IRP_MJ_READ, IRP_MJ_WRITE,
// and IRP_MJ_DEVICE_CONTROL request.

queueConfig.EvtIoRead = ToasterEvtIoRead;
queueConfig.EvtIoWrite = ToasterEvtIoWrite;
queueConfig.EvtIoDeviceControl =
ToasterEvtIoDeviceControl;

// Create the queue.

status = WdfIoQueueCreate (
hDevice,
&queueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&queue
);

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

return status;
}


The following discussions step through the actions of this function.

 
Others
 
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 4) - Creating a WDF Driver Object: DriverEntry
- 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
 
 
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