2021-12-12 20:04:13 +00:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <string>
|
|
|
|
#include <winerror.h>
|
2023-06-12 02:51:49 +00:00
|
|
|
#include <winrt/base.h>
|
2021-12-12 20:04:13 +00:00
|
|
|
|
2022-04-12 19:27:28 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2021-12-12 20:04:13 +00:00
|
|
|
namespace Common
|
|
|
|
{
|
|
|
|
std::string GetHResultMessage(HRESULT hr);
|
|
|
|
|
|
|
|
// Wrapper for HRESULT to be used with fmt. Note that we can't create a fmt::formatter directly
|
|
|
|
// for HRESULT as HRESULT is simply a typedef on long and not a distinct type.
|
|
|
|
struct HRWrap
|
|
|
|
{
|
|
|
|
constexpr explicit HRWrap(HRESULT hr) : m_hr(hr) {}
|
|
|
|
const HRESULT m_hr;
|
|
|
|
};
|
|
|
|
} // namespace Common
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<Common::HRWrap>
|
|
|
|
{
|
|
|
|
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
|
|
|
|
template <typename FormatContext>
|
2022-01-13 01:16:29 +00:00
|
|
|
auto format(const Common::HRWrap& hr, FormatContext& ctx) const
|
2021-12-12 20:04:13 +00:00
|
|
|
{
|
|
|
|
return fmt::format_to(ctx.out(), "{} ({:#010x})", Common::GetHResultMessage(hr.m_hr),
|
|
|
|
static_cast<u32>(hr.m_hr));
|
|
|
|
}
|
|
|
|
};
|
2023-06-12 02:51:49 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct fmt::formatter<winrt::hresult>
|
|
|
|
{
|
|
|
|
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
|
|
|
|
template <typename FormatContext>
|
|
|
|
auto format(const winrt::hresult& hr, FormatContext& ctx) const
|
|
|
|
{
|
|
|
|
return fmt::format_to(ctx.out(), "{} ({:#010x})", Common::GetHResultMessage(hr), hr.value);
|
|
|
|
}
|
|
|
|
};
|