예제 #1
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 DeviceInterfaceDetailData? Run(IntPtr deviceInfoSet, DeviceInterfaceData deviceInterfaceData)
        {
            var bufferSize = 0;
            var interfaceDetail = new DeviceInterfaceDetailData
            {
                Size = IntPtr.Size == 4 ? 4 + Marshal.SystemDefaultCharSize : 8
            };

            SetupDiGetDeviceInterfaceDetailBuffer(deviceInfoSet, ref deviceInterfaceData, IntPtr.Zero, 0, ref bufferSize, IntPtr.Zero);

            if (SetupDiGetDeviceInterfaceDetailMethod(
                deviceInfoSet,
                ref deviceInterfaceData,
                ref interfaceDetail,
                bufferSize,
                ref bufferSize, IntPtr.Zero))
                return interfaceDetail;
            else
                return null;
        }
예제 #3
0
 static internal extern bool SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, ref DeviceInfoData deviceInfoData, ref Guid interfaceClassGuid, uint memberIndex, ref DeviceInterfaceData deviceInterfaceData);
 static internal extern bool SetupDiGetDeviceInterfaceDetailMethod(IntPtr deviceInfoSet, ref DeviceInterfaceData deviceInterfaceData, ref DeviceInterfaceDetailData deviceInterfaceDetailData, int deviceInterfaceDetailDataSize, ref int requiredSize, IntPtr deviceInfoData);