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

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

问题描述

我为我们从供应商那里获得的 x86 库创建了一个 x86包装器".我一直在按照这篇文章中的步骤进行操作以及用于调用 COM 的几个链接 此处此处.

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 接口找到并将其标记为使用代理进程".所以希望我在 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.

在我们的例子中,我们在包装器项目中丢失了一些程序集,这很可能导致 tlbimp 在使用 dll 调用时失败.但是由于我们的小接口,我们选择坚持使用后期动态绑定.

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天全站免登陆