Sending Large amouts of data from Unmannaged C++ application to Managed C#
we have two applications, a native C++ application and a managed C#/WPF UI that creates input for, executes & reads output generated by the native application. Currently, communication between the two is done with XML & plain txt files.
However, the amount of output data is quite large & we are looking for a bette开发者_运维知识库r approach to this. A solution that uses something like Memorystream would be ideal because it would easy to switch the output generation from a filestream to a memorystream.
However, how does one bridge the gap between managed & unmanaged? What is the most efficient way to do this?
Note: Many of the questions related to this are about a function call from a managed to an unmaged dll. These are two separate applications running independently. The UI spawns the native application, this is the only link between the two.
Thanks
You could try a named pipe http://www.switchonthecode.com/tutorials/interprocess-communication-using-named-pipes-in-csharp
it depends on the way you produce/consume data
- named pipes or socket - constant stream of data
- shared memory - continuous updated data
Why not use standard input/output? Your C++ program can write to stdout using normal "printf" or "cout" commands.
Your .NET app can then capture this data using http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx, for example. Same goes for standard input: use stdin to send commands to the C++ program.
Using named pipes is nice and might be the answer if you need more than two streams. But it would probably be more work on the C++ end of things.
精彩评论