Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


C++
// EnumDevice.cpp : Defines the entry point for the console application.
//

#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							// 
			);

		// Enumerate
		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(	// This returns ERROR 0x103 for all devices
					DeviceInfoSet,
					NULL, //pDeviceInfoData,
					pGUID,
					MemberIndex,
					pDeviceInterfaceData
					);

				if (!moreInterfaceToEnum)
					cout << "Error: " << GetLastError() << "\n";

				if (moreInterfaceToEnum){
					MemberIndex++;
					cout << "Device found!" << endl;
				}
				else{
					if (ERROR_NO_MORE_ITEMS == GetLastError()){
						// cout << "No more interfaces left to enumerate." << endl;
					}
				}
			}

		}

		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;
}
Posted
Updated 6-Oct-14 21:10pm
v3

1 solution

You are using the same DeviceInfoSet handle for SetupDiEnumDeviceInfo and SetupDiEnumDeviceInterfaces. According to the MSDN[^] you should call SetupDiGetClassDevs with the flag DIGCF_DEVICEINTERFACE to retrieve device interfaces.

You are also passing the GUID found by enumerating the device info sets to SetupDiEnumDeviceInterfaces. But this GUID must specify a device interface class while the found GUID is probably not of that type.

So the function returns with the information that no matching entry has been found.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900