Common codebase for C++ and C#?
-
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 astring EditBox.Text
in C# (and not aSystem.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
-
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 astring EditBox.Text
in C# (and not aSystem.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
Hello, the common codebase of
C++
andC#
isC
language. So, code the oldie-goldie and forget the fancy-sissies-object-oriented-paradigms. :-DIf 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] -
Hello, the common codebase of
C++
andC#
isC
language. So, code the oldie-goldie and forget the fancy-sissies-object-oriented-paradigms. :-DIf 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]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
-
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
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] -
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]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
-
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
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]