BT

CXXI Brings Advanced C++ Interop To Mono

by Roopesh Shenoy on Dec 20, 2011 |

CXXI, a new C++ Interop framework, allows easy interoperability between C# and C++ in Mono. Developers can, from C#, easily instantiate C++ objects, invoke C++ methods, subclass C++ classes, and more.

Normally, for any managed code to call native libraries, you need to either use P/Invoke, Com Interop or an interceptor, each options having a lot of boiler plate code. Some things like subclassing are not even possible. With CXXI, this is made much simpler.

How does it work? The CXXI toolchain creates a CXXI Binding and produces a .NET library. The library contains a C# class, which acts as a wrapper to the underlying C++ class in the native library. Miguel de Icaza explains in detail about how this is made possible.

How does this compare with the alternatives? .NET already has C++/CLI which allows managed C++ code to interop with C#. However this is not the same as using existing native C++ libraries directly in C#, which still requires one of the above three methods (besides it is not supported by mono). Then there is SWIG which generates a wrapper/interface around C++ classes to expose it to various higher level programming languages including C#. However, CXXI is different – Miguel explains:

This one supports not only creating a binding and consuming a C++ API, but creating new subclasses of the existing C++ class and passing those instances back to C++ for consumption.   This is done by patching the vtables when the user overrides methods.

The library is still new and not fully stable, especially around the tooling. You can see refer to the tests on the github project to see what scenarios are supported. 

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT