Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use C++/CLI (.NET Winforms/WPF ) to provide GUI for app written in native C & C++

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.

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

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

like image 398
claws Avatar asked May 06 '10 05:05

claws


People also ask

Can you use C++ with WPF?

You can use WPF with C++/CLI. It is a . NET API, however, so it requires the . NET Framework.

Does. net Core support c++?

NET Core 3.1 and Visual Studio 2019, C++/CLI projects can target . NET Core. This support makes it possible to port Windows desktop applications with C++/CLI interop layers to .


3 Answers

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.

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#.

Otherwise, a C++ library like Qt or wxWidgets would also suffice for doing a "native" 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).

like image 130
Dean Harding Avatar answered Nov 04 '22 18:11

Dean Harding


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).

like image 24
Conrad Albrecht Avatar answered Nov 04 '22 18:11

Conrad Albrecht


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

like image 28
daveangel Avatar answered Nov 04 '22 18:11

daveangel