xInterop C++ .NET Bridge 4.0 is available now

xInterop C++ .NET Bridge 4.0 is available now

We are pleased to announce the release of xInterop C++ .NET Bridge 4.0, a Code Generator for Creating Two-Ways Bridges between C++ Native World and .NET World. Visual Studio 2017 is now supported.

xInterop C++ .NET Bridge 4.0 is available to the public for evaluation to anyone who is interested in using xInterop C++ .NET Bridge to

  • Generating C# .NET Wrapper/Bridge for native C++ DLLs so that you can call native C++ DLL from .NET.
  • Generating C++ Native DLL Bridge for .NET assemblies so that you can call .NET assemblies from native C++.

You may want to download it from the link below and start evaluating it and experiencing how powerful xInterop C++ .NET Bridge is. Once you start using xInterop C++ .NET Bridge, you will find that it is so easy to bridge between the C++ native world to C# .NET managed world by using xInterop C++ .NET Bridge. You will be able to evaluate the software for free for 30 days.


To anyone who is interested in purchasing xInterop C++ .NET Bridge, the licensing model and pricing document is available to you upon request. If you have any questions regarding xInterop C++ .NET Bridge software, licensing or pricing, please feel free to contact us using the Contact Us Page.

Ultimate Guide to Call .NET Assembly from Native C/C++ Using Unmanaged Exports

I have been mentioning Unmanaged Exports in a few of my articles, which is a very basic technique allowing us to export managed methods from .NET world to native C and C++. The resulting assembly is a mixed mode DLL containing native-like export entry. You can use Unmanaged Exports Nuget Package to create such DLLs, As long as you can write the native C/C++ declaration of the functions correctly, you should be able to create export function with simple and primitive types. But I went further to write an article named Unmanaged Exports, An Ultimate Guide to Call .NET Assembly from Native C/C++ Using Unmanaged Exports, once you learn those advanced tips, you should be able to even export classes, structs.

xInterop .NET Bridge: Calling .NET assembly by using reflection from native C++

Native C++ application calls into C# .NET classes, methods using .NET reflection

With xInterop .NET Bridge technology, it is quite easy to access the C# .NET classes, properties, instance methods and static methods from native C++ application using .NET reflection.

The C++ bridge DLL generated by xInterop .NET bridge is strong-typed, which means all the C++ bridge class is mapped to a specific .NET class. By design, the methods of any class created in the C++ are the public methods of the .NET class. If you simply want to create a native C++ DLL wrapping around an existing .NET assembly at compile-time statically, you have nothing to worry, there is no need to use C# .NET reflection at all, the C++ header file created by xInterop .NET Bridge will have everything defined including all strong-typed classes for you to call into the original C# .NET classes, methods and properties.


What if I want to call the protected method or private method like I would in the .NET managed world using reflection?

What if I want to call a method from another assembly which I have not created a strong-typed C++ DLL for?

What if I want to call a method whose name is only known run-time?

What if I want to call a method from a .NET assembly loaded dynamically?

Thanks to xInterop .NET Bridge and .NET reflection technology, we will be able to achieve all of the above by simply creating a C++ bridge DLL for a few reflection-related classes in System.Reflection namespace.

With xInterop .NET Bridge, you will be able to load any .NET assembly and call into any class and any method from the .NET assembly.  The way we call the .NET methods from C++ will be same as the way calling from .NET except the difference that we will be using the C++ bridge classes of the reflection-related classes, most notable as shown below,

  • Type, type class is used to retrieve whatever class we would like to call via .NET reflection
  • MethodInfo, MethodInfo is used to retrieve the information of specific method which is then called by using Invoke method via .NET reflection.

Both classes shall have matching C++ bridge class created so that we will be able to call them from native C++ using .NET reflection through the C++ bridge DLL and .NET bridge assembly.

For a simple demonstration, this is all we need.

The following C# code is the little application if we would call method using .NET reflection.

Immediately after the C# code, I would like to show you how neat the corresponding C++ code is to call the same method using C++ bridge classes.

Let’s start xInterop .NET Bridge and creates the native C++ Bridge DLL step by step.

Step 1: Create a C# library project which contains the reference to the required .NET classes

xInterop .NET Bridge currently requires a .NET library assembly as input to generate a corresponding C++ native bridge DLL, we think it is the natural way and the best way to create a C/C++ bridge native DLL.


Step 2: Create xInterop .NET Bridge project and build C++ bridge DLL and .NET bridge assembly.

After running xInterop .NET Bridge, we will create a native C++ bridge DLL and a .NET bridge assembly for the original TypeDemo .NET assembly, and also a testing application so that we can instantly verify if everything works fine.

What we are interested in seeing in the C++ header file is NType class and MethodInfo class.


xInterop .NET Bridge shall create both MethodInfo and MethodBase since we set “Depth of inheritance” to 1, which means including the direct base class of any class whose reference is  found in the original C# .NET assembly.

Step 3: Running the testing application.

Opening the newly created testing application named “TestApp”, it should look like the following, everything has been taken care of, such as loading the .NET bridge assembly and the original .NET assembly automatically.

This is the final resulting console application looks like and its output.

A very useful C++ debugging tip, if you plan to debug a native C++ application release version, you will need to turn off the optimization of the console application, otherwise, you will not be able to watch or monitor most of the variables because the code has been optimized and its code is not the same as the one you are reading in the Visual Studio IDE C++ code editor.