public void RegisterDeviceNotification(Guid guid, WindowInteropHelper windowInteropHelper) { DEV_BROADCAST_DEVICEINTERFACE devIF = new DEV_BROADCAST_DEVICEINTERFACE(); IntPtr devIFBuffer; //Set to HID GUID devIF.dbcc_size = Marshal.SizeOf(devIF); devIF.dbcc_devicetype = USBPnpDetection.DBT_DEVTYP_DEVICEINTERFACE; devIF.dbcc_reserved = 0; devIF.dbcc_classguid = guid; //AloCATE A buffer for DLL call devIFBuffer = Marshal.AllocHGlobal(devIF.dbcc_size); //Copy devIF to buffer Marshal.StructureToPtr(devIF, devIFBuffer, true); //Register for HID device notification m_hNotifyDevNode = USBPnpDetection.RegisterDeviceNotification(windowInteropHelper.Handle, devIFBuffer, USBPnpDetection.DEVICE_NOTIFY_WINDOW_HANDLE); //Copy buffer to devIF devIF = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(devIFBuffer, typeof(DEV_BROADCAST_DEVICEINTERFACE)); //Free buffer Marshal.FreeHGlobal(devIFBuffer); }
public static USBPnpDetection GetInstance() { if (instance == null) { instance = new USBPnpDetection(); } return(instance); }
public void UnregisterNotification() { uint ret = USBPnpDetection.UnregisterDeviceNotification(m_hNotifyDevNode); }