Call C# dll from unmanaged C++ app without COM

岁酱吖の 提交于 2019-11-29 22:24:01

问题


Is there a way to call c# dll from c++ unmanaged application without COM usage?


回答1:


You can do this using Reverse P/Invoke - example and discussion here.




回答2:


It is actually possible to disassemble, modify the IL, and reassemble it with exported functions. I messed with this a few years ago, and created an application that would disassemble a dll, provide a list of functions that could potentially be exported - allowing the user to select them, then re-write the IL and reassemble everything. Then, I could call directly into the dll from unmanaged code...or p-invoke into the dll from managed code (not really practical, but interesting nonetheless).

Surely there is a reason that this isn't supported in the .net languages themselves (even tho it is supported in MSIL). I wouldn't use this in production:

Dead link: http://www.csharphelp.com/2007/03/exporting-managed-code-as-unmanaged/

Wayback Machine: https://web.archive.org/web/20140213030149/http://www.csharphelp.com/2007/03/exporting-managed-code-as-unmanaged/




回答3:


I might be a bit late, but check this out.

Using this little msbuild task, you can create a C# library that can be called as if it were a native DLL. (e.g. write plugins for apps that require them to be native dlls)

Oh and don't forget to use the project template, which will setup everything for you.




回答4:


Your only option really is to either use C++.net or create a C++.net wrapper for it that exports what you need.

Calling C# code from C++



来源:https://stackoverflow.com/questions/4465639/call-c-sharp-dll-from-unmanaged-c-app-without-com

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