This article may be too technical for most readers to understand. Please help improve it to make it understandable to non-experts, without removing the technical details. (March 2019) (Learn how and when to remove this template message)
|Original author(s)||Kenny Kerr|
|Initial release||June 23, 2015|
2.0.200728.4 / 28 July 2020
|Operating system||Microsoft Windows|
|Type||Software development tools|
C++/WinRT is a C++ library for Microsoft's Windows Runtime platform, designed to provide access to modern Windows APIs. C++/WinRT is provided as a standard C++17 header file library, unlike C++/CX, which is an extension to C++ and requires a recent version of Microsoft Visual C++.
C++/WinRT was introduced as part of the Microsoft Windows SDK in version 10.0.17134.0 (Windows 10, version 1803). Microsoft Visual Studio support for C++/WinRT is provided by an officially-supported extension.
C++/WinRT was originally released in 2015 by Kenny Kerr, who shortly afterward joined 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 is 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 can be pointed 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, users can generate a library for use with any runtime class implemented in a second- or third-party Windows Runtime component, or implemented in their own application.
With C++/WinRT, users can also implement their own runtime classes using standard C++, without resorting to COM-style programming. For a runtime class, types can be described in a MIDL file (.idl), and from that file the
cppwinrt.exe tools generate the implementation boilerplate source code files, ready for users to add their own implementation. Alternatively, users can 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 function-calling via static dispatch. C++/WinRT makes use of a host of modern ISO C++11 (and later) language features to increase productivity and run-time performance; these features were not available when C++/WinRT's predecessors (WRL and C++/CX) were designed.
Standard C++ data types, algorithms, and keywords are used with C++/WinRT; however, the projection also has its own custom data types.
C++/WinRT produces smaller binaries than other language options for the Windows Runtime.
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 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."
- Kerr, Kenny; McNellis, James (November 2, 2016). "CppCon 2016: Embracing Standard C++ for the Windows Runtime". Channel 9. Microsoft. Retrieved November 1, 2019.
- Kerr, Kenny. "Modern C++ for the Windows Runtime". GitHub. Retrieved November 1, 2019.
- "C++/WinRT package". NuGet. Microsoft. Retrieved March 16, 2020.
- White, Steven (April 17, 2019). "Introduction to C++/WinRT". Windows Dev Center. Microsoft. Retrieved July 10, 2019.
- "C++/WinRT Visual Studio Extension". Visual Studio Marketplace. Microsoft. Retrieved November 1, 2019.
- Desmond, Michael (January 2017). "Outside In: How Kenny Kerr Brought C++/WinRT to Microsoft". MSDN Magazine. Microsoft. Retrieved November 1, 2019.
|Wikibooks has a book on the topic of: Windows Programming|