'WinRT GetSystemIdForPublisher() unable to execute due to C++20 coroutines?

I am trying to get the system ID using

auto info = winrt::Windows::System::Profile::SystemIdentification::GetSystemIdForPublisher();
auto id = info.Id();
auto asHex = winrt::Windows::Security::Cryptography::CryptographicBuffer::EncodeToHexString(id);

But when I try to run this code I get errors E0035 and C1189 and both have the exact same description:

The <experimental/coroutine> and <experimental/resumable> headers are only supported with /await and implement pre-C++20 coroutine support. Use coroutine for standard C++20 coroutines.

(Note: the italic coroutine above is inside <>, as soon as I put <> around the a word it disappears so I have omitted it)

I am including all the relevant files in my header that I think might be needed:

#include <Windows.h>
#include <coroutine>
#include <windows.foundation.h>
#include <winrt/Windows.System.Profile.h>
#include <winrt/Windows.Security.Cryptography.h>

I am using:

Microsoft Visual Studio Community 2019
Microsoft Visual C++ 2019
Windows 10 SDK 10.0.19041.0
c++


Solution 1:[1]

In your project, if you go to

  1. Property Pages ->
  2. Configuration Properties ->
  3. General ->
  4. C++ Language Standard,

do you by any chance have it set to "ISO C++20 Standard (/std:c++20)"? C++/WinRT only runs C++17.

A few hours ago I realized that C++/WinRT exists, and I am currently trying understand the fundamentals of it. If my memory serves me correctly, I also got this exact error message when trying some not-at-all-copy-pasted-from-msdn code out. Although I am using Visual Studio 2022 (Community Edition), I do not see why that would make a difference.

I hope this is of any use.

Kind regards, a not so experienced programmer

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user18629436