我可以使用C ++ / CLI(.NET Winforms / WPF)为使用本机C和C ++编写的应用程序提供GUI

时间:2022-09-01 15:53:56

I've an app written C & C++. Now, I need to provide a GUI for this app. MFC is the best option for me. But I'm not familiar with MFC.

我有一个用C&C ++编写的应用程序。现在,我需要为这个应用程序提供一个GUI。 MFC是我的最佳选择。但我不熟悉MFC。

So can I use .NET to build GUI for this? If so, How? Please be clear.

那么我可以使用.NET为此构建GUI吗?如果是这样,怎么样?请说清楚。

If I can use .NET I guess I can use WPF too right?

如果我可以使用.NET,我想我可以使用WPF吗?

4 个解决方案

#1


14  

You can technically write a GUI in C++/CLI, but I would highly discourage it. C++/CLI is good for writing .NET wrappers around native C++ and exposing it to other .NET languages, but not much else.

您可以在技术上用C ++ / CLI编写GUI,但我强烈反对它。 C ++ / CLI适用于在本机C ++周围编写.NET包装器并将其暴露给其他.NET语言,但不是很多。

In your case, if you're really set on using WinForms/WPF, then I would suggest using C++/CLI to create a wrapper around your C++ code and then building the actual GUI in C#.

在你的情况下,如果你真的开始使用WinForms / WPF,那么我建议使用C ++ / CLI创建一个围绕C ++代码的包装器,然后在C#中构建实际的GUI。

Otherwise, a C++ library like Qt or wxWidgets would also suffice for doing a "native" C++ GUI.

否则,像Qt或wxWidgets这样的C ++库也可以用于执行“本机”C ++ GUI。

Here's a quick introduction to C++/CLI. This is a quick-start guide for getting started with C++/CLI. Once you build a C++/CLI DLL, you can just add it as a reference to your C# project and It Just Works(tm).

这是C ++ / CLI的快速介绍。这是开始使用C ++ / CLI的快速入门指南。一旦构建了C ++ / CLI DLL,就可以将它添加为C#项目和It Just Works(tm)的引用。

#2


5  

Organize the C++ app as a "server", exporting functions which can be called by a GUI "client". Build this C++ code as a DLL, exporting said functions. Create your GUI app as a .NET EXE and let it call said functions in your DLL using Platform Invoke (P/Invoke).

将C ++应用程序组织为“服务器”,导出可由GUI“客户端”调用的函数。将此C ++代码构建为DLL,导出所述函数。将您的GUI应用程序创建为.NET EXE,并使用Platform Invoke(P / Invoke)调用DLL中的所述函数。

#3


3  

This book also deserves particular mention since it covers advanced topics and using WPF with C++/CLI: C++/CLI in Action (Manning)

本书也值得特别提及,因为它涵盖了高级主题并将WPF与C ++ / CLI结合使用:C ++ / CLI in Action(Manning)

#4


2  

Depends on if you want to learn another language? If you choose the C++/CLI or C# route you will have to get familiar with those languages before you even start with your GUI. Yeah MFC isn't the greatest but at least you can still use C++ with it. And that seems to be what Microsoft wants you to use since most of their video tutorials are MFC based: http://msdn.microsoft.com/en-us/visualc/bb693459.aspx

取决于你是否想学习另一种语言?如果选择C ++ / CLI或C#路由,则必须在开始使用GUI之前熟悉这些语言。是的MFC不是最好的,但至少你仍然可以使用C ++。这似乎是微软希望你使用的,因为他们的大多数视频教程都是基于MFC的:http://msdn.microsoft.com/en-us/visualc/bb693459.aspx

If you choose the WinForms C++/CLI route Visual Studio actually ships with a template for this. Even 2010 doesn't ship with a WPF project template like C# though so you should get the message that Microsoft wants you to use C# for GUI stuff.

如果选择WinForms C ++ / CLI路由,Visual Studio实际上附带了一个模板。即使是2010年也未附带像C#这样的WPF项目模板,所以你应该得到微软希望你使用C#来表示GUI的消息。

Anyways, if it's a trivial app or program you are porting it's not that hard using WinForms. Actually, it's just a bit harder than using C# since you get to use the same GUI editor in Visual Studio but you have to write a lot more of the code by hand than using C#.

无论如何,如果它是一个简单的应用程序或程序,你移植它并不是很难使用WinForms。实际上,它比使用C#要困难得多,因为你可以在Visual Studio中使用相同的GUI编辑器,但是你必须手动编写更多的代码而不是使用C#。

And you have to know Microsoft's C++/CLI since the template will autogenerate code in that and you need to understand what it does so you can ignore most of it.

而且您必须了解Microsoft的C ++ / CLI,因为模板会自动生成代码并且您需要了解它的功能,因此您可以忽略它的大部分内容。

Ivor Horton's Beginning Visual C++ 2010 and Visual C++ 2008 How to Program (2nd Edition) ~ Paul J. Deitel, Harvey M. Deitel are 2 of the only books I've seen that cover WinForm/C++/CLI programming so you might want to look at that or just go with C# as everyone recommends.

