gpt4 book ai didi

c++ - 为什么 SetupDiEnumDriverInfo 会为我的驱动程序提供两个版本号

转载 作者:可可西里 更新时间:2023-11-01 14:04:41 26 4
gpt4 key购买 nike

我正在尝试以编程方式获取驱动程序的版本号。这似乎是通过使用 SetupDiEnumDriverInfo 获取 SP_DRVINFO_DATA 结构并检查 DriverVersion 字段 来完成的。

以下代码有效,但为同一驱动程序返回两个不同的版本。我的设备是自定义 USB 设备,只有一个 .sys 文件。只有一台设备连接到我的机器。我指定 DIGCF_PRESENT 以仅查询当前连接的设备的驱动程序。

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

在 friend 的机器上,它打印:

Driver version is 00020004 00000000
Driver version is 00020004 00000000

第二行与设备管理器报告的数字相匹配。

免责声明:我之前问过 similar question .这是一个关于为什么 SetupDiEnumDriverInfo 返回多个驱动程序版本的新问题。

最佳答案

在编写代码时,将输出所有可能的驱动程序。尝试执行以下操作以仅过滤已安装的驱动程序:

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 找到了这个

关于c++ - 为什么 SetupDiEnumDriverInfo 会为我的驱动程序提供两个版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16063402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com