为什么SetupDiEnumDriverInfo为驱动程序提供两个版本号 [英] Why does SetupDiEnumDriverInfo give two version numbers for my driver
问题描述
我正在尝试以编程方式获取驱动程序的版本号。似乎是通过使用 SetupDiEnumDriverInfo
来获得 SP_DRVINFO_DATA
结构并检查 DriverVersion字段来完成的
。
I'm trying to get the version number of a driver programmatically. The seems to be done by using SetupDiEnumDriverInfo
to get a SP_DRVINFO_DATA
struct and inspect the DriverVersion field
.
以下代码有效,但是对于同一驱动程序返回两个不同的版本。我的设备是带有单个.sys文件的自定义USB设备。我的机器上只有一台设备连接。我指定 DIGCF_PRESENT
仅查询当前连接的设备的驱动程序。
The following code works, but returns two different versions for the same driver. My device is a custom USB device, with a single .sys file. There is only one device connected to my machine. I specify DIGCF_PRESENT
to only query the drivers of currently attached 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;
}
在我的机器上打印:
Driver version is 00000000 000015d3
Driver version is 00020004 00000000
在朋友的机器上打印:
Driver version is 00020004 00000000
Driver version is 00020004 00000000
第二行与设备管理器报告的数字匹配。
The second line matches the number reported by device manager.
免责声明:我之前曾问过类似问题。这是一个新问题,为什么SetupDiEnumDriverInfo返回多个驱动程序版本。
Disclaimer: I previously asked a similar question. This is a new question about why SetupDiEnumDriverInfo returns more than one driver version.
推荐答案
在编写代码时,所有可能的驱动程序将被输出。尝试执行以下操作仅对已安装的驱动程序进行筛选:
As your code is written, all the possible drivers will be output. Try doing the following to filter on 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
}
}
我在 http://doxygen.reactos.org/df/db2/dll_2win32_2devmgr_2misc_8c_a1cd0b33c1785392a37689433dc99e482.html
这篇关于为什么SetupDiEnumDriverInfo为驱动程序提供两个版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!