Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling C# from native C++, without /clr or COM?

This question has been asked before, but I never found a truly satisfying solution -

I have a class library written in C#, and I want to call it from a legacy native C++ application. The host application is truly native, compiled on Windows & Linux, its a console application. So how can I make it call the C# class library, assuming using Microsoft .NET on Windows, and Mono on Linux.

I have looked at SWIG and wrapping with COM interfaces on Windows, but is there a standard recognized solution that works cross platform? i.e. that is generic, works with both Microsoft .NET and Mono, a write once use everywhere implementation.

Solutions should expose the full class interfaces from the C# domain to the C++ domain.

Similar questions focus only on the Windows solutions, for example -

Call C# methods from C++ without using COM

like image 511
titanae Avatar asked Aug 22 '09 00:08

titanae


People also ask

What is a calling function in C?

Function Calling: A function call is an important part of the C programming language. It is called inside a program whenever it is required to call a function. It is only called by its name in the main() function of a program. We can pass the parameters to a function calling in the main() function.

What is call by value in C?

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. By default, C programming uses call by value to pass arguments.

What is call reference?

Whenever calling a function, rather than passing the variables' values, we pass its address instead (location of variables) to the function. Thus, it has its name as Call by Reference.


1 Answers

If you want to do this cross platform, I would recommend going with a 100% Mono approach.

Mono has a clean Embedding API which works on Linux and Windows.

like image 53
Reed Copsey Avatar answered Sep 19 '22 17:09

Reed Copsey