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.
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.