private void method_0(string string_0) { this.m_hHandle = Win32Usb.CreateFile(string_0, 3221225472u, 3u, IntPtr.Zero, 3u, 1073741824u, IntPtr.Zero); if (this.m_hHandle != Win32Usb.InvalidHandleValue) { IntPtr lpData = default(IntPtr); if (Win32Usb.HidD_GetPreparsedData(this.m_hHandle, out lpData)) { try { HidCaps hidCaps = default(HidCaps); Win32Usb.HidP_GetCaps(lpData, out hidCaps); this.m_nInputReportLength = hidCaps.InputReportByteLength; this.m_nOutputReportLength = hidCaps.OutputReportByteLength; this.m_oFile = new FileStream(new SafeFileHandle(this.m_hHandle, false), FileAccess.ReadWrite, this.m_nInputReportLength, true); } catch (Exception ex) { Console.WriteLine(ex.Message); throw GException0.GenerateWithWinError("Failed to get the detailed data from the hid."); } finally { Win32Usb.HidD_FreePreparsedData(ref lpData); } return; } throw GException0.GenerateWithWinError("GetPreparsedData failed"); } this.m_hHandle = IntPtr.Zero; throw GException0.GenerateWithWinError("Failed to create device file"); }
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); }