Error While calling C# Method in C++ Console application

0

I have prepared Class Library Project(.DLL) in C#.net which use some 3rd party references.I have added those 3rd party references projects in my C# solution. Now when I tried to call this DLL method in C++ console application using Load library procedure. I am able to get C# method reference in GetProcAddress. But when Code in the C# Method tried to call 3rd party reference then it breaks with below exception Unhandled exception at 0x76B225F2 (KernelBase.dll) in ConsoleAppCPlus.exe: 0xE0434352 (parameters: 0x80070002, 0x00000000, 0x00000000, 0x00000000, 0x73900000).

Please suggest the way forward. how we can use C# Dll with 3rd party references in C++ ?

c#
c++
dll
asked on Stack Overflow Oct 27, 2020 by krupali parekh

1 Answer

-1

What you are trying to do is not directly possible. C# has no way to export methods in a way so you can call them from C++ or any other non .Net language.

You essentially only have those options:

  • Use C++/CLI instead of C++ for your console app
  • Use C# instead of C++ for your console app

If you need to use normal C++ for your console application you would have to write some C++/CLI wrapper for your C# library. C++/CLI is able to use C# class libraries and in constrast to C# has the ability to export.

From what i know COM is an option too, but i personally don't have any experience with that.

answered on Stack Overflow Oct 27, 2020 by Eric

User contributions licensed under CC BY-SA 3.0