Skip to content

Commit

Permalink
update C++/WinRT
Browse files Browse the repository at this point in the history
  • Loading branch information
robmikh committed Dec 27, 2023
1 parent d5c1afb commit fc758e3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Win32CaptureSample/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ winrt::IAsyncOperation<winrt::GraphicsCaptureItem> 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);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ winrt::IAsyncOperation<winrt::StorageFile> App::TakeSnapshotAsync()
else
{
// Unsupported
co_await m_mainThread;
co_await wil::resume_foreground(m_mainThread);
MessageBoxW(nullptr,
L"Unsupported file format!",
L"Win32CaptureSample",
Expand Down
17 changes: 9 additions & 8 deletions Win32CaptureSample/Win32CaptureSample.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -152,6 +152,7 @@
<ItemGroup>
<ClInclude Include="App.h" />
<ClInclude Include="CaptureSnapshot.h" />
<ClInclude Include="dispatcherqueue.desktop.interop.h" />
<ClInclude Include="MonitorList.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="SampleWindow.h" />
Expand All @@ -163,17 +164,17 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\packages\robmikh.common.0.0.15-beta\build\native\robmikh.common.targets" Condition="Exists('..\packages\robmikh.common.0.0.15-beta\build\native\robmikh.common.targets')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\packages\robmikh.common.0.0.22-beta\build\native\robmikh.common.targets" Condition="Exists('..\packages\robmikh.common.0.0.22-beta\build\native\robmikh.common.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('..\packages\robmikh.common.0.0.15-beta\build\native\robmikh.common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\robmikh.common.0.0.15-beta\build\native\robmikh.common.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('..\packages\robmikh.common.0.0.22-beta\build\native\robmikh.common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\robmikh.common.0.0.22-beta\build\native\robmikh.common.targets'))" />
</Target>
</Project>
47 changes: 47 additions & 0 deletions Win32CaptureSample/dispatcherqueue.desktop.interop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.System.h>
#include <dispatcherqueue.h>

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<abi::IDispatcherQueueController**>(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<int>(msg.wParam);
}
}
6 changes: 3 additions & 3 deletions Win32CaptureSample/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.CppWinRT" version="2.0.220418.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
<package id="robmikh.common" version="0.0.15-beta" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.231216.1" targetFramework="native" />
<package id="robmikh.common" version="0.0.22-beta" targetFramework="native" />
</packages>
5 changes: 4 additions & 1 deletion Win32CaptureSample/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

// WIL
#include <wil/resource.h>
#include <wil/cppwinrt_helpers.h>

// Helpers
#include <robmikh.common/composition.interop.h>
Expand All @@ -54,7 +55,9 @@
#include <robmikh.common/d3dHelpers.desktop.h>
#include <robmikh.common/direct3d11.interop.h>
#include <robmikh.common/capture.desktop.interop.h>
#include <robmikh.common/dispatcherqueue.desktop.interop.h>
// robmikh.common needs to be updated to support newer versions of C++/WinRT
//#include <robmikh.common/dispatcherqueue.desktop.interop.h>
#include "dispatcherqueue.desktop.interop.h"
#include <robmikh.common/stream.interop.h>
#include <robmikh.common/hwnd.interop.h>
#include <robmikh.common/ControlsHelper.h>

0 comments on commit fc758e3

Please sign in to comment.