[Mono-list] how to "register" a c++ class to c#?

Christopher David Howie me at chrishowie.com
Sun Jun 6 23:01:41 EDT 2010


On 06/06/2010 09:46 PM, 冶晶邓 wrote:
> hi,dear all:
>   i'm an absolutely newbie to mono. when i'm working with lua and
> python, i often write many c++ classes to implement some core logic,
> then "register" them to script. in lua, its metatable can be used for
> simulating the class mechanism. in python, there's a builtin type system
> and corressponding c api for this. then what should i do if i want this
> to work in mono c#? where can i find some samples or tutorials? thanks
> very much!

Since pretty much every C++ compiler uses a different name-mangling
algorithm, there is no simple way to use C++ classes from C#.
Basically, you will need to write a C++ library that wraps all of the
class' methods in C-exported functions.  Or, you might try using SWIG,
which is able to generate such libraries automatically for the most part
<http://www.swig.org/>.

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers

If you correspond with me on a regular basis, please read this document:
http://www.chrishowie.com/email-preferences/

PGP fingerprint: 2B7A B280 8B12 21CC 260A DF65 6FCE 505A CF83 38F5

------------------------------------------------------------------------
                    IMPORTANT INFORMATION/DISCLAIMER

This document should be read only by those persons to whom it is
addressed.  If you have received this message it was obviously addressed
to you and therefore you can read it.

Additionally, by sending an email to ANY of my addresses you are
agreeing that I am, by definition, "the intended recipient," and that I
may do whatever I wish with the contents of any message you send me,
unless a pre-existing agreement prohibits me from so doing.

This overrides any disclaimer or statement of confidentiality that may
be included on your message.


More information about the Mono-list mailing list