Exemple #1
0
 /// <summary>
 /// Unregisters the window for USB device notifications
 /// </summary>
 public void RemoveDeviceNotification()
 {
     foreach (var handel in _notificationHandles)
     {
         if (handel != null)
         {
             NativeImportMethods.UnregisterDeviceNotification(handel);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Registers a window to receive notifications when USB devices are plugged or unplugged.
        /// </summary>
        private void SetDeviceNotification(BroadcastDeviceinterface devInterface)
        {
            devInterface.Size = Marshal.SizeOf(devInterface);
            IntPtr filterPtr = Marshal.AllocHGlobal(devInterface.Size);

            Marshal.StructureToPtr(devInterface, filterPtr, true);

            var _notificationHandle = NativeImportMethods.RegisterDeviceNotification(_winHandle.Handle, filterPtr, 0);

            _notificationHandles.Add(_notificationHandle);

            Marshal.FreeHGlobal(filterPtr);
        }