How in C++ to call the function from a loadable C# DLL?

Try in C++ to load a DLL library written in C#
Main program:
HMyDLL HINSTANCE = LoadLibrary(L"ClassLibrary1.dll");
if (NULL == hMyDLL) {
 std::cout << "LoadLibrary failed\n";
 return -1;

typedef int (WINAPI * function) ();
function f = (function)GetProcAddress(hMyDLL, "Class1.test");
if (NULL == f) {
 std::cout << ":(\n";

Code of a DLL file:
namespace ClassLibrary1 {
 public class Class1 {
 public static int test() {
 return 5;

How to access a method of a class?
June 10th 19 at 15:46
2 answers
June 10th 19 at 15:48
Out of the box it seems as if nothing but COM
June 10th 19 at 15:50
Microsoft MSDN has an article about this, .
In short, I propose to work through COM.

Even before I met like - .
The point is that in C++ you can write managed code, and there you can add a full exported functions, according to the author. Advise you to pay attention.

Find more questions by tags C++C#DLL