簡體   English   中英

WinUI3/Desktop/C++: 無法編譯 winrt::resume_foreground(Microsoft::System::DispatcherQueue const& dispatcher)

[英]WinUI3/Desktop/C++: Can't compile winrt::resume_foreground(Microsoft::System::DispatcherQueue const& dispatcher)

我想使用:

co_await winrt::resume_foreground(window.DispatcherQueue());

(“窗口”的類型是:“winrt::Microsoft::UI::Xaml::Window”)

但我無法編譯它,因為

winrt::resume_foreground(Microsoft::System::DispatcherQueue const& dispatcher)

沒有定義。

我不能包含包含 DispatcherQueue 類的#include <winrt/Microsoft.System.h>

我的環境:
Windows 10 專業版,21H1,19043.1083
Visual Studio 社區 2019 (16.10.3)
Visual Studio 擴展:Project Reunion 版本 0.8.0.46122163
項目模板:C++,空白應用程序,打包(桌面版 WinUI 3)

為了重現錯誤,我使用了上面的項目模板並將以下方法添加到“App”類。

應用程序.xaml.h

winrt::Windows::Foundation::IAsyncAction foo();

應用程序.xaml.cpp

winrt::Windows::Foundation::IAsyncAction App::foo()
{
    co_await winrt::resume_foreground(window.DispatcherQueue());
}

我收到錯誤消息:

D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,21): error C2039: 'resume_foreground': is not a member of 'winrt'
1>D:\Solution\WinUi3 Test\WinUi3 Test\MainWindow.xaml.h(23): message : see declaration of 'winrt'
1>D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,38): error C3861: 'resume_foreground': identifier not found
1>Done building project "WinUi3 Test.vcxproj" -- FAILED.

如果我嘗試包含#include <winrt/Microsoft.System.h>我得到:

1>D:\Solution\WinUi3 Test\WinUi3 Test\pch.h(25,10): fatal error C1083: Cannot open include file: 'winrt/Microsoft.System.h': No such file or directory
1>Done building project "WinUi3 Test.vcxproj" -- FAILED.

如果我包含#include <winrt/Windows.System.h>#include <winrt/Windows.UI.Core.h>我得到:

1>D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,63): error C2665: 'winrt::resume_foreground': none of the 2 overloads could convert all the argument types
1>D:\Solution\WinUi3 Test\WinUi3 Test\Generated Files\winrt\Windows.UI.Core.h(2805,31): message : could be 'winrt::resume_foreground::awaitable winrt::resume_foreground(const winrt::Windows::UI::Core::CoreDispatcher &,const winrt::Windows::UI::Core::CoreDispatcherPriority) noexcept' (compiling source file App.xaml.cpp)
1>D:\Solution\WinUi3 Test\WinUi3 Test\Generated Files\winrt\Windows.System.h(4529,31): message : or       'winrt::resume_foreground::awaitable winrt::resume_foreground(const winrt::Windows::System::DispatcherQueue &,const winrt::Windows::System::DispatcherQueuePriority) noexcept' (compiling source file App.xaml.cpp)
1>D:\Solution\WinUi3 Test\WinUi3 Test\App.xaml.cpp(50,63): message : while trying to match the argument list '(winrt::Microsoft::UI::Dispatching::DispatcherQueue)'
1>Done building project "WinUi3 Test.vcxproj" -- FAILED.

包括

#include <winrt/Microsoft.UI.Dispatching.h>
#include <Microsoft.UI.Dispatching.co_await.h>

從 0.8.0 預覽版更新到 0.8.0 時,命名空間從Microsoft.System更改為Microsoft.UI.Dispatching並且resume_foreground現在在Microsoft.UI.Dispatching.co_await.h定義。

Markus 的回答在 WinUI3 1.0 版本中對我不起作用,因為Microsoft.UI.Dispatching.co_await.h頭文件不存在。 但是,以下確實有效:

#include <wil/cppwinrt.h>
#include <wil/cppwinrt_helpers.h>

co_await wil::resume_foreground(DispatcherQueue());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM