Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call a .NET assembly from C/C++?

Tags:

c++

c#

.net

Suppose I am writing an application in C++ and C#. I want to write the low level parts in C++ and write the high level logic in C#. How can I load a .NET assembly from my C++ program and start calling methods and accessing the properties of my C# classes?

like image 995
cwick Avatar asked Sep 19 '08 22:09

cwick


People also ask

How can I call C# from C++?

Create a Managed C++ DLL and reference it in your C# project. This exports your function ShowMessageBox in an unmanaged format. Inside the exported function, call the Managed C++ method which calls your C# methods. Create your unmanaged C or C++ DLL or EXE and call the exposed C++ method in your managed code.

What is assembly reference in C#?

Reference assemblies are usually distributed with the Software Development Kit (SDK) of a particular platform or library. Using a reference assembly enables developers to build programs that target a specific library version without having the full implementation assembly for that version.

What is assembly in C# with example?

An assembly is a file that is automatically generated by the compiler upon successful compilation of every . NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated.

How assemblies are implemented and used in the .NET framework?

NET Framework, you can build an assembly from one or more source code files. In . NET Framework, assemblies can contain one or more modules. This allows larger projects to be planned so that several developers can work on separate source code files or modules, which are combined to create a single assembly.


1 Answers

You should really look into C++/CLI. It makes tasks like this nearly trivial.

Otherwise, you'll have to generate COM wrappers around the C# code and have your C++ app call the COM wrappers.

like image 50
Kevin Avatar answered Sep 22 '22 02:09

Kevin