## The EVWAIT Sample

The EVWAIT Sample accompanies Chapter 9 and illustrates how an application can wait on an event set by a WDM driver. This sample was considerably simplified for the 2d edition.

The sample includes two components:

- EVWAIT.SYS (SYS subdirectory) is a WDM driver for a non-existent hardware device.
- TEST.EXE (TEST subdirectory) is a Win32 console program for testing EVWAIT.SYS.

### Building EVWAIT

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

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 EVWAIT

First install EVWAIT.SYS. Follow the general instructions for using FastInst in Windows XP or Windows 98/Me. The INF file is named SYS\EVWAIT.INF.

To test EVWAIT, open a command prompt and launch TEST.EXE from the TEST\DEBUG subdirectory. TEST will use an I/O Control operation to communicate an event handle to EVWAIT and then wait for you to type a keystroke on the keyboard. You can perform three different tests:

- Type a key. TEST will print a message to the effect that the event has happened, and then it will exit.
- Type Ctrl+Break. TEST will exit. If you’re watching in a debugger, you should find that EVWAIT correctly cleans up.
- Use the Device Manager to disable or remove the EVWAIT device. You will have to terminate TEST with Ctrl+Break, but you should find that EVWAIT correctly cleans up.

### What to look for

The meat of this sample is in the handler for the IOCTL_REGISTER_EVENT control code in control.cpp.