## The RESOURCE Sample

The RESOURCE Sample accompanies Chapter 3 and illustrates how to read values from the resource script attached to a kernel-mode driver. The sample includes two files (KmdResource.h and KmdResource.cpp) that can be used in any driver. This sample was added in Service Pack 8 in the 1st edition.

The sample includes two components:

- RESOURCE.SYS (SYS subdirectory) is a WDM driver for a non-existent device.
- TEST.EXE (TEST subdirectory) is a Win32 console application that tests the RESOURCE driver.

### Building RESOURCE

To build RESOURCE.SYS, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named RESOURCE.DSP in the SYS subdirectory. Unfortunately, you cannot use the BUILD utility for this sample program because BUILD is unable to cope with modules that have different compile options than other modules in the project, and FILEIO98.CPP requires special options.

To build TEST.EXE, follow the general instructions for building user-mode programs. The Microsoft Visual C++ project file is named TEST.DSP in the TEST subdirectory.

### Testing RESOURCE

First arrange a way to see debug messages. You can run under control of a kernel debugger such as Soft-Ice, or you can run Mark Russinovitch’s DbgView utility (see http://www.sysinternals.com).

Now install RESOURCE.SYS. Follow the instructions for using FASTINST in either Windows XP or Windows 98/Me. The INF file is named SYS\Resource.inf. As RESOURCE starts up, it will locate a FIRMWARE resource. In a real driver, this might be a binary resource that you could download to your hardware. In this driver, it’s just a string value, which the driver prints to the debug console. If you have set your system’s locale such that German or French is your default language, the message will be in the appropriate language. Otherwise, it will be in English.

Finally, open a DOS prompt and navigate to the TEST\DEBUG subdirectory. Issue the “TEST” command, which will use a DeviceIoControl to interrogate the revision level of the RESOURCE driver (1.42) by means of the imbedded version resource. The driver’s handler for the DeviceIoControl will also display the Comments string in all the languages that the version resource contains.

### Special Note

The resources package uses the portable file libraries from the FILEIO sample, which requires WDMSTUB.SYS in Windows 98/Me. If you copy the KmdResource files to your own project, be sure you also copy the FILEIO routines and that you ship WDMSTUB.SYS along with your driver. Bear in mind that WDMSTUB requires a royalty-free redistribution license from me. (WDMSTUB is actually only needed because the Win2K version of SetFilePosition calls ZwSetInformationFile.)

### What to look for

This key part of this sample is the file KmdResource.cpp, which contains a platform-portable set of subroutines for accessing objects in a driver's resource script. KmdResource.h declares the interface to these subroutines and provides usage instructions.