- 最後登錄
- 2021-11-29
- 在線時間
- 0 小時
- 註冊時間
- 2012-6-19
- 閱讀權限
- 20
- 精華
- 0
- UID
- 11527950
- 帖子
- 46
- 積分
- 47 點
- 潛水值
- 1260 米
| 若有安裝色情守門員,可用無界、自由門等軟件瀏覽伊莉。或使用以下網址瀏覽伊莉: http://www.eyny.com:81/index.php 下列程式碼是FindDevice
其中 while (SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, (uint)nIndex, ref oInterface))一直為false
oInterface的值為UsbLibrary.Win32Usb.DeviceInterfaceData
nIndex的值為0
gHid的值為{4d1e55b2-f16f-11cf-88cb-001111000030}
hInfoSet的值為466972656
不知是為何原因一直無法為true 麻煩各位大大熱心解說
public static HIDDevice FindDevice(int nVid, int nPid, Type oType)
{
string strPath = string.Empty;
string strSearch = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); // first, build the path search string
Guid gHid = HIDGuid;
//HidD_GetHidGuid(out gHid); // next, get the GUID from Windows that it uses to represent the HID USB interface
IntPtr hInfoSet = SetupDiGetClassDevs(ref gHid, null, IntPtr.Zero, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); // this gets a list of all HID devices currently connected to the computer (InfoSet)
try
{
DeviceInterfaceData oInterface = new DeviceInterfaceData(); // build up a device interface data block
oInterface.Size = Marshal.SizeOf(oInterface);
// Now iterate through the InfoSet memory block assigned within Windows in the call to SetupDiGetClassDevs
// to get device details for each device connected
int nIndex = 0;
while (SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, (uint)nIndex, ref oInterface)) // this gets the device interface information for a device at index 'nIndex' in the memory block
{
string strDevicePath = GetDevicePath(hInfoSet, ref oInterface); // get the device path (see helper method 'GetDevicePath')
if (strDevicePath.IndexOf(strSearch) >= 0) // do a string search, if we find the VID/PID string then we found our device!
{
HIDDevice oNewDevice = (HIDDevice)Activator.CreateInstance(oType); // create an instance of the class for this device
oNewDevice.Initialise(strDevicePath); // initialise it with the device path
return oNewDevice; // and return it
}
nIndex++; // if we get here, we didn't find our device. So move on to the next one.
}
}
catch(Exception ex)
{
throw HIDDeviceException.GenerateError(ex.ToString());
//Console.WriteLine(ex.ToString());
}
finally
{
// Before we go, we have to free up the InfoSet memory reserved by SetupDiGetClassDevs
SetupDiDestroyDeviceInfoList(hInfoSet);
}
return null; // oops, didn't find our device
} ... |
|