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. General Programming
  3. C#
  4. Converting from C to C#

Converting from C to C#

Scheduled Pinned Locked Moved C#
csharpasp-nethardwarehelpquestion
14 Posts 7 Posters 0 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.
  • A Offline
    A Offline
    AseelHadlaq
    wrote on last edited by
    #1

    hi, I'm developing a web application for my graduation project and it's my first time to use asp.net and C# , the problem is I have an essential part of a code written in C and I need it to be converted or embedded in my project. I found a couple of converters but they all say that they are not reliable, another problem is that the C code has LOTS of pointers and I'm afraid that I'll mess things up.. is there a reliable converter or a reliable way ? or anyone who can compare both and make sure that they are right ? Thanks

    F J D D B 5 Replies Last reply
    0
    • A AseelHadlaq

      hi, I'm developing a web application for my graduation project and it's my first time to use asp.net and C# , the problem is I have an essential part of a code written in C and I need it to be converted or embedded in my project. I found a couple of converters but they all say that they are not reliable, another problem is that the C code has LOTS of pointers and I'm afraid that I'll mess things up.. is there a reliable converter or a reliable way ? or anyone who can compare both and make sure that they are right ? Thanks

      F Offline
      F Offline
      fjdiewornncalwe
      wrote on last edited by
      #2

      To ensure that your C# works properly, you'll probably need to translate the code manually. The pointers issue isn't really that big a deal, but will require a great deal of diligence and accuracy in your translation. I've never trusted auto-converters between languages. I find they tend to introduce some pretty crazy and hard to find bugs.

      I wasn't, now I am, then I won't be anymore.

      1 Reply Last reply
      0
      • A AseelHadlaq

        hi, I'm developing a web application for my graduation project and it's my first time to use asp.net and C# , the problem is I have an essential part of a code written in C and I need it to be converted or embedded in my project. I found a couple of converters but they all say that they are not reliable, another problem is that the C code has LOTS of pointers and I'm afraid that I'll mess things up.. is there a reliable converter or a reliable way ? or anyone who can compare both and make sure that they are right ? Thanks

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        AseelHadlaq wrote:

        embedded in my project.

        You can use 'interop' to call external code in C#.

        A 1 Reply Last reply
        0
        • J jschell

          AseelHadlaq wrote:

          embedded in my project.

          You can use 'interop' to call external code in C#.

          A Offline
          A Offline
          AseelHadlaq
          wrote on last edited by
          #4

          How can I use it ? I'm new to C# and can I send and retrieve variables ?

          J 1 Reply Last reply
          0
          • A AseelHadlaq

            hi, I'm developing a web application for my graduation project and it's my first time to use asp.net and C# , the problem is I have an essential part of a code written in C and I need it to be converted or embedded in my project. I found a couple of converters but they all say that they are not reliable, another problem is that the C code has LOTS of pointers and I'm afraid that I'll mess things up.. is there a reliable converter or a reliable way ? or anyone who can compare both and make sure that they are right ? Thanks

            D Offline
            D Offline
            Dave Doknjas
            wrote on last edited by
            #5

            All converters will offer a free trial/demo version. Try it out and compare the results with some common sense. Even if the conversion is less than 100%, it may give you something you would have missed. The main challenge of converting C/C++ code to other languages, especially with pointers, is that a C/C++ declaration alone does not tell you how something is used. This is in contrast to C# where the declaration does tell you all you need to know for a translation to other languages.

            David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter

            A 1 Reply Last reply
            0
            • A AseelHadlaq

              hi, I'm developing a web application for my graduation project and it's my first time to use asp.net and C# , the problem is I have an essential part of a code written in C and I need it to be converted or embedded in my project. I found a couple of converters but they all say that they are not reliable, another problem is that the C code has LOTS of pointers and I'm afraid that I'll mess things up.. is there a reliable converter or a reliable way ? or anyone who can compare both and make sure that they are right ? Thanks

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #6

              Conversion isn't usually that difficult once you get underway. Pointers are fairly straight forward. In C# all classes are 'reference' types, meaning that a pointer (actually a copy of the pointer) is passed, not the value - so these are often directly interchangeable with C code when translating. structs are 'value' types so the value is copied rather than the reference. This can be changed by using out or ref to retrieve or pass a pointer. Only if there is pointer arithmetic involved or pointers to pointers do matters get more complicated. Much of the time, by carefull examination of the code and refactoring it into smaller sections, you will find you can get rid of the pointers altogether :) Good luck, and if you get stuck with any individual parts feel free to post.

              Dave
              Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

              A 1 Reply Last reply
              0
              • A AseelHadlaq

                How can I use it ? I'm new to C# and can I send and retrieve variables ?

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                AseelHadlaq wrote:

                How can I use it ?

                By learning how to use it of course. You can google for information on it.

                A 1 Reply Last reply
                0
                • A AseelHadlaq

                  hi, I'm developing a web application for my graduation project and it's my first time to use asp.net and C# , the problem is I have an essential part of a code written in C and I need it to be converted or embedded in my project. I found a couple of converters but they all say that they are not reliable, another problem is that the C code has LOTS of pointers and I'm afraid that I'll mess things up.. is there a reliable converter or a reliable way ? or anyone who can compare both and make sure that they are right ? Thanks

                  B Offline
                  B Offline
                  Bernhard Hiller
                  wrote on last edited by
                  #8

                  Use DllImport to get your C functions into your C# project. If you actually wrote C++ objects, you can create a wrapper for them in managed C++, and the managed C++ dll can be called from you C# code.

                  A 1 Reply Last reply
                  0
                  • J jschell

                    AseelHadlaq wrote:

                    How can I use it ?

                    By learning how to use it of course. You can google for information on it.

                    A Offline
                    A Offline
                    AseelHadlaq
                    wrote on last edited by
                    #9

                    Yea I noticed it was a stupid question, I read about it and I found it a bit confusing and I didnt get the concept of it, can you give me a link where it is explained in a clear way ? and can I send and retrieve variables through interop ? thank you

                    J 1 Reply Last reply
                    0
                    • D Dave Doknjas

                      All converters will offer a free trial/demo version. Try it out and compare the results with some common sense. Even if the conversion is less than 100%, it may give you something you would have missed. The main challenge of converting C/C++ code to other languages, especially with pointers, is that a C/C++ declaration alone does not tell you how something is used. This is in contrast to C# where the declaration does tell you all you need to know for a translation to other languages.

                      David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter

                      A Offline
                      A Offline
                      AseelHadlaq
                      wrote on last edited by
                      #10

                      thnx I found it earlier but it's not free and I dont know about its reliability , I guess I have to try it

                      1 Reply Last reply
                      0
                      • D DaveyM69

                        Conversion isn't usually that difficult once you get underway. Pointers are fairly straight forward. In C# all classes are 'reference' types, meaning that a pointer (actually a copy of the pointer) is passed, not the value - so these are often directly interchangeable with C code when translating. structs are 'value' types so the value is copied rather than the reference. This can be changed by using out or ref to retrieve or pass a pointer. Only if there is pointer arithmetic involved or pointers to pointers do matters get more complicated. Much of the time, by carefull examination of the code and refactoring it into smaller sections, you will find you can get rid of the pointers altogether :) Good luck, and if you get stuck with any individual parts feel free to post.

                        Dave
                        Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                        A Offline
                        A Offline
                        AseelHadlaq
                        wrote on last edited by
                        #11

                        That is scary a bit but I have to try ,, thank you

                        1 Reply Last reply
                        0
                        • B Bernhard Hiller

                          Use DllImport to get your C functions into your C# project. If you actually wrote C++ objects, you can create a wrapper for them in managed C++, and the managed C++ dll can be called from you C# code.

                          A Offline
                          A Offline
                          AseelHadlaq
                          wrote on last edited by
                          #12

                          My questions will sound stupid I know :^) But can I send and retrieve variables ? without changing my C code ? can you explain more about it plzz

                          P 1 Reply Last reply
                          0
                          • A AseelHadlaq

                            My questions will sound stupid I know :^) But can I send and retrieve variables ? without changing my C code ? can you explain more about it plzz

                            P Offline
                            P Offline
                            Pete OHanlon
                            wrote on last edited by
                            #13

                            You might want to start here[^].

                            AseelHadlaq wrote:

                            But can I send and retrieve variables ? without changing my C code ?

                            That really depends on how your C is written. In 10 years of working with .NET, I've never found a case where I couldn't P/Invoke because of variables, but that's not to say that some weird and wacky pointer manipulation couldn't cause an issue (although I do recall dealing with a particularly tricky void** parameter that caused some real headaches).

                            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                            1 Reply Last reply
                            0
                            • A AseelHadlaq

                              Yea I noticed it was a stupid question, I read about it and I found it a bit confusing and I didnt get the concept of it, can you give me a link where it is explained in a clear way ? and can I send and retrieve variables through interop ? thank you

                              J Offline
                              J Offline
                              jschell
                              wrote on last edited by
                              #14

                              I can't figure out for you if it is clear. You can use the following in google to search for links that would most likely be of help to you.

                              "C#" interop example -com

                              This is dependent on you knowing a non-trivial amount of C and having some non-trivial experience in writing code. If you have neither then this is going to be a difficult task. Especially since if you mess it up the most likely outcome will be a system exception and the C# VM will exit will little information.

                              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