How do I set up a named pipe between .NET and MFC?
How do I set up named p开发者_开发技巧ipe between a .NET (specifically WPF) application and an MFC application running in the background? I need to provide synchronous and asynchronous messaging sending XML instances. Is there a way to use a call back architecture?
In the MFC application: I don't think there are any MFC classes specifically to help with named pipes, but the Windows Named Pipes API is not too difficult, or you could look to open source/shareware classes for higher level abstractions (for example here)
In the .NET application, the types in the System.IO.Pipes namespace provide a nice stream abstraction over a named pipe which is fairly straightforward to use.
Decisions you will have to make include:
- Which application is the pipe server, responsible for creating the pipe and listening for the other application (pipe client) to connect.
- Can you work directly with the message-streaming mode provided by the OS (each write to the pipe is deemed one message), or do you need to build your own message framing over the pipe byte-stream.
Duplex operation is supported, so you can build "callback architecture" over the pipe messaging if you want to.
Windows Communication Framework provides a Named Pipe transport binding. But this won't be useful to you even on the WPF application side unless you are up for reimplementing on the MFC side a host of partly-documented Microsoft protocols layered on top of the raw pipe communication (you can read more on this on my blog if you are interested).
精彩评论