Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. how hard to rewrite a legacy software from C++ to C# in WinForm?

how hard to rewrite a legacy software from C++ to C# in WinForm?

Scheduled Pinned Locked Moved The Lounge
csharpc++question
26 Posts 18 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Southmountain
    wrote on last edited by
    #1

    I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

    diligent hands rule....

    K H J R A 12 Replies Last reply
    0
    • S Southmountain

      I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

      diligent hands rule....

      K Offline
      K Offline
      Kenneth Haugland
      wrote on last edited by
      #2

      MFC to WPF or what? I did some conversions from C++ to C# for a complex math problem. That was pretty straight-forward since the finished C# code was not that different from C++ once you got into it.

      S 1 Reply Last reply
      0
      • S Southmountain

        I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

        diligent hands rule....

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        It varies widely depending on the project. For user interface stuff (at least assuming windows) if you were using like, MFC before, you're basically going to need to rewrite that part using the original code as a reference. For algorithmic stuff it depends. If you're doing pointer ops all over the place that will be difficult to port as you need to change it to indexing into arrays (typically). Otherwise, if you're using things like vector and map they have direct corollaries in C# so that kind of thing is easier. Just remember structs are on the stack and classes are on the heap in C#. That has a lot of different ramifications, such as changing how they are passed to functions (byval instead of byref). Be careful when porting that kind of thing from C++ which makes little distinction between classes and structs.

        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

        Richard Andrew x64R 1 Reply Last reply
        0
        • S Southmountain

          I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

          diligent hands rule....

          J Offline
          J Offline
          Jo_vb net
          wrote on last edited by
          #4

          Don't fear the reaper... ... just start re-writing the code. For smaller parts you can use https://www.codeconvert.ai/c++-to-csharp-converter[^] But you have to revise this converted code anyway.

          S 1 Reply Last reply
          0
          • H honey the codewitch

            It varies widely depending on the project. For user interface stuff (at least assuming windows) if you were using like, MFC before, you're basically going to need to rewrite that part using the original code as a reference. For algorithmic stuff it depends. If you're doing pointer ops all over the place that will be difficult to port as you need to change it to indexing into arrays (typically). Otherwise, if you're using things like vector and map they have direct corollaries in C# so that kind of thing is easier. Just remember structs are on the stack and classes are on the heap in C#. That has a lot of different ramifications, such as changing how they are passed to functions (byval instead of byref). Be careful when porting that kind of thing from C++ which makes little distinction between classes and structs.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            Out of curiosity, is an enum a class or struct?

            The difficult we do right away... ...the impossible takes slightly longer.

            H 1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              Out of curiosity, is an enum a class or struct?

              The difficult we do right away... ...the impossible takes slightly longer.

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #6

              In C and C++ it doesn't really matter. In fact it's compiled into constant nothings basically (removed). In C# it's a ValueType which makes it closer to a struct than a class in terms of how it behaves - stack vs heap, etc.

              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

              S 1 Reply Last reply
              0
              • S Southmountain

                I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

                diligent hands rule....

                R Offline
                R Offline
                RedDk
                wrote on last edited by
                #7

                It's easy. Start a new project in the target language of your choice. Copy the bare minimum from the source language, paste it in the new language target husk, and attempt to compile. You'll get tons of errors and warnings. Pick through them and eliminate them one-by-one. Obviously there's a lot of personal experience in "attempting" to do anything using a compiler and a linker. Done this, have I. Learned much have I.

                Richard Andrew x64R O J 3 Replies Last reply
                0
                • R RedDk

                  It's easy. Start a new project in the target language of your choice. Copy the bare minimum from the source language, paste it in the new language target husk, and attempt to compile. You'll get tons of errors and warnings. Pick through them and eliminate them one-by-one. Obviously there's a lot of personal experience in "attempting" to do anything using a compiler and a linker. Done this, have I. Learned much have I.

                  Richard Andrew x64R Offline
                  Richard Andrew x64R Offline
                  Richard Andrew x64
                  wrote on last edited by
                  #8

                  RedDk wrote:

                  You'll get tons of errors and warnings. Pick through them an eliminate them one-by-one.

                  It's hard to tell if that's sage advice or sarcasm.

                  The difficult we do right away... ...the impossible takes slightly longer.

                  P 1 Reply Last reply
                  0
                  • Richard Andrew x64R Richard Andrew x64

                    RedDk wrote:

                    You'll get tons of errors and warnings. Pick through them an eliminate them one-by-one.

                    It's hard to tell if that's sage advice or sarcasm.

                    The difficult we do right away... ...the impossible takes slightly longer.

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    It sounds like the advice to start with a block of stone and remove the parts which don't look like an elephant.

                    1 Reply Last reply
                    0
                    • K Kenneth Haugland

                      MFC to WPF or what? I did some conversions from C++ to C# for a complex math problem. That was pretty straight-forward since the finished C# code was not that different from C++ once you got into it.

                      S Offline
                      S Offline
                      Southmountain
                      wrote on last edited by
                      #10

                      WinForm in my mind.

                      diligent hands rule....

                      1 Reply Last reply
                      0
                      • H honey the codewitch

                        In C and C++ it doesn't really matter. In fact it's compiled into constant nothings basically (removed). In C# it's a ValueType which makes it closer to a struct than a class in terms of how it behaves - stack vs heap, etc.

                        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                        S Offline
                        S Offline
                        Southmountain
                        wrote on last edited by
                        #11

                        :thumbsup:

                        diligent hands rule....

                        1 Reply Last reply
                        0
                        • J Jo_vb net

                          Don't fear the reaper... ... just start re-writing the code. For smaller parts you can use https://www.codeconvert.ai/c++-to-csharp-converter[^] But you have to revise this converted code anyway.

                          S Offline
                          S Offline
                          Southmountain
                          wrote on last edited by
                          #12

                          :rose::rose::rose:

                          diligent hands rule....

                          1 Reply Last reply
                          0
                          • R RedDk

                            It's easy. Start a new project in the target language of your choice. Copy the bare minimum from the source language, paste it in the new language target husk, and attempt to compile. You'll get tons of errors and warnings. Pick through them and eliminate them one-by-one. Obviously there's a lot of personal experience in "attempting" to do anything using a compiler and a linker. Done this, have I. Learned much have I.

                            O Offline
                            O Offline
                            obermd
                            wrote on last edited by
                            #13

                            This is exactly how I converted about 10,000 lines of VB6 code to VB 2005. The biggest changes were file handling and error reporting. To this day I'll occasionally use On Error Resume Next in short Subs and Functions when it's appropriate. Otherwise I use Try/Catch/Finally.

                            R N 2 Replies Last reply
                            0
                            • O obermd

                              This is exactly how I converted about 10,000 lines of VB6 code to VB 2005. The biggest changes were file handling and error reporting. To this day I'll occasionally use On Error Resume Next in short Subs and Functions when it's appropriate. Otherwise I use Try/Catch/Finally.

                              R Offline
                              R Offline
                              RedDk
                              wrote on last edited by
                              #14

                              That's it exactly. Initially posting line-numbered QBASIC code into a C++ project ... I was surprised how little squawking the VS interface returned. I like that "On Error Resume" trick. Next time ...

                              1 Reply Last reply
                              0
                              • O obermd

                                This is exactly how I converted about 10,000 lines of VB6 code to VB 2005. The biggest changes were file handling and error reporting. To this day I'll occasionally use On Error Resume Next in short Subs and Functions when it's appropriate. Otherwise I use Try/Catch/Finally.

                                N Offline
                                N Offline
                                Nelek
                                wrote on last edited by
                                #15

                                obermd wrote:

                                To this day I'll occasionally use On Error Resume Next

                                as long as you put something in between... :rolleyes: ;P :laugh:

                                M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                O 1 Reply Last reply
                                0
                                • S Southmountain

                                  I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

                                  diligent hands rule....

                                  A Offline
                                  A Offline
                                  Amarnath S
                                  wrote on last edited by
                                  #16

                                  Outsource to someone here (me?).

                                  1 Reply Last reply
                                  0
                                  • S Southmountain

                                    I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

                                    diligent hands rule....

                                    B Offline
                                    B Offline
                                    Bruno van Dooren
                                    wrote on last edited by
                                    #17

                                    Does it 'need' to be C#? Or can you use C++/CLI? Because the latter would be much simpler, in the sense that you can keep your algorithms and the back end stuff in C++, and do the user interface in C++/CLI. Is your user interface in MFC, or WTL or something else? The user interface would have to be re-built from scratch

                                    1 Reply Last reply
                                    0
                                    • S Southmountain

                                      I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

                                      diligent hands rule....

                                      G Offline
                                      G Offline
                                      Gary R Wheeler
                                      wrote on last edited by
                                      #18

                                      You're going to have to rewrite UI code regardless. The one advantage going to WinForms would be correspondence in the UI. WinForms is something of a wrapper around Windows GDI controls for C#, in the same sense that MFC is a wrapper for C++.

                                      Software Zen: delete this;

                                      1 Reply Last reply
                                      0
                                      • S Southmountain

                                        I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

                                        diligent hands rule....

                                        M Offline
                                        M Offline
                                        MSBassSinger
                                        wrote on last edited by
                                        #19

                                        In my experience of rewriting from one language into C#, there are a few principles I applied that helped me. 1 - Understand the requirements, architecture, and intent of the original code (which may have to be determined with only the original code at hand). 2 - Understand WHAT the original code is doing. 3 - In the new language (e.g. C#), determine how it best does what the original code did. Just translating code from original to new is a trap. 4 - What does the new language offer (including third party components if you want) that would be useful, that was not used for the original app with the original language? 5 - What new language architecture gives you the lowest total SDLC cost with the best acceptable performance, scalability, and support? Apply these principles and you will avoid a myriad of booby-traps and sloughs of despond.

                                        1 Reply Last reply
                                        0
                                        • S Southmountain

                                          I have a legacy software to draw very sophisticated charts. but I only need a small piece of these charts. I want to re-write the code charting this small piece of charts. How hard it is to do this? any experience to share?

                                          diligent hands rule....

                                          B Offline
                                          B Offline
                                          Behzad Sedighzadeh
                                          wrote on last edited by
                                          #20

                                          Isn't it better to use an existing product? Have you looked at ScottPlot ?

                                          Behzad

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups