Home > Software engineering >  O: c get connected usb
O: c get connected usb

Time:09-26

C + + for the connected usb device information

CodePudding user response:

Is there any API can be used

CodePudding user response:

SetupDiEnumDeviceInterfaces apis, such as

CodePudding user response:

Can read the registry, the Hardware \ \ DeviceMap \ \ SerialComm, can refer to my code
 void CComDlg: : FindComPort () 
{
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);
}
}
I insert all current information into the usb port into the combox

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 to

CodePudding user response:

  • Related