CodePudding user response:
Is there any API can be usedCodePudding user response:
SetupDiEnumDeviceInterfaces apis, such asCodePudding user response:
Can read the registry, the Hardware \ \ DeviceMap \ \ SerialComm, can refer to my codevoid CComDlg: : FindComPort ()I insert all current information into the usb port into the combox
{
Hkeys hkeys;
If (RegOpenKeyEx (HKEY_LOCAL_MACHINE, _T (" Hardware \ \ DeviceMap \ \ SerialComm "), NULL, KEY_READ, & amp; Hkeys)==ERROR_SUCCESS)
{
SzComName TCHAR szPortName [256], [256].
DWORD dwLong dwSize;
Int nCount=0;
M_pCombox=(CComboBox *) GetDlgItem (IDC_COMBO_COM);
M_pCombox - & gt; ResetContent ();
While (true)
{
DwLong=dwSize=256;
If (RegEnumValue (hkeys, nCount szPortName, & amp; DwLong, NULL, NULL, PUCHAR szComName, & amp; DwSize)==ERROR_NO_MORE_ITEMS)
break;
M_pCombox - & gt; InsertString (nCount, szComName);
NCount++;
}
RegCloseKey (hkeys);
M_pCombox - & gt; SetCurSel (0);
}
}
CodePudding user response:
//according to equipment installation class GUID create empty equipment information collection
HDEVINFO DeviceInfoSet=SetupDiCreateDeviceInfoList (SetupClassGuid, NULL);
//according to the installation of equipment class GUID equipment information collection
HDEVINFO HDEVINFO;
If (InterfaceClassGuid==NULL)
{
HDevInfo=SetupDiGetClassDevsEx (NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_DEVICEINTERFACE | DIGCF_PRESENT, DeviceInfoSet, NULL, NULL);
}
The else
{
HDevInfo=SetupDiGetClassDevsEx (InterfaceClassGuid (PCSTR) & amp;" USB ", NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT, DeviceInfoSet, NULL, NULL);
}
//equipment information data
DWORD DeviceIndex=0;
Bool k=true;
While (SetupDiEnumDeviceInfo (hDevInfo DeviceIndex++, & amp; DeviceInfoData))
{
//access device instance ID
If (SetupDiGetDeviceInstanceId (hDevInfo, & amp; DeviceInfoData DeviceInstanceId, DeviceInstanceIdSize, NULL) & amp; & K)
{
SetupDiGetDeviceRegistryProperty (hDevInfo, & amp; DeviceInfoData,
SPDRP_HARDWAREID,
0, (PBYTE) fname,
Sizeof (fname),
NULL);
}
}
CodePudding user response:
In the WDK USBView source code, can refer toCodePudding user response: