Calling unmanaged code from a managed or spawning process
Since you have the C ++ library source code, you can use C ++ / CLI to compile it to mixed mode dll, so it is easy to use by C # application.
The advantage of this would be most flexible in data flow (input or output of that C ++ module).
There is one advantage when running C ++ code from a process. If your C ++ code is not very robust, this can make your main C # process stable so it doesn't break into C ++ code.
a source to share
Another disadvantage of the spawning process is that it is a very expensive (slow) operation to open the windows. If you intend to call your C ++ code frequently, this is worth considering. The benefit may be that you are automatically isolated from crashes in your C ++ program. There might also be the benefit of replacing the C ++ executable. Also, writing interop code can be a big problem in C #. If this is a tricky interace and you decide to do interop, look at C ++ / cli for the interop layer.
a source to share
You are much better off taking a subset of the functionality of a C ++ executable and building it in a library. You will maintain type safety and you can make better use of exception handling (not to mention finer grain control how you manage calls to functions in the library).
If you go with capturing data from the OutputStream of the executable, you will not have visibility to the processes of the executable, no real exception handling, and you will lose the type information you might have.
a source to share
The main disadvantage of being in the process would be to make sure you are managing the managed / native interactions correctly.
1)
The C ++ code will probably depend on deterministic destruction for cleanup / resource, etc. I'm talking probably because this is common practice and good practice in C ++.
In managed code, this means that you have to be careful to properly manage your C ++ cli code. If your code is used once, the C # use clause will do it for you. If the object is to live for some time as a member, you will find that the utility must be bound in its entirety through your application.
2)
Another problem depends on how hungry your application is. The managed garbage collector can be lazy. It is guaranteed that in case the managed allocation requires more space than is available. However, the unmanaged valve is not connected. Therefore, you need to tell the managing allocator that you will be making unmanaged allocations and that he must keep this space available. This is done using the AddMemoryPressure method.
The main disadvantages of exiting the process are:
1) Speed.
2) Code overhead for message management.
3) Code overhead for tracking a process when it is not expected.
a source to share