Hi all,
I’m trying to write a simple routine to walk through the device nodes on
my system, and for each of them find out which driver is currently
installed (just as the device manager is able to do).
I’m using SetupApi to enumerate devices just like described in
‘Reinstalling an Unplugged Device’ on MSDN
(http://www.osronline.com/DDKx/install/custom-install_7n53.htm), but
rather than modifying device flags I call SetupDiGetSelectedDriver(…),
and for every device I examine GetLastError() returns me
ERROR_NO_DRIVER_SELECTED (0x203)
Am I approaching this from the wrong angle, or is there something wrong
with my code example? (How does device manager do it?)
Thanks,
Nick
int i;
HDEVINFO DeviceInfoSet;
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
DeviceInfoSet = SetupDiGetClassDevs(NULL, “USB”,
NULL, DIGCF_ALLCLASSES);
for (i=0; SetupDiEnumDeviceInfo(DeviceInfoSet, i, OUT &DeviceInfoData); i++)
{
BOOL bRes;
DWORD err;
SP_DRVINFO_DATA DriverInfoData;
bRes = SetupDiBuildDriverInfoList(DeviceInfoSet,
&DeviceInfoData, SPDIT_COMPATDRIVER);
if (!bRes) {
err = GetLastError();
return;
}
DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
bRes = SetupDiGetSelectedDriver(DeviceInfoSet,
&DeviceInfoData, &DriverInfoData);
if (!bRes) {
err = GetLastError();
// always returns ERROR_NO_DRIVER_SELECTED! >:-(
if (err == ERROR_NO_DRIVER_SELECTED) continue;
return;
}
}