## The NOTIFY Sample

The NOTIFY Sample accompanies Chapter 9 and illustrates how to use an I/O Control operation to send a notification to a user-mode application. This sample was completely revised for the 2d edition to use GENERIC.SYS.

The sample includes two components:

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

### Building NOTIFY

To build NOTIFY.SYS, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named NOTIFY.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 NOTIFY

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

To test NOTIFY, open a command prompt and launch TEST.EXE from the TEST\DEBUG subdirectory. TEST will use an I/O control operation to wait for an "interesting" event from NOTIFY. You trigger the "interesting" event by pressing a key, whereupon the test program simulates a hardware event to complete the I/O control operation. 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 NOTIFY correctly cleans up.
- Use the Device Manager to disable or remove the NOTIFY device. You will have to terminate TEST with Ctrl+Break, but you should find that NOTIFY correctly cleans up.

### What to look for

The point of this sample is to show how to use the GenericCacheControlRequest and GenericUncacheControlRequest functions to keep track of a pending IOCTL request in a cancel-safe way. Refer to the code in control.cpp. You can refer to the code in GENERIC.SYS to see how these functions work.