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

狂风中的少年 提交于 2019-12-30 11:07:07

问题


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?


回答1:


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



回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/971645/what-are-my-options-for-c-dll-to-call-a-c-sharp-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!