private void CheckMessage(object?sender, WindowMessageEventArgs e)
 {
     if ((int)e.WParam == deviceNodesChanged)
     {
         DeviceArrived?.Invoke(sender, e);
     }
 }
Exemplo n.º 2
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == WM_DEVICECHANGE)
            {
                DEV_BROADCAST_HDR hdr;

                switch ((int)wParam)
                {
                case DBT_DEVICEARRIVAL:
                    Debug.WriteLine("Device added.");

                    hdr = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_HDR));

                    if (hdr.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        var deviceInterface =
                            (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(lParam,
                                                                                  typeof(DEV_BROADCAST_DEVICEINTERFACE));

                        DeviceArrived?.Invoke(deviceInterface.dbcc_name);
                    }

                    break;

                case DBT_DEVICEREMOVECOMPLETE:
                    Debug.WriteLine("Device removed.");

                    hdr = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_HDR));

                    if (hdr.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        var deviceInterface =
                            (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(lParam,
                                                                                  typeof(DEV_BROADCAST_DEVICEINTERFACE));

                        DeviceRemoved?.Invoke(deviceInterface.dbcc_name);
                    }

                    break;
                }
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 3
0
        private void ProcessMessage(Message message)
        {
            if (message.Msg == WM_DEVICECHANGE)
            {
                switch (message.WParam.ToInt32())
                {
                case DBT_DEVICEARRIVAL:
                    if (Marshal.ReadInt32(message.LParam, 4) == DBT_DEVTYP_VOLUME)
                    {
                        DEV_BROADCAST_VOLUME volume = Marshal.PtrToStructure <DEV_BROADCAST_VOLUME>(message.LParam);
                        string deviceName           = DeviceMaskToDeviceName(volume.DBVC_UnitMask);

                        DeviceArrived?.Invoke(this, new DeviceNotificationEventArgs(deviceName));
                        RegisterDeviceNotification(deviceName);
                    }
                    break;

                case DBT_DEVICEQUERYREMOVE:
                    if (Marshal.ReadInt32(message.LParam, 4) == DBT_DEVTYP_HANDLE)
                    {
                        DEV_BROADCAST_HANDLE data = Marshal.PtrToStructure <DEV_BROADCAST_HANDLE>(message.LParam);
                        if (DeviceHandles.ContainsKey(data.DBCH_HDevNotify))
                        {
                            DeviceQueryRemove?.Invoke(this, new DeviceNotificationEventArgs(DeviceHandles[data.DBCH_HDevNotify]));
                        }

                        UnregisterDeviceNotification(data.DBCH_HDevNotify, data.DBCH_Handle);
                    }
                    break;

                case DBT_DEVICEREMOVECOMPLETE:
                    if (Marshal.ReadInt32(message.LParam, 4) == DBT_DEVTYP_VOLUME)
                    {
                        DEV_BROADCAST_VOLUME volume = Marshal.PtrToStructure <DEV_BROADCAST_VOLUME>(message.LParam);
                        string deviceName           = DeviceMaskToDeviceName(volume.DBVC_UnitMask);

                        DeviceRemoveComplete?.Invoke(this, new DeviceNotificationEventArgs(deviceName));
                    }
                    break;
                }
            }
        }
Exemplo n.º 4
0
        private void OnDeviceArrival()
        {
            _debugger.Trace();

            // Searching for new devices
            foreach (var driveInfo in DriveInfo.GetDrives())
            {
                // Ignore already presented devices
                if (IsPresent(driveInfo.GetHashCode()))
                {
                    continue;
                }

                // Creating and initializing new device
                var device = _container.GetInstance <IDevice>();
                device.Initialize(driveInfo);

                // Adding to list and throwing event about that
                Devices.Add(device);
                DeviceArrived?.Invoke(this, new DeviceArrivedEventArgs(device));
            }
        }
Exemplo n.º 5
0
        protected virtual void OnDeviceArrived(DEV_BROADCAST_VOLUME volume)
        {
            // Get the drive letter
            char c = DriveMaskToLetter(volume.dbcv_unitmask);
            var  e = new RemovableMediaEventArgs {
                Drive = c + ":\\"
            };

            DeviceArrived?.Invoke(this, e);

            // Register for query remove if requested
            if (e.HookQueryRemove)
            {
                // If something is already hooked, unhook it now
                if (this.deviceNotifyHandle != IntPtr.Zero)
                {
                    RegisterForDeviceChange(false, null);
                }

                RegisterQuery(c + ":\\");
            }
        }
Exemplo n.º 6
0
 void IDeckLinkDeviceNotificationCallback.DeckLinkDeviceArrived(IDeckLink deckLinkDevice)
 {
     DeviceArrived?.Invoke(deckLinkDevice);
 }