Click here to Skip to main content
13,349,032 members (65,358 online)
Click here to Skip to main content
Add your own
alternative version


116 bookmarked
Posted 26 Mar 2002

Communication between GUI Application and Device Driver

, 26 Mar 2002
Rate this:
Please Sign up or sign in to vote.
An article on Communication between GUI Application and Device Driver
<!-- Download Links -->


Recently I read a good article in which the author wrote a device driver and a GUI program, and he wanted to notify the GUI App when some event happened in the device driver. In his article, when a new process was created, a callback function in his driver would be called and it would notify the GUI App and display some information about the new process immediately. In the device driver, the author create a named event and opened it in GUI App. Then when an event happened, he handled it like this:

KeSetEvent(Event, 0, FALSE);

At this time, the GUI App was waiting for the event. Between the interval of the two functions, the App must got information of the new process. It works, but I don't think it's a good solution.

Why does the author code like this? Because, if we create an event in kernel mode, we can't modify its state in user mode, we only can check its state. But normally, we want the GUI App to modify the event to to non signaled, and it can wait the event again. I think this is the eligible IPC model to deal with this question.

About my solution

Kernel mode has higher priority than user mode. In kernel mode we can modify data in user mode conveniently. So I create an event object in user mode, and refer it in kernel mode. Now both device driver and GUI App can check and modify the state of the event object.

How to integrate it into your application

In your App, you must open the device object firstly, then code like this:

  1. Create an event object and down it into driver.
    HANDLE m_hCommEvent = CreateEvent(NULL, false, false, NULL);
    //download event object to device driver, m_hCommDevice is the device object
                    (LPVOID) m_hCommEvent, 
  2. Wait the event object to be signaled.
    	WaitForSingleObject(m_hCommEvent, INFINITE);
    	//After this function, the event is set to non signaled. 
    	//Get information and deal with it.

In the device driver the code like this:

  1. In the IRP_MJ_DEVICE_CONTROL major routine:
    hEvent = (HANDLE) irpStack->Parameters.DeviceIoControl.Type3InputBuffer;
    status = ObReferenceObjectByHandle(

    the gpEventObject is a PRKEVENT object, so we can use KeEventXXX and KeWaitForXXX to operate it.

  2. When the object event happened
    KeSetEvent(gpEventObject, 0, FALSE);
  3. When we don't need it, we should dereference it:

I have tested my solution in a personal firewall product. It works well. When my IP Filter Driver got an IP packet, it checks the IP header as my security rules. If the packet will be intercepted, it reports to my GUI App.

The sample download include two projects: a GUI app and a device driver. The GUI App is a dialog based MFC application. It has a log window which can register the operations on event object. The device driver is only a very simple kernel mode device driver. It can operate the event object as the GUI App requries. I you want to run this demo, you must install and start the driver firstly.

Because there are so many tools can install and start device deriver, so I don't include the code to do this work.

If you have any problems and advices, Please notify me.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Amir Mohammad Nasrollahi9-Aug-13 21:06
professionalAmir Mohammad Nasrollahi9-Aug-13 21:06 
GeneralMy vote of 5 Pin
gndnet22-Aug-12 2:52
membergndnet22-Aug-12 2:52 
GeneralMy vote of 5 Pin
memberCHRISTINE GREEN29-Mar-12 4:26 
QuestionPersonnal Firewall Pin
tigzy3-Jul-11 20:56
membertigzy3-Jul-11 20:56 
GeneralCommunication between Driver an Application Pin
dereck78_zg10-Dec-08 6:01
memberdereck78_zg10-Dec-08 6:01 
Questionhow to install driver Pin
romon13-May-07 2:27
memberromon13-May-07 2:27 
AnswerRe: how to install driver Pin
Maruf Maniruzzaman9-Jul-07 3:26
memberMaruf Maniruzzaman9-Jul-07 3:26 
Questionhow to build Pin
dhirendra_19803-Nov-05 19:35
memberdhirendra_19803-Nov-05 19:35 
ekzot6-Sep-05 5:53
memberekzot6-Sep-05 5:53 
GeneralUsing DeviceIoControl Pin
Anonymous13-Jul-05 14:26
sussAnonymous13-Jul-05 14:26 
GeneralRe: Using DeviceIoControl Pin
euacela25-Aug-05 6:24
membereuacela25-Aug-05 6:24 
GeneralDriver installation Pin
cbt382-Mar-05 2:13
membercbt382-Mar-05 2:13 
GeneralRe: Driver installation Pin
BoostedR36MK36-Sep-12 9:03
memberBoostedR36MK36-Sep-12 9:03 
QuestionHow about using WMI? Pin
sohailkadiwala19-Oct-04 20:30
membersohailkadiwala19-Oct-04 20:30 
Generaluser mode to control device driver Pin
Horsy20-Sep-04 12:19
memberHorsy20-Sep-04 12:19 
QuestionIs there .inf for the driver? Pin
Gordon Smith27-Aug-04 1:43
memberGordon Smith27-Aug-04 1:43 
GeneralHelp Required Pin
Kamran Shakir23-Aug-04 21:41
sussKamran Shakir23-Aug-04 21:41 
GeneralIf u don't answers question don't start articles Chris must be aware to on this Pin
alexwinx14-Jun-04 1:51
memberalexwinx14-Jun-04 1:51 
GeneralRe: If u don't answers question don't start articles Chris must be aware to on this Pin
tomithecat13-Dec-04 23:00
membertomithecat13-Dec-04 23:00 
QuestionCan anybody help me Pin
firstxx30-Apr-04 2:11
memberfirstxx30-Apr-04 2:11 
General Comm. between usermode Application and Device Driver Pin
SETI5127-Mar-04 8:36
memberSETI5127-Mar-04 8:36 
Generaldynamic loading of dlls in kernel mode Pin
Anonymous1-Dec-03 23:19
sussAnonymous1-Dec-03 23:19 
GeneralRe: dynamic loading of dlls in kernel mode Pin
Ketil Jensen23-May-05 22:28
sussKetil Jensen23-May-05 22:28 
GeneralI create Event in driver Pin
xenic9-Nov-03 21:44
memberxenic9-Nov-03 21:44 
QuestionIsn't it really slow? Pin
tomithecat19-Aug-03 4:30
membertomithecat19-Aug-03 4:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 27 Mar 2002
Article Copyright 2002 by lizhiwei
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid