tags:

views:

185

answers:

5

I have a large application written in C++, For various reasons I am going to rewrite it in C#, I have done plenty of Delphi to C#, VB to C# but C++ to C# I have never done, although I am competent in C++ I want this to be as smooth a conversion as possible.

Mainly what I am asking is what pitfalls await me in this conversion is there any key areas I should be aware of or any advice you can provide me.

This article is quite good, but is there anything else I should be weary of?

http://msdn.microsoft.com/en-us/magazine/cc301520.aspx

+3  A: 

I'd advice you to pay attention to the objects lifecycle.

In C++ you destroy objects explicitly when you've done with them. In C# (.NET) you don't. It can happen that an object holds on to some important resource (file handle, database connection etc.). If it is an issue, make use of the using directive.

Developer Art
+6  A: 

Main pitfall - do not think it's an upgrade. These are DIFFERENT languages, and in many places you will need complete different approach to the problems. So you should think reimplementation with minimal code reuse.

This article is decent.

BarsMonster
Thats my goal, upgrade is probably the wrong word.
kyndigs
Did you mean to link an article or were you referring to the one that the OP posted?
Default
+1  A: 

The handling of strings was a pitfall for me at the beginning. While I Visual C++ you use pointers the methods in C# have indeed return values.

dummy = dummy.Replace("a", "b");
Holli
+2  A: 

You need to translate the spirit of the code, but not the code itself. You need to leave behind all the things you had to do in C++ because that was how it was done there. Good translation is highly creative process, so be creative.

Dialecticus
+1  A: 

If you have C++ dll and you want to use them in your C# project you can used them by pinvoke and DllImport

There will be lot of differences while you will try to convert or rewrite unmanaged code to managed one. Here is a C++ to C# converter which is quite good for converting your c++ code to C# , though you can not expect to convert the whole project using it.

Subhen