如何从C ++调用C# [英] how to call C# from c++

查看:99
本文介绍了如何从C ++调用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道从C ++(本机而非C ++ CLI)代码中调用c#类方法的方式是什么?需要简单而优雅的方式

I am wondering what's the way to call a c# class method from C++(Native, not C++ CLI) code? Need simple and elegant way

推荐答案

将C#程序集转换为可见的COM并使用COM接口。据我所知,这是使其与自制IPC一起工作的唯一方法。问题来自.NET环境,必须在该环境下运行.NET程序集,而C ++必须在其本机C ++环境下运行。

Turn your C# assembly into a COM visible one and use COM interfaces. That is the only way to make it work beside self made IPC as far as I know. The problem comes from the .NET environment under which the .NET assembly must run and C++ runs under its native C++ environment.

唯一的通信方式是IPC机制(套接字,...)或使用COM,因为必须分离进程。

The only way of communicating is either an IPC mechanism (sockets, ...) or use COM, as the processes have to be "decoupled".

以下是基于COM的解决方案的教程:

Here is a tutorial for the COM based solution:

  • MSDN - COM Interop Part 2: C# Server Tutorial

这篇关于如何从C ++调用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