You don't need to go to all those unmanaged API's. The .NET WMI
wrappers provides clean access to system devices.
Here is a code snippet that will let you determine if a usb device is
plugged in. Your code will change slightly depending on what type (i.e.
CLASS) the usb device is. In any case to be alerted when a usb device
is plugged in, you can use a WQL (Windows Query Language) query, and
register a handler, as follows:
using System.Management;
.....
//create a query to look for usb devices
WqlEventQuery w = new WqlEventQuery();
w.EventClassName = "__InstanceCreationEvent";
w.Condition = "TargetInstance ISA 'Win32_USBControllerDevice'";
w.WithinInterval = new TimeSpan(0,0,2);
//use a "watcher", to run the query
ManagementEventWatcher watch = new ManagementEventWatcher(w);
watch.EventArrived+= new
EventArrivedEventHandler(this.usbDetectionHandler);
watch.Start();
//when the watcher detects the query is true, it calls the registered
handler
//in this case usb.DetectionHandler
Hope this helps. If you have follow up queries do let me know.
Revi