在不使用 COM 的情况下从 C++ 调用 C# 方法

1

本文介绍了在不使用 COM 的情况下从 C++ 调用 C# 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

有没有办法创建 C# 对象并从非托管 C++ 调用方法,但不使用 COM Iterop?我正在寻找类似 JNI(但适用于 .Net)的东西,您可以在其中手动创建 VM、创建对象等.

Is there a way to create C# objects and call methods from unmanaged C++, but without using COM Iterop? I am looking for something like JNI (but for .Net), where you can manually create the VM, create objects, etc.

推荐答案

如果您使用的是 C++/CLI,那么您可以直接与托管世界和非托管代码进行交互,因此互操作是微不足道的.

If you are using C++/CLI then you can interact directly with both the managed world and unmanaged code, so interop is trivial.

您也可以自己托管 CLR,虽然托管 API 是基于 COM 的,但您可以创建任何托管对象.这个过程并不困难,因为听起来一些 API 调用封装了很多功能.网上有很多信息,例如托管公共语言运行时".

You can also host the CLR yourself, and whilst the hosting API is COM based, you can then create any managed object. The process isn't a difficult as it sounds as a few API calls encapsulate a lot of functionality. There is a lot of info online, for example the MSDN documentation on "Hosting the Common Language Runtime".

这篇关于在不使用 COM 的情况下从 C++ 调用 C# 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14