Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I develop universal windows 10 apps with pure C++ and not C++/CLI?

I want to develop universal windows apps using C++/DirectX/XAML. But it seems like there's no way to escape Microsoft's C++/CLI language. I've already browsed through the code that isnthere by default when you make an pty project, and it is all C++/CLI.

like image 272
Gary S Avatar asked Sep 06 '15 14:09

Gary S


2 Answers

C++/CLI (/CLR) a.k.a. Managed C++ is not supported for the universal Windows apps platform, and is not supported for Windows 8 Store or Windows phone 8 either.

What you are seeing are C++/CX (/ZW) language extensions that are used on MSDN and in most of the C++ samples to consume WinRT APIs. The confusion you are having is common because the same language keywords from C++/CLI were reused when implementing C++/CX. There is no .NET Runtime, no garbage collection, and no interpreted code as there is in C++/CLI. See the Visual C++ Team blog series C++/CX Part 0 of [n]: An Introduction for more on the history of C++/CX.

You do not have to use C++/CX to author or consume WinRT APIs, but they are much easier to code against using C++/CX language extensions than pure C++. You can make use of the C++ template library Windows Runtime Library (WRL) rather than C++/CX, but you will mostly have to figure out how on your own as there are very few samples that use it and MSDN presumes you are going to use C++/CX.

The standard samples make use of Microsoft::WRL::ComPtr smart-pointer when dealing with non-WinRT COM APIs like Direct3D, but generally that's the only part of WRL used by the standard samples. I make use of WRL in DirectX Tool Kit to consume some specific WinRT APIs if you want to see some limited examples of using it instead of C++/CX.

Authoring WinRT APIs with WRL also requires a lot of manual sync work with MSIL files to generate the required metadata (but not code). If you are an expert in ATL, you would be equipped to use WRL for authoring WinRT APIs, but otherwise it's likely not worth the productivity hit to avoid C++/CX entirely.

That said, you can easily isolate C++/CX usage to specific modules in your application. I do this in my Direct3D UWP Visual Studio template so that the majority of the code is in fact 'pure' C++.

like image 180
Chuck Walbourn Avatar answered Oct 15 '22 12:10

Chuck Walbourn


Have a look at Modern C++ for the Windows Runtime

From the project description page:

The Modern C++ Library provides a Standard C++ language projection for the Windows Runtime. No need to use non-standard language extensions or cryptic ABI interfaces and functions. With Modern you get a power library for the Windows Runtime, whether you want the convenience of a class-based API or the ability to go under-the-hood for more control.

It looks like a very complete implementation.


Update (2016-10-07): The author of Modern has joined Microsoft to continue work on a Standard C++ language projection. It has been re-named to C++/WinRT, and was recently presented at CppCon 2016 (see Embracing Standard C++ for the Windows Runtime (on YouTube)).

A pre-release version of the library (just the header files without the compiler) should be available soon. In the CppCon talk it has been announced that "we [Microsoft] hope to have something available for you [us] soon".

like image 23
John Avatar answered Oct 15 '22 12:10

John