简体   繁体   中英

Calling C# dll in C++

My current requirement is to call some methods of C# dll in c++ console application. I have a sample C# console application code which is calling the methods from the c# dll.

C# dll was added as a reference into the C# console application project.

using CSharp;

void fn()
{
string retVal;
CSharpApi obj = new CSharpApi("Something");
retVal = obj.Invoke("Something");
obj.Dispose();
....
....
}

The definition of CSharpApi

namespace CSharp
{
    public class CSharpApi : IDisposable
    {
        public CSharpApi();
        public CSharpApi(string param1);
        public string Invoke(string param1);
        public void Dispose();
    }
}

I need to write a c++ console application equivalent to the above c# console application but not sure how to achieve it. Is is possible to call C# dll methods using LoadLibrary and GetProcAddress APIs? I would be very grateful if you could give me some examples.

正如Joachim在他的评论中提到的那样,最简单的方法是使用C ++ / CLI托管的.NET应用程序 ,它为您提供了两全其美的方法,您仍然可以以非托管的方式编写大部分代码,并且调用托管代码的相对简单的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM