internal USBDevice(Guid g) { _drvGuid = g; // Find-out the HID GUID PInvoke.HidD_GetHidGuid(ref _hidGuid); }
bool RegisterForPnpEvents(IntPtr h) { PInvoke.HidD_GetHidGuid(ref HidGuid); DEV_BROADCAST_DEVICEINTERFACE dFilter = new DEV_BROADCAST_DEVICEINTERFACE(); dFilter.dbcc_size = Marshal.SizeOf(dFilter); dFilter.dbcc_devicetype = gc.DBT_DEVTYP_DEVICEINTERFACE; dFilter.dbcc_classguid = HidGuid; hDevNotification = PInvoke.RegisterDeviceNotification(h, dFilter, gc.DEVICE_NOTIFY_WINDOW_HANDLE); if (hDevNotification == IntPtr.Zero) { return(false); } return(true); }
public USBDeviceList(byte DeviceMask, App_PnP_Callback fnCallBack) { Items = new ArrayList(); hDevNotifications = new ArrayList(); USBDriverGuids = new ArrayList(); EventCallBack = new App_PnP_Callback(PnP_Event_Handler); MsgWin.AppCallback = EventCallBack; AppCallBack = fnCallBack; // Get the HID GUID PInvoke.HidD_GetHidGuid(ref HidGuid); // Create list of driver GUIDs for this instance FillDriverGuids(DeviceMask); USBDevice tmpDev, tmp; int devs = 0; foreach (Guid guid in USBDriverGuids) { // tmpDev is just used for the DeviceCount functionality if (guid.Equals(CyConst.StorGuid)) { tmpDev = new CyUSBStorDevice(guid); } else if (guid.Equals(HidGuid)) { tmpDev = new CyHidDevice(HidGuid); } else { tmpDev = new CyFX2Device(guid); } // DeviceCount is IO intensive. Don't use it as for loop limit devs = tmpDev.DeviceCount; for (int d = 0; d < devs; d++) { // Create the new USBDevice objects of the correct type, based on guid if (guid.Equals(CyConst.StorGuid)) { tmp = new CyUSBStorDevice(guid); } else if (guid.Equals(HidGuid)) { tmp = new CyHidDevice(HidGuid); } else { tmp = new CyFX2Device(guid); if (tmp.Open((byte)d)) {// open handle to check device type CyUSBDevice t = tmp as CyUSBDevice; if (!t.CheckDeviceTypeFX3FX2()) {//FX3 tmp.Close(); tmp = new CyFX3Device(guid); } else { tmp.Close(); } } } if (tmp.Open((byte)d)) { Items.Add(tmp); // This creates new reference to tmp in Items tmp.RegisterForPnPEvents(MsgWin.Handle); } } if (guid.Equals(CyConst.StorGuid)) // We're not sure which drivers were identified, so setup PnP with both { RegisterForPnpEvents(MsgWin.Handle, CyConst.DiskGuid); RegisterForPnpEvents(MsgWin.Handle, CyConst.CdGuid); } else { RegisterForPnpEvents(MsgWin.Handle, guid); } } // foreach guid }