Skip to content

Commit 8f9d77b

Browse files
committed
Merge branch 'master' into user/dmachaj/no-loadlibrary
2 parents d7292ac + febda5d commit 8f9d77b

File tree

17 files changed

+56
-76
lines changed

17 files changed

+56
-76
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,6 @@ jobs:
373373
- name: Run nuget test
374374
run: |
375375
cmd /c "$env:VSDevCmd" "&" msbuild /m /clp:ForceConsoleColor "$env:msbuild_config_props" test\nuget\NugetTest.sln
376-
if ($LastExitCode -ne 0) {
377-
echo "::warning::nuget test failed"
378-
}
379-
# FIXME: This build was failing from the start
380-
exit 0
381376
382377
build-nuget:
383378
name: Build nuget package with MSVC

cppwinrt/code_writers.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,16 +1130,16 @@ namespace cppwinrt
11301130
{
11311131
// we intentionally ignore errors when unregistering event handlers to be consistent with event_revoker
11321132
//
1133-
// The `noexcept` versions will crash if check_cast_result throws but that is no different than previous
1133+
// The `noexcept` versions will crash if check_hresult throws but that is no different than previous
11341134
// behavior where it would not check the cast result and nullptr crash. At least the exception will terminate
11351135
// immediately while preserving the error code and local variables.
11361136
format = R"( template <typename D%> auto consume_%<D%>::%(%) const noexcept
11371137
{%
11381138
if constexpr (!std::is_same_v<D, %>)
11391139
{
1140-
auto const& castedResult = static_cast<% const&>(static_cast<D const&>(*this));
1140+
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1141+
check_hresult(code);
11411142
auto const abiType = *(abi_t<%>**)&castedResult;
1142-
check_cast_result(abiType);
11431143
abiType->%(%);
11441144
}
11451145
else
@@ -1156,9 +1156,9 @@ namespace cppwinrt
11561156
{%
11571157
if constexpr (!std::is_same_v<D, %>)
11581158
{
1159-
auto const& castedResult = static_cast<% const&>(static_cast<D const&>(*this));
1159+
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1160+
check_hresult(code);
11601161
auto const abiType = *(abi_t<%>**)&castedResult;
1161-
check_cast_result(abiType);
11621162
WINRT_VERIFY_(0, abiType->%(%));
11631163
}
11641164
else
@@ -1176,9 +1176,9 @@ namespace cppwinrt
11761176
{%
11771177
if constexpr (!std::is_same_v<D, %>)
11781178
{
1179-
auto const& castedResult = static_cast<% const&>(static_cast<D const&>(*this));
1179+
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1180+
check_hresult(code);
11801181
auto const abiType = *(abi_t<%>**)&castedResult;
1181-
check_cast_result(abiType);
11821182
check_hresult(abiType->%(%));
11831183
}
11841184
else

strings/base_error.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -538,27 +538,6 @@ namespace winrt::impl
538538
}
539539
return result;
540540
}
541-
542-
inline WINRT_IMPL_NOINLINE void check_cast_result(void* from, winrt::impl::slim_source_location const& sourceInformation = winrt::impl::slim_source_location::current())
543-
{
544-
if (!from)
545-
{
546-
com_ptr<impl::IRestrictedErrorInfo> restrictedError;
547-
if (WINRT_IMPL_GetRestrictedErrorInfo(restrictedError.put_void()) == 0)
548-
{
549-
WINRT_IMPL_SetRestrictedErrorInfo(restrictedError.get());
550-
551-
int32_t code;
552-
impl::bstr_handle description;
553-
impl::bstr_handle restrictedDescription;
554-
impl::bstr_handle capabilitySid;
555-
if (restrictedError->GetErrorDetails(description.put(), &code, restrictedDescription.put(), capabilitySid.put()) == 0)
556-
{
557-
throw hresult_error(code, take_ownership_from_abi, sourceInformation);
558-
}
559-
}
560-
}
561-
}
562541
}
563542

564543
#undef WINRT_IMPL_RETURNADDRESS

strings/base_extern.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ extern "C"
3232
int32_t __stdcall WINRT_IMPL_RoCaptureErrorContext(int32_t error) noexcept WINRT_IMPL_LINK(RoCaptureErrorContext, 4);
3333
void __stdcall WINRT_IMPL_RoFailFastWithErrorContext(int32_t) noexcept WINRT_IMPL_LINK(RoFailFastWithErrorContext, 4);
3434
int32_t __stdcall WINRT_IMPL_RoTransformError(int32_t, int32_t, void*) noexcept WINRT_IMPL_LINK(RoTransformError, 12);
35-
int32_t __stdcall WINRT_IMPL_GetRestrictedErrorInfo(void**) noexcept WINRT_IMPL_LINK(GetRestrictedErrorInfo, 4);
36-
int32_t __stdcall WINRT_IMPL_SetRestrictedErrorInfo(void*) noexcept WINRT_IMPL_LINK(SetRestrictedErrorInfo, 4);
3735

3836
#ifdef WINRT_REG_FREE
3937
void* __stdcall WINRT_IMPL_LoadLibraryExW(wchar_t const* name, void* unused, uint32_t flags) noexcept WINRT_IMPL_LINK(LoadLibraryExW, 12);

strings/base_implements.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,20 @@ namespace winrt::impl
792792
{
793793
return m_inner.operator bool();
794794
}
795+
796+
template <typename To, typename From>
797+
friend auto winrt::impl::try_as_with_reason(From ptr) noexcept;
798+
795799
protected:
796800
static constexpr bool is_composing = true;
797801
Windows::Foundation::IInspectable m_inner;
802+
803+
private:
804+
template <typename Qi>
805+
auto try_as_with_reason() const noexcept
806+
{
807+
return m_inner.try_as_with_reason<Qi>();
808+
}
798809
};
799810

