Re: Listening for event call from device driver using WaitForMultipleObjects



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


.



Relevant Pages

  • Re: Cant add a usb Cannon i960 printer
    ... the printer gets defined with a device string like the ... it is hardly interesting to repeat it unless the usblp kernel driver ... >and then the kernel discovers its devcies as it enumerates and probes buses. ...
    (comp.os.linux.setup)
  • Access web cam with multiple web cams
    ... tuner seem to use the same driver ... Private Const WS_VISIBLE As Integer = &H10000000 ... (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As ... Dim DriverVersion As String = Space ...
    (microsoft.public.dotnet.languages.vb)
  • AddPrinter in Windows 98
    ... Public Type PRINTER_DEFAULTS ... (ByVal pName As String, ByVal Level As Long, pPrinter As PRINTER_INFO_2) ... ' Driver Name - Driver must be installed already ... pi2.pDriverName = AddString(strDriver, bBuffer) ...
    (microsoft.public.vb.winapi)
  • Re: Is C# support load device driver?
    ... how to manage driver loading/unloading using both PInvoke interop and WMI. ... string driverName; ... IntPtr fileHandle; ... databaseName, uint dwDesiredAccess); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is C# support load device driver?
    ... I can see my driver is loaded. ... > string driverName; ... > internal static extern IntPtr OpenSCManager(string machineName, ... > uint dwDesiredAccess, uint serviceType, uint startType, uint ...
    (microsoft.public.dotnet.languages.csharp)

Loading