Why SetupDiEnumDriverInfo provides two version numbers for my driver

I am trying to get the driver version number programmatically. This seems to be done using SetupDiEnumDriverInfo to get the SP_DRVINFO_DATA structure and check the DriverVersion field .

The following code works, but returns two different options for the same driver. My device is a USB user device with one .sys file. Only one device is connected to my machine. I specify DIGCF_PRESENT only to request drivers for connected devices.

 int main(void) { // Get the "device info set" for our driver GUID HDEVINFO devInfoSet = SetupDiGetClassDevs( &GUID_DEVINTERFACE_USBSPI, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // Cycle through all devices currently present for (int i = 0; ; i++) { // Get the device info for this device SP_DEVINFO_DATA devInfo; devInfo.cbSize = sizeof(SP_DEVINFO_DATA); if (!SetupDiEnumDeviceInfo(devInfoSet, i, &devInfo)) break; // Build a list of driver info items that we will retrieve below if (!SetupDiBuildDriverInfoList(devInfoSet, &devInfo, SPDIT_COMPATDRIVER)) return -1; // Exit on error // Get all the info items for this driver // (I don't understand why there is more than one) for (int j = 0; ; j++) { SP_DRVINFO_DATA drvInfo; drvInfo.cbSize = sizeof(SP_DRVINFO_DATA); if (!SetupDiEnumDriverInfo(devInfoSet, &devInfo, SPDIT_COMPATDRIVER, j, &drvInfo)) break; printf("Driver version is %08x %08x\n", (unsigned)(drvInfo.DriverVersion >> 32), (unsigned)(drvInfo.DriverVersion & 0xffffffffULL)); } } SetupDiDestroyDeviceInfoList(devInfoSet); return 0; } 

On my machine, this prints:

 Driver version is 00000000 000015d3 Driver version is 00020004 00000000 

On another computer, it prints:

 Driver version is 00020004 00000000 Driver version is 00020004 00000000 

The second line corresponds to the number specified by the device manager.

Disclaimer: I previously asked a similar question . This is a new question about why SetupDiEnumDriverInfo returns more than one driver version.

+4
source share
1 answer

As you write your code, all possible drivers will be displayed. Try the following to filter only the installed driver:

 SP_DEVINSTALL_PARAMS InstallParams; if ( !SetupDiGetDeviceInstallParams( devInfoSet, &devInfo, &InstallParams ) ) { //Error } else { InstallParams.FlagsEx |= DI_FLAGSEX_INSTALLEDDRIVER; if ( !SetupDiSetDeviceInstallParams( devInfoSet, &devInfo, &InstallParams) ) { //Errror } } 

I found this at http://doxygen.reactos.org/df/db2/dll_2win32_2devmgr_2misc_8c_a1cd0b33c1785392a37689433dc99e482.html

+5
source

All Articles