从设置 api 获取 SATA HBA 列表
我不确定我错过了什么,但是时候向比我更有知识的人询问了。我正在使用我找到的 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 的了解非常有限,而且我现在除了白手起家什么也没做。
感谢您的任何帮助。
I'm not sure what I'm missing but it's time to ask from more knowledgeable people than I. I'm using the HDC GUID that I found here. I'm trying to open with this in my C++ code:
// 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");
}
}
This call passes and hDevices holds a valid reference. However, when I call SetupDiEnumDeviceInterfaces() it iterates over nothing:
// 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() sets the system error code to 249 which is "no more items" but nothing has been iterated. Apparently, the handle points to an empty list. What is it I'm getting wrong on the call to SetupDiGetClassDevs()? I thought that it might be the GUID isn't an "interface" GUID (i.e. the word "interface" isn't in the name). So, I tried taking off the bitwise-or with DIGCF_DEVICEINTERFACE, but this didn't help.
My knowledge of how to make use of this API is quite limited and I'm doing nothing now but spinning my wheels.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我显然不知道接口在这种情况下意味着什么。答案似乎是调用SetupDiEnumDeviceInfo()而不是使用SetupDiEnumDeviceInterfaces()。显然,当我问这个问题时,我的思路是正确的。事实上,问题似乎与尝试迭代我没有的接口有关。
无论如何,我现在可以通过此代码启用/禁用我的 ATA 设备(这就是我所追求的)。作为参考,我从上一篇文章转到 Stack Overflow:Win32 API以编程方式启用/禁用设备的函数
该代码适用于 C++。
对于任何非常熟悉 SetupApi 的人来说,我肯定会很感激有关这些东西的一些教育。
I'm apparently ignorant of what an interface means in this context. The answer seems to have been with calling SetupDiEnumDeviceInfo() instead of using SetupDiEnumDeviceInterfaces(). Apparently, I was on the right track when I'd asked the question. Indeed, it would seem, that the problem had to do with trying to iterate over interfaces of which I had none.
At any rate, I'm now able to enable/disable my ATA devices through this code (which is what I was after). For reference, I went off of this past article to Stack Overflow: Win32 API function to programatically enable/disable device
That code was adapted for C++.
To anyone quite familiar with the SetupApi, I'd sure appreciate some education about what these things are.