Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I need convert a C# program to C++.
Posted
Updated 15-Apr-13 1:14am
v2
Comments
jsolutions_uk 15-Apr-13 6:06am    
You probably need a bit more detail than that to get an answer. Some answers to the following questions might be useful:

1. Why do you need to convert it?
2. Is it a console or GUI app?
3. Does it provide a network client or server?
4. Does it rely on any other specific technology, (eg XML, Database etc)

That way, you might get some pointers as to how to approach whatever problem you have.
Nelek 15-Apr-13 6:37am    
And do you think that with the information you have given, is there anyone here able to help you?
Mehrdad keshavarzi 15-Apr-13 8:38am    
1)I am have main program in c++
Because i need convert
2)I did not understand what you're saying
3)client
4)no
johannesnestler 15-Apr-13 9:19am    
I think jsolution_uk had some very good and valid questions (you should have asked that yourself). Let's have another look at these questions:

1. Main Program in C++ - this doesn't answer why.. it depends on the c# functions you want to convert. If you are porting them for performace reasons you are maybe right but easiest is going over COM Callable Wrapper (http://msdn.microsoft.com/en-us/library/f07c8z1c.aspx)
2. Is there a graphical user Interface or just a lib or console app? (GUI is more difficult to port)
nv3 15-Apr-13 8:43am    
So, what's keeping you from starting with the conversion? You didn't hope for someone else doing for you, did you?

1 solution

There's no automatic way to do this, you will have to rewrite by hand. Probably best to go for C++/CLI as the initial step if you can so that all the CLR calls and objects can still be used.

Each C# class will need to be converted to a C++ class in separate header (.h) and implementation (.cpp) files.

The biggest issue you are likely to have is dependency between classes i.e. which #include(s) you need in each header and what to do when they conflict.
This can be solved with a set of techniques that include introducing abstract base classes and factoring out single classes into common and intermediate bases. In some cases additional use of templates will be appropriate to create mixin classes and not just where C# would be using Generics.
Anyone helping you with this will need to know what the size of you codebase is and where you intend the end result C++ to run, Windows? Linux? Embedded? Cross platform?
 
Share this answer
 
Comments
Mehrdad keshavarzi 15-Apr-13 8:37am    
Tank
Linux
Matthew Faithfull 15-Apr-13 8:45am    
If you're going as far as Linux/C++ that's going to be a hard road. Have you considered using Mono to run the C# on Linux without conversion?
johannesnestler 15-Apr-13 9:45am    
Why didn't you state this in the first place? Here at CP are a lot of good coders reading questions and trying to help others. I got good advices here in the past and if I come across a question I may can answer (I did C/C++/C#/Linux/Windows ports in all directions in my past) I try to help.
So I thought maybe I can help you, but if you aren't even willing to formulate a real question, why should I? So maybe sit down 5 mins and consider what Matthew was saying, maybe try to answer jsolution_uk's again. Tell us if you have to port "specialities" of .NET difficult to write in C++ (LINQ, generics, ...). After that I will try to help you - if you want!
Mehrdad keshavarzi 17-Apr-13 7:06am    
Programming language C + + on Linux is my home and I'll walk a piece of software used on this site and I'll add it to the language of C#
jsolutions_uk 17-Apr-13 8:34am    
Correct me if I'm wrong, but are you taking C# code from codeproject and converting it to C++ ? If that is the case, just point us to the code in question :)

If this is a general question: "What is the best way to convert C# to C++", I think you have your answer: "There is no best way, it is very dependent on the C# code in question and the platform the C++ code is being written for".

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