Click here to Skip to main content
15,860,859 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am tring to compile c++ code in c# and I got errors, If someone know what the problem it will help me very mach.
Here i the code:

C#
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;
       }
   }
Posted
Updated 3-Mar-13 2:02am
v2
Comments
Maciej Los 3-Mar-13 8:05am    
Do not repost!!!
Use "Improve question" widget.
[no name] 3-Mar-13 8:36am    
This is just a reposting to a question that you already have an answer to. Even if it was not a reposting, how are we supposed to know what the errors are that you are getting?
[no name] 3-Mar-13 8:54am    
I saw those samples, But I didn't find a real answer.
The error that I got:
The method or operation is not implemented
[no name] 3-Mar-13 9:03am    
Then you should update your original question instead of reposting. Read the FAQ on how to ask a question might help. "The method or operation is not implemented" is pretty self explanatory, but since you did not say what line that error is occurring on....
[no name] 3-Mar-13 9:07am    
Thank you for helping me. This is the line
CompilerResults res = codeProvider.CompileAssemblyFromSource(parms, codeText);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900