简体   繁体   English

如何使用C#等托管代码中的ActiveX组件嵌入式免注册清单?

[英]How to use embedded registration-free manifest for ActiveX component from managed code like C#?

I would like to use a specific version of ActiveX component that is not registered system- or user-wide. 我想使用未注册系统或用户范围的特定版本的ActiveX组件。 Everything works as expected if I use manifest files. 如果我使用清单文件,一切都按预期工作。 However embedded manifest works only for C++ client code only. 但是,嵌入式清单仅适用于C ++客户端代码。

Here is dependency declaration 这是依赖声明

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

If I use SxStrace, I see the following 如果我使用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.

So apparently it just wants DLL no matter what. 显然它无论如何都只想要DLL。 The problem is that DLL I get from AxImp does not have an embedded manifest. 问题是我从AxImp获得的DLL没有嵌入式清单。 Is there a nice way to use embedded manifest? 有没有一种很好的方法来使用嵌入式清单? I feel like I can try for mt to embed one into DLL I get from AxImp but that seems hackish. 我觉得我可以尝试将mt嵌入到我从AxImp获得的DLL中,但这似乎是hackish。

PS I'm not sure whether renaming ocx into dll is a good approach as AxImp also generates same name DLL for COM stuff and it looks like there is no flags to explicitly provide output name for COM CLR proxy. PS我不确定是否将ocx重命名为dll是一个很好的方法,因为AxImp也为COM东西生成相同的名称DLL,看起来没有标志显式提供COM CLR代理的输出名称。

Your manifest is missing essential entries, like <comClass> . 您的清单缺少基本条目,例如<comClass> Which is why you see Windows continue hunting for another manifest to find what it needs. 这就是为什么你看到Windows继续寻找另一个清单来找到它需要的东西。 The workaround you found isn't that great, it puts the manifest entries in the wrong file. 您找到的解决方法并不是那么好,它会将清单条目放在错误的文件中。 It should go in the manifest of the EXE. 它应该出现在EXE的清单中。

The Smart Way to do this is to just let the build system take care of this. 实现这一目标的智能方法是让构建系统处理这个问题。 Register the .ocx and just set the Isolated property of the reference to True. 注册.ocx并将引用的Isolated属性设置为True。 That will get the build system to read the required manifest entries from the registry and merge them into the application manifest. 这将使构建系统从注册表中读取所需的清单条目,并将它们合并到应用程序清单中。

If you don't want to leave the .ocx registered for some reason then do this just once. 如果您因某些原因不想让.ocx注册,请执行此操作一次。 Find the .manifest file back in the build directory. 在build目录中找到.manifest文件。 Open it with a text editor and copy/paste the entries into your app manifest. 使用文本编辑器打开它,并将条目复制/粘贴到您的应用清单中。 Do beware that this can invoke DLL Hell, if you update the COM server then your manifest will be outdated. 请注意,这可以调用DLL Hell,如果更新COM服务器,那么您的清单将会过时。 Always hard to troubleshoot since this will happen a year or two from now and probably to a programmer that doesn't have a clue what you did. 总是很难排除故障,因为这将在一年或两年后发生,可能发生在一个程序员身上,他们不知道你做了什么。

Well... the trick with 好吧......诀窍

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

worked for me. 为我工作。 Although it does not seem neat. 虽然它看起来并不整洁。 Is there a way without copying embedded manifest into a CLR proxy and intermediate registration? 有没有办法不将嵌入式清单复制到CLR代理和中间注册?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM