从64位项目引用x86 COM包装器 [英] Referencing x86 COM wrapper from 64 bit project

查看:245
本文介绍了从64位项目引用x86 COM包装器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为供应商提供的x86库创建了x86包装器。我主要按照这篇文章的步骤进行操作,以及在此处此处

I have created an x86 "wrapper" for an x86 library we have from a vendor. I've been following the steps mostly from this post as well a couple links for calling COM here and here.

我将项目标记为注册COM互操作。我可以使用oleview通过COM界面找到它,并将其标记为 Use Surrogate Process。因此,希望就DllSurrogate注册表设置而言,我可以做到这一点。

I marked the project as "Register for COM interop". I was able to find by COM interface using oleview and marked it as "Use Surrogate Process". So hopefully I'm good to this point as far as the DllSurrogate registry settings go.

现在,我似乎无法正确地使用x86 COM。据说我可以通过COM进行直接引用,也可以使用tlbimp来创建可以在x64项目中使用的RCW程序集。

Now I can't seem to get the reference correct to consume the x86 COM. Supposedly I can either do a direct reference through COM, or use tlbimp, in order to create the RCW assemblies which I can use from my x64 project.

带有COM参考我收到错误消息 ActiveX类型库是从.NET程序集导出的,不能添加为引用。

With a COM reference I get the error "The ActiveX type library was exported from a .NET assembly and cannot be added as a reference."

当我将dll传递给tlbimp时,我得到了错误TI1002:输入文件不是有效的类型库。

When I pass the dll to tlbimp I get "error TI1002: The input file is not a valid type library."

当我将tlb传递给tlbimp时,我收到了错误TI1029:类型库是从CLR程序集导出的并且不能重新导入为CLR程序集。

When I pass the tlb to tlbimp I get "error TI1029 : Type library was exported from a CLR assembly and cannot be re-imported as a CLR assembly."

对于我在这里可能会缺少的任何帮助,我们将不胜感激。

Any help on what I could be missing here is greatly appreciated.

推荐答案

希望这将对落在此上的其他人有所帮助。从COM角度来看,我已经正确配置了。从那里开始,真正的问题就变成了早期绑定与后期绑定。

Hopefully this will help someone else who lands on this. I was already configured correctly from the COM perspective. From there it really became a question of early binding vs late binding.

后期绑定通过一些简单的代码行就可以很好地工作:

Late binding worked well with a few simple lines of code:

var type = Type.GetTypeFromProgID("ProgId");
dynamic o = Activator.CreateInstance(type);
var foo = o.DoSomething();

早期绑定意味着您将需要RCW程序集引用。在某些情况下,当您直接引用COM对象时,VS会自动为您创建这些对象。但是,在这种情况下,从.Net程序集创建COM,然后尝试从COM转换回.Net-VS认为您正在做循环操作,并且不允许这样做。如果您在tlb文件而不是dll上运行tlbimp,也会出现类似的错误。

Early binding means you will need the RCW assemblies to reference. In some cases VS will automatically create these for you when you reference a COM object directly. However in this case of creating a COM from a .Net assembly, then trying to convert from COM back to .Net - VS thinks you are doing something circular and disallows it. tlbimp will give you the similar error if you run it on the tlb file rather than the dll.

在我们的案例中,我们在包装项目中缺少了一些程序集,用dll调用时可能导致tlbimp失败。但是由于我们琐碎的小界面,我们选择了后期动态绑定。

In our case we were missing some assemblies down in our wrapper project, which was likely causing tlbimp to fail when called with the dll. But we chose to stick with late dynamic binding due to our trivial little interface.

这篇关于从64位项目引用x86 COM包装器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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