string code = @"struct MyStructe { int x; MyStructe *next; };"; ExecuteCode(code, "j"); } public void CompileCode() ///C# function to compile C++ code public string ExecuteCode(string codeText, string 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; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)