Example #1
0
        public IEnumerable<string> FindDevices(Guid guid, string vendorId, string productId)
        {
            var deviceInfoSet = IntPtr.Zero;
            var deviceDetailData = IntPtr.Zero;
            var devices = new List<string>();

            try
            {
                deviceInfoSet = InteropSetupAPI.SetupDiGetClassDevs(ref guid, IntPtr.Zero, IntPtr.Zero,
                                                                    (int)InteropSetupAPI.DIGCFFlags.DIGCF_DEVICEINTERFACE |
                                                                    (int)InteropSetupAPI.DIGCFFlags.DIGCF_PRESENT);

                var deviceInterfaceData = new InteropDevices.SP_DEVICE_INTERFACE_DATA();
                deviceInterfaceData.cbSize = Marshal.SizeOf(deviceInterfaceData);

                // find all the devices of the selected vendor/product ID
                for (var i = 0; InteropSetupAPI.SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref guid, i, ref deviceInterfaceData); i++)
                {
                    var devicePath = CheckDevice(deviceInterfaceData, deviceInfoSet, out deviceDetailData, vendorId, productId);
                    if (devicePath != null) { devices.Add(devicePath); }
                }

                return devices;
            }
            finally
            {
                if (deviceInfoSet != IntPtr.Zero)
                    InteropSetupAPI.SetupDiDestroyDeviceInfoList(deviceInfoSet);

                if (deviceDetailData != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(deviceDetailData);
                }
            }
        }
Example #2
0
 public static extern Boolean SetupDiGetDeviceInterfaceDetail(IntPtr DeviceInfoSet, ref InteropDevices.SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, IntPtr DeviceInterfaceDetailData, Int32 DeviceInterfaceDetailDataSize, ref Int32 RequiredSize, IntPtr DeviceInfoData);
Example #3
0
 public static extern Boolean SetupDiEnumDeviceInterfaces(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, ref System.Guid InterfaceClassGuid, Int32 MemberIndex, ref InteropDevices.SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);