在C ++中code。使用C#DLL [英] Using C# dll in C++ code

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

问题描述

我需要这个 C#DLL 整合
在我的C ++ code。我想打电话从DLL用C#编写的一些功能和code ++写的在C ++中休息。什么是做到这一点的最简单快捷的方式?该程序只能在Windows上执行。

I need to integrate this C# dll in my C++ code. I want to call some functions written in C# from dll and the rest of code write in C++. What is the easiest and quickest way to do it? The program will be executed only on Windows.

推荐答案

基本上有两种情况调用从非托管code的.NET的DLL:

There are basically two cases to call a .NET DLL from unmanaged code:


  1. 的.NET的DLL公开一个COM接口。在这种情况下,你可以使用COM从C ++ code。

  2. 在.NET的DLL不公开COM接口。在这种情况下,你有两种可能性(以使其简单):

  1. The .NET DLL exposes a COM interface. In this case, you can use COM from your C++ code.
  2. The .NET DLL does not expose a COM interface. In this case, you have two possibilities (to make it simple):

2.A。举办​​CLR如下所述:加载公共语言运行库到工艺结果
2.B.写一段托管C ++ code的(另一个DLL - 写在C ++ / CLI)来包装.NET的DLL和揭露'老办法'的DLL出口到非受管客户

2.a. host the CLR as described here: Loading the Common Language Runtime into a Process
2.b. write a piece of managed C++ code (another DLL - written in C++/CLI) to wrap the .NET DLL and expose 'old way' DLL exports to unmanaged clients.

我不知道具体的sharpbox系统,但它看起来像它的纯.NET和不公开的COM接口,因此2.B可能做到这一点(不是那么容易的......)的最佳方式。也许它您可以使用REST /网络更容易API。

I don't specifically know the sharpbox system, but it looks like it's pure .NET and does not expose COM interfaces, so 2.b might be the best way to do it (not so easy...). Maybe it has a REST/Web easier API you could use.

PS:你也可以出口添加到.NET的DLL。这说明如下:<一href=\"http://stackoverflow.com/questions/4818850/is-is-possible-to-export-functions-from-a-c-sharp-dll-like-in-vs-c\">Is可以从C#中的DLL VS C ++中导出函数样?但它有点哈克。

PS: you can also add exports to a .NET DLL. This is described here: Is is possible to export functions from a C# DLL like in VS C++? but it's kinda hacky.

这篇关于在C ++中code。使用C#DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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