C++/WinRT: Getting Started

With the recent public release of C++/WinRT, I thought I would start writing a few short “how to” and “how it works” articles to help developers understand some of the fundamental principles of the C++ language projection for the Windows Runtime. If you’re wondering what C++/WinRT is or need a more detailed introduction I can suggest the following resources:

moderncpp.com – The original home of C++/WinRT includes all the motivating demos, examples and white papers.

C++/WinRT with Kenny Kerr – My interview on CppCast.

Our CppCon talks on C++/WinRT:

Embracing Standard C++ for the Windows Runtime (Slides)

Putting Coroutines to Work with the Windows Runtime (Slides)

With that, let’s get started. You can download the latest public release here:


One option is to clone the git repository (you can also download it as a ZIP file):

git clone https://github.com/Microsoft/cppwinrt.git

Cloning into 'cppwinrt'...
remote: Counting objects: 1499, done.
remote: Total 1499 (delta 0), reused 0 (delta 0), pack-reused 1499
Receiving objects: 100% (1499/1499), 3.20 MiB | 530.00 KiB/s, done.
Resolving deltas: 100% (663/663), done.
Checking connectivity... done.
Checking out files: 100% (1465/1465), done.

You should now have a folder called cppwinrt that contains your own copy of the repository:

dir /b cppwinrt

Getting Started.md

The 10.0.14393.0 folder represents a build or projection of C++/WinRT for the Windows 10 build 14393 SDK (RS1). Within that folder are actually two folders:

dir /b cppwinrt\10.0.14393.0


The winrt folder contains the actual projection, the header-only library that you need to #include to use C++/WinRT. The Samples folder contains a few Visual C++ projects to get you started. Let’s start with a simple app just to make sure everything’s working:

type HostNames.cpp

#pragma comment(lib, "windowsapp")
#include "winrt/Windows.Networking.Connectivity.h"
using namespace winrt;
using namespace Windows::Networking;
using namespace Windows::Networking::Connectivity;
int main()
for (HostName const & name : NetworkInformation::GetHostNames())
printf("%ls\n", name.ToString().c_str());

view raw


hosted with ❤ by GitHub

You can then make sure it builds using the Visual C++ compiler as follows:

cl HostNames.cpp /I cppwinrt\10.0.14393.0 /EHsc /std:c++latest

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.


The output should be something like this:



Join me next time as we continue to explore C++/WinRT. Got a question? Post it here and we’ll do our best to help.

Next: Consumption and Production

6 thoughts on “C++/WinRT: Getting Started

  1. Cédric Mialaret

    This is what I get at step cl HostNames.cpp /I cppwinrt\10.0.14393.0 /EHsc /std:c++latest

    f:\dev\github\cppwinrt\10.0.14393.0\winrt\internal\../base.h(6): fatal error C1083: Cannot open include file: ‘restrictederrorinfo.h’: No such file or directory

    Am I supposed to have C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\ in my PATH environment variable ?

    1. Kenny Kerr Post author

      Right, the assumption was that you would run this from the Visual Studio tools command prompt where you have your paths already set to include the Windows SDK.

  2. Simon Rühle

    I have a perhaps a kind of stupid question, but I cannot really find out which kind of Visual Studio project is suitable for using the C++/WinRT code. I tried with several but with most some kind of error occurs. What is the official recommendet project type? I have looked at the samples but that was not really helpfull to find out.

  3. Hongtao

    Hi Kenny, Using other native windows API in C++ WinRT, is that supported? My understanding is that, since WinRT is running in a security sand box, so, still not all the Windows API are supported. Is that correct?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s