// Ask the OS to give us notifications for USB devices with the indicated interface void GetUSBDeviceNotificationsFor(Guid guidDevInterface) { lock (this.deviceListLock) { DEV_BROADCAST_DEVICEINTERFACE_MANAGED filter = new DEV_BROADCAST_DEVICEINTERFACE_MANAGED(); filter.Initialize(guidDevInterface); IntPtr hDeviceNotify = RegisterDeviceNotification(this.notificationHandle, filter, this.notificationHandleIsService ? DEVICE_NOTIFY_SERVICE_HANDLE : DEVICE_NOTIFY_WINDOW_HANDLE); ThrowIfFail(hDeviceNotify); this.deviceNotificationHandles.Add(hDeviceNotify); } }
public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, DEV_BROADCAST_DEVICEINTERFACE_MANAGED filter, int Flags);