SetupAPI函数实现设备分类GUID和类名之间的转换SetupDiClassNameFromGuidEx和SetupDiClassGuidsFromNameEx
2022-01-26
120
0
类名与其GUID之间的切换
GUID guid;
ULONG rtn = 0;
if (SetupDiClassGuidsFromNameEx(TEXT("USB"), &guid, 1, &rtn, NULL, NULL))
{
rtn = rtn;
}
返回:
{36FC9E60-C465-11CF-8056-444553540000}
这和INF文件中的对应一致:
[Version]
Signature="$WINDOWS NT$"
Class=USB
ClassGuid={36FC9E60-C465-11CF-8056-444553540000}
当然也有一个反向的从GUI获取类名的函数SetupDiClassNameFromGuidEx
{
GUID guid;
ULONG rtn = 0;
if (SetupDiClassGuidsFromNameEx(TEXT("USB"), &guid, 1, &rtn, NULL, NULL))
{
rtn = rtn;
}
TCHAR GuidName[64] = { 0 };
if (SetupDiClassNameFromGuidEx(&guid, GuidName, sizeof(GuidName), &rtn, NULL,NULL))
{
rtn = rtn;
}
}
GuidName返回USB字符串。
Windows预定义的设备分类和其对应的GUID详见:http://www.pnpon.com/article/detail-146.html