1. 按照设备的连接去遍历设备管理器
int EnumDevs::ListByConnection(char *szXML)
{
if (!szXML) return -1;
CONFIGRET cr;
DEVINST root;
char *ACPI = _T("ROOT\\ACPI_HAL\\0000");
XMLDocument doc;
XMLElement *xml_root = doc.NewElement("DeviceTree");
doc.InsertEndChild(xml_root);
cr = CM_Locate_DevNode(&root, ACPI, 0);
if (cr != CR_SUCCESS)
{
_tprintf(_T("[Error] CM_Locate_DevNode() failed, cr= 0x%lx\n"),cr);
return 1;
}
cr = ListSubNodes(root, 0, doc, xml_root);
if (cr != CR_SUCCESS)
return 2;
doc.SaveFile(szXML);
return 0;
}
CONFIGRET EnumDevs::GetDeviceInfo(DEVINST DevInst, PDEVICE_INFO pDevInfo)
{
CONFIGRET cr;
ULONG ulSize;
//description
ulSize = sizeof(pDevInfo->szDevDescription);
cr = CM_Get_DevNode_Registry_Property(DevInst, CM_DRP_FRIENDLYNAME, NULL, pDevInfo->szDevDescription, &ulSize, 0);
if (cr != CR_SUCCESS)
{
ulSize = sizeof(pDevInfo->szDevDescription);
cr = CM_Get_DevNode_Registry_Property(DevInst, CM_DRP_DEVICEDESC, NULL, pDevInfo->szDevDescription, &ulSize, 0);
if (cr != CR_SUCCESS)
{
_tprintf(_T("[Error] CM_Get_DevNode_Registry_Property() failed,cr = 0x%lx\n"), cr);
return cr;
}
}
//class guid
ulSize = sizeof(pDevInfo->szClassGUID);
cr = CM_Get_DevNode_Registry_Property(DevInst, CM_DRP_CLASSGUID, NULL, pDevInfo->szClassGUID, &ulSize, 0);
if (cr != CR_SUCCESS)
{
_tprintf(_T("[Err