I have been experimenting with sending messages from two .NET Windows Forms applications using WM_COPYDATA
, and it works great.
I would like to know if
@tommieb75: XDMessaging is actually my library :) WM_COPYDATA doesn't work for console applications as they don't have a message pump. The library does however include a IOStream based IPC implementation that works for console apps and services. http://thecodeking.github.com/XDMessaging.Net/
The most common IPC methods (aside from WM_COPYDATA
) are memory-mapped files and named pipes. I suggest you check out the latter.
MSDN has an example of named-pipe communication. Specifically the classes you need to use are NamedPipeServerStream
and NamedPipeClientStream
, which behave largely like ordinary network streams once they're created.
The nice thing is that it also works over a network, although you can obviously use it on a single machine as well.
Setting up an actual Windows message loop in a console application is complicated, to say the least. If you really need to do it, here's a rather long-winded article on the subject. I'd strongly recommend using named pipes instead if all you want to do is transfer data; if you don't actually need to handle standard Windows messages then this isn't going to be worth the effort.