Next: 5.3 Developing Your Driver
Up: 5. Developing a Driver
Previous: 5.1 Using the DriverWizard
Contents
Subsections
5.2 Writing the Device Driver Without the DriverWizard
There may be times when you choose to write your driver directly, without
using DriverWizard. In such cases, either follow the steps outlined in this
section to create a new driver project, or use one of the WinDriver samples,
which most closely resembles your target driver, and modify the sample to suite
your specific requirements.
5.2.1 Include the Required WinDriver Files
- Include the relevant WinDriver header files in your driver project
(all header files are found under the WinDriver/include/
directory).
All WinDriver projects require the windrvr.h header
file.
When using the WDC_xxx API [B.2], include the
wdc_lib.h and wdc_defs. header
files (these files already include windrvr.h).
Include any other header file that provides APIs that you wish to use
from your code (e.g. files from the
WinDriver/samples/shared/ directory, which provide
convenient diagnostics functions.)
- Include the relevant header files from your source code:
For example, to use API from the windrvr.h header file,
add the following line to the code:
#include "windrvr.h"
- Link your code with the wdapi901
library/shared object:
- For Windows 98/Me/2000/XP/Server 2003/Vista: WinDriver
lib
<CPU>
wdapi901.lib or wdapi901_borland.lib (for Borland C++ Builder), where the
<CPU> directory is either
x86
(32-bit binaries for x86 platforms),
am64
(64-bit binaries for x64 platforms) or
am64
x86
(32-bit binaries for x64 platforms).
- For Windows CE:
WinDriver
lib
WINCE
<CPU>
wdapi901.lib.
- For Linux and Solaris:
WinDriver/lib/libwdapi901.so.
You can also include the library's source files in your project instead of
linking the project with the library. The C source files are located under
the WinDriver/src/wdapi directory.
NOTE: When linking your project with the the
wdapi901 library/shared object, you will need to
distribute the wdapi901 DLL/shared object with
your driver. For Windows, get wdapi901.dll /
wdapi901_32.dll (for 32-bit applications targeted
at 64-bit platforms) from the WinDriver
redist or
WinDriver
redist_win98_compat directory.
For Linux and Solaris, distribute WinDriver/lib/libwdapi901.so.
For details, refer to the driver distribution instructions in Chapter 14.
- Add any other WinDriver source files that implement API that you
which to use in your code (e.g. files from the
WinDriver/samples/shared directory.)
5.2.2 Write Your Code
This section outlines the calling sequence when using the WDC_xxx
API [B.2].
- Call WDC_DriverOpen() [B.3.2] to open a handle
to WinDriver and the WDC library, compare the version of the loaded
driver with that of your driver source files, and register your
WinDriver license (for registered users).
- For PCI/CardBus/PCMCIA devices, call WDC_PciScanDevices() [B.3.4] / WDC_PcmciaScanDevices() [B.3.6] to scan the PCI/PCMCIA bus and locate your
device.
- For PCI/CardBus/PCMCIA devices, call WDC_PciGetDeviceInfo() [B.3.7] / WDC_PcmciaGetDeviceInfo() [B.3.8] to retrieve the resources information
for your selected device.
For ISA devices, define the resources yourself within a WD_CARD
structure.
- Call WDC_PciDeviceOpen() [B.3.9] /
WDC_PcmciaDeviceOpen() [B.3.10] /
WDC_IsaDeviceOpen() [B.3.11] (depending on your
device) and pass to the function the device's resources information.
These functions return a handle to the device, which you can later
use to communicate with the device using the WDC_xxx API.
- Communicate with the device using the WDC_xxx API (see
description in Appendix B).
To enable interrupts, call WDC_IntEnable() [B.3.43].
To register to receive notifications for Plug and Play and power
management events, call WDC_EventRegister()
[B.3.46].
- When you are done, call WDC_IntDisable() [B.3.44]
to disable interrupt handling (if previously enabled), call
WDC_EventRegister() [B.3.46] to unregister Plug
and Play and power management event handling (if previously registered),
and then call WDC_PciDeviceClose() [B.3.12] /
WDC_PcmciaDeviceClose() [B.3.13] /
WDC_IsaDeviceClose() [B.3.14] (depending on your
device) in order to close the handle to the device.
- Call WDC_DriverClose() [B.3.3] to close the
handles to WinDriver and the WDC library.
Next: 5.3 Developing Your Driver
Up: 5. Developing a Driver
Previous: 5.1 Using the DriverWizard
Contents