IT tutorials
 
Windows
 

Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 6) - Device Object and Device Context Area, 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:26:02 PM

4.3. Device Object and Device Context Area

The first task of the ToasterEvtDeviceAdd callback is to initialize the context area and attributes for the WDFDEVICE object. The context area for this device object is a structure of type FDO_DATA, which is defined as follows in the header file toaster.h:

typedef struct _FDO_DATA
{
WDFWMIINSTANCE WmiDeviceArrivalEvent;
BOOLEAN WmiPowerDeviceEnableRegistered;
TOASTER_INTERFACE_STANDARD BusInterface;
} FDO_DATA, *PFDO_DATA;

WDF_DECLARE_CONTEXT_TYPE_WITH(FDO_DATA, ToasterFdoGetData)

As the example shows, the header file defines the context area and then invokes the WDF_DECLARE_CONTEXT_TYPE_WITH_NAME macro. This macro creates an accessor method that is associated with a context type. Thus, when the ToasterEvtDeviceAdd function is called, the accessor method ToasterFdoGetData has already been created to read and write a context area of type FDO_DATA.

To associate the named context area with an object, the driver must initialize the object’s attribute structure with information about the context area. The ToasterEvtDeviceAdd function invokes the WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE macro to do this:

WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&fdoAttributes,
FDO_DATA);

This macro performs the following tasks:

  • Initializes fdoAttributes, which is a WDF_OBJECT_ATTRIBUTES structure.

  • Sets pointers to the name and length of the context area and to the context area itself in the WDF_OBJECT_ATTRIBUTES structure.

The variable fdoData, of type PFDO_DATA, is defined to hold a pointer to the context area.

Next, the driver creates the WDFDEVICE object by calling WdfDeviceCreate, passing as parameters the addresses of the WDFDEVICE_INIT and WDF_OBJECT_ATTRIBUTES structures and a location to receive a handle to the create object:

status = WdfDeviceCreate(&DeviceInit, &fdoAttributes,
&hDevice);

The framework allocates the WDFDEVICE_INIT structure, which is opaque to the driver writer. This object supports several methods that a driver can use to initialize device and driver characteristics, including the type of I/O that the driver supports, the device name, and a security descriptor definition language (SDDL) string for the device, among others. (These settings correspond to the device characteristics fields of the WDM device object, which is familiar to WDM driver writers.) By default, KMDF sets the I/O type to buffered I/O. This default, along with all the others, is appropriate for the Simple Toaster, so the driver does not call any methods on this object.

WdfDeviceCreate creates a WDFDEVICE object that is associated with an underlying WDM device object, connects the device object to the device stack, and sets the appropriate flags and attributes. It returns a handle to the WDFDEVICE object in hDevice.

After creating the device object, the driver gets a pointer to the context area by calling the accessor method ToasterFdoGetData:

fdoData = ToasterFdoGetData(hDevice);

The ToasterEvtDeviceAdd function does not use the returned pointer; this statement appears only for demonstration purposes.

4.4. Device Interface

Every device that a user-mode application or system component opens must have an interface. A device interface can be created in any of three ways:

  • A user-mode installation application can create the interface using SetupDi function.

  • An INF can create the interface by including a DDInstall.Interfaces section.

  • The driver can create the interface by calling WdfDeviceCreateInterface.

The following shows how the Simple Toaster driver creates an interface:

status = WdfDeviceCreateDeviceInterface (
hDevice,
(LPUID) &GUID_DEVINTERFACE_TOASTER,
NULL
);
If (!NT_SUCCESS (status)) {
KdPrinte(("WdfDeviceCreateDeviceInterface failed"
"0x%x\n", status));
return status;
}

The driver passes a handle to the device object, a pointer to a Globally Unique Identifier (GUID), and a pointer to an optional string. The GUID identifies the interface and is defined in the driver.h header file. The string enables the driver to distinguish two or more devices of the same interface class (that is, two or more devices that have identical GUIDs). The Simple Toaster driver passes NULL for the string.

 
Others
 
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 5) - Creating the Device Object, Device Interface
- 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
 
 
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