I am having difficulty tying to call the SetupDiEnumDeviceInterfaces() in Setupapi.h but it keeps returning false. When I call GetLastError() I got this:
ERROR_NO_MORE_ITEMS 259 (0x103)
SetupDiEnumDeviceInfo() is the last function I called before SetupDiEnumDeviceInterfaces(), and it works fine, as I was able to retrieve the device GUIDs.
Any suggestions for this error?
Regards
Ang
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <Setupapi.h>
#include "Devpkey.h"
#include <initguid.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Program starts.\n";
HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE;
SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL;
try {
DeviceInfoSet = SetupDiGetClassDevs(
NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT );
SP_DEVINFO_DATA DeviceInfoData;
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
DWORD DeviceIndex = 0;
std::cout << "Enumerating: " << hex << endl;
while (SetupDiEnumDeviceInfo(
DeviceInfoSet,
DeviceIndex,
&DeviceInfoData)) {
DeviceIndex++;
GUID guid;
guid = DeviceInfoData.ClassGuid;
printf("Found GUID : {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
const GUID * pGUID = &DeviceInfoData.ClassGuid;
PSP_DEVINFO_DATA pDeviceInfoData = &DeviceInfoData;
PSP_DEVICE_INTERFACE_DATA pDeviceInterfaceData = new SP_DEVICE_INTERFACE_DATA;
pDeviceInterfaceData->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
DWORD MemberIndex = 0;
BOOL moreInterfaceToEnum = true;
while (moreInterfaceToEnum){
moreInterfaceToEnum = SetupDiEnumDeviceInterfaces( DeviceInfoSet,
NULL, pGUID,
MemberIndex,
pDeviceInterfaceData
);
if (!moreInterfaceToEnum)
cout << "Error: " << GetLastError() << "\n";
if (moreInterfaceToEnum){
MemberIndex++;
cout << "Device found!" << endl;
}
else{
if (ERROR_NO_MORE_ITEMS == GetLastError()){
}
}
}
}
cout << "Total device indexed: " << dec << DeviceIndex << endl;
} catch (string strCatchErr) {
cerr << "Error: " << strCatchErr.c_str() << endl;
return 1;
}
if (pDetData != NULL)
delete[](char*)pDetData;
if (DeviceInfoSet != INVALID_HANDLE_VALUE)
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
std::cout << "Program ends.\n";
cin.get();
return 0;
}