Using legacy C/C++ code with C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bit Byte

    Using legacy C/C++ code with C#

    I have legacy code I wrote in C (and some C++). What is the recommended
    way to use my legacy code from C# ?
  • Peter Duniho

    #2
    Re: Using legacy C/C++ code with C#

    On Thu, 12 Jun 2008 17:14:24 -0700, Bit Byte <root@yourbox.c omwrote:
    I have legacy code I wrote in C (and some C++). What is the recommended
    way to use my legacy code from C# ?
    It really depends on the code. IMHO, the best way is to just port it and
    abandon the original. :)

    But sometimes you'd prefer to stick with the original (for example, it's
    still used elsewhere and you only want to maintain one code base).

    In that case, your two main options are to compile it to a DLL and use
    p/invoke, or wrap the code in managed C++ and produce a managed DLL
    directly usable from C#. The latter is basically the same as the former,
    but more explicit. In other words, it could be more work, but you have
    more control over the resulting interface too.

    Pete

    Comment

    • Kenneth Porter

      #3
      Re: Using legacy C/C++ code with C#

      "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in
      news:op.ucnv30o r8jd0ej@petes-computer.local:
      In that case, your two main options are to compile it to a DLL and use
      p/invoke, or wrap the code in managed C++ and produce a managed DLL
      directly usable from C#. The latter is basically the same as the
      former, but more explicit. In other words, it could be more work,
      but you have more control over the resulting interface too.
      My C++ code needs to remain as portable code for other platforms, so I took
      the latter route, wrapping it in C++/CLI (the name adopted for managed
      C++). Check out the sister newsgroup
      "microsoft.publ ic.dotnet.langu ages.vc" for help with that language.

      Comment

      Working...