如何从VS 2010解决方案(针对64位计算机)中调用32位COM互操作dll [英] How to invoke a 32bit COM interop dll from VS 2010 Solution which is targetting 64 bit machines

查看:433
本文介绍了如何从VS 2010解决方案(针对64位计算机)中调用32位COM互操作dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#开发Windows客户端应用程序,在VS 2010解决方案中有两个项目,一个是启动项目,另一个是使用第三方COM interop DLL的类库。我的桌面是64位的,所有客户端计算机都是也是64位。

I am working on Windows client application using c#, have two projects in my VS 2010 solution, the start-up project and a class library which uses third party COM interop DLL.My desktop is 64 bit and all the client machines are 64 bit as well.

如果我将启动项目保留为(构建设置)中的任何cpu,并且将第二个项目调用COM DLL的x86保留为x86,则出现以下错误:

If I keep the start-up project as any cpu in (build settings) and x86 for the second project which invokes the COM DLL, I am getting the following error:

Could not load file or assembly ... or one of its dependencies. An attempt was made load a program with an incorrect format.

如果我将两个项目都保留为Any cpu,则会出现以下错误:

If I keep both the projects as Any cpu, I am getting the following error:

由于以下错误,检索具有CLSID ..的组件的COM类工厂失败:

任何想法都可以解决,而无需将解决方案(所有项目)转换为x86。

Any idea how to resolve the issue without converting the solution (all projects) to x86.

推荐答案

嗯,我建议您看看 DLL替代。此技巧绝对可以解决您的问题,但前提是您可以在注册表中更改DLL inrpoc服务器的注册信息。
如果将类配置为使用代理,它将在单独的进程中运行。 COM允许一个人通过64位应用程序使用进程外的32位COM服务器。

Well, I suggest you to look at DLL surrogates. This trick will definitely solve your problem, but only as long as you may change the registration info of the DLL inrpoc server in the registry. If the class is configured to use a surrogate, it will run in a separate process. COM allows one to use an out-of-proc 32bit COM server from a 64bit application.

您需要更改的所有内容如下所示:

All you need to change is shown below:

查看注册表中的以下条目:

Look at the following entry in the registry:

HKCR\CLSID\{CLSID_CoClass}

然后查看它是否具有AppID字段。如果是这样,只需访问此注册表项:

And look if it has the AppID field. If it does, just visit this registry key:

HKLM\Software\Classes\AppID\{APPID}

并添加没有值的DllSurrogate字符串键。

and add the DllSurrogate string key with no value.

如果该类没有关联的AppID,则可以自己创建。然后,您可以使用64位目标.net应用程序中的32位inproc库。

If the class doesn't have an assosiated AppID, you may create it yourself. Then you may use your 32 -bit inproc library from the 64bit targeted .net application.

这篇关于如何从VS 2010解决方案(针对64位计算机)中调用32位COM互操作dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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