question

KaranAhlawat-6550 avatar image
0 Votes"
KaranAhlawat-6550 asked Castorix31 commented

WinUI in Desktop with C++

Hello, I am quite new to application development on and for Windows. I have learnt some beginner stuff for making WinUI applications in C#, thanks to all the resources out there.
But, the resources for doing the same in C++ are quite few in number, and not very approachable for someone who does not know anything about how C++ application development works. The MSFT documentation isn't of much help either.

Hence, can anyone recommend some good resources that aren't aimed at experienced people, for getting started with WinUI with C++, and WinRT/C++?

windows-uwpc++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 commented

Usually, everything is in MSDN, but there are not a lot of things for C++/WinUI, WinUI being a new technology.
(I use C++/Win32, other people use MFC, or there is also C++/CLI (like C#)) :

Create your first WinUI 3 app
Windows App SDK Hello World Sample


· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How reasonable would you say is using Win32 at this point in time? I was reading the Charles Pretzold book on it, the 5th ed, but quite frankly I do not know if it's worth the time. Can we get the WinUI controls in apps built using the Win32 API?

0 Votes 0 ·

MFC is a compromise between unmanaged Win32 and managed .Net. MFC was the first object-oriented library for C++ developed by Microsoft for Windows.

Define what you mean by WinUI.

0 Votes 0 ·

By WinUI I mean the new UI/UX stack Microsoft has made available under Project Reunion. It can be used with both Win32 desktop apps and UWP apps. I have been successful in using it to create both UWP and Desktop apps using C#. Now, however, I would like to use C++, as mentioned in the original question.

0 Votes 0 ·
Show more comments

It depends on what you want to do, but it seems a bit late to learn Win32 api now (I use it since 1990...)
For fast GUI, I use Winforms with C# or VB.
I can do about everything with C++/Win32 + Direct2D or WPF, but it needs more code/time...

0 Votes 0 ·

I don't want to use Winforms, since they are generally not very good for maintainable applications and such.

I am able to make native looking apps in WinUI desktop using with C#, which effectively works the same WPF except for how the UI looks and what namespaces you use.

I just want to be able to do that, but have my business logic and data access and whatever code behind I have written in C++.

They have project templates for it, but I haven't been able to understand how things work with C++, with all the precompiled headers and WinRT stuff and IDL files.

0 Votes 0 ·
Show more comments
SimpleSamples avatar image
0 Votes"
SimpleSamples answered flaviu edited

I wish I could give you an answer you would like. Unfortunately Microsoft has made things really complicated. I have even read that they are moving away from UWP.

For what it is worth, there is something new for making applications that can execute in most major environments, not just Windows; see:

I am not sure how useful that is to you but it is another complication.

There was something called either C++/CLI or CLI/C++; I have seen both. It is a non-standard managed version of the C++ language.

Then there was C++/CX. I know nothing about it. But then Microsoft developed C++/WinRT. See the following.

I think that C++/WinRT is worth learning. I am still using VS 2017 and I generated a C++ UWP program. I am not sure but I think it is using C++/CX. So unfortunately there are no easy answers but if you are using VS 2019 then try generating a C++ UWP program. I am not sure but as best as I can see if it uses C++/WinRT then there will be a NuGet package for that.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, thanks for taking the time to reply!
I have heard about and read alot about .NET MAUI, but right now I do not want to target multiple platforms, just Windows. Also pretty sure i read that they recommend C++/WinRT over C++/CX. Also CX is non-standard which just adds to the pains i suppose.

I did use VS2019, the latest stable release, to generate both WinUI dekstop projects using C++, and C++ UWP projects. The problem remains the same for me. The file structure and how one is supposed to go about implementing everything feels very different than in C#, and hence I feel out of place. Other than a few things on a WinRT/C++ command line project, I am unable to get much done.

0 Votes 0 ·

Microsoft is great at promoting but if you look back in history it doesn't always work out as MS said it would. With Win 8.1 there were "Metro" apps which morphed into UWP. UWP was supposed to be the write once and run everywhere solution but it hasn't worked out that way. Don't believe everything you read. Remember when MS was touting Silverlight? Where is it now?

2 Votes 2 ·

I am not skilled in many platforms, but I could tell a nice experience with MFC: I was found an MFC app wandering on a company network drive. Compiled in 2003. And when I started, ran it without any problem (in Win10). That's not a less thing.

0 Votes 0 ·

Yes .Net was not designed to work well with C++. Microsoft has been struggling to support .Net using C++ and they are still struggling with it.

0 Votes 0 ·