Answers
void CDeviceScan::EnumAllDevices()
{
HDEVINFO hDevInfo = 0L;
SP_DEVINFO_DATA spDevInfoData = {0};
short wIndex = 0;
TCHAR szSetupClass[MAX_PATH] = {0};
int wImageIdx = 0;
hDevInfo = SetupDiGetClassDevs(0L, 0L, NULL, DIGCF_PRESENT |
DIGCF_ALLCLASSES | DIGCF_PROFILE);
if (hDevInfo == (void*)-1)
{
return;
}
wIndex = 0;
spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
while (1)
{
if (SetupDiEnumDeviceInfo(hDevInfo,
wIndex,
&spDevInfoData))
{
TCHAR szBuf[MAX_PATH] = {0};
short wItem = 0;
if (!SetupDiGetDeviceRegistryProperty(hDevInfo,
&spDevInfoData,
SPDRP_CLASS, //SPDRP_CLASS,
0L,
(PBYTE)szSetupClass,
MAX_PATH,
0))
{
wIndex++;
continue;
}
if (!IsInBlackList(szSetupClass))
{
if (SetupDiGetClassImageIndex(&m_spImageData,
&spDevInfoData.ClassGuid,
(int*)&wImageIdx))
{
TCHAR szName[128] = {0};
TCHAR szID[LINE_LEN] = {0};
TCHAR szPath[MAX_PATH] = {0};
DWORD dwRequireSize;
short wOrder;
if (!SetupDiGetClassDescription(&spDevInfoData.ClassGuid,
szBuf,
MAX_PATH,
&dwRequireSize))
{
wIndex++;
continue;
}
wOrder = FindDeviceOrder(szBuf);
if (!AddNewDeviceOrderNode(szBuf, wImageIdx))
{
wIndex++;
continue;
}
GetDeviceInstanceID(hDevInfo, &spDevInfoData, szID);
GetDeviceInterfaceInfo(hDevInfo, spDevInfoData, szPath);
if (SetupDiGetDeviceRegistryProperty(hDevInfo,
&spDevInfoData,
SPDRP_FRIENDLYNAME,
0L,
(PBYTE)szName,
127,
0))
{
AddNewDeviceNode(spDevInfoData.ClassGuid, szName, szID, szPath, wIndex, wImageIdx, wOrder, szSetupClass,szBuf);
}
else if (SetupDiGetDeviceRegistryProperty(hDevInfo,
&spDevInfoData,
SPDRP_DEVICEDESC,
0L,
(PBYTE)szName,
127,
0))
{
AddNewDeviceNode(spDevInfoData.ClassGuid, szName, szID, szPath, wIndex, wImageIdx, wOrder, szSetupClass,szBuf);
}
else
{
DWORD dError = GetLastError();
}
}
}
}
else
{
DWORD dError = GetLastError();
break;
}
wIndex++;
}
SetupDiDestroyDeviceInfoList(hDevInfo);
天衣無縫D亡靈
answered 10 years, 3 months ago