Pass binary data from C to C# through the console

こ雲淡風輕ζ 提交于 2019-12-13 02:36:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!