diff --git a/Win32CaptureSample/App.cpp b/Win32CaptureSample/App.cpp index d56ecf6..9c46d42 100644 --- a/Win32CaptureSample/App.cpp +++ b/Win32CaptureSample/App.cpp @@ -102,7 +102,7 @@ winrt::IAsyncOperation App::StartCaptureWithPickerAs // a DispatcherQueue. See CaptureSnapshot for an example that uses // Direct3D11CaptureFramePool::CreateFreeThreaded, which doesn't now have this // requirement. See the README if you're unsure of which version of 'Create' to use. - co_await m_mainThread; + co_await wil::resume_foreground(m_mainThread); StartCaptureFromItem(item); } @@ -158,7 +158,7 @@ winrt::IAsyncOperation App::TakeSnapshotAsync() else { // Unsupported - co_await m_mainThread; + co_await wil::resume_foreground(m_mainThread); MessageBoxW(nullptr, L"Unsupported file format!", L"Win32CaptureSample", diff --git a/Win32CaptureSample/Win32CaptureSample.vcxproj b/Win32CaptureSample/Win32CaptureSample.vcxproj index 44564fc..ead304e 100644 --- a/Win32CaptureSample/Win32CaptureSample.vcxproj +++ b/Win32CaptureSample/Win32CaptureSample.vcxproj @@ -1,6 +1,6 @@ - + Debug @@ -152,6 +152,7 @@ + @@ -163,17 +164,17 @@ - - - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - + + + + \ No newline at end of file diff --git a/Win32CaptureSample/dispatcherqueue.desktop.interop.h b/Win32CaptureSample/dispatcherqueue.desktop.interop.h new file mode 100644 index 0000000..f968ee2 --- /dev/null +++ b/Win32CaptureSample/dispatcherqueue.desktop.interop.h @@ -0,0 +1,47 @@ +#pragma once +#include +#include +#include + +namespace robmikh::common::desktop +{ + namespace impl + { + inline void ShutdownAndThenPostQuitMessage(winrt::Windows::System::DispatcherQueueController const& controller, int exitCode) + { + auto action = controller.ShutdownQueueAsync(); + action.Completed([exitCode](auto&&, auto&&) + { + PostQuitMessage(exitCode); + }); + } + } + + inline auto CreateDispatcherQueueControllerForCurrentThread() + { + namespace abi = ABI::Windows::System; + + DispatcherQueueOptions options + { + sizeof(DispatcherQueueOptions), + DQTYPE_THREAD_CURRENT, + DQTAT_COM_NONE + }; + + winrt::Windows::System::DispatcherQueueController controller{ nullptr }; + winrt::check_hresult(CreateDispatcherQueueController(options, reinterpret_cast(winrt::put_abi(controller)))); + return controller; + } + + inline int ShutdownDispatcherQueueControllerAndWait(winrt::Windows::System::DispatcherQueueController const& controller, int exitCode) + { + impl::ShutdownAndThenPostQuitMessage(controller, exitCode); + MSG msg = {}; + while (GetMessageW(&msg, nullptr, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + return static_cast(msg.wParam); + } +} \ No newline at end of file diff --git a/Win32CaptureSample/packages.config b/Win32CaptureSample/packages.config index 4b0a8ab..2509606 100644 --- a/Win32CaptureSample/packages.config +++ b/Win32CaptureSample/packages.config @@ -1,6 +1,6 @@  - - - + + + \ No newline at end of file diff --git a/Win32CaptureSample/pch.h b/Win32CaptureSample/pch.h index 3fef2cf..588fb97 100644 --- a/Win32CaptureSample/pch.h +++ b/Win32CaptureSample/pch.h @@ -46,6 +46,7 @@ // WIL #include +#include // Helpers #include @@ -54,7 +55,9 @@ #include #include #include -#include +// robmikh.common needs to be updated to support newer versions of C++/WinRT +//#include +#include "dispatcherqueue.desktop.interop.h" #include #include #include