C++/WinRT

Last updated
C++/WinRT
Original author(s) Kenny Kerr [1]
Developer(s) Microsoft
Initial releaseJune 23, 2015(9 years ago) (2015-06-23) [2]
Stable release
2.0.240405.15 / 5 April 2024;3 months ago (2024-04-05) [3]
Repository github.com/Microsoft/cppwinrt
Written in C++
Operating system Microsoft Windows
Predecessor C++/CX, WRL
Type Software development tools
License MIT License
Website aka.ms/cppwinrt

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++. [4]

Contents

C++/WinRT was introduced as part of the Microsoft Windows SDK in version 10.0.17134.0 (Windows 10, version 1803) and is a component of Windows App SDK (formerly known as Project Reunion). Microsoft Visual Studio support for C++/WinRT is provided by an officially-supported extension. [5]

C++/WinRT was originally released in 2015 by Kenny Kerr, who shortly afterward joined Microsoft. [6] C++/WinRT is now Microsoft's recommended replacement for both the Windows Runtime C++ Template Library (WRL), and for C++/CX. [4]

Overview

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). [4] 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 midl.exe and 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.

History

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." [6]

"I had had some previous experience projecting COM APIs into modern C++, so I decided to see whether I could apply those same techniques to the Windows Runtime." One early challenge in developing C++/WinRT was managing the trade-offs that the Windows Runtime makes to support projections for JavaScript and managed .NET languages out of the box. The complexity in the way that generic collections work across language projections is another example of these design challenges, as was coming up with an efficient way for standard C++ to handle the Windows Runtime's interface-versioning model. "It really pushed my understanding of C++ at that time, and it's since pushed the Microsoft Visual C++ compiler to more efficiently handle such techniques at this scale."

Related Research Articles

The Common Language Infrastructure (CLI) is an open specification and technical standard originally developed by Microsoft and standardized by ISO/IEC and Ecma International that describes executable code and a runtime environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures. This implies it is platform agnostic. The .NET Framework, .NET and Mono are implementations of the CLI. The metadata format is also used to specify the API definitions exposed by the Windows Runtime.

<span class="mw-page-title-main">Windows API</span> Microsofts core set of application programming interfaces on Windows

The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running.

<span class="mw-page-title-main">Microsoft Visual C++</span> Integrated development environment product

Microsoft Visual C++ (MSVC) is a compiler for the C, C++, C++/CLI and C++/CX programming languages by Microsoft. MSVC is proprietary software; it was originally a standalone product but later became a part of Visual Studio and made available in both trialware and freeware forms. It features tools for developing and debugging C++ code, especially code written for the Windows API, DirectX and .NET.

JScript is Microsoft's legacy dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer web browser.

Cabinet is an archive-file format for Microsoft Windows that supports lossless data compression and embedded digital certificates used for maintaining archive integrity. Cabinet files have .cab filename extensions and are recognized by their first four bytes MSCF. Cabinet files were known originally as Diamond files.

<span class="mw-page-title-main">IBM System Object Model</span> Programming framework

The System Object Model (SOM) is an object-oriented shared library technology developed by IBM that supports defining an interface to an object so that its interface is separate from its implementation.

Managed Extensions for C++ or Managed C++ is a deprecated set of language extensions for C++, including grammatical and syntactic extensions, keywords and attributes, to bring the C++ syntax and language to the .NET Framework. These extensions were created by Microsoft to allow C++ code to be targeted to the Common Language Runtime (CLR) in the form of managed code, as well as continue to interoperate with native code.

Metadata, in the Common Language Infrastructure (CLI), refers to certain data structures embedded within the Common Intermediate Language (CIL) code that describes the high-level structure of the code. Metadata describes all classes and class members that are defined in the assembly, and the classes and class members that the current assembly will call from another assembly. The metadata for a method contains the complete description of the method, including the class, the return type and all of the method parameters.

Microsoft Windows SDK, and its predecessors Platform SDK, and .NET Framework SDK, are software development kits (SDKs) from Microsoft that contain documentation, header files, libraries, samples and tools required to develop applications for Microsoft Windows and .NET Framework. Platform SDK specializes in developing applications for Windows 2000, XP and Windows Server 2003. .NET Framework SDK is dedicated to developing applications for .NET Framework 1.1 and .NET Framework 2.0. Windows SDK is the successor of the two and supports developing applications for Windows XP and later, as well as .NET Framework 3.0 and later.

The Speech Application Programming Interface or SAPI is an API developed by Microsoft to allow the use of speech recognition and speech synthesis within Windows applications. To date, a number of versions of the API have been released, which have shipped either as part of a Speech SDK or as part of the Windows OS itself. Applications that use SAPI include Microsoft Office, Microsoft Agent and Microsoft Speech Server.

