从 64 位 exe 访问 32 位 DLL 的方法 [英] Ways to access a 32bit DLL from a 64bit exe

查看:27
本文介绍了从 64 位 exe 访问 32 位 DLL 的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须在 64 位模式下编译和运行的项目.不幸的是,我需要调用仅在 32 位模式下可用的 DLL,因此我无法将所有内容都包含在 1 Visual Studio 项目中.我正在努力寻找将 32 位 DLL 包装在其自己的 exe/服务中并从我的 64 位应用程序远程(尽管在同一台机器上)调用该 exe/服务的最佳方法.我的操作系统是 Win7 Pro 64 位.

I have a project that must be compiled and run in 64 bit mode. Unfortunately, I am required to call upon a DLL that is only available in 32 bit mode, so there's no way I can house everything in a 1 Visual Studio project. I am working to find the best way to wrap the 32 bit DLL in its own exe/service and issue remote (although on the same machine) calls to that exe/service from my 64 bit app. My OS is Win7 Pro 64 bit.

对这个 32 位进程所需的调用是每秒几十次,但数据量很小.这是一个实时图像分析应用程序,因此尽管体积很小,但响应时间仍然很关键.大量发送/接收单个原语.

The required calls to this 32 bit process are several dozen per second, but low data volume. This is a realtime image analysis application so response time is critical despite low volume. Lots of sending/receiving single primitives.

理想情况下,我会托管一个 WCF 服务来容纳这个 DLL,但在 64 位操作系统中,不能强制该服务作为 x86 运行!来源.这真的很不幸,因为我对 WCF 服务的函数调用在我的机器上计时只有 4 毫秒.

Ideally, I would host a WCF service to house this DLL, but in a 64 bit OS one cannot force the service to run as x86! Source. That is really unfortunate since I timed function calls to the WCF service to be only 4ms on my machine.

我已经尝试过命名管道是 .net.我发现它们比 WCF 慢 40-50 倍(我无法使用).

I have experimented with named pipes is .net. I found them to be 40-50 times slower than WCF (unusable for me).

对于解决我的难题的最佳方式,还有其他选择或建议吗?

Any other options or suggestions for the best way to approach my puzzle?

推荐答案

正如您正确地注意到的,没有办法在同一进程中混合位.您的 32 位部分需要一个单独的过程.

As you correctly note, there is no way to mix bitness in the same process. You need a separate process for your 32-bit part.

我认为托管 WCF 服务是正确的方法.您的链接仅讨论 wcfsvchost.我很确定您可以创建自己的 Windows 服务,并在 32 位上托管 WCF 服务.

I think hosting a WCF Service is the right way to go. Your link only talks about wcfsvchost. I am pretty sure you can create your own Windows Service, and host the WCF service in that on 32 bit.

请参阅此链接:如何在托管应用程序中托管 WCF 服务.您可以在任何托管应用程序(包括 Windows 服务)中托管您的服务,并在您喜欢的位数下运行它.

See this link: How to host a WCF service in a managed application. You can host your service in any managed application, including a Windows Service, and run it under the bitness you like.

这是在应用程序中自托管 WCF 服务所需的代码量,假设您刚刚创建了一个名为 MyService 的新服务,并且已将适当的配置添加到 app.config:

This is the amount of code required to self-host a WCF service in your application, assuming you have just created a new service called MyService, and the appropiate configuration has been added to app.config:

class Program
{
    static void Main(string[] args)
    {
        using(ServiceHost host = new ServiceHost(typeof(MyService), new Uri[0]))
        {
            host.Open();
            Console.ReadKey();    
        }
    }
}

上述程序也能运行,如果您将其明确编译为 32 位或 64 位.

The above program will run just as well, also if you compile it explicitly as 32 or 64 bit.

这篇关于从 64 位 exe 访问 32 位 DLL 的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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