Skip to content

Commit

Permalink
Allow base::WinRT::TryCreateInstance on Win7.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 22, 2022
1 parent a4a53db commit 2bd3ac7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions base/platform/win/base_windows_winrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ using TryResult = std::conditional_t<
[[nodiscard]] bool Supported();

template <typename Method>
inline details::TryResult<Method> Try(Method &&method) noexcept {
if (!Supported()) {
return {};
} else try {
inline details::TryResult<Method> TryNoCheck(Method &&method) noexcept {
try {
if constexpr (details::ReturnsVoid<Method>) {
method();
return true;
Expand All @@ -56,12 +54,20 @@ inline details::TryResult<Method> Try(Method &&method) noexcept {
}
}

template <typename Method>
inline details::TryResult<Method> Try(Method &&method) noexcept {
if (!Supported()) {
return {};
}
return TryNoCheck(std::forward<Method>(method));
}

template <typename Interface>
auto TryCreateInstance(
const winrt::guid &clsid,
uint32_t context = 0x1 /*CLSCTX_INPROC_SERVER*/,
void *outer = nullptr) {
return Try([&] {
return TryNoCheck([&] {
return winrt::create_instance<Interface>(clsid, context, outer);
}).value_or(winrt::com_ptr<Interface>());
}
Expand Down

0 comments on commit 2bd3ac7

Please sign in to comment.