views:

72

answers:

1

I am writing a piece of software that consists of a kernel mode driver and a user mode Windows service. The kernel driver needs to notify the service of different events and information, which the service will then process.

My question is this: What is the best way to set up this communication? I know it is possible to get a message from the kernel using a minifilter and FilterGetMessage(), but this would require polling the kernel for new data. I need a system that lets the kernel notify the service when there is new data to process.

As a side note, the service itself is using the producer consumer pattern, so there will be a thread devoted only to getting data from the kernel and putting into a queue for another set of worker threads to process. Any thoughts on this design are also welcome.

+2  A: 

Why not just use ReadFile or DeviceIoControl on the service side? Simple IRP on the driver side, complete it when you have something to report. The service will need to spin up a thread or use an I/O completion callback. And CancelIo to cancel the blocking call when the service exits.

Hans Passant
Is it possible to use the ReadFile method on the service side to provide a callback way of doing things if the kernel driver has new data, or would one have to constantly poll for new info?
Wade Tandy
The ReadFile() call will just block until the driver has something available. No need for polling.
Hans Passant
Oh right. Good point.
Wade Tandy
ReadFileEx does allow for a callback if that's somehow more attractive to you. You can see the Cancel example in the WDK to get a feel for how this works. That uses ReadFileEx, but the basic pattern would be the same for ReadFile. If you're moving lots of data consider I/O completion ports.
snoone