Skip to content

Commit 830f854

Browse files
authored
Update C++ samples to use Visual Studio 2022, Platform Toolset v143, and the latest C++/WinRT (#109)
* Update AdvancedColorImages (cpp) * Update HelloComposition (cpp) * Update HelloVectors (cpp) * Update ScreenCaptureforHWND (cpp) * Update VirtualSurfaces (cpp) * Fix null deref in VisualLayerIntegration (dotnet wpf) * Use "latest" SDK for cpp projects * Update cpp READMEs * Fix accidental move of header file * update to latest C++/WinRT version
1 parent 9e9c23c commit 830f854

26 files changed

Lines changed: 172 additions & 127 deletions

cpp/AdvancedColorImages/AdvancedColorImages/AdvancedColorImages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
141141
{
142142
return FALSE;
143143
}
144-
m_winComp = new WinComp();
144+
m_winComp = winrt::make_self<WinComp>().detach();
145145
// Ensure that the DispatcherQueue is initialized. This is required by the Compositor.
146146
auto controller = m_winComp->EnsureDispatcherQueue();
147147

cpp/AdvancedColorImages/AdvancedColorImages/AdvancedColorImages.vcxproj

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props')" />
34
<ItemGroup Label="ProjectConfigurations">
45
<ProjectConfiguration Include="Debug|Win32">
56
<Configuration>Debug</Configuration>
@@ -23,32 +24,32 @@
2324
<ProjectGuid>{740EF6CC-CDDA-4413-8D66-FF32C113F077}</ProjectGuid>
2425
<Keyword>Win32Proj</Keyword>
2526
<RootNamespace>AdvancedColorImages</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
27+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2728
</PropertyGroup>
2829
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2930
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3031
<ConfigurationType>Application</ConfigurationType>
3132
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v142</PlatformToolset>
33+
<PlatformToolset>v143</PlatformToolset>
3334
<CharacterSet>Unicode</CharacterSet>
3435
</PropertyGroup>
3536
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3637
<ConfigurationType>Application</ConfigurationType>
3738
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v142</PlatformToolset>
39+
<PlatformToolset>v143</PlatformToolset>
3940
<WholeProgramOptimization>true</WholeProgramOptimization>
4041
<CharacterSet>Unicode</CharacterSet>
4142
</PropertyGroup>
4243
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4344
<ConfigurationType>Application</ConfigurationType>
4445
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v141</PlatformToolset>
46+
<PlatformToolset>v143</PlatformToolset>
4647
<CharacterSet>Unicode</CharacterSet>
4748
</PropertyGroup>
4849
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4950
<ConfigurationType>Application</ConfigurationType>
5051
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v142</PlatformToolset>
52+
<PlatformToolset>v143</PlatformToolset>
5253
<WholeProgramOptimization>true</WholeProgramOptimization>
5354
<CharacterSet>Unicode</CharacterSet>
5455
</PropertyGroup>
@@ -104,7 +105,7 @@
104105
<SDLCheck>true</SDLCheck>
105106
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106107
<ConformanceMode>true</ConformanceMode>
107-
<LanguageStandard>stdcpplatest</LanguageStandard>
108+
<LanguageStandard>stdcpp17</LanguageStandard>
108109
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
109110
</ClCompile>
110111
<Link>
@@ -180,8 +181,17 @@
180181
</ItemGroup>
181182
<ItemGroup>
182183
<None Include="hdr-image.jxr" />
184+
<None Include="packages.config" />
183185
</ItemGroup>
184186
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
185187
<ImportGroup Label="ExtensionTargets">
188+
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
186189
</ImportGroup>
190+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
191+
<PropertyGroup>
192+
<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>
193+
</PropertyGroup>
194+
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
195+
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
196+
</Target>
187197
</Project>

cpp/AdvancedColorImages/AdvancedColorImages/AdvancedColorImages.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@
7474
<None Include="hdr-image.jxr">
7575
<Filter>Resource Files</Filter>
7676
</None>
77+
<None Include="packages.config" />
7778
</ItemGroup>
7879
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Windows.CppWinRT" version="2.0.221121.5" targetFramework="native" />
4+
</packages>

cpp/AdvancedColorImages/AdvancedColorImages/stdafx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <ppltasks.h>
2020

2121

22+
#include <winrt/Windows.Foundation.h>
23+
#include <winrt/Windows.Foundation.Collections.h>
2224
#include <winrt/Windows.System.h>
2325
#include <winrt/Windows.Storage.h>
2426
#include <winrt/Windows.Storage.Streams.h>
@@ -31,8 +33,6 @@
3133
#include <winrt/Windows.Graphics.DirectX.h>
3234
#include <winrt/Windows.Web.Syndication.h>
3335

34-
WINRT_WARNING_PUSH
35-
3636
#include <dxgi1_6.h>
3737
#include <d2d1_3.h>
3838
#include <d3d11_3.h>

cpp/AdvancedColorImages/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This sample includes the following features:
2626

2727
This sample requires:
2828

29-
- Visual Studio 2017 or later - [Get a free copy of Visual Studio](http://go.microsoft.com/fwlink/?LinkID=280676)
29+
- Visual Studio 2022 or later - [Get a free copy of Visual Studio](http://go.microsoft.com/fwlink/?LinkID=280676)
3030
- Windows 10 version 1903 or later
3131
- Windows 10 SDK 18362 or later - [Get the SDK](https://developer.microsoft.com/windows/downloads/windows-10-sdk)
3232

cpp/HelloComposition/HelloComposition/HelloComposition.vcxproj

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props')" />
34
<ItemGroup Label="ProjectConfigurations">
45
<ProjectConfiguration Include="Debug|Win32">
56
<Configuration>Debug</Configuration>
@@ -23,32 +24,32 @@
2324
<ProjectGuid>{3719BE61-52D1-4F42-8A4C-E575BA16E65F}</ProjectGuid>
2425
<Keyword>Win32Proj</Keyword>
2526
<RootNamespace>HelloComposition</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
27+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2728
</PropertyGroup>
2829
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2930
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3031
<ConfigurationType>Application</ConfigurationType>
3132
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v141</PlatformToolset>
33+
<PlatformToolset>v143</PlatformToolset>
3334
<CharacterSet>Unicode</CharacterSet>
3435
</PropertyGroup>
3536
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3637
<ConfigurationType>Application</ConfigurationType>
3738
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v141</PlatformToolset>
39+
<PlatformToolset>v143</PlatformToolset>
3940
<WholeProgramOptimization>true</WholeProgramOptimization>
4041
<CharacterSet>Unicode</CharacterSet>
4142
</PropertyGroup>
4243
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4344
<ConfigurationType>Application</ConfigurationType>
4445
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v141</PlatformToolset>
46+
<PlatformToolset>v143</PlatformToolset>
4647
<CharacterSet>Unicode</CharacterSet>
4748
</PropertyGroup>
4849
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4950
<ConfigurationType>Application</ConfigurationType>
5051
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v141</PlatformToolset>
52+
<PlatformToolset>v143</PlatformToolset>
5253
<WholeProgramOptimization>true</WholeProgramOptimization>
5354
<CharacterSet>Unicode</CharacterSet>
5455
</PropertyGroup>
@@ -183,7 +184,18 @@
183184
<Image Include="HelloComposition.ico" />
184185
<Image Include="small.ico" />
185186
</ItemGroup>
187+
<ItemGroup>
188+
<None Include="packages.config" />
189+
</ItemGroup>
186190
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
187191
<ImportGroup Label="ExtensionTargets">
192+
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
188193
</ImportGroup>
194+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
195+
<PropertyGroup>
196+
<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>
197+
</PropertyGroup>
198+
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
199+
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
200+
</Target>
189201
</Project>

cpp/HelloComposition/HelloComposition/HelloComposition.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@
5858
<Filter>Resource Files</Filter>
5959
</Image>
6060
</ItemGroup>
61+
<ItemGroup>
62+
<None Include="packages.config" />
63+
</ItemGroup>
6164
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Windows.CppWinRT" version="2.0.221121.5" targetFramework="native" />
4+
</packages>

cpp/HelloComposition/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This sample includes the following features:
1919

2020
This sample requires:
2121

22-
- Visual Studio 2017 or later - [Get a free copy of Visual Studio](http://go.microsoft.com/fwlink/?LinkID=280676)
22+
- Visual Studio 2022 or later - [Get a free copy of Visual Studio](http://go.microsoft.com/fwlink/?LinkID=280676)
2323
- .NET Framework 4.7.2 or later
2424
- Windows 10 version 1803 or later
2525
- Windows 10 SDK 17134 or later

0 commit comments

Comments
 (0)