我有一个 UMDF 驱动程序,目前通过 2 个独立安装程序重新分发,一个用于 x64,一个用于 x86。
安装驱动函数就是这个,从devcon复制的:
bool InstallDriver(const TCHAR* InfPath, const wchar_t* TargetID)
{
#define MAX_CLASS_NAME_LEN 32
GUID ClassGUID = {};
TCHAR ClassName[MAX_CLASS_NAME_LEN] = {};
TCHAR hwIdList[LINE_LEN + 4] = {};
//
// List of hardware ID's must be double zero-terminated
//
ZeroMemory(hwIdList, sizeof(hwIdList));
if (FAILED(StringCchCopy(hwIdList, LINE_LEN, TargetID)))
{
return false;
}
//
// Use the INF File to extract the Class GUID.
//
if (!SetupDiGetINFClass(InfPath, &ClassGUID, ClassName, sizeof(ClassName) / sizeof(ClassName[0]), 0))
{
return false;
}
//
// Create the container for the to-be-created Device Information Element.
//
HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE;
DeviceInfoSet = SetupDiCreateDeviceInfoList(&ClassGUID, 0);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
{
return false;
}
//
// Now create the element.
// Use the Class GUID and Name from the INF file.
//
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if (!SetupDiCreateDeviceInfo(DeviceInfoSet,
ClassName,
&ClassGUID,
NULL,
0,
DICD_GENERATE_ID,
&DeviceInfoData))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return false;
}
//
// Add the HardwareID to the Device's HardwareID property.
//
if (!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,
&DeviceInfoData,
SPDRP_HARDWAREID,
(LPBYTE)hwIdList,
(lstrlen(hwIdList) + 1 + 1) * sizeof(TCHAR)))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return false;
}
//
// Transform the registry element into an actual devnode
// in the PnP HW tree.
//
if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,
DeviceInfoSet,
&DeviceInfoData))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return false;
}
//
// update the driver for the device we just created
//
if (!UpdateDriverForPlugAndPlayDevices(0, TargetID, InfPath, INSTALLFLAG_FORCE, 0))
{
int y = GetLastError();
if (y == ERROR_IN_WOW64 || y == ERROR_NO_SUCH_DEVINST || y == ERROR_NO_SUCH_DEVINST || y == ERROR_FILE_NOT_FOUND)
{
}
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return false;
}
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return true;
}
这工作正常,但我想要一个包含 x86 和 x64 驱动程序的单个 x86 可再发行组件,并检测是否在 WOW64 中运行并安装 x64 驱动程序。
这次InstallDriver
函数在这个调用中失败了:
if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,
DeviceInfoSet,
&DeviceInfoData))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
return false;
}
最后一个错误 3758096949。
我找不到有关该错误的更多信息,而且我在SetupDiSetDeviceRegistryProperty中没有看到任何将注册表设置为 x64 的提示,例如 RegCreateKeyEx 的 KEY_WOW64_64KEY 标志。
有没有办法避免这两个可执行文件?