我不确定我错过了什么,但现在是时候向比我更有知识的人提问了。我正在使用我在这里找到的 HDC GUID 。我试图在我的 C++ 代码中打开它:
// note: devGuid is pointer of type struct GUID in the class this ctor belongs to
DeviceHelper::DeviceManager::DeviceManager(GUID devClassGuid) : devGuid(new GUID(devClassGuid)) {
hDevices = SetupDiGetClassDevs(&devClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(INVALID_HANDLE_VALUE == hDevices) {
throw std::exception("Failure to get a handle to a list of device classes");
}
}
这个调用通过并且 hDevices 持有一个有效的引用。但是,当我调用 SetupDiEnumDeviceInterfaces() 时,它不会迭代:
// hDevices is assigned in the c-tor as is devGuid which is a pointer
DWORD index(0);
SP_DEVICE_INTERFACE_DATA devInterfaceData = {sizeof(SP_DEVICE_INTERFACE_DATA)};
while(SetupDiEnumDeviceInterfaces(hDevices, NULL, devGuid, index, &devInterfaceData)) {
// look for the HBA I want from parameters passed to the class function
// FindHba()
}
SetupDiEnumDeviceInterfaces() 将系统错误代码设置为 249,即“没有更多项目”,但没有进行任何迭代。显然,句柄指向一个空列表。我在调用 SetupDiGetClassDevs() 时遇到了什么问题?我认为可能是 GUID 不是“接口”GUID(即名称中没有“接口”一词)。所以,我尝试使用 DIGCF_DEVICEINTERFACE 取消按位或,但这没有帮助。
我对如何使用这个 API 的了解非常有限,我现在除了旋转我的轮子什么都不做。
谢谢你的帮助。