InfoQ Homepage News CXXI Brings Advanced C++ Interop To Mono

CXXI Brings Advanced C++ Interop To Mono


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. 

We need your feedback

How might we improve InfoQ for you

Thank you for being an InfoQ reader.

Each year, we seek feedback from our readers to help us improve InfoQ. Would you mind spending 2 minutes to share your feedback in our short survey? Your feedback will directly help us continually evolve how we support you.

Take the Survey

Rate this Article


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.

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

Community comments

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

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


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.