SAMPLE: Async Notification from Kernel Mode Driver

Last reviewed: February 17, 1998
Article ID: Q126415
The information in this article applies to:
  • Microsoft Win32 Device Development Kit (DDK) for Windows NT, versions 3.5, 3.51

SUMMARY

This ASYNC sample code for the Windows NT DDK demonstrates how to notify a user-mode application that a certain event that it has been waiting for has occurred. Frequently, this type of operation is performed when the application needs to be notified of a hardware interrupt.

The following file is available for download from the Microsoft Software Library:

 ~ Async.exe (size: 25782 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

MORE INFORMATION

The driver consists of two pieces, a kernel-mode driver and a user-mode application. You could use your own user-mode application with this driver, however the one supplied demonstrates the preferred method.

In the kernel-mode driver, an interrupt is simulated by using an IoTimer routine to maintain a time-out count. When this count has been reached, the routine completes the IOCTL request from the user-mode application that asked to be notified of this event. In the meantime, the driver is free to process other requests.

The user-mode application is a multi-threaded application. The first thread is responsible for sending down an IOCTL_HOLD_REQUEST. This IOCTL will, when handled by the kernel-mode driver, cause the IRP to be held in the driver until the IoTimer routine releases the IRP. The second thread sends down an IOCTL_DO_NOTHING, which does nothing except return every 1000 ms.

When installing the driver, you should create a subkey named parameters under the master key for the driver. In this key, you should have three DWORD values DebugValue, DelayValue, and BreakOnEntry. If BreakOnEntry is set to value not equal to zero (0), it will execute a hardcoded breakpoint in DriverEntry. If DebugValue is greater than or equal to one, it will print out a verbose level of DbgPrint statements, otherwise it will print out statements only on errors, DriverEntry, and the unload routine. DelayValue will indicate how many seconds should go by before the IOCTL_HOLD_REQUEST IRP should be completed. Generally speaking, this value

should be five or greater. The default value if not specified is five.

Keywords          : kbcode kbfile kbsample
Version           : 3.50 3.51
Platform          : winnt


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 17, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.