Developing Drivers with the Windows Driver Foundation (Pro Developer)

This section provides a walkthrough that creates a checked build of Fx2_Driver for Windows Vista and discusses the details of some the supporting files mentioned in the previous section.

Sources File for Fx2_Driver

The Sources file contains most of the project-specific information that the Build utility uses to build the project. It consists of a series of directives that assign project-specific values to a set of macros and environment variables. The example in Listing 19-2 shows the contents of the Fx2_Driver Sources file, edited to remove comments. It is a typical Sources file for a simple UMDF driver.

Listing 19-2: The Fx2_Driver Sources file

UMDF_VERSION=1 UMDF_MINOR_VERSION=5 TARGETNAME=WUDFOsrUsbFx2 TARGETTYPE=DYNLINK USE_MSVCRT=1 WIN32_WINNT_VERSION=$(LATEST_WIN32_WINNT_VERSION) _NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINXP) NTDDI_VERSION=$(LATEST_NTDDI_VERSION) MSC_WARNING_LEVEL=/W4 /WX MSC_WARNING_LEVEL=$(MSC_WARNING_LEVEL) /wd4201 C_DEFINES = $(C_DEFINES) /D_UNICODE /DUNICODE DLLENTRY=_DllMainCRTStartup DLLDEF=exports.def INCLUDES=$(INCLUDES);..\inc;..\..\inc SOURCES=\ OsrUsbFx2.rc \ dllsup.cpp \ comsup.cpp \ driver.cpp \ device.cpp \ queue.cpp \ ControlQueue.cpp \ ReadWriteQueue.cpp TARGETLIBS=\ $(SDK_LIB_PATH)\strsafe.lib \ $(SDK_LIB_PATH)\kernel32.lib \ $(SDK_LIB_PATH)\advapi32.lib NTTARGETFILES=$(OBJ_PATH)\$(O)\WUDFOsrUsbFx2.inf MISCFILES=$(NTTARGETFILES) RUN_WPP= $(SOURCES) -dll -scan:internal.h

The following section gives brief descriptions of the macros and environment variables used in the Fx2_Driver Sources file.

 Tip   See "Utilizing a Sources File Template" in the WDK for a complete list of the possible contents of a Sources file, plus links to documentation about environment variables and macros-online at http://go.microsoft.com/fwlink/?LinkId=79350.

Macros Used in the Sources File for Fx2_Driver

This section discusses the macros and environment variables in the Fx2_Driver example.

UMDF Version Numbers

The following macros define the UMDF version number:

These macros define the UMDF version numbers, which control the following:

Chapter 20, "How to Install WDF Drivers," provides more information on WDF co-installers and versioning.

Standard Targets

The following macros describe the standard build targets, such as the driver binary:

Custom Targets

The following macros describe custom targets, such as an INF file that the Build utility produces by processing an INX file:

Source Files, Headers, and Libraries

The following macros describe the source files, headers, and libraries used to build the targets:

Build Configuration

The following macros describe the build configuration:

Makefile and Makefile.inc for Fx2_Driver

The contents of Makefile are the same for all driver projects, as discussed in "Build Utility Supporting Files" earlier in this chapter. Fx2_Driver also includes an optional file, Makefile.inc. This file contains some additional make directives to handle a target that Makefile.def does not cover: converting the project's INX file into an appropriate INF file. The example in Listing 19-3 shows the contents of Fx2_Driver's Makefile.inc file.

Listing 19-3: The Fx2_Driver Makefile.inc file

.SUFFIXES: .inx STAMP=stampinf .inx{$(OBJ_PATH)\$(O)}.inf: copy $(@B).inx $@ $(STAMP) -f $@ -a $(_BUILDARCH) -u $(UMDF_VERSION).$(UMDF_MINOR_VERSION).0

This example Makefile.inc file contains the following three directives:

How to Build Fx2_Driver

The following procedure shows how to build Fx2_Driver for the x86 version of Windows Vista.

To Build Fx2_Driver for the x86 Version of Window Vista

  1. Open the Windows Vista and Windows Server Longhorn x86 Checked Build Environment console window.

    The window opens in the %wdk% folder.

  2. Use cd to move to the project folder: %wdk%\src\umdf\usb\Fx2_Driver\Final.

  3. Build the project by running the following command:

    • build.exe -ceZ

This is not the only way to build the project, but the example shows a commonly used set of flags. The output files for the Fx2_Driver are placed in the project's objchk_wlh_x86\i386 subfolder.

Категории