调用从C#托管C#COM对象

调用从C#托管C#COM对象

问题描述:

我试图调用从C#C#的COM对象。
我创建了C#类库,并使用tlbexe.exe导出的类型库。我然后使用regtlibv12.exe注册的类型库。然而,当我添加引用在Visual Studio中我的COM对象,我得到一个错误说:

I am trying to call a C# COM object from C#. I created a class library in C# and exported a Type Library using tlbexe.exe. I then registered the type library using regtlibv12.exe. However when I add a reference to my COM object in Visual Studio I get an error saying:

的Active X的类型库......是从.NET程序集导出并且不能被添加作为参考。添加到.NET集的引用,而不是。

"The Active X type library ... was exported from a .NET assembly and cannot be added as a reference. Add a reference to the .NET assembly instead."

任何援助将不胜感激。

一个64位的过程不能直接访问32位取消管理代码。有2个域为64位系统上的COM对象。一个64位的过程,一个是32位的进程。他们在不同登记注册的地区,因此,如果您值寄存器32位唯一的COM对象,只要64位进程而言是不存在的。现在,如果你有一个组件,它是ANY_CPU目标可以被装入由CLR一个64位或32位进程。然而,如果ANY_CPU组件被加载到64位的方法,它仍然是不goign能够加载任何32位unmaged代码。在 ARTICAL 使用DCOM和IPC创建一个进程外调用从64位到32位的代码。

A 64bit process cannot access the 32bit unmanage code directly. There are 2 domains for COM objects on a 64bit system. One for 64bit processes and one for 32bit processes. They have different registration areas in the registry, so if you regsiter a 32bit only Com object, as far as a 64bit process is concerned is does not exist. Now if you have an assembly that is target for ANY_CPU it can be loaded into either a 64bit or 32bit process by the CLR. However, if ANY_CPU assembly is loaded into a 64bit process, it still is not goign to be able to load any 32bit unmaged code. The solution metioned in the artical uses DCOM and IPC to create an out of process call from 64bit to 32bit code.

您可以做同样的事情很多easyer在.NET中使用WCF。您创建一个WCF服务器进程是32位的acesses您的32位托管代码。你的64位的过程是一个WCF客户端并完成对32位服务器调用。您可以通过使用WCF protical支持的命名管道避免网络堆栈。

You can do the same thing a lot easyer in .Net with WCF. You create a WCF server process that is 32bit that acesses your 32bit managed code. Your 64bit process is a WCF client and makes calls to the 32bit server. You can avoid the network stack by using the Named Pipes protical supported by WCF.