Search code examples
.netc++remoting

Easiest way to do remote calls between a C++ program and a .NET program


I have a .NET program running in the background and need to create a Windows Shell Extension that can communicate with that program. At first I thought I would create my Shell Extension in .NET and used IpcServerChannel and IpcClientChannel to make remote calls between server (.NET program) and client (.NET Shell Exension). This was really simple to do and worked fine really quick.

Now I realize that creating the Shell Extension in .NET is not such a good idea as it can fail to load in some cases (if a .NET 1.0 Shell Extension would be loaded first for example). I think I might go the C++ route then, but in that case is there a simple way to make my C++ Shell Extension do remote calls to my .NET Program ? Or do you have any other idea to make my two programs communicate (I'd prefer if I didn't have to design a communication protocol and could just drop in a library).

Thanks !


Solution

  • Well, you could try SendMessage(WM_COPYDATA).

    But then, if you are into it, it would be far more extensible (and maintenable) do just do a named pipe or a local inet socket. Actually, designing a communication protocol is not as difficult as it sounds: just send a serialized struct with the parameters and wait for a serialized reply. Then handle the timeouts and format errors, and done!