简体   繁体   English

从64位模式运行的c#调用32位COM

[英]Calling 32bit COM from c# running in 64bit mode

I have a 3rd party COM object(32 bit) that I need to call from my c# application (64 bit). 我有一个第三方COM对象(32位),我需要从我的c#应用程序(64位)调用。 I know I have to run the COM object in a separate process. 我知道我必须在一个单独的进程中运行COM对象。 This COM object has many classes implemented in it, so I'm trying to avoid writing my own remoting wrapper that exposes all the methods. 这个COM对象有很多类实现,所以我试图避免编写自己的远程包装器来公开所有的方法。 COM+ seems to be the most straightforward solution. COM +似乎是最直接的解决方案。 I opened the Component Services menu, created a new COM+ Application, added my COM object as a component to this application. 我打开了“组件服务”菜单,创建了一个新的COM +应用程序,将我的COM对象作为组件添加到此应用程序中。 Everything seemed to import beautifully. 一切似乎都很美妙。

In my C# application, I added the original COM object as a reference (which automatically generates the type library). 在我的C#应用​​程序中,我添加了原始COM对象作为引用(自动生成类型库)。 Using the type library reference, I can create objects from from the COM+ component (I see them begin to spin in the Component Services window), but when I try to access on of the methods of the object, I get an error saying the interface is not registered. 使用类型库引用,我可以从COM +组件创建对象(我看到它们开始在组件服务窗口中旋转),但是当我尝试访问对象的方法时,我得到一个错误说接口没有注册。

Does anyone have a clue? 有人有线索吗? I went back and ran regsvr32 on the COM object, but I don't think it was necessary, and it didn't help. 我回去并在COM对象上运行了regsvr32,但我认为没有必要,并没有帮助。 Is my usage in C# correct? 我在C#中的用法是否正确? VS2008 autocomplete had no problem seeing those methods. VS2008自动完成没有问题看到这些方法。

The exact exception is: "Interface not registered (Exception from HRESULT:0x80040155)" 确切的例外是:“未注册接口(HRESULT异常:0x80040155)”

Unclear about exactly what the permissions and roles are about in the Component Services, I tried setting up the COM+ object identity to run under the System Account, both as a local service and as interactive user. 我不清楚组件服务中的权限和角色究竟是什么,我尝试将COM +对象标识设置为在系统帐户下运行,既作为本地服务又作为交互式用户。 I've added Everyone as a user in the Roles. 我在角色中添加了Everyone作为用户。 Everything is running locally, so there shouldn't be an issue with file privileges or anything like that. 一切都在本地运行,所以不应该有文件权限或类似的问题。

I also want to reiterate that this COM object contains many classes. 我还想重申一下这个COM对象包含很多类。 I successfully instantiated one class object in my client and set some property values. 我在客户端成功实例化了一个类对象并设置了一些属性值。 I also successfully instantiated another class object, but received this exception when attempting to call a method of this second object .... so I don't think there is an issue with which registry my COM object is registered in. 我也成功实例化了另一个类对象,但在尝试调用第二个对象的方法时收到了这个异常....所以我认为我的COM对象注册的注册表存在问题。

We had a similar situation, working with a COM dll from VFP. 我们遇到了类似的情况,使用VFP的COM dll。

It all depends on rights and permissions, like Yahia says. 这一切都取决于权利和权限,如Yahia所说。 We got it working by doing this: 我们通过这样做得到它:

  • Install VFP oledb 9 drivers (dunno what you have so probably not required). 安装VFP oledb 9驱动程序(不知道你有什么可能不需要)。
  • give Network Service IIS_IUSR full control on the COM folder (required so the DLL can do some logging in its own folder, when called from the website). 给网络服务IIS_IUSR完全控制COM文件夹(需要这样DLL,当从网站调用时,可以在自己的文件夹中进行一些日志记录)。
  • run regsvr32.exe "c:\\xxx\\yourfile.dll" -> this should be successful! 运行regsvr32.exe“c:\\ xxx \\ yourfile.dll” - >这应该会成功!
  • Create COM+ application, and add the DLL as a part 创建COM +应用程序,并添加DLL作为一部分
  • Set the application COM+ credentials on a user wigh sufficient rights 在具有足够权限的用户上设置应用程序COM +凭据

and we had to do some more settings on rights in application pool / IIS, but thats not required for you I guess. 我们不得不对应用程序池/ IIS中的权限进行更多设置,但我猜这不是必需的。

Anyways, just make sure you have enough logging, make sure the dll is registered, and after that its all about rights rights rights.. 无论如何,只要确保你有足够的日志记录,确保dll已注册,之后它的所有权利权利..

Good luck with it! 祝你好运!

Sorry to use the "Answer" to respond to comments, but it seems to be my only avenue. 很抱歉使用“答案”回复评论,但这似乎是我唯一的途径。

The whole purpose of moving to a 64bit operating system was to gain the extra addressable memory space, so running the entire application in 32bit mode is not an option. 迁移到64位操作系统的全部目的是获得额外的可寻址内存空间,因此无法以32位模式运行整个应用程序。

It might be relevant to the problem that after successfully creating three class objects, I was able to set properties in one, call a method with no arguments in the second, but it was calling a method in the third, which took the other two objects as arguments that threw the exception. 可能与以下问题有关:在成功创建三个类对象之后,我能够在一个中设置属性,在第二个中调用一个没有参数的方法,但是它在第三个中调用了一个方法,它接受了另外两个对象作为抛出异常的参数。

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

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