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. Common codebase for C++ and C#?

Common codebase for C++ and C#?

Scheduled Pinned Locked Moved C#
csharpc++questioncomfunctional
6 Posts 2 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.
  • B Offline
    B Offline
    Bartosz Bien
    wrote on last edited by
    #1

    Hello All, I am about to create a custom windowing system for both native C++ and fully managed .NET applications (plus perhaps non-Windows platforms as well). Although some aspects of the code, such as rendering routines, are environment-dependent and must be rewritten, there are certain immutable elements, such as behavior of common controls (e.g. reaction of a button or an edit control to user's input, or logical events that these controls can fire, such as "Clicked" in a button, or "TextChanged" in an edit control). Therefore, I would like to code these reusable parts only once. I know one solution would be to implement them in C++ and then wrap them up in a C++/CLI managed assembly. However, the managed interface must be written in order to reflect all events, methods and properties from the C++ implementation to .NET. That forces me to add each new event or property in two places: one in the C++ part, and another one in the C++/CLI interface, which is something I don't want. Considering I have my own RTTI implementation in my native C++ library, would it be feasible to automatically generate required .NET wrappers? Note that I would like to use the library with comparable ease in both C++ and C#. If I got a std::string EditBox::Text in C++, there must be a string EditBox.Text in C# (and not a System.Runtime.InteropServices.Marshal.GetMyDamnedString(IntPtr(EditBox.Tag).ToPointer()), nor any similarly beautiful construct). That's quite an architectural question, but I didn't want to crosspost - that's why it ended up here. :)

    Best regards, BB http://bartoszbien.com

    CPalliniC 1 Reply Last reply
    0
    • B Bartosz Bien

      Hello All, I am about to create a custom windowing system for both native C++ and fully managed .NET applications (plus perhaps non-Windows platforms as well). Although some aspects of the code, such as rendering routines, are environment-dependent and must be rewritten, there are certain immutable elements, such as behavior of common controls (e.g. reaction of a button or an edit control to user's input, or logical events that these controls can fire, such as "Clicked" in a button, or "TextChanged" in an edit control). Therefore, I would like to code these reusable parts only once. I know one solution would be to implement them in C++ and then wrap them up in a C++/CLI managed assembly. However, the managed interface must be written in order to reflect all events, methods and properties from the C++ implementation to .NET. That forces me to add each new event or property in two places: one in the C++ part, and another one in the C++/CLI interface, which is something I don't want. Considering I have my own RTTI implementation in my native C++ library, would it be feasible to automatically generate required .NET wrappers? Note that I would like to use the library with comparable ease in both C++ and C#. If I got a std::string EditBox::Text in C++, there must be a string EditBox.Text in C# (and not a System.Runtime.InteropServices.Marshal.GetMyDamnedString(IntPtr(EditBox.Tag).ToPointer()), nor any similarly beautiful construct). That's quite an architectural question, but I didn't want to crosspost - that's why it ended up here. :)

      Best regards, BB http://bartoszbien.com

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Hello, the common codebase of C++ and C# is C language. So, code the oldie-goldie and forget the fancy-sissies-object-oriented-paradigms. :-D

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      B 1 Reply Last reply
      0
      • CPalliniC CPallini

        Hello, the common codebase of C++ and C# is C language. So, code the oldie-goldie and forget the fancy-sissies-object-oriented-paradigms. :-D

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        B Offline
        B Offline
        Bartosz Bien
        wrote on last edited by
        #3

        Hi, thanks for your voice. :) My question was rather on how to automatically generate .NET wrappers for an existing native C++ code (or code the C++ core logic in a way that it can be easily reused with .NET, without manual reflection of each change). Perhaps I might use C++/CLI-based tool to convert my own existing RTTI to the .NET Reflection, and compile the generated .NET classes into a new managed assembly? What do you people think?

        Best regards, BB http://bartoszbien.com

        CPalliniC 1 Reply Last reply
        0
        • B Bartosz Bien

          Hi, thanks for your voice. :) My question was rather on how to automatically generate .NET wrappers for an existing native C++ code (or code the C++ core logic in a way that it can be easily reused with .NET, without manual reflection of each change). Perhaps I might use C++/CLI-based tool to convert my own existing RTTI to the .NET Reflection, and compile the generated .NET classes into a new managed assembly? What do you people think?

          Best regards, BB http://bartoszbien.com

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          My question is: Why should you do that? Cannot you live happy with a fully managed solution? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          B 1 Reply Last reply
          0
          • CPalliniC CPallini

            My question is: Why should you do that? Cannot you live happy with a fully managed solution? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            B Offline
            B Offline
            Bartosz Bien
            wrote on last edited by
            #5

            Not in this case. Although most of my projects are fully managed, I would also like to use this particular library for certain time-critical applications written in native C++, whose performance might suffer from .NET boxing.

            Best regards, BB http://bartoszbien.com

            CPalliniC 1 Reply Last reply
            0
            • B Bartosz Bien

              Not in this case. Although most of my projects are fully managed, I would also like to use this particular library for certain time-critical applications written in native C++, whose performance might suffer from .NET boxing.

              Best regards, BB http://bartoszbien.com

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Performance and interoperability are often on opposite sides, hence I suppose your task will be hard: Good luck. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              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