HidLibrary.NativeMethods.SetupDiEnumDeviceInfo C# (CSharp) Method

SetupDiEnumDeviceInfo() private method

private SetupDiEnumDeviceInfo ( IntPtr deviceInfoSet, int memberIndex, SP_DEVINFO_DATA &deviceInfoData ) : bool
deviceInfoSet System.IntPtr
memberIndex int
deviceInfoData SP_DEVINFO_DATA
return bool
        internal static extern bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, int memberIndex, ref SP_DEVINFO_DATA deviceInfoData);

Usage Example

Example #1
0
        internal static IEnumerable <DeviceInfo> EnumerateDevices()
        {
            var devices       = new List <DeviceInfo>();
            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);
                        var description = GetBusReportedDeviceDescription(deviceInfoSet, ref deviceInfoData) ??
                                          GetDeviceDescription(deviceInfoSet, ref deviceInfoData);
                        devices.Add(new DeviceInfo {
                            Path = devicePath, Description = description
                        });
                    }
                }
                NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
            }
            return(devices);
        }
All Usage Examples Of HidLibrary.NativeMethods::SetupDiEnumDeviceInfo