// Token: 0x0600002B RID: 43 RVA: 0x00003FA4 File Offset: 0x000021A4 public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string empty = string.Empty; string value = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); Guid hidguid = Win32Usb.HIDGuid; IntPtr intPtr = Win32Usb.SetupDiGetClassDevs(ref hidguid, null, IntPtr.Zero, 18u); try { Win32Usb.DeviceInterfaceData deviceInterfaceData = default(Win32Usb.DeviceInterfaceData); deviceInterfaceData.Size = Marshal.SizeOf(deviceInterfaceData); int num = 0; while (Win32Usb.SetupDiEnumDeviceInterfaces(intPtr, 0u, ref hidguid, (uint)num, ref deviceInterfaceData)) { string devicePath = HIDDevice.GetDevicePath(intPtr, ref deviceInterfaceData); if (devicePath.IndexOf(value) >= 0) { HIDDevice hiddevice = (HIDDevice)Activator.CreateInstance(oType); hiddevice.Initialise(devicePath); return(hiddevice); } num++; } } catch (Exception ex) { throw HIDDeviceException.GenerateError(ex.ToString()); } finally { Win32Usb.SetupDiDestroyDeviceInfoList(intPtr); } return(null); }
public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string str = $"vid_{nVid:x4}&pid_{nPid:x4}"; Guid hIDGuid = Win32Usb.HIDGuid; IntPtr lpDeviceInfoSet = Win32Usb.SetupDiGetClassDevs(ref hIDGuid, null, IntPtr.Zero, 0x12); try { Win32Usb.DeviceInterfaceData structure = new Win32Usb.DeviceInterfaceData(); structure.Size = Marshal.SizeOf(structure); for (int i = 0; Win32Usb.SetupDiEnumDeviceInterfaces(lpDeviceInfoSet, 0, ref hIDGuid, (uint)i, ref structure); i++) { string devicePath = GetDevicePath(lpDeviceInfoSet, ref structure); if (devicePath.IndexOf(str) >= 0) { HIDDevice device = (HIDDevice)Activator.CreateInstance(oType); device.Initialise(devicePath); return(device); } } } catch (Exception exception) { throw HIDDeviceException.GenerateError(exception.ToString()); } finally { Win32Usb.SetupDiDestroyDeviceInfoList(lpDeviceInfoSet); } return(null); }
public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string value = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); Guid hIDGuid = Win32Usb.HIDGuid; IntPtr intPtr = Win32Usb.SetupDiGetClassDevs(ref hIDGuid, null, IntPtr.Zero, 18u); try { DeviceInterfaceData deviceInterfaceData = default(DeviceInterfaceData); deviceInterfaceData.Size = Marshal.SizeOf(deviceInterfaceData); int num = 0; while (Win32Usb.SetupDiEnumDeviceInterfaces(intPtr, 0u, ref hIDGuid, (uint)num, ref deviceInterfaceData)) { string text = HIDDevice.smethod_0(intPtr, ref deviceInterfaceData); if (text.IndexOf(value) < 0) { num++; continue; } HIDDevice hIDDevice = (HIDDevice)Activator.CreateInstance(oType); hIDDevice.method_0(text); return(hIDDevice); } } catch (Exception ex) { throw GException0.GenerateError(ex.ToString()); } finally { Marshal.GetLastWin32Error(); Win32Usb.SetupDiDestroyDeviceInfoList(intPtr); } return(null); }