|Original author(s)||Kenny Kerr|
|Developer(s)||Kenny Kerr, Scott Jones, Ryan Shepherd|
|Initial release||June 23, 2015|
1.0.180227.3 / 30 April 2018
1.0.180801.3 / 4 July 2018
|Type||Software development tools|
C++/WinRT is the officially supported, modern C++ language projection for Microsoft's Windows Runtime platform, designed to provide you with first-class access to the modern Windows API. The C++/WinRT language projection is not an extension to the C++ language; rather, it's implemented as an entirely standard modern ISO C++17 header-file-based library. With C++/WinRT, you can author and consume Windows Runtime APIs using any standards-compliant C++17 compiler.
C++/WinRT ships as part of the Microsoft Windows SDK. It was introduced in version 10.0.17134.0 (Windows 10, version 1803) of the SDK. There is also Microsoft Visual Studio support for C++/WinRT, by means of project and item templates, as well as MSBuild properties and targets. Visual Studio support is provided in the form of the C++/WinRT Visual Studio Extension (VSIX), which you can download and install from the Visual Studio Marketplace.
C++/WinRT was originally released in 2015 by Kenny Kerr. Shortly afterward, the technology and Kerr's expertise were brought in-house to Microsoft. C++/WinRT is now Microsoft's recommended replacement for both the Windows Runtime C++ Template Library (WRL), and for C++/CX.
Microsoft's Windows Runtime is based on Component Object Model (COM) APIs, and it's designed to be accessed through language projections. A language projection hides the COM details, and provides a more natural programming experience for a given language. For C++ developers, C++/WinRT is the officially supported, modern C++ language projection.
As of version 10.0.17134.0 (Windows 10, version 1803), the Microsoft Windows SDK contains a header-file-based standard C++ library for consuming first-party Windows APIs (that is, Windows Runtime APIs in Windows namespaces). C++/WinRT also ships with the
cppwinrt.exe tool, which you can point at a Windows Runtime metadata (.winmd) file to generate a header-file-based standard C++ library that projects the APIs described in the metadata for consumption from C++/WinRT code. Windows Runtime metadata (.winmd) files provide a canonical way of describing a Windows Runtime API surface. By pointing the
cppwinrt.exe tool at metadata, you can generate a library for use with any runtime class implemented in a second- or third-party Windows Runtime component, or implemented in your own application.
With C++/WinRT, you can also implement your own runtime classes using standard C++, without resorting to COM-style programming. For a runtime class, you describe your types in a MIDL file (.idl), and from that file the
cppwinrt.exe tools generate your implementation boilerplate source code files for you, ready for you to add your implementation. You can alternatively just implement interfaces by deriving from a base class that's part of the C++/WinRT header library. These techniques employ the curiously recurring template pattern for convenient and performant function-calling via static dispatch. In general, C++/WinRT makes clever and efficient use of a host of modern ISO C++11 (and later) language features to the benefit of developer productivity and run-time performance. Features that were not available when C++/WinRT's predecessors (WRL and C++/CX) were designed.
You use standard C++ data types, algorithms, and keywords when you use C++/WinRT. The projection does have its own custom data types, but in most cases you don't need to learn them because they provide appropriate conversions to and from standard types. That way, you can continue to use the standard C++ language features that you're accustomed to using, and the source code that you already have. C++/WinRT makes it extremely easy to call Windows Runtime APIs in any C++ application, from Win32 to UWP.
C++/WinRT performs better and produces smaller binaries than any other language option for the Windows Runtime. It even outperforms handwritten code using the application binary interface (ABI) directly. That's because the abstractions use modern C++ idioms that the Visual C++ compiler is designed to optimize. This includes magic statics, empty base classes, strlen elision, as well as many newer optimizations in the latest version of Microsoft Visual C++ targeted specifically at improving the performance of C++/WinRT.
Design and development of C++/WinRT was begun in 2014 by the then-independent software developer Kenny Kerr. At the time, the prevailing way for developers to call Windows Runtime APIs using C++ was with the C++/CX language projection. C++/CX adds non-standard extensions to the C++ language, such as the
ref new and
^ (hat) notation inherited from C++/CLI. It hadn't been fully appreciated then that advances in ISO C++ language features meant that it had become possible to design a Windows Runtime language projection for pure standard C++, without extensions. "There are a lot of very experienced C++ developers at Microsoft who have spent decades-long careers working with C++ and COM," Kerr says. "I think it took someone who didn't realize that it was impossible to just try it anyway and show that it works."
There is good reason for C++/WinRT's name to reference the Windows Runtime (WinRT), rather than the Universal Windows Platform (UWP). This is because you can call Windows Runtime APIs (and, therefore, you can benefit from C++/WinRT) in any C++ application, from Win32 to UWP.
- "Embracing Standard C++ for the Windows Runtime".
- "Modern C++ for the Windows Runtime".
- "Start developing on Windows 10 April 2018 Update today".
- "Windows 10 SDK Preview Build 17749 available now!".
- How Kenny Kerr Brought C++/WinRT to Microsoft MSDN Magazine
- Introduction to C++/WinRT docs.microsoft.com