Converting a project from C ++ to C #

I have a medium-sized project (turn-based game) that is currently written in C / C ++. Only one person works on it. This will match / clr, although I have not tried / clr: pure.

I am looking for advice on the general process of converting it to C #.

This is mainly C with a thin veneer C ++ on it (C with static / single classes to define the scope). Yes, this is not a "real" OO, I planned to convert C # first to avoid creating any problems during the conversion.

It uses the STL (queue class) in the path tracking module to a very limited extent, and because it is a game, it also does not perform any memory allocation outside the third-party sound library in the DLL and what is needed to load graphic bitmaps.

I want to convert it to idiomatic C #. I would prefer not to discuss whether this is a good idea, I understand that this is not so, please let the part go. Suppose I have the main reasons.

I also did my research, and there is a stream that is somewhat important for converting methods using a reflector. I plan to delve deeper into it when I get a chance.

Translate C ++ / CLI to C #

There is also one paid application that will convert from C ++ to C #, which I can look at if this does not work as I would like.

The hardest part is to rewrite the interface in WPF / Silverlight or XNA (or both). Each of them has its pros and cons, but now I'm leaning towards WPF because of font support, and because in this way I do not have to write all the widgets. In the end, I can do both fast and fast XNA port, and WPF later.

There are several possible approaches to this, and I wanted to know if anyone has experience with such a conversion, as well as any suggestions or pitfalls.

1) First create a user interface. This includes either exiting the graphics module as is, or converting from GDI to raw GDI, like calling in XNA, and then converting it to WPF one dialog at a time.

2) First, convert the guts and leave the main interface in C ++ / CLI, now, after converting the guts, switch the interface one dialog box to WPF.

A related question is whether it is worth doing this module modulo or, basically, right away, and is it better to do a rough conversion in C # and clear each of them or clear everything in C ++ and then convert to C # .

The idea now is to rewrite the event loops to use a home common loop such as MFC, and then try to convert everything all at once to C #. Leave the graphics in C ++ and see what the breaks are. After that, go to XNA and give the WPF layer later. The last two steps are arbitrary, I think the XNA port will be easier, but using the main WPF panel can be quite simple.

I am open to any suggestions that may help.

Thanks, Ralph

+4
source share
6 answers

I found out that CodeRush (which I already have) has a smart paste operation that does a reasonable job of transforming what you can assign. There is also a googleplex CR_Paste add-on that does something similar. (CR_Paste add-on may not require Coderush, only the free DXCore app.

Since I will have full access to the parsing tree (and understand the parsing trees), I can (and cannot) configure it to change char * to String, etc. If I make a lot of tweaks, I will probably create an open source version, possibly on CodePlex.

Ralph

+2
source

I have to say that the best best advice I can give you is to rewrite the application. C ++ and C # are so different that if you are sure you want to convert the whole thing, rewriting is likely to be your best option.

I think my main question is why do you want to convert this project to C #? I understand that this is not your question, but since you are undertaking what I consider significant for this to be done, I hope that you will understand what you are driving towards.

+7
source

With Visual Studio 2013 Express

In fact, you can open two Windows (say, VSEx 2013 (1) and VSEx 2013 (2)).

First you open it, you open your existing project, than: you right-click on its icon in the taskbar and click on Visual Studio 2013 Express ... This will open the application a second time, you will run it twice in the same time.

Because the reason I got to your post ... lol ... because I was looking for the same thing.

What I did next was enjoyable.

Edit: Select all Copy ...

Switch to another "window" VS Express 2013, Paste ...

Then, of course, you can get mini errors, such as colors that need to be reset, shapes that need to be redefined, and all :: and → to change replace: by. and → by. (You will probably have to recreate all the "Events", but usually: all the properties will be set by default if you set them in the original settings.

Then, if you have errors when inserting a type (the object cannot be found), this basically means that one of your controls is actually a .COM or inline thing ... Just add it the same way as in older versions of Visual C ++ (example: show: toolbox, then right-click on it and add ITems (or select items) and then add it as usual) ..

Hope this helps.

(I actually reprogram my entire program VC ++ 2010, in C # 2013.)

Good luck :)

+2
source

It looks like you need to reverse engineer the application, not just convert the code. Converting non-OO C / C ++ applications to C # doesn't seem like a realistic goal.

0
source

I am busy converting C ++ code to C # code.

I find it much faster and easier than I thought. and yes, I also first want it to be identical before making changes in some cases, such as scientific algorithms, which you want to get in the same way if there are no check marks.

Well, since your code is more c based on this, you just need to provide the C # spagetti code, which you will need to reorganize later into classes. Probably, initially you will have many static methods that would be your c-functions. Try combining some data and methods together, where they describe the behavior of objects.

I am doing this file by file, line by line. starting from the guts. When I find something completely obsolete, I replace it with the C # equivalent using lists, IEnumerables, etc. Some low-level computing can be replaced with standard C # libraries.

I would advise using unsafe C #. Often around it is easier and safer. Pointer calculations can often be very similar to C ++ code and are some of the fastest things to translate.

eg.

double * array_p;

converted to

double [] array_p

now, while you are referencing array_p [i] after that, where I am int, this code remains the same if you specified the array_p ++ increment, use the int that you start at 0 and increment. For example, I ++. and call

array_p [I]

Passing pointers to pointers from one method to another, for example. * array_p just passes the reference to array_p in C #. In fact, in C # all classes are passed by reference anyway, so there is no need to have all of these pointers.

Guy, I would write from scratch. OO and non-OO are too different for this.

Good luck. Check the low level code and clean it where possible.

0
source
#include <iostream> using namespace std; int main(int argc, char *argv[]) { char a;//letra int num;//cantidad a imprimir //Ingresa los datos cout<<"Introduce la letra "<<endl; cin>>a; cout<<"Introduce la cantidad para imprimir "<<endl; cin>>num; //imprime de 5 a 1 for(int i=num; i>0; i--) { for(int c=0; c<i; c++) cout<<a; cout<<endl; } //imprime de 1 a 5 for(int i=0; i<num; i++) { for(int c=0; c<=i; c++) cout<<a; cout<<endl; } return 0; } 
-1
source

Source: https://habr.com/ru/post/1286575/


All Articles