【发布时间】:2022-01-11 18:18:39
【问题描述】:
我有一个代码可以修改 缓存的(不是正在安装的)msi 安装程序数据库,当在独立的 exe 中执行时,它工作正常。但是当它从一个 msi 自定义操作中运行时,我得到一个非常奇怪的访问冲突。
const auto& msiProductCode = ::GetProductCode(::msiUpgradeCode);
const auto& msiPath = ::GetCachedMSIPath(msiProductCode);
PMSIHANDLE dbHandle{};
const auto res = MsiOpenDatabaseW(msiPath.data(), MSIDBOPEN_TRANSACT, &dbHandle); // access violation here within msi castom aciton
异常信息:
Exception thrown at 0x76246E10 (rpcrt4.dll) in msiexec.exe: 0xC0000005: Access violation reading location 0x00000001.
我无法理解的是它是如何以rpcrt4.dll 结尾的,因为独立的可执行文件没有这种依赖关系:
Dump of file .\disable_custom_action.exe
File Type: EXECUTABLE IMAGE
Image has the following dependencies:
msi.dll
MSVCP140D.dll
VCRUNTIME140D.dll
VCRUNTIME140_1D.dll
ucrtbased.dll
KERNEL32.dll
然而,用于 msi 自定义操作的 dll 具有这种依赖关系,因为在其他应用中使用了 RPC
自定义操作功能。此自定义操作的In-Script execution 配置为Immediate Execution。
1 在 msi 自定义操作中运行时可能导致访问冲突的原因是什么?
2 MsiOpenDatabaseW 能否以某种方式依赖于rpcrt4.dll?
3 会不会是C/Cpp Runtime链接可能不一致(不同CRT版本)造成的?
我最初的问题描述为here。我虽然我想通了,但在答案显示在活动安装期间我无法调用MsiOpenDatabaseW 的部分之前。
【问题讨论】:
标签: c++ debugging windows-installer access-violation