Search code examples
c++windows-runtimecppwinrt

Library includes WinRT brocken


I am trying to compile this project: https://github.com/bucienator/ble-win-cpp

After cloning the repository, I got the error "wait_for" is not a member of "winrt :: impl". Using NuGet, I added the Microsoft.Windows.CppWinRT package to the project. But after that my imports of all libraries broke:

#include <winrt / Windows.Foundation.h>
#include <winrt / Windows.Devices.Bluetooth.h>
#include <winrt / Windows.Devices.Enumeration.h>
#include <winrt / Windows.Devices.Bluetooth.Advertisement.h>
#include <winrt / Windows.Devices.Bluetooth.GenericAttributeProfile.h>
#include <winrt / Windows.Storage.Streams.h>

Tell me how do I get Visual Studio to compile my project?


Solution

  • Not sure how this used to compile but it's 3 years old so it's possible it compiled with an older C++/WinRT.

    The "wait_for" issue is mentioned here: https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47 and my solution is to add the Microsoft.Windows.CppWinRT package.

    Then you will have other issues and you have to fix the pch.h like this:

    ...
    #include <iostream>
    #include <sstream>
    #include <iomanip>
    #include <mutex> // add this
    #include <winrt/Windows.Foundation.h>
    #include <winrt/Windows.Foundation.Collections.h> // add this
    #include <winrt/Windows.Devices.Bluetooth.h>
    #include <winrt/Windows.Devices.Enumeration.h>
    #include <winrt/Windows.Devices.Bluetooth.Advertisement.h>
    #include <winrt/Windows.Devices.Bluetooth.GenericAttributeProfile.h>
    #include <winrt/Windows.Storage.Streams.h>
    ...