Example #1
0
        /// <summary>
        /// Registers a window to receive windows messages when a device is inserted/removed. Need to call this
        /// from a form when its handle has been created, not in the form constructor. Use form's OnHandleCreated override.
        /// </summary>
        /// <param name="hWnd">Handle to window that will receive messages</param>
        /// <param name="gClass">Class of devices to get messages for</param>
        /// <returns>A handle used when unregistering</returns>
        public static IntPtr RegisterForUsbEvents(IntPtr hWnd, Guid gClass)
        {
            var oInterfaceIn = new DeviceBroadcastInterface {
                ClassGuid = gClass, DeviceType = DEVTYP_DEVICEINTERFACE, Reserved = 0
            };

            oInterfaceIn.Size = Marshal.SizeOf(oInterfaceIn);
            return(RegisterDeviceNotification(hWnd, oInterfaceIn, DEVICE_NOTIFY_WINDOW_HANDLE));
        }
 public static IntPtr RegisterForUsbEvents(IntPtr hWnd, Guid gClass)
 {
     DeviceBroadcastInterface oInterfaceIn = new DeviceBroadcastInterface();
     oInterfaceIn.Size = Marshal.SizeOf(oInterfaceIn);
     oInterfaceIn.ClassGuid = gClass;
     oInterfaceIn.DeviceType = DEVTYP_DEVICEINTERFACE;
     oInterfaceIn.Reserved = 0;
     return RegisterDeviceNotification(hWnd, oInterfaceIn, DEVICE_NOTIFY_WINDOW_HANDLE);
 }
Example #3
0
        /// <summary>
        /// Registers a window to receive windows messages when a device is inserted/removed. Need to call this
        /// from a form when its handle has been created, not in the form constructor. Use form's OnHandleCreated override.
        /// </summary>
        /// <param name="hWnd">Handle to window that will receive messages</param>
        /// <param name="gClass">Class of devices to get messages for</param>
        /// <returns>A handle used when unregistering</returns>
        protected static IntPtr RegisterForUsbEvents(IntPtr hWnd, Guid gClass)
        {
            var oInterfaceIn = new DeviceBroadcastInterface();

            oInterfaceIn.Size       = Marshal.SizeOf(oInterfaceIn);
            oInterfaceIn.ClassGuid  = gClass;
            oInterfaceIn.DeviceType = DeviceType.Interface;
            return(RegisterDeviceNotification(hWnd, oInterfaceIn, DeviceNotificationRecipient.Window));
        }
Example #4
0
        public static IntPtr RegisterForUsbEvents(IntPtr hWnd, Guid gClass)
        {
            DeviceBroadcastInterface deviceBroadcastInterface = new DeviceBroadcastInterface();

            deviceBroadcastInterface.Size       = Marshal.SizeOf(deviceBroadcastInterface);
            deviceBroadcastInterface.ClassGuid  = gClass;
            deviceBroadcastInterface.DeviceType = 5;
            deviceBroadcastInterface.Reserved   = 0;
            return(Win32Usb.RegisterDeviceNotification(hWnd, deviceBroadcastInterface, 0u));
        }
