Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从安装api获取SATA HBA的列表_C++_Setupapi - Fatal编程技术网

C++ 从安装api获取SATA HBA的列表

C++ 从安装api获取SATA HBA的列表,c++,setupapi,C++,Setupapi,我不确定我遗漏了什么,但是时候向比我更有知识的人提问了。我正在使用我找到的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)) { hDevi

我不确定我遗漏了什么,但是时候向比我更有知识的人提问了。我正在使用我找到的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持有有效引用。但是,当我调用SetupDienumDeviceInterface时,它不进行任何迭代:

// 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()
}
SetupDienumDeviceInterface将系统错误代码设置为249,这是没有更多项,但没有迭代任何内容。显然,句柄指向一个空列表。我打给SetupDiGetClassDevs的电话出错了是什么?我认为可能是GUID不是接口GUID,即名称中没有“接口”一词。因此,我尝试使用DIGCF_DEVICEINTERFACE删除按位or,但这没有帮助

我对如何使用这个API的了解非常有限,我现在什么都不做,只是在旋转我的轮子


感谢您的帮助。

我显然不知道在这种情况下接口意味着什么。答案似乎是调用SetupDiEnumDeviceInfo而不是使用SetupDienumDeviceInterface。显然,当我问这个问题时,我的思路是正确的。事实上,问题似乎与试图迭代我没有的接口有关

无论如何,我现在能够通过这段代码启用/禁用我的ATA设备,这正是我所追求的。作为参考,我在上一篇文章中谈到了堆栈溢出:

该代码适用于C++。 对于任何熟悉SetupApi的人来说,我一定会很感激对他们进行一些关于这些东西是什么的教育