Skip to content

Commit b82340f

Browse files
authored
Bug: Projected winrt::consume_ methods will nullptr crash if the underlying QueryInterface call fails (#1442)
# Why is this change being made? The generated projection code for interfaces that the metadata declares as required for a runtimeclass assume that QueryInterface never fails. Assuming the metadata is correct in the first place, this is a valid assumption for inproc calls. However, for cross-process calls the QI can fail even if the metadata is correct and the class really does implement all of the required interfaces. It can fail with E_ACCESSDENIED and a variety of other RPC error codes. When this happens there is a nullptr crash in the generated consume method. This can be very painful to debug because the HRESULT is lost by the time it crashes. # Briefly summarize what changed This set of changes fixes the crash by detecting the QueryInterface error and throwing an exception when that occurs during one of these required casts. The try_as method was changed to capture COM error context when the QI fails. The code gen surrounding WINRT_IMPL_STUB was changed to save the result into a temporary variable and then pass it to a new check_cast_result method. check_cast_result is marked noinline so that the binary size impact of throwing exceptions is limited to a single function instead of inlining into high-volume generated code. If the cast succeeded then nothing happens. If the cast failed, returning null, then the stored COM exception is retrieved. Assuming it is available the HRESULT is pulled out of it and it is thrown. This then propagates like any other exception. Callers are free to try and catch it or let it go uncaught and crash. Now they have the choice. I also added a new file of test code that exercises this code path. The test_component IDL declares a runtimeclass that implements IStringable. And then the implementation fails to implement IStringable. When ToString is called on this object it hits the failure path. The cppwinrt code gen will not allow this to happen so I had to directly use winrt::implements. # How was this change tested? Besides the new test cases I also wrote a little console app that crashes this way. I built and ran it using the latest stable cppwinrt as well as my private new one. As expected the debugger blame is far more useful with these changes.
1 parent 2744f5c commit b82340f

File tree

9 files changed

+106
-236
lines changed

9 files changed

+106
-236
lines changed

Diff for: cppwinrt.sln

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ EndProject
8888
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fast_fwd", "fast_fwd\fast_fwd.vcxproj", "{A63B3AD1-AB7B-461E-9FFF-2447F5BCD459}"
8989
EndProject
9090
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scratch", "scratch\scratch.vcxproj", "{E893622C-47DE-4F83-B422-0A26711590A4}"
91+
ProjectSection(ProjectDependencies) = postProject
92+
{D613FB39-5035-4043-91E2-BAB323908AF4} = {D613FB39-5035-4043-91E2-BAB323908AF4}
93+
EndProjectSection
9194
EndProject
9295
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_module_lock_none", "test\test_module_lock_none\test_module_lock_none.vcxproj", "{D48A96C2-8512-4CC3-B6E4-7CFF07ED8ED3}"
9396
ProjectSection(ProjectDependencies) = postProject

Diff for: cppwinrt/code_writers.h

+17-3
Original file line numberDiff line numberDiff line change
@@ -1129,17 +1129,27 @@ namespace cppwinrt
11291129
if (is_remove_overload(method))
11301130
{
11311131
// we intentionally ignore errors when unregistering event handlers to be consistent with event_revoker
1132+
//
1133+
// The `noexcept` versions will crash if check_cast_result throws but that is no different than previous
1134+
// behavior where it would not check the cast result and nullptr crash. At least the exception will terminate
1135+
// immediately while preserving the error code and local variables.
11321136
format = R"( template <typename D%> auto consume_%<D%>::%(%) const noexcept
11331137
{%
1134-
WINRT_IMPL_SHIM(%)->%(%);%
1138+
auto const& castedResult = static_cast<% const&>(static_cast<D const&>(*this));
1139+
auto const abiType = *(abi_t<%>**)&castedResult;
1140+
check_cast_result(abiType);
1141+
abiType->%(%);%
11351142
}
11361143
)";
11371144
}
11381145
else
11391146
{
11401147
format = R"( template <typename D%> auto consume_%<D%>::%(%) const noexcept
11411148
{%
1142-
WINRT_VERIFY_(0, WINRT_IMPL_SHIM(%)->%(%));%
1149+
auto const& castedResult = static_cast<% const&>(static_cast<D const&>(*this));
1150+
auto const abiType = *(abi_t<%>**)&castedResult;
1151+
check_cast_result(abiType);
1152+
WINRT_VERIFY_(0, abiType->%(%));%
11431153
}
11441154
)";
11451155
}
@@ -1148,7 +1158,10 @@ namespace cppwinrt
11481158
{
11491159
format = R"( template <typename D%> auto consume_%<D%>::%(%) const
11501160
{%
1151-
check_hresult(WINRT_IMPL_SHIM(%)->%(%));%
1161+
auto const& castedResult = static_cast<% const&>(static_cast<D const&>(*this));
1162+
auto const abiType = *(abi_t<%>**)&castedResult;
1163+
check_cast_result(abiType);
1164+
check_hresult(abiType->%(%));%
11521165
}
11531166
)";
11541167
}
@@ -1161,6 +1174,7 @@ namespace cppwinrt
11611174
bind<write_consume_params>(signature),
11621175
bind<write_consume_return_type>(signature, false),
11631176
type,
1177+
type,
11641178
get_abi_name(method),
11651179
bind<write_abi_args>(signature),
11661180
bind<write_consume_return_statement>(signature));

