/// <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); }
/// <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)); }
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)); }
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())); } }
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); } }
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())); } }
protected static extern IntPtr RegisterDeviceNotification(IntPtr hwnd, DeviceBroadcastInterface oInterface, uint nFlags);
/// <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); }
/// <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);
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())); }
private static extern IntPtr RegisterDeviceNotification(IntPtr handle, ref DeviceBroadcastInterface filter, int flags);
/// <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);
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); }
public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, DeviceBroadcastInterface NotificationFilter, uint Flags);
void SignalDeviceChange(DeviceChange state, DeviceBroadcastInterface volume) { _manager.EnqueueEvent(_manager.DeviceChanged, new DeviceChangeArgs(state, volume.Name)); }