Communicating with Native (C++) Code/Process

Hi all,

I’m currently developing a game in MonoGame. The game’s AI is provided by a 3rd party, open source executable binary that is written in C++ (let’s call it 3rdParty.exe). I’ve been developing the application on a Windows machine. The process for communicating with the program in Windows is easy. I have simply been spinning up a new process (launching the .exe) and then writing to the program’s stdin and reading from its stdout. Example below:

using System.Diagnostics;
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false; //required to redirect standard input/output

// redirects stdin and stdout
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;

startInfo.FileName = "3rdParty.exe"

Process process = new Process();
process.StartInfo = startInfo;

process.StandardInput.WriteLine("<<WRITE SOME COMMAND>>");

However, I’m unsure about how I would do something similar on Android. I know that I can compile the source code of the 3rd party library into a *.so binary using the Android NDK, but how would I go about starting the 3rd party process and writing to the program’s stdin and reading from the program’s stdout in Android? Can someone that has experience using native code in Monogame give me guidance?


Build it as a .so and then use P/Invoke to define your C#-to-C++ interop and Xamarin’s support for linking to native Android libraries. You can also do the same on Windows if you build their code as a DLL.


Thanks for taking the time to reply. This response was good and the links were helpful. This puts me on the right track!