Diff for: scratch/scratch.vcxproj

+23-232
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\nuget\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\nuget\Microsoft.Windows.CppWinRT.props')" />
34
<ItemGroup Label="ProjectConfigurations">
45
<ProjectConfiguration Include="Debug|ARM">
56
<Configuration>Debug</Configuration>
@@ -35,277 +36,67 @@
3536
</ProjectConfiguration>
3637
</ItemGroup>
3738
<PropertyGroup Label="Globals">
39+
<CppWinRTOptimized>true</CppWinRTOptimized>
40+
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
41+
<CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata>
42+
<MinimalCoreWin>true</MinimalCoreWin>
3843
<VCProjectVersion>16.0</VCProjectVersion>
3944
<ProjectGuid>{E893622C-47DE-4F83-B422-0A26711590A4}</ProjectGuid>
4045
<RootNamespace>scratch</RootNamespace>
4146
<ProjectName>scratch</ProjectName>
42-
</PropertyGroup>
43-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
44-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
45-
<ConfigurationType>Application</ConfigurationType>
46-
<UseDebugLibraries>true</UseDebugLibraries>
47-
</PropertyGroup>
48-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
49-
<ConfigurationType>Application</ConfigurationType>
50-
<UseDebugLibraries>true</UseDebugLibraries>
51-
</PropertyGroup>
52-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
5347
<ConfigurationType>Application</ConfigurationType>
54-
<UseDebugLibraries>true</UseDebugLibraries>
48+
<!-- Not using the real nuget package so override-->
49+
<CppWinRTPackageDir>..\_build\$(Platform)\$(Configuration)</CppWinRTPackageDir>
50+
<CppWinRTPackage>false</CppWinRTPackage>
5551
</PropertyGroup>
56-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
57-
<ConfigurationType>Application</ConfigurationType>
58-
<UseDebugLibraries>false</UseDebugLibraries>
59-
<WholeProgramOptimization>true</WholeProgramOptimization>
60-
</PropertyGroup>
61-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
62-
<ConfigurationType>Application</ConfigurationType>
63-
<UseDebugLibraries>false</UseDebugLibraries>
64-
<WholeProgramOptimization>true</WholeProgramOptimization>
65-
</PropertyGroup>
66-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
67-
<ConfigurationType>Application</ConfigurationType>
68-
<UseDebugLibraries>false</UseDebugLibraries>
69-
<WholeProgramOptimization>true</WholeProgramOptimization>
70-
</PropertyGroup>
71-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
72-
<ConfigurationType>Application</ConfigurationType>
52+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
53+
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
7354
<UseDebugLibraries>true</UseDebugLibraries>
7455
</PropertyGroup>
75-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
76-
<ConfigurationType>Application</ConfigurationType>
56+
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
7757
<UseDebugLibraries>false</UseDebugLibraries>
7858
<WholeProgramOptimization>true</WholeProgramOptimization>
7959
</PropertyGroup>
8060
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
81-
<ImportGroup Label="ExtensionSettings">
82-
</ImportGroup>
83-
<ImportGroup Label="Shared">
84-
</ImportGroup>
85-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
87-
</ImportGroup>
88-
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="PropertySheets">
89-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
90-
</ImportGroup>
91-
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
92-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
93-
</ImportGroup>
94-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
95-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
96-
</ImportGroup>
97-
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="PropertySheets">
98-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
99-
</ImportGroup>
100-
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
101-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
102-
</ImportGroup>
103-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
105-
</ImportGroup>
106-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
107-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
108-
</ImportGroup>
109-
<PropertyGroup Label="UserMacros" />
110-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
111-
<ClCompile>
112-
<Optimization>MaxSpeed</Optimization>
113-
<FunctionLevelLinking>true</FunctionLevelLinking>
114-
<IntrinsicFunctions>true</IntrinsicFunctions>
115-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
116-
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
117-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
118-
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
119-
</ClCompile>
120-
<Link>
121-
<SubSystem>Console</SubSystem>
122-
<EnableCOMDATFolding>true</EnableCOMDATFolding>
123-
<OptimizeReferences>true</OptimizeReferences>
124-
</Link>
125-
<PreBuildEvent>
126-
<Command>
127-
</Command>
128-
</PreBuildEvent>
129-
<PostBuildEvent>
130-
<Command>
131-
</Command>
132-
</PostBuildEvent>
133-
</ItemDefinitionGroup>
134-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
135-
<ClCompile>
136-
<Optimization>Disabled</Optimization>
137-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
138-
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
139-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
140-
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
141-
</ClCompile>
142-
<Link>
143-
<SubSystem>Console</SubSystem>
144-
</Link>
145-
<PreBuildEvent>
146-
<Command>
147-
</Command>
148-
</PreBuildEvent>
149-
<PostBuildEvent>
150-
<Command>
151-
</Command>
152-
</PostBuildEvent>
153-
</ItemDefinitionGroup>
154-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
61+
<ItemDefinitionGroup>
15562
<ClCompile>
156-
<Optimization>Disabled</Optimization>
157-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
158-
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
159-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
160-
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
63+
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;</AdditionalIncludeDirectories>
16164
</ClCompile>
16265
<Link>
16366
<SubSystem>Console</SubSystem>
16467
</Link>
165-
<PreBuildEvent>
166-
<Command>
167-
</Command>
168-
</PreBuildEvent>
169-
<PostBuildEvent>
170-
<Command>
171-
</Command>
172-
</PostBuildEvent>
17368
</ItemDefinitionGroup>
174-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
175-
<ClCompile>
176-
<Optimization>Disabled</Optimization>
177-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
178-
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
179-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
180-
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
181-
</ClCompile>
182-
<Link>
183-
<SubSystem>Console</SubSystem>
184-
</Link>
185-
<PreBuildEvent>
186-
<Command>
187-
</Command>
188-
</PreBuildEvent>
189-
<PostBuildEvent>
190-
<Command>
191-
</Command>
192-
</PostBuildEvent>
193-
</ItemDefinitionGroup>
194-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
195-
<ClCompile>
196-
<Optimization>Disabled</Optimization>
197-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
198-
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
199-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
200-
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
201-
</ClCompile>
202-
<Link>
203-
<SubSystem>Console</SubSystem>
204-
</Link>
205-
<PreBuildEvent>
206-
<Command>
207-
</Command>
208-
</PreBuildEvent>
209-
<PostBuildEvent>
210-
<Command>
211-
</Command>
212-
</PostBuildEvent>
213-
</ItemDefinitionGroup>
214-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
69+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
21570
<ClCompile>
21671
<Optimization>MaxSpeed</Optimization>
21772
<FunctionLevelLinking>true</FunctionLevelLinking>
21873
<IntrinsicFunctions>true</IntrinsicFunctions>
219-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
22074
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
221-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
22275
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
22376
</ClCompile>
22477
<Link>
225-
<SubSystem>Console</SubSystem>
22678
<EnableCOMDATFolding>true</EnableCOMDATFolding>
22779
<OptimizeReferences>true</OptimizeReferences>
22880
</Link>
229-
<PreBuildEvent>
230-
<Command>
231-
</Command>
232-
</PreBuildEvent>
233-
<PostBuildEvent>
234-
<Command>
235-
</Command>
236-
</PostBuildEvent>
23781
</ItemDefinitionGroup>
238-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
82+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
23983
<ClCompile>
240-
<Optimization>MaxSpeed</Optimization>
241-
<FunctionLevelLinking>true</FunctionLevelLinking>
242-
<IntrinsicFunctions>true</IntrinsicFunctions>
243-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
244-
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
245-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
246-
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
247-
</ClCompile>
248-
<Link>
249-
<SubSystem>Console</SubSystem>
250-
<EnableCOMDATFolding>true</EnableCOMDATFolding>
251-
<OptimizeReferences>true</OptimizeReferences>
252-
</Link>
253-
<PreBuildEvent>
254-
<Command>
255-
</Command>
256-
</PreBuildEvent>
257-
<PostBuildEvent>
258-
<Command>
259-
</Command>
260-
</PostBuildEvent>
261-
</ItemDefinitionGroup>
262-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
263-
<ClCompile>
264-
<Optimization>MaxSpeed</Optimization>
265-
<FunctionLevelLinking>true</FunctionLevelLinking>
266-
<IntrinsicFunctions>true</IntrinsicFunctions>
267-
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\..\..\library</AdditionalIncludeDirectories>
268-
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
269-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
270-
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
84+
<Optimization>Disabled</Optimization>
85+
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
86+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
27187
</ClCompile>
272-
<Link>
273-
<SubSystem>Console</SubSystem>
274-
<EnableCOMDATFolding>true</EnableCOMDATFolding>
275-
<OptimizeReferences>true</OptimizeReferences>
276-
</Link>
277-
<PreBuildEvent>
278-
<Command>
279-
</Command>
280-
</PreBuildEvent>
281-
<PostBuildEvent>
282-
<Command>
283-
</Command>
284-
</PostBuildEvent>
28588
</ItemDefinitionGroup>
28689
<ItemGroup>
28790
<ClCompile Include="main.cpp">
288-
<PrecompiledHeader>NotUsing</PrecompiledHeader>
289-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
290-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Use</PrecompiledHeader>
291-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Use</PrecompiledHeader>
292-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
293-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Use</PrecompiledHeader>
294-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Use</PrecompiledHeader>
295-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
296-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
91+
<PrecompiledHeader>Use</PrecompiledHeader>
29792
</ClCompile>
29893
<ClCompile Include="pch.cpp">
299-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
300-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Create</PrecompiledHeader>
301-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Create</PrecompiledHeader>
302-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
303-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Create</PrecompiledHeader>
304-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Create</PrecompiledHeader>
305-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
306-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
94+
<PrecompiledHeader>Create</PrecompiledHeader>
30795
</ClCompile>
30896
</ItemGroup>
97+
<ImportGroup Label="ExtensionTargets">
98+
<Import Project="..\nuget\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\nuget\Microsoft.Windows.CppWinRT.targets')" />
99+
</ImportGroup>
309100
<ItemGroup>
310101
<ClInclude Include="pch.h" />
311102
</ItemGroup>

Diff for: strings/base_error.h

+22
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,28 @@ namespace winrt::impl
546546
}
547547
return result;
548548
}
549+
550+
template <typename T>
551+
WINRT_IMPL_NOINLINE void check_cast_result(T* from WINRT_IMPL_SOURCE_LOCATION_ARGS)
552+
{
553+
if (!from)
554+
{
555+
com_ptr<impl::IRestrictedErrorInfo> restrictedError;
556+
if (WINRT_IMPL_GetRestrictedErrorInfo(restrictedError.put_void()) == 0)
557+
{
558+
WINRT_IMPL_SetRestrictedErrorInfo(restrictedError.get());
559+
560+
int32_t code;
561+
impl::bstr_handle description;
562+
impl::bstr_handle restrictedDescription;
563+
impl::bstr_handle capabilitySid;
564+
if (restrictedError->GetErrorDetails(description.put(), &code, restrictedDescription.put(), capabilitySid.put()) == 0)
565+
{
566+
throw hresult_error(code, take_ownership_from_abi WINRT_IMPL_SOURCE_LOCATION_FORWARD);
567+
}
568+
}
569+
}
570+
}
549571
}
550572

551573
#undef WINRT_IMPL_RETURNADDRESS

0 commit comments

Comments
 (0)