void RegisterHidNotification() { Win32.DEV_BROADCAST_DEVICEINTERFACE dbi = new Win32.DEV_BROADCAST_DEVICEINTERFACE(); int size = Marshal.SizeOf(dbi); dbi.dbcc_size = size; dbi.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE; dbi.dbcc_reserved = 0; dbi.dbcc_classguid = Win32.GUID_DEVINTERFACE_HID; dbi.dbcc_name = string.Empty; IntPtr buffer = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(dbi, buffer, true); IntPtr r = Win32.RegisterDeviceNotification(Handle, buffer, Win32.DEVICE_NOTIFY_WINDOW_HANDLE | Win32.DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); if (r == IntPtr.Zero) { label1.Text = Win32.GetLastError().ToString(); } }
void RegisterHidNotification() { Win32.DEV_BROADCAST_DEVICEINTERFACE dbi = new Win32.DEV_BROADCAST_DEVICEINTERFACE(); int size = Marshal.SizeOf(dbi); dbi.dbcc_size = size; dbi.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE; dbi.dbcc_reserved = 0; dbi.dbcc_classguid = Win32.GUID_DEVINTERFACE_HID; dbi.dbcc_name = string.Empty; IntPtr buffer = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(dbi, buffer, true); IntPtr r = Win32.RegisterDeviceNotification(Handle, buffer, Win32.DEVICE_NOTIFY_WINDOW_HANDLE | Win32.DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); if (r == IntPtr.Zero) { labelTouchpadMouseStatus.Text = Win32.GetLastError().ToString(); } }