SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES)
The posted question asked about the above SetupApi function call. I could not reproduce the Questioner's issue when I used the following:
#include <Windows.h>
#include <SetupAPI.h>
#pragma comment(lib, "setupapi")
#define INITGUID
#include <guiddef.h>
#include <devpkey.h>
#include <stdio.h>
#include <tchar.h>
int wmain()
{
auto hSet = SetupDiGetClassDevsW(NULL, NULL, NULL, DIGCF_ALLCLASSES);
if (hSet != INVALID_HANDLE_VALUE)
{
SP_DEVINFO_DATA spdd{ sizeof spdd};
DWORD ndx{ 0 };
DWORD err{ ERROR_SUCCESS };
while(err != ERROR_NO_MORE_ITEMS)
{
if (SetupDiEnumDeviceInfo(hSet, ndx, &spdd))
{
WCHAR szGuid[39]{};
WCHAR szName[512]{};
DEVPROPTYPE proptype{};
StringFromGUID2(spdd.ClassGuid, szGuid, ARRAYSIZE(szGuid));
if (SetupDiGetDevicePropertyW(hSet, &spdd, &DEVPKEY_NAME, &proptype, (PBYTE)szName, sizeof szName, NULL, 0))
wprintf_s(L"%u. Class GUID is %s, name is %s\n", ndx, szGuid, szName);
else
wprintf_s(L"SetupDiGetDevicePropertyW for index %u failed with %u\n", ndx, GetLastError());
++ndx;
}
else
{
err = GetLastError();
if (err != ERROR_NO_MORE_ITEMS)
{
wprintf_s(L"Device enumeration for index %u failed with %u\n", ndx, err);
++ndx;
}
}
}
wprintf_s(L"Enumerated %u devices\n", ndx);
SetupDiDestroyDeviceInfoList(hSet);
}
return 0;
}
The code snippet that the Questioner posted was incomplete and diverged from the posted question and so it was ignored.