从非托管 C++ 调用 C# dll没有 COM 的应用程序

发布于 2024-10-08 04:34:39 字数 48 浏览 2 评论 0原文

有没有办法在不使用 COM 的情况下从 C++ 非托管应用程序调用 C# DLL?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寂寞花火° 2024-10-15 04:34:39

您可以使用Reverse P/Invoke来完成此操作 - 示例和讨论这里

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

朮生 2024-10-15 04:34:39

实际上可以反汇编、修改 IL,并使用导出函数重新组装它。几年前我搞砸了这个问题,创建了一个应用程序来反汇编 dll,提供可能导出的函数列表 - 允许用户选择它们,然后重新编写 IL 并重新组装所有内容。然后,我可以从非托管代码直接调用 dll...或者从托管代码调用 dll(不太实用,但仍然很有趣)。

当然,.net 语言本身不支持这一点是有原因的(即使它在 MSIL 中受支持)。我不会在生产中使用它:

死链接:
http://www.csharphelp.com/ 2007/03/将托管代码导出为非托管/

回溯机:
https://web.archive.org/web/20140213030149/http://www.csharphelp.com/2007/03/exporting-management-code-as-unmanagement/

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/

挽清梦 2024-10-15 04:34:39

我可能有点晚了,但请查看

使用这个小小的 msbuild 任务,您可以创建一个可以像本机 DLL 一样调用的 C# 库。 (例如,为需要本机 dll 的应用程序编写插件)

哦,不要忘记使用 项目模板,它将为您设置一切。

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.

神经暖 2024-10-15 04:34:39

您唯一的选择实际上是使用 C++.net 或为其创建一个 C++.net 包装器来导出您需要的内容。

从 C++ 调用 C# 代码

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++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文