microsoft / cppwinrt

C++/WinRT
MIT License
1.65k stars 238 forks source link

Bug: Visual Studio integration? #1388

Closed rlewkowicz closed 8 months ago

rlewkowicz commented 8 months ago

Version

2.0.240111.5

Summary

I think there's a real bug but I don't know how to constructively articulate that really this whole space just feels like it sucks. The docs suck and the api is esoteric. docs comment here: https://github.com/MicrosoftDocs/winrt-api/issues/2445

The bug:

Severity    Code    Description Project File    Line    Suppression State
Error   C3779   'winrt::impl::consume_Windows_Foundation_IAsyncOperation<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Devices::Enumeration::DeviceInformationCollection>,TResult>::get': a function that returns 'auto' cannot be used before it is defined  ConsoleApplication1 C:\Users\Ryan\source\repos\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp  17  

Reproducible example

#include <iostream>
#include <winrt/base.h>
#include <winrt/Windows.Graphics.Display.h>
#include <winrt/Windows.Devices.Enumeration.h>
#include <winrt/Windows.Devices.Display.Core.h>

using namespace winrt;
using namespace winrt::Windows::Graphics;
using namespace winrt::Windows::Devices::Display;
using namespace winrt::Windows::Devices::Enumeration;

int main()
{
    init_apartment();

    const auto monitorSelector = DisplayMonitor::GetDeviceSelector();
    const auto devices = DeviceInformation::FindAllAsync(monitorSelector).get();
}

Expected behavior

But it doesn't return auto? https://learn.microsoft.com/en-us/uwp/api/windows.devices.enumeration.deviceinformation.findallasync?view=winrt-22621

Actual behavior

This should just work?

Additional comments

I'm just exhausted with the WinRT ecosystem. There seems to be literally no meaningful c++ examples for any of it. I don't know where I'm just wrong or things don't work.

dmachaj commented 8 months ago

That error indicates that you are missing a necessary #include statement. You need #include <winrt/Windows.Foundation.h> because IAsyncOperation is in the Windows::Foundation namespace.

kennykerr commented 8 months ago

https://devblogs.microsoft.com/oldnewthing/20190530-00/?p=102529

rlewkowicz commented 8 months ago

That was it, ty!