如何从非托管 C++ 调用托管 .NET 代码 Windows 中的代码,反之亦然?

发布于 2024-07-25 16:41:54 字数 167 浏览 3 评论 0原文

我有一个使用 VC 6.0 开发的纯 C++ 应用程序。 我希望这个应用程序能够使用用 C# 开发的库。 如何从本机可执行文件调用 C# 库中的方法? 我不想将非托管 C++ 本机应用程序转换为托管代码。 同样的,我该如何做相反的事情呢? PInvoke 是唯一的选择吗? 我将不胜感激任何相同的参考或指示。

I have a pure C++ application developed using VC 6.0. I would like this application to make use of a library developed in C#. How do I call the methods in the C# library from my native executable? I do not want to convert my un-managed C++ native application to managed code. Similarly, how do I do the reverse? Is PInvoke the only option? I would appreciate any references or pointers for the same.

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

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

发布评论

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

评论(2

幻想少年梦 2024-08-01 16:41:54

要从非托管 C++ 调用托管代码,请使用 ClrCreateManagedInstance,或导出您的托管程序集中的类型为 COM 可见,并使用 COM。 要从托管调用非托管代码,请使用 COM 或 P/Invoke。

To call into managed code from unmanaged C++, use ClrCreateManagedInstance, or export your types in your managed assembly as COM visible, and use COM. To call into unmanaged code from managed, use COM or P/Invoke.

话少心凉 2024-08-01 16:41:54

微软在这方面的主线是使用COM互操作。 然而,还有另一种选择,有时称为“反向 P/Invoke”,有一篇有趣的博客文章 此处以及更多此处

另外,如果您有 Delphi.NET(现已不存在),这种语言允许您像导出任何 dll 函数一样导出静态方法,那么您可以像普通的本机 Dll 一样调用 Delphi.NET 程序集。

Microsoft's main line on this is use COM interop. There is however another option, sometimes referred to as "Reverse P/Invoke" there is a interesting blog post here and some more here

Also, if you have Delphi.NET (now defunct) this language allows you to export static methods like you would any dll function then you can call into the Delphi.NET assembly just like a normal native Dll.

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