Example #5
0
        public static IntPtr RegisterForUsbEvents(IntPtr hWnd, Guid gClass)
        {
            DeviceBroadcastInterface structure = new DeviceBroadcastInterface();

            structure.Size       = Marshal.SizeOf(structure);
            structure.ClassGuid  = gClass;
            structure.DeviceType = 5;
            structure.Reserved   = 0;
            return(RegisterDeviceNotification(hWnd, structure, 0));
        }
        private void OnDeviceArrival(DeviceBroadcastHeader dbh, IntPtr ptr)
        {
            if (dbh.DeviceType == 0x05)
            {
                DeviceBroadcastInterface dbi =
                    (DeviceBroadcastInterface)Marshal.PtrToStructure(ptr, typeof(DeviceBroadcastInterface));

                if (dbi.ClassGuid == _deviceClass && DeviceArrival != null)
                {
                    DeviceArrival(this, EventArgs.Empty);
                }
            }
        }
        public bool EnableHidNotification(IntPtr hWnd)
        {
            DeviceBroadcastInterface oInterfaceIn = new DeviceBroadcastInterface();

            oInterfaceIn.Size       = Marshal.SizeOf(oInterfaceIn);
            oInterfaceIn.ClassGuid  = guid;
            oInterfaceIn.DeviceType = DEVTYP_DEVICEINTERFACE;
            oInterfaceIn.Reserved   = 0;
            _regHandle = RegisterDeviceNotification(hWnd, oInterfaceIn, DEVICE_NOTIFY_WINDOW_HANDLE);
            if (_regHandle == IntPtr.Zero)
            {
                return(false);
            }
            return(true);
        }
        internal void RegisterDeviceArrival()
        {
            DeviceBroadcastInterface dbi = new DeviceBroadcastInterface();

            dbi.Size       = Marshal.SizeOf(dbi);
            dbi.DeviceType = 0x5;
            dbi.ClassGuid  = _deviceClass;

            _handleDeviceArrival = RegisterDeviceNotification(Handle, ref dbi, 0);

            if (_handleDeviceArrival == IntPtr.Zero)
            {
                throw new Exception(string.Format("Failed in call to RegisterDeviceNotification ({0})", GetLastError()));
            }
        }
Example #9
0
        internal void RegisterDeviceArrival()
        {
            DeviceBroadcastInterface dbi = new DeviceBroadcastInterface();

            dbi.Size       = Marshal.SizeOf(dbi);
            dbi.DeviceType = 0x5;
            dbi.ClassGuid  = Class;

            _handleDeviceArrival = RegisterDeviceNotification(Handle, ref dbi, 0);
            int lastError = Marshal.GetLastWin32Error();

            if (_handleDeviceArrival == IntPtr.Zero)
            {
                throw new Win32Exception(lastError);
            }
        }
Example #10
0
        internal void RegisterDeviceArrival()
        {
            DeviceBroadcastInterface dbi = new DeviceBroadcastInterface();

            dbi.Size       = Marshal.SizeOf(dbi);
            dbi.DeviceType = 0x5;
            dbi.ClassGuid  = _deviceClass;

            try
            {
                _handleDeviceArrival = new SafeFileHandle(RegisterDeviceNotification(Handle, ref dbi, 0), true);
            }
            catch
            {
                MceRemoteReceiver.LogInfo("DeviceWatcher.RegisterDeviceArrival: Error={0}.", Marshal.GetLastWin32Error());
            }

            if (_handleDeviceArrival.IsInvalid)
            {
                throw new Exception(string.Format("Failed in call to RegisterDeviceNotification ({0})", GetLastError()));
            }
        }
Example #11
0
 protected static extern IntPtr RegisterDeviceNotification(IntPtr hwnd, DeviceBroadcastInterface oInterface, uint nFlags);
Example #12
0
 protected static extern IntPtr RegisterDeviceNotification(IntPtr hwnd, DeviceBroadcastInterface oInterface, uint nFlags);
Example #13
0
 /// <summary>
 /// Registers a window to receive windows messages when a device is inserted/removed. Need to call this
 /// from a form when its handle has been created, not in the form constructor. Use form's OnHandleCreated override.
 /// </summary>
 /// <param name="hWnd">Handle to window that will receive messages</param>
 /// <param name="gClass">Class of devices to get messages for</param>
 /// <returns>A handle used when unregistering</returns>
 protected static IntPtr RegisterForUsbEvents(IntPtr hWnd, Guid gClass)
 {
     var oInterfaceIn = new DeviceBroadcastInterface();
     oInterfaceIn.Size = Marshal.SizeOf(oInterfaceIn);
     oInterfaceIn.ClassGuid = gClass;
     oInterfaceIn.DeviceType = DeviceType.Interface;
     return RegisterDeviceNotification(hWnd, oInterfaceIn, DeviceNotificationRecipient.Window);
 }
