-1

So basically I designed this c# application that has a cool design, but instead of remaking it to put back into c++ I want to make my life easier and just make it run inside of a c++ console application. The problem is I can only figure out a way to run the application in the c++ console as an external process and not actually embedded in the c++ console (they are both console applications) Is there any way that I can start the c# console inside the c++ console?

This is my code on c++ int result = system(location);

If anyone has any ideas, please let me know. Thanks!

Ðаn
  • 10,934
  • 11
  • 59
  • 95
Velmillion
  • 19
  • 4

1 Answers1

1

Since you're already using the system() command in your question, I'm assuming you're okay with me using it in my solution. In which case, just resort to the Batch (CMD) commands for starting a process in the current window.

First, you'll need to compile the C# code. This post explains how to do that in detail. If you want to do this inside a C++ program, simply wrap the compile command in the system() command (e.g. system("/* path to csc.exe */ \t:exe \out:App.exe App.cs");).

After that, simply wrap the name of the exe in another system() command (e.g. system(App.exe)).

So, if I had a cs script named "Books.cs," here's how I can compile (if needed) and run from C++:


// PATH_TO_CSC should be replaced with the path to csc.exe on your machine

int main()
{
    system("PATH_TO_CSC \t:exe \out:Books.exe Books.cs");
    system(Books.exe);
}

Note, for this to work, your working directory will have to be the same as the C# script. This is untested on my end for C# programs, but I was able to run a C++ executable console app that did not open a new window. Another executable should have a similar outcome.

Drake Johnson
  • 640
  • 3
  • 19
  • Thank you. I will try this out today. And just to make sure will this allow me to use the c# console inside the c++ console? Thanks so much. – Velmillion Jan 18 '20 at 10:40