Common codebase for native C++ and .NET? RRS feed

  • Question

  • 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).

    Best regards,

    Wednesday, January 7, 2009 11:29 AM


  • RTTI is no solution, it not nearly rich enough.  I don't see a good way to do this, the impedance mismatch is too great.  That starts at the basics, not taking advantage of the garbage collector and delegates is not going to make your class library competitive with Windows Forms.
    Hans Passant.
    Wednesday, January 7, 2009 12:29 PM