2

我想使用未在系统范围或用户范围内注册的特定版本的 ActiveX 组件。如果我使用清单文件,一切都会按预期工作。但是嵌入式清单仅适用于 C++ 客户端代码。

这是依赖声明

<dependency>
  <dependentAssembly>
    <assemblyIdentity type="win32" name="MapWinGIS.ocx" version="4.9.1.0" />
  </dependentAssembly>
</dependency>

如果我使用 SxStrace,我会看到以下内容

INFO: Parsing Manifest File C:\OSGeo4W\bin\TestApplication.exe.
    INFO: Manifest Definition Identity is MyApplication.app,version="1.0.0.0".
    INFO: Reference: MapWinGIS.ocx,type="win32",version="4.9.1.0"
INFO: Resolving reference MapWinGIS.ocx,type="win32",version="4.9.1.0".
    INFO: Resolving reference for ProcessorArchitecture MapWinGIS.ocx,type="win32",version="4.9.1.0".
        INFO: Resolving reference for culture Neutral.
            INFO: Applying Binding Policy.
                INFO: No binding policy redirect found.
            INFO: Begin assembly probing.
                INFO: Did not find the assembly in WinSxS.
                INFO: Attempt to probe manifest at C:\OSGeo4W\bin\MapWinGIS.ocx.DLL.
                INFO: Attempt to probe manifest at C:\OSGeo4W\bin\MapWinGIS.ocx.MANIFEST.
                INFO: Attempt to probe manifest at C:\OSGeo4W\bin\MapWinGIS.ocx\MapWinGIS.ocx.DLL.
                INFO: Attempt to probe manifest at C:\OSGeo4W\bin\MapWinGIS.ocx\MapWinGIS.ocx.MANIFEST.
                INFO: Did not find manifest for culture Neutral.
            INFO: End assembly probing.
    ERROR: Cannot resolve reference MapWinGIS.ocx,type="win32",version="4.9.1.0".
ERROR: Activation Context generation failed.

所以显然它无论如何都只想要DLL。问题是我从 AxImp 获得的 DLL 没有嵌入式清单。有没有使用嵌入式清单的好方法?我觉得我可以尝试让 mt 将一个嵌入到我从 AxImp 获得的 DLL 中,但这似乎很老套。

PS 我不确定将 ocx 重命名为 dll 是否是一种好方法,因为 AxImp 也会为 COM 内容生成同名 DLL,而且看起来没有标志可以为 COM CLR 代理显式提供输出名称。

4

2 回答 2

2

您的清单缺少基本条目,例如<comClass>. 这就是为什么您会看到 Windows 继续寻找另一个清单以找到它需要的内容。您找到的解决方法不是很好,它将清单条目放在错误的文件中。它应该在 EXE 的清单中。

做到这一点的聪明方法是让构建系统处理这个问题。注册 .ocx 并将Isolated引用的属性设置为 True。这将使构建系统从注册表中读取所需的清单条目并将它们合并到应用程序清单中。

如果您出于某种原因不想让 .ocx 注册,那么只需执行一次。在构建目录中找到 .manifest 文件。使用文本编辑器打开它并将条目复制/粘贴到您的应用清单中。请注意,这可能会调用 DLL Hell,如果您更新 COM 服务器,那么您的清单将会过时。总是很难排除故障,因为这将在一两年后发生,并且可能会发生在一个不知道你做了什么的程序员身上。

于 2014-02-21T22:41:32.570 回答
0

嗯......诀窍

regsvr32 MapWinGIS.ocx
AxImp MapWinGIS.ocx
mt -inputresource:MapWinGIS.ocx;#2 -outputresource:MapWinGIS.dll;#2
regsvr32 /u MapWinGIS.ocx

为我工作。虽然看起来并不整洁。有没有办法不将嵌入式清单复制到 CLR 代理和中间注册中?

于 2014-02-21T03:00:06.933 回答