Calling C# dll from C++

别说谁变了你拦得住时间么 提交于 2020-02-16 05:22:41

问题


I have a native C++ DLL, and I want to import a C# DLL and use some of its functions (for example connecting to a database).

Now I have read that you can turn the DLL into a TLB COM file, and I have done that no problems. My problem lies with the C++. To call that TLB file I need to set CLR support. I use themida to help secure all my DLL's as well as PEC. They do not support .net DLL's and when I enable CLR the programs recognize it as a .net DLL.

Is there anyway to call a c# function inside a .net DLL from inside a native C++ DLL without enabling CLR?


回答1:


The best way in my opinion is to crate a C++/CLI lib that you can use to communicate between the layers.

This 3rd party library will be compiled with /clr enabled.

Then you can use the header definitions to the proper c++ function wrappers to call the C# functions.

C++/CLI can help you manage the call just the way you want it, and let you design the type casts the way you want them.



来源:https://stackoverflow.com/questions/9752029/calling-c-sharp-dll-from-c

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