Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 04-05-2011, 02:17 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: May 2011
Posts: 6
Default c++ c# question


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
bagsfr is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 04-05-2011, 03:18 PM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: c++ c# question

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;
   }
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.

Last edited by arpanmukherjee1; 04-05-2011 at 03:27 PM.
arpanmukherjee1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:27 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2