B
bb
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
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