BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

CXXI Brings Advanced C++ Interop To Mono

| by Roopesh Shenoy Follow 0 Followers on Dec 20, 2011. Estimated reading time: 1 minute |

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. 

Rate this Article

Adoption Stage
Style

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

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT