添加到C ++应用程序C#GUI [英] Add to C++ application C# GUI

查看:138
本文介绍了添加到C ++应用程序C#GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加我的C ++应用程序一个C#.NET GUI。
我的C ++应用程序很简单,但我有一个指针和引用。

I would like to add my C++ application a C# .NET GUI . My C++ application is very simple but I have a some Pointer and Reference .

什么是最好的方法C#将识别这个指针和参考? >

What is the Best way C# will recognize this pointer and Reference?

推荐答案

有几种方法,这里有一些,这取决于你的口味和你的项目。

There are several ways, here are some, and it depends on your taste and on your project.

a)如果你的C ++项目是用COM写的,使用COM interop。

a) Use COM interop, if your C++ project is written in COM.

b)使用COM interop,

b) Use COM interop, you can write COM wrappers to your C++ application and use it from C#.

c)使用C ++ / CLI,即将项目转换为托管C ++应用程序,并使用C ++创建托管类,你的C ++代码。
您还可以编写一个托管C ++ dll加载您的C ++ dll或静态库。

c) Use C++/CLI, that is, convert your project to become a Managed C++ application and create managed classes in C++ that use your C++ code. You can also write a managed C++ dll that loads your C++ dll or static library.

d)使用P INVOKE C调用,导出DLL C函数从C ++代码,使用C ++类,使用[dllimport]属性从C#调用C函数。
你可以使用类型IntPtr和更好更安全的SafeHandle来表示指针和引用。

d) Use P INVOKE C calls, exports DLL C functions from your C++ code that work with your C++ class, call the C functions from C# using [dllimport] attribute. You can use type IntPtr and the better and safer SafeHandle to express pointers and references.

所有方法都有好的东西和缺点,但每个列出的语言需要一个中间层,你不能从C#直接调用C ++代码。

All ways have good things and drawbacks, but every listed tehcnique need a "middle layer", you cannot call C++ code directly from C#.

这篇关于添加到C ++应用程序C#GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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