SetupDiGetDeviceRegistryProperty函数使用示例
2022-02-09
329
0
原文转自:https://blog.csdn.net/haart/article/details/120708900
通过SetupDiOpenDeviceInterface函数打开设备路径,在通过SetupDiGetDeviceInterfaceDetail函数获取SP_DEVINFO_DATA结构的值,有了这个结构的值就可以调用SetupDiGetDeviceRegistryProperty函数获取设备的一系列属性值了。
void GetDevPathInfo(LPCTSTR szIntfPath)
{
HDEVINFO hDevInfo = SetupDiCreateDeviceInfoList(NULL, NULL);
if (INVALID_HANDLE_VALUE == hDevInfo)
{
return;
}
BYTE Buf[1024] = {0};
TCHAR szTemp[MAX_PATH] = {0};
SP_DEVICE_INTERFACE_DATA spdid = {0};
spdid.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)Buf;
pspdidd->cbSize = sizeof(*pspdidd);
SP_DEVINFO_DATA spdd = {0};
spdd.cbSize = sizeof(spdd);
DWORD dwSize = 0;
do
{
if (!SetupDiOpenDeviceInterface(
hDevInfo,
szIntfPath,
0,
&spdid))
{
break;
}
dwSize = sizeof(Buf);
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, &spdid, pspdidd, dwSize, &dwSize, &spdd))
{
break;
}
//INFO(TEXT("DevicePath = %s\n"), pspdidd->DevicePath);
if(SetupDiClassNameFromGuid(&spdd.ClassGuid, szTemp, MAX_PATH, &dwSize))
{
INFO(TEXT("Class = %s\n"), szTemp);
}
if (SetupDiGetClassDescription(&spdd.ClassGuid, szTemp, MAX_PATH, &dwSize))
{
INFO(TEXT("ClassDescription = %s\n"), szTemp);
}
if (SetupDiGetDeviceRegistryProperty(hDevInfo, &spdd, SPDRP_DEVICEDESC, NULL, (PBYTE)szTemp, MAX_PATH - 1, NULL))
{
INFO(TEXT("DeviceDesc = %s\n"), szTemp);
}
if (SetupDiGetDeviceRegistryProperty(hDevInfo, &spdd, SPDRP_SERVICE, NULL, (PBYTE)szTemp, MAX_PATH - 1, NULL))
{
INFO(TEXT("Service = %s\n"), szTemp);
}
if (SetupDiGetDeviceRegistryProperty(hDevInfo, &spdd, SPDRP_LOCATION_PATHS, NULL, (PBYTE)szTemp, MAX_PATH - 1, NULL))
{
INFO(TEXT("LocationPath = %s\n"), szTemp);
}
if (SetupDiGetDeviceRegistryProperty(hDevInfo, &spdd, SPDRP_FRIENDLYNAME, NULL, (PBYTE)szTemp, MAX_PATH - 1, NULL))
{
INFO(TEXT("FriendlyName = %s\n"), szTemp);
}
GetLocationInfo(spdd.DevInst, szTemp, MAX_PATH);
INFO(TEXT("\n"));
}
while (0);
SetupDiDestroyDeviceInfoList(hDevInfo);
}