C++/WinRT is a C++ binding (officially "language projection") for the WinRT[^1] APIs. Originally developed by Kenny Kerr, it has become a part of the official Windows SDK and the recommended way to consume WinRT APIs from C++. See also the official introduction to C++/WinRT and the WinRT API reference.
C++/WinRT was made with MSVC in mind, but a series of changes to make it compatible with GCC and Clang (also libstdc++ and libc++ respectively) has been merged upstream, making it usable with various MinGW-w64 toolchains (with some limitations). This is a collection of documentation and example code intended to help you understand how to use this binding with a MinGW-w64 toolchain.
If you want to see how C++/WinRT works within Visual Studio, I attempted to document it in a separate file.
Note: If you are using MSVC and Visual Studio, please use the official NuGet package instead.
Warning: The information here is work in progress and experimental.
[^1]: Windows Runtime, not to be confused with the operating system that was called "Windows RT".
C++/WinRT requires C++20 for its coroutine support. (C++/WinRT officially supports C++17 but only with MSVC-specific coroutine extensions.) You will need a rather recent compiler. You should also try to get the latest MinGW-w64 runtime and headers.
Compilers:
std::to_chars
implementation in libc++, but can be worked around by disabling the winrt::to_hstring(float)
and winrt::to_hstring(double)
overloads (https://github.com/microsoft/cppwinrt/pull/1257). It also contains only experimental coroutine support (the stabilized implementation is only available since libc++ 14) so anything involving coroutines should be considered unstable and to be avoided.std::to_chars
implementation in libc++ (same as LLVM 13).Tested toolchains:
Headers are built on GitHub Actions workflow runs and made available as build artifacts.
This project provides both CMake config file and pkg-config file in the releases for using the headers with build systems such as CMake and Autotools. To see how these integrations work, you can check the examples. Better documentation may be added in the future.
(I am still figuring this out, so details are subject to change.)
If you want to use the upstream cppwinrt tool directly and without build system integration, please refer to Using Upstream cppwinrt.
All code and resources in this repository are released under the MIT License, unless otherwise specified.