I have a C++ console Exe which does some progamming. Now i wanted to write a C# GUI which does some of the programming that the C++ exe does. I was thinking of few approaches,
- Write the C# GUI with all programming in C++ done from scratch.(I do not want to do this for the amount of rework it entails)
- Build a C++ dll which does the programming and have it imported in GUI app.(Now here i have a concern. How do i capture the output of the routines in c++ dll and display it in GUI? Should i return the output as string for every routine that the app calls.? Since i dont know managed c++ iam going to build an unmanaged C++ dll. )
Building a C++/CLI dll really isn’t that hard. You basically use unmanaged C++ code except that you define a “
public ref class” which hosts the functions you want the C# code to see.What kind of data are you returning? Single numbers, matrices of numbers, complex objects?
UPDATE: Since it has been clarified that the “output” is iostreams, here is a project demonstrating redirection of
coutto a .NET application calling the library. Redirectingclogorcerrwould just require a handful of additional lines inDllMainpatterned after the existing redirect.The zip file includes VS2010 project files, but the source code should also work in 2005 or 2008.
The iostreams capture functionality is contained in the following code: