如何从托管代码(如C#)中为ActiveX组件使用嵌入式免注册清单? [英] How to use embedded registration-free manifest for ActiveX component from managed code like C#?

查看:129
本文介绍了如何从托管代码(如C#)中为ActiveX组件使用嵌入式免注册清单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to use a specific version of ActiveX component that is not registered system- or user-wide. Everything works as expected if I use manifest files. However embedded manifest works only for C++ client code only.

这里是依赖项声明

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

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

If I use SxStrace, I see the following

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中,但这似乎有点黑。

So apparently it just wants DLL no matter what. The problem is that DLL I get from AxImp does not have an embedded manifest. 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.

P.S。我不确定将ocx重命名为dll是否是一种好方法,因为AxImp还会为COM东西生成相同名称的DLL,并且看起来没有标志为COM CLR代理显式提供输出名称。

P.S. 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.

推荐答案

您的清单缺少必填项,例如< comClass> 。这就是为什么您看到Windows继续寻找另一个清单以查找所需内容的原因。您发现的解决方法不是很好,它会将清单条目放在错误的文件中。它应该出现在EXE的清单中。

Your manifest is missing essential entries, like <comClass>. Which is why you see Windows continue hunting for another manifest to find what it needs. 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.

执行此操作的明智方法是仅由构建系统来处理。注册.ocx,只需将引用的 Isolated 属性设置为True。这样一来,构建系统就可以从注册表中读取所需的清单条目,并将它们合并到应用程序清单中。

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. That will get the build system to read the required manifest entries from the registry and merge them into the application manifest.

如果您不想保留.ocx的状态,由于某种原因,请只执行一次。在构建目录中找到.manifest文件。使用文本编辑器将其打开,然后将条目复制/粘贴到您的应用清单中。请注意,这会调用DLL Hell,如果更新COM服务器,则清单将过时。总是很难进行故障排除,因为这种情况从现在开始会发生一两年,甚至可能是一个对您所做的事情一无所知的程序员。

If you don't want to leave the .ocx registered for some reason then do this just once. Find the .manifest file back in the build directory. 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. 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.

这篇关于如何从托管代码(如C#)中为ActiveX组件使用嵌入式免注册清单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