From: alexfiftyfour on
Hello,

I am a .NET developer and new to writing kernel mode drivers. I read some
tutorials and guides on the internet, downloaded the WDK and got a very basic
driver running :-)

So far so good. Now I want, that my driver notifies an application, which is
written with .NET. I want the driver to have something like an "event" to
which my application can subscribe. The event should have some parameters.

I know, that there might no "events", but that is the functionality I want
to have.
So what is the way I have to go, to get such a functionality work?

If you have some links, a tutorial or guide, how I can do this, it would
help me a lot.

Thx

Alex
From: Thomas F. Divine on
The accepted approach to this problem is for an application to make an
asynchronous DeviceIoControl call of some sort. The call from user-mode can
define an output buffer that will (eventually...) be filled with
notification information.

The driver "pends" the notification IRP and keeps it around until it needs
to notify the application of something. On that occasion the driver fetches
the pended IRP, fills in notification information in the output buffer and
completes the IRP.

The application devises some way to detect when the asynchronous operation
has completed, and when it has the notification has been done.

This is typically called the "inverted call" approach to notification.
Although it may initially sound "backwards" it is the way to go.

Look through WDK sample drivers. I suspect that you'll find an example.

Good luck,

Thomas F. Divine

"alexfiftyfour" <alexfiftyfour(a)discussions.microsoft.com> wrote in message
news:11B3CC6B-6CBC-42B2-8D15-FE762165E98A(a)microsoft.com...
> Hello,
>
> I am a .NET developer and new to writing kernel mode drivers. I read some
> tutorials and guides on the internet, downloaded the WDK and got a very
> basic
> driver running :-)
>
> So far so good. Now I want, that my driver notifies an application, which
> is
> written with .NET. I want the driver to have something like an "event" to
> which my application can subscribe. The event should have some parameters.
>
> I know, that there might no "events", but that is the functionality I want
> to have.
> So what is the way I have to go, to get such a functionality work?
>
> If you have some links, a tutorial or guide, how I can do this, it would
> help me a lot.
>
> Thx
>
> Alex

From: Pavel A. on
alexfiftyfour" <alexfiftyfour(a)discussions.microsoft.com> wrote in message
news:11B3CC6B-6CBC-42B2-8D15-FE762165E98A(a)microsoft.com...
> Hello,
>
> I am a .NET developer and new to writing kernel mode drivers. I read some
> tutorials and guides on the internet, downloaded the WDK and got a very
> basic
> driver running :-)
>
> So far so good. Now I want, that my driver notifies an application, which
> is
> written with .NET. I want the driver to have something like an "event" to
> which my application can subscribe. The event should have some parameters.
>
> I know, that there might no "events", but that is the functionality I want
> to have.

Read on FilterConnectCommunicationPort & friends.
This is the standard way to talk to minifilters. Somewhere you can find
PInvoke definitions.
http://msdn.microsoft.com/en-us/library/ff540460(VS.85).aspx:

Regards,
-- pa


From: Brett on
I did this a while back with .NET. I don't really remember many of the
specifics; I did a bunch of research at the time. I've pasted more or less
the code I used to accomplish this.
This should at least get you started.

*** In Driver ***

#define DRIVER_EVENT_NAME_DRV L"\\BaseNamedObjects\\Global\\myDriverEvent"
VOID SomeFunction()
{
HANDLE hEventHandle = NULL;
PKEVENT pEvent = NULL;
RtlInitUnicodeString(&EventName, DRIVER_EVENT_NAME_DRV);
pEvent = IoCreateNotificationEvent(&EventName, &hEventHandle);
if(pEvent != NULL)
{
KeSetEvent(pEvent, 0, FALSE);
}
if(hEventHandle != NULL)
{
ZwClose(hEventHandle);
hEventHandle = NULL;
pEvent = NULL;
}
}


*** In .NET (C#) ***

[DllImport("kernel32.dll")]
internal static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool
bManualReset, bool bInitialState, string lpName);

[DllImport("kernel32.dll")]
internal static extern uint WaitForSingleObjectEx(IntPtr hHandle, uint
dwMilliseconds, bool bAlertable);

private const string DriverEventName = "Global\\myDriverEvent";
void SomeOtherFunction()
{
IntPtr _hDriverEvent = CreateEvent(IntPtr.Zero, true, false,
DriverEventName);

uint waitResult = WaitForSingleObjectEx(_hDriverEvent, 10000, false);
}


"alexfiftyfour" wrote:

> Hello,
>
> I am a .NET developer and new to writing kernel mode drivers. I read some
> tutorials and guides on the internet, downloaded the WDK and got a very basic
> driver running :-)
>
> So far so good. Now I want, that my driver notifies an application, which is
> written with .NET. I want the driver to have something like an "event" to
> which my application can subscribe. The event should have some parameters.
>
> I know, that there might no "events", but that is the functionality I want
> to have.
> So what is the way I have to go, to get such a functionality work?
>
> If you have some links, a tutorial or guide, how I can do this, it would
> help me a lot.
>
> Thx
>
> Alex