Example #14
0
		/// <summary>
		/// Registers a window for device insert/remove messages
		/// </summary>
		/// <param name="hwnd">Handle to the window that will receive the messages</param>
        /// <param name="oInterface">DeviceBroadcastInterrface structure</param>
		/// <param name="nFlags">set to DEVICE_NOTIFY_WINDOW_HANDLE</param>
		/// <returns>A handle used when unregistering</returns>
        [DllImport("user32.dll",   SetLastError = true)] protected static extern IntPtr RegisterDeviceNotification(IntPtr hwnd, DeviceBroadcastInterface oInterface, uint nFlags);
Example #15
0
    internal void RegisterDeviceArrival()
    {
      DeviceBroadcastInterface dbi = new DeviceBroadcastInterface();

      dbi.Size = Marshal.SizeOf(dbi);
      dbi.DeviceType = 0x5;
      dbi.ClassGuid = _deviceClass;

      _handleDeviceArrival = RegisterDeviceNotification(Handle, ref dbi, 0);

      if (_handleDeviceArrival == IntPtr.Zero)
        throw new Exception(string.Format("Failed in call to RegisterDeviceNotification ({0})", GetLastError()));
    }
Example #16
0
 private static extern IntPtr RegisterDeviceNotification(IntPtr handle, ref DeviceBroadcastInterface filter,
                                                         int flags);
Example #17
0
 /// <summary>
 /// Registers a window for device insert/remove messages
 /// </summary>
 /// <param name="hwnd">Handle to the window that will receive the messages</param>
 /// <param name="lpInterface">DeviceBroadcastInterrface structure</param>
 /// <param name="nFlags">set to DEVICE_NOTIFY_WINDOW_HANDLE</param>
 /// <returns>A handle used when unregistering</returns>
 [DllImport("user32.dll", SetLastError = true)] protected static extern IntPtr RegisterDeviceNotification(IntPtr hwnd, DeviceBroadcastInterface oInterface, uint nFlags);
Example #18
0
    internal void RegisterDeviceArrival()
    {
      DeviceBroadcastInterface dbi = new DeviceBroadcastInterface();

      dbi.Size = Marshal.SizeOf(dbi);
      dbi.DeviceType = 0x5;
      dbi.ClassGuid = _deviceClass;

      try
      {
        _handleDeviceArrival = new SafeFileHandle(RegisterDeviceNotification(Handle, ref dbi, 0), true);
      }
      catch
      {
        MceRemoteReceiver.LogInfo("DeviceWatcher.RegisterDeviceArrival: Error={0}.", Marshal.GetLastWin32Error());
      }

      if (_handleDeviceArrival.IsInvalid)
      {
        throw new Exception(string.Format("Failed in call to RegisterDeviceNotification ({0})", GetLastError()));
      }
    }
Example #19
0
 private static extern IntPtr RegisterDeviceNotification(IntPtr handle, ref DeviceBroadcastInterface filter,
                                                         int flags);
    internal void RegisterDeviceArrival()
    {
      DeviceBroadcastInterface dbi = new DeviceBroadcastInterface();

      dbi.Size = Marshal.SizeOf(dbi);
      dbi.DeviceType = 0x5;
      dbi.ClassGuid = Class;

      _handleDeviceArrival = RegisterDeviceNotification(Handle, ref dbi, 0);
      int lastError = Marshal.GetLastWin32Error();
      if (_handleDeviceArrival == IntPtr.Zero)
        throw new Win32Exception(lastError);
    }
Example #21
0
 public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, DeviceBroadcastInterface NotificationFilter, uint Flags);
Example #22
0
 void SignalDeviceChange(DeviceChange state, DeviceBroadcastInterface volume)
 {
     _manager.EnqueueEvent(_manager.DeviceChanged, new DeviceChangeArgs(state, volume.Name));
 }