Ivor Horton的Beginning Visual C ++ 2010和Visual C ++ 2008如何编程(第2版)~Paul J. Deitel,Harvey M. Deitel是我见过的两本涵盖WinForm / C ++ / CLI编程的书籍,所以你可能想要看看那个,或者只是按照每个人的建议去C#。

#1


14  

You can technically write a GUI in C++/CLI, but I would highly discourage it. C++/CLI is good for writing .NET wrappers around native C++ and exposing it to other .NET languages, but not much else.

您可以在技术上用C ++ / CLI编写GUI,但我强烈反对它。 C ++ / CLI适用于在本机C ++周围编写.NET包装器并将其暴露给其他.NET语言,但不是很多。

In your case, if you're really set on using WinForms/WPF, then I would suggest using C++/CLI to create a wrapper around your C++ code and then building the actual GUI in C#.

在你的情况下,如果你真的开始使用WinForms / WPF,那么我建议使用C ++ / CLI创建一个围绕C ++代码的包装器,然后在C#中构建实际的GUI。

Otherwise, a C++ library like Qt or wxWidgets would also suffice for doing a "native" C++ GUI.

否则,像Qt或wxWidgets这样的C ++库也可以用于执行“本机”C ++ GUI。

Here's a quick introduction to C++/CLI. This is a quick-start guide for getting started with C++/CLI. Once you build a C++/CLI DLL, you can just add it as a reference to your C# project and It Just Works(tm).

这是C ++ / CLI的快速介绍。这是开始使用C ++ / CLI的快速入门指南。一旦构建了C ++ / CLI DLL,就可以将它添加为C#项目和It Just Works(tm)的引用。

#2


5  

Organize the C++ app as a "server", exporting functions which can be called by a GUI "client". Build this C++ code as a DLL, exporting said functions. Create your GUI app as a .NET EXE and let it call said functions in your DLL using Platform Invoke (P/Invoke).

将C ++应用程序组织为“服务器”,导出可由GUI“客户端”调用的函数。将此C ++代码构建为DLL,导出所述函数。将您的GUI应用程序创建为.NET EXE,并使用Platform Invoke(P / Invoke)调用DLL中的所述函数。

#3


3  

This book also deserves particular mention since it covers advanced topics and using WPF with C++/CLI: C++/CLI in Action (Manning)

本书也值得特别提及,因为它涵盖了高级主题并将WPF与C ++ / CLI结合使用:C ++ / CLI in Action(Manning)

#4


2  

Depends on if you want to learn another language? If you choose the C++/CLI or C# route you will have to get familiar with those languages before you even start with your GUI. Yeah MFC isn't the greatest but at least you can still use C++ with it. And that seems to be what Microsoft wants you to use since most of their video tutorials are MFC based: http://msdn.microsoft.com/en-us/visualc/bb693459.aspx

取决于你是否想学习另一种语言?如果选择C ++ / CLI或C#路由,则必须在开始使用GUI之前熟悉这些语言。是的MFC不是最好的,但至少你仍然可以使用C ++。这似乎是微软希望你使用的,因为他们的大多数视频教程都是基于MFC的:http://msdn.microsoft.com/en-us/visualc/bb693459.aspx

If you choose the WinForms C++/CLI route Visual Studio actually ships with a template for this. Even 2010 doesn't ship with a WPF project template like C# though so you should get the message that Microsoft wants you to use C# for GUI stuff.

如果选择WinForms C ++ / CLI路由,Visual Studio实际上附带了一个模板。即使是2010年也未附带像C#这样的WPF项目模板,所以你应该得到微软希望你使用C#来表示GUI的消息。

Anyways, if it's a trivial app or program you are porting it's not that hard using WinForms. Actually, it's just a bit harder than using C# since you get to use the same GUI editor in Visual Studio but you have to write a lot more of the code by hand than using C#.

无论如何,如果它是一个简单的应用程序或程序,你移植它并不是很难使用WinForms。实际上,它比使用C#要困难得多,因为你可以在Visual Studio中使用相同的GUI编辑器,但是你必须手动编写更多的代码而不是使用C#。

And you have to know Microsoft's C++/CLI since the template will autogenerate code in that and you need to understand what it does so you can ignore most of it.

而且您必须了解Microsoft的C ++ / CLI,因为模板会自动生成代码并且您需要了解它的功能,因此您可以忽略它的大部分内容。

Ivor Horton's Beginning Visual C++ 2010 and Visual C++ 2008 How to Program (2nd Edition) ~ Paul J. Deitel, Harvey M. Deitel are 2 of the only books I've seen that cover WinForm/C++/CLI programming so you might want to look at that or just go with C# as everyone recommends.

Ivor Horton的Beginning Visual C ++ 2010和Visual C ++ 2008如何编程(第2版)~Paul J. Deitel,Harvey M. Deitel是我见过的两本涵盖WinForm / C ++ / CLI编程的书籍,所以你可能想要看看那个,或者只是按照每个人的建议去C#。