Using Visual Studio to Build Drivers

< BACK  NEXT >
[oR]

Although Visual Studio is quite obviously promoted as an application development tool for C++ (and several other languages), it is nonetheless an IDE for the standard compiler and linker. Therefore, using the proper compile and link switch settings, the tool can be used to build kernel-mode device drivers.

The DDAppWiz Tool

The CD that accompanies this book includes an App Wizard that conveniently provides the necessary compile and link switch settings for Visual Studio to build a device driver. The file, DDAppWiz.AWX, must be copied into the Visual Studio path: ...\Microsoft Visual Studio\Common\MSDev98\Template. Thereafter, a new Project type appears in the New Project dialog box: W2K Device Driver.

The use of the App Wizard is straightforward and described in Chapter 6. This section lists the Visual Studio environment settings modified or added by the wizard.

Preprocessor Symbols Modification

The table below shows the compiler preprocessor symbols removed from the standard Win32 project, normally generated by Visual Studio.

Table
Preprocessor Symbol Modification Reason
WIN32 Deleted Driver is not a Win32 application
_WINDOWS Deleted Driver is not a Windows application
_MBCS Deleted Driver uses Unicode, not multibyte character set
_DEBUG Deleted Driver is not Win32 debug target
DBG Added Driver's standard debug symbol definition (1=checked, 0=free)
_X86_ Added DDAppWiz produces driver for Intel platform
WIN32_WINNT=0x500 Added Version of Windows 2000

Compiler Switch Modifications

Several compile switches are required for driver builds, as shown in the following table:

Table
Compiler Switch Modification Reason
/GX and -GX Deleted Do not enable synchronous exception handling
/GZ Deleted Do not attempt to catch release build errors
-Gz Added Use __stdcall calling convention

Compiler Include Directories

The Device Driver App Wizard adds two include directories to the set of compiler options (-I switch). The paths are listed below.

 \NTDDK\inc    and \NTDDK\inc\ddk 

These may require modification, depending upon choices specified when the DDK is installed.

Link Modifications

All of the standard Win32 libraries are removed from linker input and replaced with the following list of libraries:

  • int64.lib

  • ntoskrnl.lib

  • hal.lib

The /nodefaultlib linker option is selected. Depending on the configuration (Debug or Release), a library path is added of either

 /libpath:\NTDDK\libchk\i386 or /libpath:\NTDDK\libfre\i386 

Either of these link settings may require manual modification based on where the DDK is actually installed.

The remaining linker switch modifications are as follows:

Table
Link Option Modification Reason
/subsystem:windows Deleted Driver is not a Win32 application
-driver Added Link for kernel-mode driver
-subsystem:NATIVE,5.00 Added Required for driver build
-base:0x10000 Added Drivers specify load of 0x10000, kernel relocates
-entry:DriverEntry Added Entry point for all drivers

No MFC

To ensure that the driver project is not MFC based (for obvious reasons), the option is removed by the App Wizard.

< BACK  NEXT >


The Windows 2000 Device Driver Book(c) A Guide for Programmers
The Windows 2000 Device Driver Book: A Guide for Programmers (2nd Edition)
ISBN: 0130204315
EAN: 2147483647
Year: 2000
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net