Example #1
0
        public static string Description(IntPtr deviceInfoSet, DeviceInfoData devInfoData)
        {
            if (Environment.OSVersion.Version.Major > 5)
            {
                var descriptionBuffer = new byte[1024];
                ulong propertyType = 0;
                var requiredSize = 0;

                var has = SetupDiGetDevicePropertyW(deviceInfoSet,
                                                    ref devInfoData,
                                                    ref DevicePropertyKeyDeviceDescription,
                                                    ref propertyType,
                                                    descriptionBuffer,
                                                    descriptionBuffer.Length,
                                                    ref requiredSize,
                                                    0);

                if (has)
                    return descriptionBuffer.ToUTF16String();
                else
                    return null;
            }
            else
                return null;
        }
Example #2
0
        public static void ForEach(IntPtr deviceInfoSet, Guid hidClass, Action<DeviceInfoData, DeviceInterfaceData> action)
        {
            var deviceInfoData = new DeviceInfoData
            {
                DevInst = 0,
                ClassGuid = Guid.Empty,
                Reserved = IntPtr.Zero
            };
            deviceInfoData.cbSize = Marshal.SizeOf(deviceInfoData);

            uint deviceIndex = 0;
            while (SetupDiEnumDeviceInfo(deviceInfoSet, deviceIndex, ref deviceInfoData))
            {
                deviceIndex += 1;

                var deviceInterfaceData = new DeviceInterfaceData
                {
                    Flags = 0,
                    InterfaceClassGuid = Guid.Empty,
                    Reserved = IntPtr.Zero
                };
                deviceInterfaceData.cbSize = Marshal.SizeOf(deviceInterfaceData);

                uint deviceInterfaceIndex = 0;
                while (SetupDiEnumDeviceInterfaces(deviceInfoSet, ref deviceInfoData, ref hidClass, deviceInterfaceIndex, ref deviceInterfaceData))
                {
                    deviceInterfaceIndex++;

                    action(deviceInfoData, deviceInterfaceData);
                }
            }
        }
        public static string Description(IntPtr deviceInfoSet, DeviceInfoData deviceInfoData)
        {
            var descriptionBuffer = new byte[1024];

            var requiredSize = 0;
            var type = 0;

            SetupDiGetDeviceRegistryPropertyMethod(deviceInfoSet,
                                                   ref deviceInfoData,
                                                   0,
                                                   ref type,
                                                   descriptionBuffer,
                                                   descriptionBuffer.Length,
                                                   ref requiredSize);

            return descriptionBuffer.ToUTF8String();
        }
Example #4
0
 static internal extern bool SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, ref DeviceInfoData deviceInfoData, ref Guid interfaceClassGuid, uint memberIndex, ref DeviceInterfaceData deviceInterfaceData);
Example #5
0
 static internal extern bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, uint memberIndex, ref DeviceInfoData deviceInfoData);
Example #6
0
 static internal extern bool SetupDiGetDevicePropertyW(IntPtr deviceInfo, ref DeviceInfoData deviceInfoData, ref DevicePropertyKey propkey, ref ulong propertyDataType, byte[] propertyBuffer, int propertyBufferSize, ref int requiredSize, uint flags);
 static internal extern bool SetupDiGetDeviceRegistryPropertyMethod(IntPtr deviceInfoSet, ref DeviceInfoData deviceInfoData, int propertyVal, ref int propertyRegDataType, byte[] propertyBuffer, int propertyBufferSize, ref int requiredSize);