## The STUPID Sample

The STUPID Sample accompanies Chapter 2 and illustrates the basics of the DriverEntry, DriverUnload, and AddDevice functions. This sample was added to the 2d edition.

The sample includes one component:

- STUPID.SYS is a WDM driver for a non-existent hardware device.

### Building STUPID

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

### Testing STUPID

Follow the general instructions for using FastInst in Windows XP or Windows 98/Me. The INF file is named STUPID.INF.

The whole point of this sample is for you to single step it in a debugger. Therefore, install and run the kernel debugger of your choice and set breakpoints at DriverEntry and AddDevice.

Note that AddDevice returns an error code, which is decidedly not the right thing to do in a production driver. The error code causes the system to remove STUPID.SYS from memory. If AddDevice were to succeed, there would be no way to get rid of the driver without removing the device in Device Manager and then rebooting the computer. This is because STUPID doesn't handle the PnP requests that are needed for a driver to unload.

Do not turn the Driver Verifier on for this sample. It doesn't have dispatch functions for the required types of IRP. The Driver Verifier would bug check immediately upon detecting this fact.

### What to look for

DriverEntry.cpp contains slightly simplified versions of the standard DriverEntry and AddDevice functions that a "real" driver would contain.