800811
template <typename D, bool>

strings/base_windows.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,31 @@ namespace winrt::impl
128128
}
129129

130130
void* result{};
131-
hresult code = ptr->QueryInterface(guid_of<To>(), &result);
132-
if (code < 0)
131+
ptr->QueryInterface(guid_of<To>(), &result);
132+
return wrap_as_result<To>(result);
133+
}
134+
135+
template <typename To, typename From, std::enable_if_t<is_com_interface_v<To>, int> = 0>
136+
std::pair<com_ref<To>, hresult> try_as_with_reason(From* ptr) noexcept
137+
{
138+
#ifdef WINRT_DIAGNOSTICS
139+
get_diagnostics_info().add_query<To>();
140+
#endif
141+
142+
if (!ptr)
133143
{
134-
WINRT_IMPL_RoCaptureErrorContext(code);
144+
return { nullptr, 0 };
135145
}
136-
return wrap_as_result<To>(result);
146+
147+
void* result{};
148+
hresult code = ptr->QueryInterface(guid_of<To>(), &result);
149+
return { wrap_as_result<To>(result), code };
150+
}
151+
152+
template <typename To, typename From>
153+
auto try_as_with_reason(From ptr) noexcept
154+
{
155+
return ptr->template try_as_with_reason<To>();
137156
}
138157
}
139158

@@ -209,6 +228,12 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
209228
return impl::try_as<To>(m_ptr);
210229
}
211230

231+
template <typename To>
232+
auto try_as_with_reason() const noexcept
233+
{
234+
return impl::try_as_with_reason<To>(m_ptr);
235+
}
236+
212237
template <typename To>
213238
void as(To& to) const
214239
{

test/nuget/ConsoleApplication1/ConsoleApplication1.vcxproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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.201102.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.201102.2\build\native\Microsoft.Windows.CppWinRT.props')" />
43
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
54
<PropertyGroup Label="Globals">
65
<CppWinRTOptimized>true</CppWinRTOptimized>
@@ -54,7 +53,6 @@
5453
</ImportGroup>
5554
<ImportGroup Label="PropertySheets">
5655
<Import Project="PropertySheet.props" />
57-
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.201102.2\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.201102.2\build\native\Microsoft.Windows.CppWinRT.targets')" />
5856
</ImportGroup>
5957
<PropertyGroup Label="UserMacros" />
6058
<ItemDefinitionGroup>
@@ -121,11 +119,4 @@
121119
</ItemGroup>
122120
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
123121
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
124-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
125-
<PropertyGroup>
126-
<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>
127-
</PropertyGroup>
128-
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.201102.2\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.201102.2\build\native\Microsoft.Windows.CppWinRT.props'))" />
129-
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.201102.2\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.201102.2\build\native\Microsoft.Windows.CppWinRT.targets'))" />
130-
</Target>
131122
</Project>

test/nuget/ConsoleApplication1/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/nuget/TestRuntimeComponentCSharp/TestRuntimeComponentCSharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<AssemblyName>TestRuntimeComponentCSharp</AssemblyName>
1212
<DefaultLanguage>en-US</DefaultLanguage>
1313
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
14-
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
15-
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
14+
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.22621.0</TargetPlatformVersion>
15+
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
1616
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
1717
<FileAlignment>512</FileAlignment>
1818
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

test/nuget/TestRuntimeComponentNamespaceUnderscore/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)