开发者

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

开发者 https://www.devze.com 2022-12-29 02:45 出处:网络
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.

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开发者_JS百科 .NET I guess I can use WPF too right?


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


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


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


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

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.

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

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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号