Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Upgrading from 2.0.221104.6 to a later version no longer builds co_await on a DispatcherQueue #1391

Closed
jaimecbernardo opened this issue Feb 12, 2024 · 6 comments

Comments

@jaimecbernardo
Copy link

Version

2.0.240111.5

Summary

After updating CppWinRT from 2.0.221104.6, which build this code, to 2.0.221117.1 or later, this code no longer builds.

I've uploaded a repository to make this easier to try to build and fail.
https://github.com/jaimecbernardo/Sample-CppWinRT-DispatcherQueue-build-regression

The code is taken from https://www.nuget.org/packages/robmikh.common/0.0.22-beta package, from this file: https://github.com/robmikh/robmikh.common/blob/aaa31a1bcd4fac19ce4c544d2cfd415612add7f0/robmikh.common/include/robmikh.common/dispatcherqueue.desktop.interop.h

CppWinRT 2.0.221104.6 builds this code. This repo can be built at this commit: jaimecbernardo/Sample-CppWinRT-DispatcherQueue-build-regression@c1a7221

The next version available (2.0.221117.1) jaimecbernardo/Sample-CppWinRT-DispatcherQueue-build-regression@7742b75 , and the lastest (2.0.221104.6) jaimecbernardo/Sample-CppWinRT-DispatcherQueue-build-regression@c1a7221 , no longer allow build this repository.

Reproducible example

#pragma once
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.System.h>
#include <dispatcherqueue.h>

// This code on a pre-compiled header file will no longer build.
inline winrt::fire_and_forget ShutdownAndThenPostQuitMessage(winrt::Windows::System::DispatcherQueueController const& controller, int exitCode)
{
    auto queue = controller.DispatcherQueue();
    co_await controller.ShutdownQueueAsync();
    co_await queue;
    PostQuitMessage(exitCode);
    co_return;
}

Expected behavior

The code should be able to build successfully.

Actual behavior

1>------ Build started: Project: TestBuildCppWinRT, Configuration: Debug x64 ------
1>pch.cpp
1>C:\prog\janeasystems\TestBuildCppWinRT\x64\Debug\Generated Files\winrt\impl\Windows.Graphics.Capture.0.h(27,12): error C3312: no callable 'await_resume' function found for type 'winrt::Windows::System::DispatcherQueue'
1>(compiling source file 'pch.cpp')
1>Done building project "TestBuildCppWinRT.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Additional comments

No response

@kennykerr
Copy link
Collaborator

This may be a change in C++/ADL rules/compliance. If you add using namespace winrt; it works.

If that's not suitable, you can use co_await winrt::resume_foreground(queue); explicitly.

@kennykerr
Copy link
Collaborator

cc @robmikh

@robmikh
Copy link
Member

robmikh commented Feb 13, 2024

Ah, thanks! I used the wil version in the past as a substitute, good to know it's still there in C++/WinRT. At some point I need to update those headers, but I've been spending most of my free time using Rust.

@sylveon
Copy link
Contributor

sylveon commented Feb 13, 2024

Worth pointing out that the wil version has some extra fixes that the cppwinrt one doesn't, as well as being the only one that works on WinUI 3.

@kennykerr
Copy link
Collaborator

but I've been spending most of my free time using Rust

Don't look back. 😏

@jaimecbernardo
Copy link
Author

Thank you. 😄
Ended up going with the same workaround as @robmikh : robmikh/Win32CaptureSample@fc758e3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants