Beispiel #1
0
        public void ProcessWindowsMessage(ref Message m)
        {
            Win32Wrapper.DBTDEVTYP devType;

            if (m.Msg == Win32Wrapper.WM_DEVICECHANGE)
            {
                switch (m.WParam.ToInt32())
                {
                case (int)Win32Wrapper.DBTDEVICE.DBT_DEVICEARRIVAL:
                    // New device has just arrived
                    devType = (Win32Wrapper.DBTDEVTYP)Marshal.ReadInt32(m.LParam, 4);
                    if (devType == Win32Wrapper.DBTDEVTYP.DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        var e = new USBDeviceEventArgs();
                        USBDeviceAttached(this, e);
                    }

                    break;

                case (int)Win32Wrapper.DBTDEVICE.DBT_DEVICEQUERYREMOVE:
                    // Device is about to be removed, any application can cancel the removal
                    devType = (Win32Wrapper.DBTDEVTYP)Marshal.ReadInt32(m.LParam, 4);
                    if (devType == Win32Wrapper.DBTDEVTYP.DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        var e = new USBDeviceEventArgs();

                        /*Win32Wrapper.DEV_BROADCAST_DEVICEINTERFACE deviceInterface = new Win32Wrapper.DEV_BROADCAST_DEVICEINTERFACE();
                         *
                         *  int size = Marshal.SizeOf(deviceInterface);
                         *  deviceInterface.dbcc_size = size;
                         *  Marshal.PtrToStructure(m.LParam, typeof(Win32Wrapper.DEV_BROADCAST_DEVICEINTERFACE));*/

                        USBDeviceQueryRemove(this, e);
                    }

                    break;

                case (int)Win32Wrapper.DBTDEVICE.DBT_DEVICEREMOVECOMPLETE:
                    // Device has been removed
                    devType = (Win32Wrapper.DBTDEVTYP)Marshal.ReadInt32(m.LParam, 4);
                    if (devType == Win32Wrapper.DBTDEVTYP.DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        USBDeviceRemoved(this, new USBDeviceEventArgs());
                    }
                    break;
                }
            }
        }
Beispiel #2
0
        public void ProcessWindowsMessage(ref Message m)
        {
            Win32Wrapper.DBTDEVTYP devType;

            if (m.Msg == Win32Wrapper.WM_DEVICECHANGE)
            {
                // WM_DEVICECHANGE can have several meanings depending on the WParam value...
                switch (m.WParam.ToInt32())
                {
                    case (int)Win32Wrapper.DBTDEVICE.DBT_DEVICEARRIVAL:
                        // New device has just arrived
                        devType = (Win32Wrapper.DBTDEVTYP)Marshal.ReadInt32(m.LParam, 4);
                        if (devType == Win32Wrapper.DBTDEVTYP.DBT_DEVTYP_DEVICEINTERFACE)
                        {
                            USBDeviceEventArgs e = new USBDeviceEventArgs();
                            USBDeviceAttached(this, e);
                        }
                     break;

                    case (int)Win32Wrapper.DBTDEVICE.DBT_DEVICEQUERYREMOVE:
                        // Device is about to be removed, any application can cancel the removal
                        devType = (Win32Wrapper.DBTDEVTYP)Marshal.ReadInt32(m.LParam, 4);
                        if (devType == Win32Wrapper.DBTDEVTYP.DBT_DEVTYP_DEVICEINTERFACE)
                        {
                            USBDeviceEventArgs e = new USBDeviceEventArgs();
                            /*Win32Wrapper.DEV_BROADCAST_DEVICEINTERFACE deviceInterface = new Win32Wrapper.DEV_BROADCAST_DEVICEINTERFACE();

                            int size = Marshal.SizeOf(deviceInterface);
                            deviceInterface.dbcc_size = size;
                            Marshal.PtrToStructure(m.LParam, typeof(Win32Wrapper.DEV_BROADCAST_DEVICEINTERFACE));*/

                            USBDeviceQueryRemove(this, e);
                        }
                    break;
                    case (int)Win32Wrapper.DBTDEVICE.DBT_DEVICEREMOVECOMPLETE:
                        // Device has been removed
                        devType = (Win32Wrapper.DBTDEVTYP)Marshal.ReadInt32(m.LParam, 4);
                        if (devType == Win32Wrapper.DBTDEVTYP.DBT_DEVTYP_DEVICEINTERFACE)
                        {
                            USBDeviceEventArgs e = new USBDeviceEventArgs();
                            USBDeviceRemoved(this, e);
                        }
                        break;
                }
            }
        }