What are my options for C++ DLL to call a C# DLL?

2019-02-19 16:50发布

I have a C++ DLL that needs to call a function (pass a value, return a value) in a C# class library.

Is my only option to give the C# DLL a COM interface and call it from C++ with IDispatch?

Is this the best method?

4条回答
We Are One
2楼-- · 2019-02-19 17:20

One approach that would work would be to call it though COM. You can use the Regasm tool to create the COM wrapper.

查看更多
我想做一个坏孩纸
3楼-- · 2019-02-19 17:31

It's not the only option.

You could also compile your C++ DLL as a managed DLL.

You could host your C# DLL as a service and remote into it.

查看更多
Viruses.
4楼-- · 2019-02-19 17:35

Couple of options available for you here

  1. Use a mixed mode C++/CLI assembly as a bridge between the C++ and C# DLL
  2. Use the a COM bridge by exposing several of the key C# types as COM objects. This can then be accessed via the C++ code by normal COM semantics
查看更多
放荡不羁爱自由
5楼-- · 2019-02-19 17:39

This project Creates dll exports for static methods in classes. You could then call a C# static method from unmanaged code.

查看更多
登录 后发表回答