Exemple #1
0
        public UsbDeviceList(Hardware hardware)
        {
            InitializeComponent();

            _hardware = hardware;
            _hardware.DeviceInterfaceChanged += Hardware_DeviceInterfaceChanged;

            RefreshList();
        }
Exemple #2
0
        protected Device(IntPtr enumeration, ref Hardware.SP_DEVINFO_DATA device)
        {
            HardwareIds = (string[])GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.HardwareId);
            Manufacturer = (string)GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.Manufacturer);
            DeviceDescription = (string)GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.DeviceDescription);
            FriendlyName = (string)GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.FriendlyName);
            LocationInformation = (string)GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.LocationInformation);
            PhysicalDeviceObjectName = (string)GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.PhysicalDeviceObjectName);

            Configuration = (ConfigFlags)GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.ConfigFlags);
            InstallState = (InstallStates)GetDeviceRegistryProperty(enumeration, ref device, RegistryProperty.InstallState);

            LargeIcon = LoadDeviceIcon(enumeration, ref device, 48);
            SmallIcon = LoadDeviceIcon(enumeration, ref device, 16);
        }
Exemple #3
0
 private Bitmap LoadDeviceIcon(IntPtr enumeration, ref Hardware.SP_DEVINFO_DATA device, uint size)
 {
     IntPtr hIcon;
     return (SetupDiLoadDeviceIcon(enumeration, ref device, size, size, 0, out hIcon)) ? Bitmap.FromHicon(hIcon) : null;
 }
Exemple #4
0
        private static extern bool SetupDiLoadDeviceIcon(
			IntPtr deviceInfoSet,
			ref Hardware.SP_DEVINFO_DATA deviceInfoData,
			uint cXIcon,
			uint cYIcon,
			uint flags,
			out IntPtr hIcon
		);
Exemple #5
0
        private static extern bool SetupDiGetDeviceRegistryProperty(
			IntPtr deviceInfoSet,
			ref Hardware.SP_DEVINFO_DATA deviceInfoData,
			Device.RegistryProperty property,
			out RegistryDataType propertyRegDataType,
			IntPtr propertyBuffer,
			uint propertyBufferSize,
			out UInt32 requiredSize
		);
Exemple #6
0
        private static object GetDeviceRegistryProperty(IntPtr h, ref Hardware.SP_DEVINFO_DATA devInfo, RegistryProperty property)
        {
            RegistryDataType dataType;
            uint bufferLength;
            SetupDiGetDeviceRegistryProperty(h, ref devInfo, property, out dataType, IntPtr.Zero, 0, out bufferLength);

            object result = null;
            IntPtr buffer = Marshal.AllocHGlobal((int)bufferLength);
            if (SetupDiGetDeviceRegistryProperty(h, ref devInfo, property, out dataType, buffer, bufferLength, out bufferLength)) {
                switch (dataType) {
                    case RegistryDataType.REG_SZ:
                        result = Marshal.PtrToStringAuto(buffer);
                        break;

                    case RegistryDataType.REG_MULTI_SZ:
                        var bytes = PtrToByteArray(buffer, bufferLength);
                        var text = Encoding.Unicode.GetString(bytes);
                        result = text.TrimEnd('\0').Split('\0');
                        break;

                    case RegistryDataType.REG_BINARY:
                        result = PtrToByteArray(buffer, bufferLength);
                        break;

                    case RegistryDataType.REG_DWORD:
                        result = Marshal.ReadInt32(buffer);
                        break;

                    default:
                        throw new Exception(string.Format("Unsupported data type: {0}", dataType));
                }
            }
            Marshal.FreeHGlobal(buffer);
            return result;
        }
Exemple #7
0
 private void UsbDeviceList_FormClosed(object sender, FormClosedEventArgs e)
 {
     _hardware.DeviceInterfaceChanged -= Hardware_DeviceInterfaceChanged;
     _hardware = null;
 }
Exemple #8
0
 public DeviceInterfaceChangedArgs(Hardware.DeviceEvent eventType, Guid classId, string deviceName)
 {
     EventType = eventType;
     ClassId = classId;
     DeviceName = deviceName;
 }