如何创建使用.NET的C ++应用程序接口?应用程序、接口、NET

2023-09-05 01:39:45 作者:有点小任性

我写的所有code在C应用++。这是标准的C ++使用Visual Studio 2010中写

I have written all the code for an application in C++. It is standard C++ written using Visual Studio 2010.

我想创建一个使用.NET的GUI。可能吗? 谢谢!

I want to create a GUI using .NET. Is it possible? Thank you!

推荐答案

有很多的选择,这里是我的头几关上:

There a plenty of options, here's a few off the top of my head:

裹在C ++ code在Windows DLL, 调用C ++ $ C $从.net用c P /调用。

Wrap the c++ code in a Windows DLL, call the c++ code from .NET using p/invoke.

裹在C ++ code在一个COM对象, .NET可以直接使用COM对象。

Wrap the c++ code in a com object, .NET can directly use com objects.

裹在C ++ code里面的一些类型的 托管C ++包装(C ++ / CLI),负载和使用 新装配的.NET GUI。

Wrap the c++ code inside some type of managed c++ wrapper (c++/CLI), load and use that new assembly in the .NET GUI.

一些更奇特的想法:

使用某种类型的进程间 通信,就像插座。你的C ++ code将不得不在另一个运行 处理。我猜你也可以做 C ++的code到Web服务。 C 应用程序界面开发基础 窗体控制 3 文件类控件

Use some type of inter-process communication, like sockets. Your c++ code would have to run in another process. I guess you could also make the c++ code into a web service.

运行命令行C ++ code, 由.NET GUI启动。通过 通过命令行参数 参数,捕捉和解析 从C标准输出的文本++ 计划早在.NET应用程序。

Run the c++ code on the command line, launched by the .NET GUI. Pass parameters via command line parameters, capture and parse the standard-out text from the c++ program back in the .NET app.

编辑: 我建议你​​的DLL和P / Invoke的。 COM对象将有超过一个普通的老DLL优势,通过更复杂的类型和暴露一个对象模型,但COM对象的一个​​痛苦的创建和安装/寄存器(甚至是W / ATL,清单文件,等等)。使用C ++ / CLI似乎总是更复杂的比它的价值了很多的项目 - 但它是值得学习的一点关于它,如果其他的选项也限制

I'd recommend the DLL and p/invoke. The COM object would have advantages over a plain-old dll for passing more complicated types and exposing an object model, but COM objects a pain to create and install/register (even w/ ATL, manifest files, etc). Using C++/CLI always seems more complicated than it's worth for a lot of projects - but it's worth learning a bit about it if the other options become too limiting.