Exemple #1
0
        IntPtr hwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == WM_DEVICECHANGE)
            {
                if ((int)wParam == DBT_DEVICEARRIVAL)
                {
                    DEV_BROADCAST_DEVICEINTERFACE info = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));
                    if (info.dbcc_classguid == HidClassGuid)
                    {
                        if (SUDDriver.DescribeSUD(info.dbcc_name).ProductType == SeneyeProductType.SUDv2e)
                        {
                            this.MessageBus.SendMessage <string>(info.dbcc_name, "SUDArrived");
                        }
                    }
                }
                else if ((int)wParam == DBT_DEVICEREMOVECOMPLETE)
                {
                    DEV_BROADCAST_DEVICEINTERFACE info = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));

                    if (info.dbcc_classguid == HidClassGuid)
                    {
                        this.MessageBus.SendMessage <string>(info.dbcc_name, "HIDDisconnected");
                    }
                }
            }
            return(IntPtr.Zero);
        }
Exemple #2
0
        private void _EnumerateDevices()
        {
            List <string> paths         = new List <string>();
            var           hidClass      = HidClassGuid;
            var           deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref hidClass, null, 0, NativeMethods.DIGCF_PRESENT | NativeMethods.DIGCF_DEVICEINTERFACE);

            if (deviceInfoSet.ToInt64() != NativeMethods.INVALID_HANDLE_VALUE)
            {
                var deviceInfoData = CreateDeviceInfoData();
                var deviceIndex    = 0;

                while (NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, deviceIndex, ref deviceInfoData))
                {
                    deviceIndex += 1;

                    var deviceInterfaceData = new NativeMethods.SP_DEVICE_INTERFACE_DATA();
                    deviceInterfaceData.cbSize = Marshal.SizeOf(deviceInterfaceData);
                    var deviceInterfaceIndex = 0;

                    while (NativeMethods.SetupDiEnumDeviceInterfaces(deviceInfoSet, ref deviceInfoData, ref hidClass, deviceInterfaceIndex, ref deviceInterfaceData))
                    {
                        deviceInterfaceIndex++;
                        var devicePath = GetDevicePath(deviceInfoSet, deviceInterfaceData);

                        if (!paths.Contains(devicePath))
                        {
                            paths.Add(devicePath);
                        }
                    }
                }
                NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
            }
            paths.ForEach(x => {
                if (SUDDriver.DescribeSUD(x).ProductType == SeneyeProductType.SUDv2e)
                {
                    this.MessageBus.SendMessage <string>(x, "SUDArrived");
                }
            });
        }