ObjectARX is an API for customizing and extending AutoCAD. The ObjectARX SDK is published by Autodesk and freely available under license from Autodesk. The ObjectARX SDK consists primarily of C++ headers and libraries that can be used to build Windows DLLs that can be loaded into the AutoCAD process and interact directly with the AutoCAD application. ObjectARX modules use the file extensions .arx and .dbx instead of the more common .dll.

In Microsoft Windows applications programming, OLE Automation is an inter-process communication mechanism created by Microsoft. It is based on a subset of Component Object Model (COM) that was intended for use by scripting languages – originally Visual Basic – but now is used by several languages on Windows. All automation objects are required to implement the IDispatch interface. It provides an infrastructure whereby applications called automation controllers can access and manipulate shared automation objects that are exported by other applications. It supersedes Dynamic Data Exchange (DDE), an older mechanism for applications to control one another. As with DDE, in OLE Automation the automation controller is the "client" and the application exporting the automation objects is the "server".

The Microsoft Windows operating system supports a form of shared libraries known as "dynamic-link libraries", which are code libraries that can be used by multiple processes while only one copy is loaded into memory. This article provides an overview of the core libraries that are included with every modern Windows installation, on top of which most Windows applications are built.

Component Object Model (COM) is a binary-interface technology for software components from Microsoft that enables using objects in a language-neutral way between different programming languages, programming contexts, processes and machines.

<span class="mw-page-title-main">.NET Framework</span> Software platform developed by Microsoft

The .NET Framework is a proprietary software framework developed by Microsoft that runs primarily on Microsoft Windows. It was the predominant implementation of the Common Language Infrastructure (CLI) until being superseded by the cross-platform .NET project. It includes a large class library called Framework Class Library (FCL) and provides language interoperability across several programming languages. Programs written for .NET Framework execute in a software environment named the Common Language Runtime (CLR). The CLR is an application virtual machine that provides services such as security, memory management, and exception handling. As such, computer code written using .NET Framework is called "managed code". FCL and CLR together constitute the .NET Framework.

Windows Runtime (WinRT) is a platform-agnostic component and application architecture first introduced in Windows 8 and Windows Server 2012 in 2012. It is implemented in C++ and officially supports development in C++, Rust/WinRT, Python/WinRT, JavaScript-TypeScript, and the managed code languages C# and Visual Basic (.NET) (VB.NET).

<span class="mw-page-title-main">Mono (software)</span> Computer software project

Mono is a free and open-source .NET Framework-compatible software framework. Originally by Ximian, it was later acquired by Novell, and is now being led by Xamarin, a subsidiary of Microsoft and the .NET Foundation. Mono can be run on many software systems.

C++/CX(C++ component extensions) is a language projection for Microsoft's Windows Runtime platform. It takes the form of a language extension for C++ compilers, and it enables C++ programmers to write programs that call Windows Runtime (WinRT) APIs. C++/CX is superseded by the C++/WinRT language projection, which is not an extension to the C++ language; rather, it's an entirely standard modern ISO C++17 header-file-based library.

Windows UI Library is a user interface API that is part of the Windows Runtime programming model that forms the backbone of Universal Windows Platform apps for the Windows 8, Windows 8.1, Windows 10 and Windows Phone 8.1 operating systems. It enables declaring user interfaces using Extensible Application Markup Language (XAML) technology.

<span class="mw-page-title-main">Windows App SDK</span> Software development kit from Microsoft

Windows App SDK is a software development kit (SDK) from Microsoft that provides a unified set of APIs and components that can be used to develop desktop applications for both Windows 11 and Windows 10 version 1809 and later. The purpose of this project is to offer a decoupled implementation of capabilities which were previously tightly-coupled to the UWP app model. Windows App SDK allows native Win32 (USER32/GDI32) or .NET (WPF/WinForms) developers alike a path forward to enhance their apps with modern features.

References

  1. Kerr, Kenny; McNellis, James (November 2, 2016). "CppCon 2016: Embracing Standard C++ for the Windows Runtime". Channel 9. Microsoft. Retrieved November 1, 2019.
  2. Kerr, Kenny. "Modern C++ for the Windows Runtime". GitHub. Retrieved November 1, 2019.
  3. "C++/WinRT package". NuGet. Microsoft. Retrieved July 15, 2024.
  4. 1 2 3 White, Steven (April 17, 2019). "Introduction to C++/WinRT". Windows Dev Center. Microsoft. Retrieved July 10, 2019.
  5. "C++/WinRT Visual Studio Extension". Visual Studio Marketplace. Microsoft. Retrieved November 1, 2019.
  6. 1 2 Desmond, Michael (January 2017). "Outside In: How Kenny Kerr Brought C++/WinRT to Microsoft". MSDN Magazine. Microsoft. Retrieved November 1, 2019.