## The GENERIC Sample

The GENERIC Sample is a kernel-mode library used by most of the book sample drivers.

The sample includes one component:

- GENERIC.SYS is a WDM library.

You may find differences in the electronic copy of GENERIC and the code described in the book. Those differences have arisen because I continued (and still continue) to improve GENERIC after the book was frozen by the editorial process.

[Note: the WIN98SAFE conditional compilation switch was added in SP-10 to overcome a bug in the initial release of Windows 98. In that version, the system would incorrectly interpret the return value from a DllInitialize function, leading to a failure to load a driver. If you #define WIN98SAFE in driver.h and remove the export definitions of DllInitialize and DllUnload from generic.def, you can build a version of GENERIC.SYS that will work correctly in Win98. Your version will not, however, unload in Win2K/Xp.]

### Building GENERIC

To build GENERIC.SYS, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named GENERIC.DSP.

### Testing GENERIC

It’s not necessary for you to specifically install GENERIC.SYS. In fact, the setup program for the book samples automatically does this for you because most of the other samples depend on it being present. If you rebuild the DEBUG version of GENERIC, the build script will copy your new GENERIC.SYS module to the Drivers directory. It will be used the next time you restart your system.

If you're using a separate machine for testing than where you installed the sample programs, be sure to copy the original and any rebuilt version of GENERIC.SYS from the OBJCHK_WXP_X86\I386 directory to the drivers directory by hand.

### Documentation

Extensive documentation of GENERIC is available in the hypertext help file GENERIC.CHM.

### Redistributing GENERIC

You may not redistribute the GENERIC.SYS library. You may, however, build a library from this project under a different name and redistribute that. Here’s how to accomplish this:

1. Pick a new name that's customized to the name of your company so that it will be unlikely to conflict with a driver already installed on the end user's computer. For purposes of illustration, I'll proceed as if you had settled on FRED.SYS.
2. Copy the entire GENERIC directory (not including any subdirectories) to a new directory named FRED.
3. Rename GENERIC.DSP to FRED.DSP. Delete the files with extensions DSW, MAK, NCB, OPT, and PLG.
4. Start Visual Studio. Open FRED.DSP *as a text file* and globally replace "generic.sys" with "fred.sys". Save this file.
5. Open FRED.DSP as a Visual Studio project. Don’t forget that you will be using the DDK compiler for building this project; follow the link in "Building GENERIC" above if you’re doubtful about what this remark means. It's a good idea to set the option that generates a browse database.
6. Change the first line of GENERIC.DEF to read "NAME FRED.SYS".
7. Do a Build All for the checked and release builds. At this point, you will have objchk_wxp_x86\i386 and objfre_wxp_x86\i386 subdirectories that contain fred.sys and fred.lib along with other intermediate files.
8. Use fred.lib instead of generic.lib in your build script. Distribute fred.sys instead of generic.sys. Your driver's demand for functions in the GENERIC library are being satisifed by exports of those functions from FRED.SYS.

Please do not distribute the checked version of your new library: you will be embarrassed when your knowledgeable end users call up and complain about the debug spew!

### What to look for

GENERIC is a library for production use and not primarily a sample.