gpt4 book ai didi

windows - 如何获取设备的设备接口(interface) GUID?

转载 作者:行者123 更新时间:2023-12-05 08:11:43 30 4
gpt4 key购买 nike

我列举了一台机器上的所有设备如下:

HDEVINFO hDevList = SetupDiGetClassDevs( NULL, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT | DIGCF_ALLCLASSES /*| DIGCF_PROFILE*/ );
for ( int i = 0; true; ++i )
{
SP_DEVINFO_DATA devinfo_data = {0};
devinfo_data.cbSize = sizeof(SP_DEVINFO_DATA);
if ( !SetupDiEnumDeviceInfo( hDevList, i, &devinfo_data ) )
break;
//TODO: get device interface GUID
//...
}
SetupDiDestroyDeviceInfoList( hDevList );

如何获取每个项目的设备界面 GUID?

我试过了

SP_DEVICE_INTERFACE_DATA interface_data = {0};
interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
SetupDiEnumDeviceInterfaces( hDevList, &devinfo_data, ???, 0, &interface_data );

但它似乎需要第三个参数的实际 GUID。这实际上是我想要得到的! NULL 不是一个选项。

最佳答案

您可以使用 Unified Device Property Model 获取大量信息在 Vista 及更高版本中可用。它有 DEVPKEY_Device_ClassDEVPKEY_Device_ClassGuid属性:

HDEVINFO list = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT | DIGCF_ALLCLASSES /*| DIGCF_PROFILE*/);
for (int i = 0; true; ++i)
{
SP_DEVINFO_DATA data = { 0 };
data.cbSize = sizeof(SP_DEVINFO_DATA);
if (!SetupDiEnumDeviceInfo(list, i, &data))
break;

// get name property
DEVPROPTYPE type;
DWORD size = 0;
SetupDiGetDeviceProperty(list, &data, &DEVPKEY_NAME, &type, NULL, 0, &size, 0);
if (size > 0)
{
LPWSTR name = (LPWSTR)malloc(size);
SetupDiGetDeviceProperty(list, &data, &DEVPKEY_NAME, &type, (PBYTE)name, size, &size, 0);
wprintf(L"name: %s\n", name);
free(name);
}

// get class name
SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_Class, &type, NULL, 0, &size, 0);
if (size > 0)
{
LPWSTR name = (LPWSTR)malloc(size);
SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_Class, &type, (PBYTE)name, size, &size, 0);
wprintf(L" class: %s\n", name);
free(name);
}

// get class guid
SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_ClassGuid, &type, NULL, 0, &size, 0);
if (size > 0)
{
GUID* guid = (GUID*)malloc(size);
SetupDiGetDeviceProperty(list, &data, &DEVPKEY_Device_ClassGuid, &type, (PBYTE)guid, size, &size, 0);
wchar_t name[64];
StringFromGUID2(*guid, (LPOLESTR)name, ARRAYSIZE(name));
wprintf(L" class guid: %s\n", name);
free(guid);
}
}
SetupDiDestroyDeviceInfoList(list);

这将输出如下内容:

name: ACPI Fan                                      
class: System
class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318}
name: ACPI Fan
class: System
class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318}
name: ACPI Fan
class: System
class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318}
name: ACPI Fan
class: System
class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318}
name: ACPI Fan
class: System
class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318}
name: Microsoft Hyper-V Virtual Machine Bus Provider
class: System
class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318}
name: Plug and Play Software Device Enumerator
class: System
class guid: {4D36E97D-E325-11CE-BFC1-08002BE10318}
etc...

关于windows - 如何获取设备的设备接口(interface) GUID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52892299/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com