简体   繁体   English

Windows x64上32位和64位应用程序之间的进程间通信

[英]Interprocess communication between 32- and 64-bit apps on Windows x64

We'd like to support some hardware that has recently been discontinued. 我们想支持最近停产的一些硬件。 The driver for the hardware is a plain 32-bit C DLL. 硬件的驱动程序是一个普通的32位C DLL。 We don't have the source code, and (for legal reasons) are not interested in decompiling or reverse engineering the driver. 我们没有源代码,并且(出于法律原因)对驱动程序的反编译或逆向工程不感兴趣。

The hardware sends tons of data quickly, so the communication protocol needs to be pretty efficient. 硬件快速发送大量数据,因此通信协议需要非常高效。

Our software is a native 64-bit C++ app, but we'd like to access the hardware via a 32-bit process. 我们的软件是原生的64位C ++应用程序,但我们希望通过32位进程访问硬件。 What is an efficient, elegant way for 32-bit and 64-bit applications to communicate with each other (that, ideally, doesn't involve inventing a new protocol)? 什么是32位和64位应用程序相互通信的有效,优雅的方式(理想情况下,这不涉及发明新协议)?

The solution should be in C/C++. 解决方案应该是C / C ++。

Update: several respondents asked for clarification whether this was a user-mode or kernel-mode driver. 更新:一些受访者要求澄清这是用户模式还是内核模式驱动程序。 Fortunately, it's a user-mode driver. 幸运的是,它是一个用户模式驱动程序。

If this is a real driver (kernel mode), you're SOL. 如果这是一个真正的驱动程序(内核模式),那么你就是SOL。 Vista x64 doesn't allow installing unsigned drivers. Vista x64不允许安装未签名的驱动程序。 It this is just a user-mode DLL, you can get a fix by using any of the standard IPC mechanisms. 它只是一个用户模式DLL,您可以通过使用任何标准IPC机制来获得修复。 Pipes, sockets, out-of-proc COM, roughly in that order. 管道,套接字,进程外COM,大致按顺序排列。 It all operates on bus speeds so as long as you can buffer enough data, the context switch overhead shouldn't hurt too much. 它都以总线速度运行,因此只要您可以缓冲足够的数据,上下文切换开销不应该太大。

I would just use sockets. 我只想使用套接字。 It would allow you to use it over IP if you need it in the future, and you won't be tied down to one messaging API. 如果将来需要它,它将允许您通过IP使用它,并且您不会被限制为一个消息传递API。 If in the future you wish to implement this on another OS or language, you can. 如果将来您希望在其他操作系统或语言上实现此功能,则可以。

This article might be of interest. 这篇文章可能会引起关注。 It discusses the problem and then suggests using COM as a solution. 它讨论了该问题,然后建议使用COM作为解决方案。 I'm not a big fan of COM but given its ubiquity in the Windows universe, it's possible that it might be efficient enough. 我不是COM的忠实粉丝,但鉴于它在Windows世界中无处不在,它可能足够高效。 You will probably want to architect your solution so that you can batch data (you don't want to do one COM call for each item of data). 您可能希望构建您的解决方案,以便您可以批量处理数据(您不希望为每个数据项执行一次COM调用)。

Elegant? 优雅? C++? C ++? DCOM/RPC calls to yourself might work, or you could create a named pipe and use that to talk between the two processes (maybe create a "CMessage class" or something), though watch out for different structure alignment between x86 and x64. 对自己的DCOM / RPC调用可能有效,或者您可以创建一个命名管道并使用它来在两个进程之间进行通信(可能创建一个“CMessage类”或其他东西),但要注意x86和x64之间的不同结构对齐。

If the driver does turn out to be a real driver, nobugz is almost right -- you're going to have to work a lot harder, you're not completely SOL. 如果司机确实是一个真正的驱动程序,nobugz几乎是正确的 - 你将不得不更加努力工作,你不是完全SOL。 One solution is to install Win32 on some other machine (or virtual machine) and then use some form of RPC, such as sockets (as suggested by Pyrolistical) or UDP or MQ or even Tibco Rendezvous (which claims to support very high throughput in order to handle the volumes of data generated by the financial markets -- at least that's what I remember from back in the old days). 一种解决方案是在其他计算机(或虚拟机)上安装Win32,然后使用某种形式的RPC,例如套接字(如Pyrolistical所建议)或UDP或MQ甚至Tibco Rendezvous(声称支持非常高的吞吐量顺序)处理金融市场产生的大量数据 - 至少这是我过去记得的情况。

A memory-mapped file, shared by both sides would have the same contents. 双方共享的内存映射文件具有相同的内容。 The OS will have to do some interesting pointer stuff to make it happen, but quite likely will be able to setup the 2 views in such a way that you're not physically copying memory around. 操作系统将不得不做一些有趣的指针来实现它,但很可能能够以这样的方式设置2个视图,即你不是在物理上复制内存。 Zero copies is about as good as it gets 零拷贝几乎和它一样好

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

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