protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                if (m.Msg != WmDevicechange)
                {
                    return;
                }

                WM_DeviceChangeMessage wp = (WM_DeviceChangeMessage)m.WParam;

                if (wp != WM_DeviceChangeMessage.DBT_DEVICEARRIVAL && wp != WM_DeviceChangeMessage.DBT_DEVICEREMOVECOMPLETE)
                {
                    return;
                }

                Guid   guid = Guid.Empty;
                string name = null;

                var        hdr  = (DeviceBroadcastHeader)Marshal.PtrToStructure(m.LParam, typeof(DeviceBroadcastHeader));
                DeviceType type = hdr.dbcc_devicetype;

                if (type == DeviceType.DBT_DEVTYP_PORT)
                {
                    var prt = (DEV_BROADCAST_PORT)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_PORT));
                    name = new string(prt.dbcp_name);
                }
                else if (type == DeviceType.DBT_DEVTYP_DEVICEINTERFACE)
                {
                    var dev = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));
                    name = new string(dev.dbcc_name);
                    guid = dev.dbcc_classguid;
                }
                name = name?.Substring(0, name.IndexOf('\0'));

                var args = new UsbNotificationEventArgs(type, name, guid);

                if (wp == WM_DeviceChangeMessage.DBT_DEVICEARRIVAL)
                {
                    OnDeviceArrival(args);
                }
                else
                {
                    OnDeviceRemoveComplete(args);
                }
            }
 private static void OnDeviceRemoveComplete(UsbNotificationEventArgs args)
 {
     DeviceRemovalComplete?.Invoke(null, args);
 }
 private static void OnDeviceArrival(UsbNotificationEventArgs args)
 {
     DeviceArrival?.Invoke(null, args);
 }