DIGIT-ARC read-only archive · snapshot: July 23, 2026

c++ c# question

2 posts · originally from https://geek.digit.in/community/threads/c-c-question.140199/

B
bagsfr Original post #1
May 4, 2011 at 2:17 PM
Hello all,
i wrote a c++ program and c# program.
i want to run both of them in a same project or i want to join them.
how can i convert c++ code to c# code to use in c# and how?

Plase help me its important for me thank you
arpanmukherjee1
May 4, 2011 at 3:18 PM
use CodeDom. if you dont know what it is, i strongly recommend to read examples from MSDN or CodeProject before you use the code below

Code:
using System.CodeDom.Compiler;
Code:
   ///C# function to compile C++ code
   public string ExecuteCode(string codeText, sting outputFileName) //pass entire C++ code as parameter and the output location
   {
        string result = ""; //final result that is displayed
        CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("Cpp"); //creating a C++ compiler
        CompilerParameters parms = new CompilerParameters();
        parms.GenerateExecutable = true;
        parms.OutputAssembly = outputFileName; //set output filename. must include check that path exists
        CompilerResults res = codeProvider.CompileAssemblyFromSource(parms, codeText);
        if (res.Errors.Count > 0)
            foreach (CompilerError err in res.Errors)
                result += "Line No.: " + err.Line + " Error No.: " + err.ErrorNumber + " - " + err.ErrorText + "\n";
        else
            result = "Executable sucessfully created with file name : " + outputFileName;

        return result;
   }