Re: Pnp notification issue
From: Pavel A. (pavel_a_at_geeklife.com)
Date: 07/02/04
- Next message: cd: "Re: memcpy to PCI Adapter Memory"
- Previous message: Stephan Wolf [MVP]: "Re: memcpy to PCI Adapter Memory"
- In reply to: yu su: "Re: Pnp notification issue"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 2 Jul 2004 17:41:48 +0300
"yu su" <su_yu@hotmail.com> wrote in message
news:eJ2H4s8XEHA.2408@tk2msftngp13.phx.gbl...
> Not yet, it is still just console application.
The RegisterServiceCtrlHandlerEx interface can be used only in services.
No matter how much C# is wrapped around it :(
--PA
> "Pavel A." <pavel_a@geeklife.com> wrote in message
> news:%23vcDYY8XEHA.4092@TK2MSFTNGP11.phx.gbl...
> > So your program is a service, and you installed it as service?
> >
> > --PA
> >
> > "jack su" <su_yu@hotmail.com> wrote in message
> > news:Ou5zA62XEHA.3420@TK2MSFTNGP12.phx.gbl...
> > > Hi all,
> > >
> > > I tried to build one C# program to receive MS RamDisk's PNP
> notification.
> > > RegisterDeviceNotification returns 0, sounds registered successfully.
> But
> > > seems it never got called.
> > >
> > > Also, is there someway to check all the PNP notification listener?
> > >
> > > Here is the URL for MS RamDisk:
> > > http://support.microsoft.com/default.aspx?scid=kb;en-us;Q257405
> > >
> > > And here is the code:
> > >
> > > using System;
> > > using System.Text;
> > > using System.Runtime.InteropServices;
> > > using System.ServiceProcess;
> > > using System.Data;
> > > using System.Threading;
> > > using System.Collections;
> > > using System.ComponentModel;
> > >
> > > using System.Diagnostics;
> > >
> > >
> > > public class test {
> > >
> > > [DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)]
> > > internal static extern IntPtr CreateFile(String filename, uint
> > > desiredAccess, uint shareMode, IntPtr attributes, uint
> creationDisposition,
> > > uint flagsAndAttributes, IntPtr templateFile);
> > >
> > > [DllImport("user32.dll", SetLastError=true)]
> > > public static extern IntPtr RegisterDeviceNotification(IntPtr
> hRecipient,
> > > IntPtr NotificationFilter, Int32 Flags);
> > >
> > > [DllImport("advapi32.dll", SetLastError=true)]
> > > static extern IntPtr RegisterServiceCtrlHandlerEx(string
> > > lpServiceName,callbackEx cbex,IntPtr context);
> > >
> > >
> > > [DllImport("kernel32.dll", SetLastError=true)]
> > > static extern int DeviceIoControl ( IntPtr hDevice, int
> dwIoControlCode,
> > > byte[] lpInBuffer, int nInBufferSize, byte[] lpOutBuffer, int
> > > nOutBufferSize, ref int lpBytesReturned, byte[] notinuse) ;
> > >
> > > public delegate void callbackEx(int control,int eventType,IntPtr
> > > eventData,IntPtr context);
> > >
> > > const uint FILE_FLAG_NO_BUFFERING = 0x20000000 ;
> > > public static void callbackexfunc(int control,int eventType,IntPtr
> > > eventData,IntPtr context){
> > > Console.WriteLine("Callback Func:" + control + ":" + eventType +
> ":" +
> > > eventData + ":" + context);
> > > }
> > >
> > > [StructLayout(LayoutKind.Sequential)]
> > > public class DEV_BROADCAST_HANDLE {
> > > public int dbch_size;
> > > public int dbch_devicetype;
> > > public int dbch_reserved;
> > > public IntPtr dbch_handle;
> > > }
> > >
> > > public const int DEVICE_NOTIFY_SERVICE_HANDLE = 1;
> > >
> > > public static void Main() {
> > > IntPtr Device = CreateFile(@"\\.\Z:", 0x80000000 | 0x40000000, 0x1 |
> 0x2,
> > > IntPtr.Zero, 3,FILE_FLAG_NO_BUFFERING, IntPtr.Zero);
> > > callbackEx myCallback = new callbackEx(callbackexfunc);
> > >
> > > DEV_BROADCAST_HANDLE dbi = new DEV_BROADCAST_HANDLE();
> > > int size = Marshal.SizeOf(dbi);
> > > dbi.dbch_size = size;
> > > dbi.dbch_devicetype = 6;//DBT_DEVTYP_HANDLE;
> > > dbi.dbch_reserved = 0;
> > > dbi.dbch_handle = Device;
> > > IntPtr buffer = Marshal.AllocHGlobal(size);
> > > Marshal.StructureToPtr(dbi, buffer, true);
> > >
> > > IntPtr handleMethod =RegisterServiceCtrlHandlerEx("DummyID",
> > > myCallback, IntPtr.Zero );
> > > IntPtr r = RegisterDeviceNotification(handleMethod, buffer,
> > > DEVICE_NOTIFY_SERVICE_HANDLE);
> > > Console.WriteLine("Reagistered>" + r);
> > > Thread.Sleep(100000);
> > > }
> > > }
> > >
> > > Thanks
> > >
> > > Jack
> > >
> > >
> >
> >
>
>
- Next message: cd: "Re: memcpy to PCI Adapter Memory"
- Previous message: Stephan Wolf [MVP]: "Re: memcpy to PCI Adapter Memory"
- In reply to: yu su: "Re: Pnp notification issue"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|