Developing Drivers with the Windows Driver Foundation (Pro Developer)
The Skeleton sample driver supports the following functionality that all UMDF drivers must implement:
-
DLL infrastructure
-
Basic COM support
-
Basic implementations of the driver and device callback objects
About the Skeleton Sample
The Skeleton sample provides code files and the following project-related files that can be used as a template for setting up a UMDF driver project:
-
A set of supporting files that the WDK Build utility uses to build the driver.
-
An INX file that the Build utility converts to an INF file for installing the driver.
This functionality is sufficient for a working, but very limited, driver. The Skeleton sample driver installs and loads, but depends on the framework's default processing to handle most I/O requests.
This chapter focuses on how to adapt the Skeleton sample code to create a full-featured UMDF driver. The Skeleton sample provides a robust and functional model for implementing the rest of the driver code. If you want to use a different approach to some of the issues covered in this chapter, you should be able to readily modify the Skeleton model to suit your preferences.
This chapter does not go into the details of how or why the various objects and methods are implemented.
Chapter 18, "An Introduction to COM," provides a more thorough discussion of topics such as class factories and the IUnknown interface.
Note The examples in this chapter are all taken from the Skeleton sample. Most have been edited for clarity and brevity. Refer to the sample itself for the complete code.
About the Skeleton Sample Files
The files in the Skeleton sample not only contain the code, but also demonstrate best practices for setting up a UMDF driver project. A simple way to start implementing your driver is to copy the sample files to your project folder. You can use those files-with appropriate modifications-for your core implementation and then add files as needed to support additional features such as I/O request queues.
Source Files
Most of the source files are in pairs-a .cpp file and an associated .h file-with a name that indicates their function. Note that code for some very simple methods, such as IUnknown::AddRef, might be located in the header file. The following source files contain basic infrastructure and usually require no modification:
Dllsup.cpp | Implements the basic DLL infrastructure. |
Comsup.cpp and Comsup.h | Implements core COM support: a class factory for the driver callback object and a base implementation of the IUnknown interface. |
The following source files contain code that must be modified to support a particular device:
Driver.cpp and Driver.h | Implements a basic driver callback object. |
Device.cpp and Device.h | Implements a basic device callback object. |
Internal.h | Contains project-wide #define and #include statements. |
Build Support Files
The following files contain the directives and data that the Build utility uses to build the driver DLL and related files:
Sources | Sources contains a list of source files and related information. |
Make files | Makefile and Makefile.inc contain the directives for building the project. |
Exports | Exports.def specifies the functions that the DLL exports by name. |
Version resource file | Skeleton.rc contains the driver version number and related information. |
Installation Support Files
INX files are essentially an architecture-independent version of an INF file. The Build utility uses the INX file to create an INF file for a particular driver build. Building INF files from an INX file is a recommended practice, so this chapter assumes that your project will use an INX. The Skeleton sample includes the following two INX files:
UMDFSkeleton_OSR.inx | Stampinf uses this INX to create an INF that installs the Skeleton sample as a driver for the OSR USB Fx2 device. |
UMDFSkeleton_Root.inx | Stampinf uses this INX to create an INF that installs the Skeleton sample as a root-enumerated driver. |
You can use the INX file that best suits your project. UMDFSkeleton_OSR.inx is probably the most useful file for most projects because it installs the Skeleton sample as a device driver.
Chapter 20, "How to Install WDFDrivers," provides a thorough discussion of INX files.
Категории