在UsbTreeView軟體里可以看到Location Info資訊,如下圖的紅色線標識的地方,可是我用SetupDiGetClassDevs,SetupDiEnumDeviceInterfaces,SetupDiGetDeviceInstanceId,SetupDiGetDeviceRegistryPropertyA,等函式都用了,怎么就是找不到這個Location Info資訊?另外用黃色標記的地方,怎么有兩個Device ID?而且還不一樣,我只能獲得第二個Device ID,怎么能獲得第一個Device ID?
uj5u.com熱心網友回復:
https://docs.microsoft.com/en-us/previous-versions/ff537421(v=vs.85)找找吧,從描述上看應該是IOCTL_INTERNAL_USB_GET_TOPOLOGY_ADDRESS
uj5u.com熱心網友回復:
自己頂一下,希望高手指導一下uj5u.com熱心網友回復:
第一個device id應該是父系屬性SetupDiGetClassDevs 取得某類設備集合比如在線USB設備集
SetupDiEnumDeviceInfo 依次列舉上面的集合,對每個設備有對應的資訊,比如實體ID
SetupDiGetDeviceInstanceId
CM_Get_Parent 取得某個設備實體的“父系”實體
uj5u.com熱心網友回復:
謝謝你的幫助,SetupDiGetClassDevs ,SetupDiEnumDeviceInfo ,SetupDiGetDeviceInstanceId這三個函式我都用了,獲得的資訊不是很多,CM_Get_Parent這個函式沒用過,我待會試試,其實我是想得到usb口的埠號,在UsbTreeView左邊目錄樹里有對應的埠號,我一直沒有獲得這個埠號,所以上面截圖沒有截目錄樹,在右邊的父系中Location Info中的port #0002對應的應該就是這個埠號,所以才想到獲得這個資訊,如下圖,如果能直接獲得左邊目錄樹里的Port2那是最好了。
uj5u.com熱心網友回復:
這方面的資訊有點少uj5u.com熱心網友回復:
SetupDiGetDeviceProperty的DEVPKEY_Device_Parent屬性是USB HUB,DEVPKEY_Device_LocationInfo屬性是USB Port.uj5u.com熱心網友回復:
謝謝,這個函式我用過,沒找到埠資訊,我待會再試一下,看是不是以前漏掉了
uj5u.com熱心網友回復:
請教一下,SetupDiGetDeviceProperty這個函式要獲得DEVPKEY_Device_LocationInfo屬性,DEVPROPKEY這個引數怎么設定?我在網上看了幾個例子,設定這個引數的.fmtid和.pid寫的都是固定的,但是還不一樣,我不知道這個怎么獲得?我設備的guid是通過 Result = HidD_GetHidGuid(HidGuid)這個獲得的,
uj5u.com熱心網友回復:
#include <Windows.h>
#include <initguid.h>
#include <devpkey.h>
#include <cfgmgr32.h>
#include <SetupAPI.h>
#pragma comment (lib, "setupapi.lib")
#include <iostream>
using namespace std;
int main()
{
HDEVINFO DeviceInfoSet = SetupDiGetClassDevsW(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return 0;
for (int i = 0; ; i++) {
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(DeviceInfoSet, i, &DeviceInfoData))
break;
DWORD RequiredSize = 0;
DEVPROPTYPE PropertyType = 0;
WCHAR PropertyBuffer[4096] = { 0 };
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_BusReportedDeviceDesc, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_LocationInfo, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
wcout << L" Device Location Info: \"" << PropertyBuffer << L"\"" << endl;
}
return 0;
}
uj5u.com熱心網友回復:
SetupDiGetDeviceProperty的DEVPKEY_Device_Parent屬性是USB HUB,DEVPKEY_Device_LocationInfo屬性是USB Port.
請教一下,SetupDiGetDeviceProperty這個函式要獲得DEVPKEY_Device_LocationInfo屬性,DEVPROPKEY這個引數怎么設定?我在網上看了幾個例子,設定這個引數的.fmtid和.pid寫的都是固定的,但是還不一樣,我不知道這個怎么獲得?我設備的guid是通過 Result = HidD_GetHidGuid(HidGuid)這個獲得的,
#include <Windows.h>
#include <initguid.h>
#include <devpkey.h>
#include <cfgmgr32.h>
#include <SetupAPI.h>
#pragma comment (lib, "setupapi.lib")
#include <iostream>
using namespace std;
int main()
{
HDEVINFO DeviceInfoSet = SetupDiGetClassDevsW(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return 0;
for (int i = 0; ; i++) {
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(DeviceInfoSet, i, &DeviceInfoData))
break;
DWORD RequiredSize = 0;
DEVPROPTYPE PropertyType = 0;
WCHAR PropertyBuffer[4096] = { 0 };
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_BusReportedDeviceDesc, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_LocationInfo, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
wcout << L" Device Location Info: \"" << PropertyBuffer << L"\"" << endl;
}
return 0;
}
謝謝你的回復,這個可以得到USB的埠資訊,但是我的設備是Hid設備,應該是這個USB下面的一個子設備,怎么通過Hid設備找到父設備USB?我在網上查到要用到這幾個函式:CM_Locate_DevNode,CM_Get_Parent,CM_Get_DevNode_Property ,但是CM_Get_Parent(ref IntPtr pdnDevInst, IntPtr dnDevInst, uint ulFlags)這個函式中的IntPtr dnDevInst這個引數我不知道怎么獲得?嘗試了用CM_Locate_DevNode這個函式獲得,沒有成功
uj5u.com熱心網友回復:
SetupDiGetDeviceProperty的DEVPKEY_Device_Parent屬性是USB HUB,DEVPKEY_Device_LocationInfo屬性是USB Port.
請教一下,SetupDiGetDeviceProperty這個函式要獲得DEVPKEY_Device_LocationInfo屬性,DEVPROPKEY這個引數怎么設定?我在網上看了幾個例子,設定這個引數的.fmtid和.pid寫的都是固定的,但是還不一樣,我不知道這個怎么獲得?我設備的guid是通過 Result = HidD_GetHidGuid(HidGuid)這個獲得的,
#include <Windows.h>
#include <initguid.h>
#include <devpkey.h>
#include <cfgmgr32.h>
#include <SetupAPI.h>
#pragma comment (lib, "setupapi.lib")
#include <iostream>
using namespace std;
int main()
{
HDEVINFO DeviceInfoSet = SetupDiGetClassDevsW(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return 0;
for (int i = 0; ; i++) {
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(DeviceInfoSet, i, &DeviceInfoData))
break;
DWORD RequiredSize = 0;
DEVPROPTYPE PropertyType = 0;
WCHAR PropertyBuffer[4096] = { 0 };
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_BusReportedDeviceDesc, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_LocationInfo, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
wcout << L" Device Location Info: \"" << PropertyBuffer << L"\"" << endl;
}
return 0;
}
謝謝你的回復,這個可以得到USB的埠資訊,但是我的設備是Hid設備,應該是這個USB下面的一個子設備,怎么通過Hid設備找到父設備USB?我在網上查到要用到這幾個函式:CM_Locate_DevNode,CM_Get_Parent,CM_Get_DevNode_Property ,但是CM_Get_Parent(ref IntPtr pdnDevInst, IntPtr dnDevInst, uint ulFlags)這個函式中的IntPtr dnDevInst這個引數我不知道怎么獲得?嘗試了用CM_Locate_DevNode這個函式獲得,沒有成功
uj5u.com熱心網友回復:
不清楚,只能到這了轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/225193.html
標籤:C++ 語言
上一篇:關于VS210MFC串口編程m_Mscom.get_Input();接收快取區資料出錯的問題
下一篇:c語言求助
