I've been doing lots of research on controlling USB devices in C# and ran across a few tutorials that seemed good until I started trying to code them. It seems like everyone seems to know how to use the function RegisterDeviceN otification to register the form to recieve WM_DEVICECHANGE messages.
I've gotten as far as importing the function from user32.dll and setting up the device filtering, but I don't really understand the concept of using RegisterDeviceN otification. Can anyone clarify what and where to get the parameters that its asking for?
Here is my code so far:
[code=text]
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Windows;
using System.Runtime. InteropServices ;
using DeviceManagemen tDeclarations;
namespace USBDevice
{
public partial class Form1 : Form
{
public const int WM_DEVICECHANGE = 0x219;
public Form1()
{
InitializeCompo nent();
RegisterDeviceN otification(thi s.Handle, ?NotificationFi lter?, ?Flags?);
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_DEVICECHANGE :
{
MessageBox.Show (m.ToString());
break;
}
}
base.WndProc(re f m);
}
[DllImport("user 32.dll", CharSet = CharSet.Auto)]
static public extern IntPtr RegisterDeviceN otification(Int Ptr hRecipient, IntPtr NotificationFil ter, int Flags);
}
}
[/code]
I've gotten as far as importing the function from user32.dll and setting up the device filtering, but I don't really understand the concept of using RegisterDeviceN otification. Can anyone clarify what and where to get the parameters that its asking for?
Here is my code so far:
[code=text]
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Windows;
using System.Runtime. InteropServices ;
using DeviceManagemen tDeclarations;
namespace USBDevice
{
public partial class Form1 : Form
{
public const int WM_DEVICECHANGE = 0x219;
public Form1()
{
InitializeCompo nent();
RegisterDeviceN otification(thi s.Handle, ?NotificationFi lter?, ?Flags?);
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_DEVICECHANGE :
{
MessageBox.Show (m.ToString());
break;
}
}
base.WndProc(re f m);
}
[DllImport("user 32.dll", CharSet = CharSet.Auto)]
static public extern IntPtr RegisterDeviceN otification(Int Ptr hRecipient, IntPtr NotificationFil ter, int Flags);
}
}
[/code]
Comment