Re: Listening for event call from device driver using WaitForMultipleObjects
- From: "Thomas F. Divine [DDK MVP]" <tdivine@xxxxxxxxxxxxxxxx>
- Date: Thu, 25 Aug 2005 11:29:49 -0400
Have you looked at the "HandleRef Structure" methods?
I use overlapped I/O from C# to the PCAUSA Rawether NDIS protocol driver. The HandleRef methods were needed to "keep the handles alive" until the asynchronous calls returned. I used my own unsafe P/Invoke calls instead of the Win32 calls you are using, so this may not be helpful to you.
Thomas F. Divine, Windows DDK MVP http://www.rawether.net
"bb" <bb@xxxxxxxx> wrote in message news:1124956198.975172.154230@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a windows network device driver written in c++ and a user interface im porting to c#, my problem is i dont seem to be getting notified of the event calls from the driver to the c# app
im using the following code in c# in the UI to create an event
public static IntPtr OpenGrantedPacketEvent() { IntPtr objDriver = Driver.OpenDriver(); IntPtr objEvent = Win32.CreateEvent(IntPtr.Zero, false, false, Driver.PW_EVENT_GRANTEDPACKET); uint nBytesReturned = 0;
if(Win32.DeviceIoControl(objDriver, Driver.IOCTL_PW_SET_GRANTEVENT, IntPtr.Zero, 0, IntPtr.Zero, 0, out nBytesReturned, IntPtr.Zero) == 0) { Driver.CloseEvent(objEvent); Driver.CloseDriver(objDriver);
throw new Exception("Failed to create granted packet event."); }
Driver.CloseDriver(objDriver);
return objEvent; }
in the driver in c++ im doing this to create a notification event
case IOCTL_PW_SET_GRANTEVENT: {
// is this event clean? if (!Globals.bGrantedEventClean) { NtStatus = STATUS_INVALID_PARAMETER; break; }
Globals.bGrantedEventClean = FALSE;
Globals.grantedEvent = IoCreateNotificationEvent(&Globals.grantedEventName, &Globals.hGrantedEvent); if (!Globals.grantedEvent) { NtStatus = STATUS_UNSUCCESSFUL; break; }
back in the c# UI, im then using waitformultipleobjects to respond to the event being hit ...
IntPtr[] objHandles = new IntPtr[] { m_objBlockEvent, m_objGrantEvent, m_objExitEvent }; uint nIndex = 0;
while(m_blnRunning == true) { nIndex = Win32.WaitForMultipleObjects(3, objHandles, false, Win32.INFINITE);
switch(nIndex) { case (uint) HANDLE.BLOCKED: //0 System.Diagnostics.Debug.WriteLine("Blocked!"); break;
case (uint) HANDLE.GRANTED: //1 System.Diagnostics.Debug.WriteLine("Granted!"); break;
case (uint) HANDLE.EXITED: //2 System.Diagnostics.Debug.WriteLine("Exited!"); m_blnRunning = false; break; } }
my problem is my switch never gets hit, nothing even returns back from waitformultipleobjects
i immediately thought that it was the string used for the event name ..
in the driver the string is declared as
#define PROTOWALL_KERNELEVENT_GRANTEDPACKET L"\\BaseNamedObjects\\ProtoWallGrantedPcktEvent"
and in the c# app its declared as [MarshalAs(UnmanagedType.LPStr)] public const string PROTOWALL_EVENT_GRANTEDPACKET = "ProtoWallGrantedPcktEvent";
although ive tried every different possible combination of declaring the string as different types (i thought .net strings where unicode by default, and therefore would not require me to do any marshalling) but nothing seems to work.
i have tried calling the event myself from inside the C# app using this code .. Win32.SetEvent(m_objExitEvent); and it does work - so it seems i can hear when the event is responded to, just seemingly not when it comes from the driver.
the subtext to this, is that i have a c++ version of the UI which does work fine, (i.e. it correctly gets notified) so i dont think the driver is at fault, either my porting of code, or some under the covers magic about talking between drivers and .net code. (also everything is running as administrator privs).
any help or things to try on this subject would be most welcome.
bb
.
- Follow-Ups:
- References:
- Prev by Date: Re: Declaration and definition change in ddk 3790.1830
- Next by Date: DDK Doc Error
- Previous by thread: Listening for event call from device driver using WaitForMultipleObjects
- Next by thread: Re: Listening for event call from device driver using WaitForMultipleObjects
- Index(es):
Relevant Pages
|
Loading