问题
I have two applications, one written in C and the other one in C#, which talk through console string messages. They both wait until the other sends a string message.
Now I want that at a certain moment the C application sends an image in binary format through the same console I/O "channel" and that the C# application recieves it and uses it as an image to display. I know it is possible, see: C/C++: is it possible to pass binary data through the console?.
I have access to the source code of both the applications. I know where the C application-code writes the image to disk. The C# application gets the C application output by this piece of code:
process.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); //void
p_OutputDataReceived(object sender, DataReceivedEventArgs e) //e.Data.
How do I have to code the C and C# part of this binary image transfer? Thanks.
回答1:
If your question is how to transfer this data, the really short answer to your question is base64. It was made specifically for this purpose, and has ready-made libraries for both C and C# (just look for e.g. "C# base64").
It is almost as efficient as a raw binary encoding (in terms of data transferred).
来源:https://stackoverflow.com/questions/9566211/pass-binary-data-from-c-to-c-sharp-through-the-console