Microsoft toolkit eases the agony of WinRT C++ development

C++/WinRT also makes Windows C++ app development a little less Microsoft-centric

Microsoft’s drift from the proprietary and toward the universal is making its mark on all aspects of Windows software development, including writing C++ software that uses the Windows Runtime (WinRT), now Universal Windows Platform (UWP).

If you wanted to write modern C++ applications that use WinRT/UWP, the traditional method was either to use custom—aka nonstandard—Microsoft C++/CX language extensions, or use the “verbose, tedious, and complex” Windows Runtime C++ Template Library.

Now Microsoft is promoting a recently produced open source toolkit, C++/WinRT, that makes it possible to write WinRT/UWP apps via the native language features in C++. With C++/WinRT, Microsoft aims to allow users of “any standards-compliant C++ compiler” to write software that has “first-class access to the modern Windows API.”

Let’s go with the standard

C++/WinRT works by taking in Windows metadata files, which WinRT uses to allow components to describe themselves and expose their interfaces. The metadata is used to generate a C++ library for connecting to the components in question, and it allows C++ developers to create their own components that use WinRT interface methods.

An immediate consequence of exposing WinRT via standard C++, according to Microsoft, is that WinRT becomes available to C++ programmers as little more than a set of standard header files and namespace declarations. Few, if any, of the components used in the Visual Studio toolchain are needed to create such apps; a simple text editor and the command-line version of the compiler are enough to get things rolling.

As an example, a C++ app that used the Windows.Web.Syndication namespace to read an RSS feed consisted of only 18 lines of C++ code. The C++/WinRT development approach is also meant to be high-level; it doesn’t burden the developer with worries about Windows internals to carry out basic functions.

Outreach program

Microsoft has touted WinRT/UWP as an option to do truly universal development for Windows devices via one code base and with common packaging that allows for distribution via the Windows Store. Worries abounded that Microsoft wanted to promote UWP at the expense of the “classic”—and less closed-ended—Win32 platform, but Microsoft has maintained that UWP apps are open to all developers and can be supported by any app store. Using UWP is a choice, not a mandate.

Still, it’s clear Microsoft wants UWP to be an appealing default going forward. Its Project Centennial utility allows conventional Win32 apps to be repackaged as UWP apps. But with C++/WinRT, the aim is bigger than making WinRT an appealing choice for C++ developers, it’s to make C++ development on Windows less hidebound to Microsoft legacy concerns, whether development tools or the APIs themselves.

Microsoft has been reaching out to C++ developers in the name of cross-platform development. Late last year it unveiled CoreRT, which can translate C# apps into platform-native C++ code. It was intended mainly as a stopgap measure to allow C# apps to be ported to platforms where the C# runtime is not fully available. But it counts as another form of outreach to C++ developers, even if they’re not writing apps directly for the Windows ecosystem.

Copyright © 2017 IDG Communications, Inc.