4#include "Stroika/Foundation/StroikaPreComp.h"
6#if qStroika_Platform_Windows
10#error "WINDOWS REQUIRED FOR THIS MODULE"
14#include "Stroika/Foundation/Common/Common.h"
16#include "Stroika/Foundation/Containers/Common.h"
18#include "Stroika/Foundation/Execution/Platform/Windows/Exception.h"
21#include "HRESULTErrorException.h"
26using namespace Stroika::Foundation::Execution::Platform;
30 class HRESULT_error_category_ :
public error_category {
32 virtual const char* name () const noexcept
override
34 return "HRESULT error";
36 virtual error_condition default_error_condition ([[maybe_unused]]
int ev)
const noexcept override
38 if (HRESULT_CODE (ev) or ev == 0) {
40 return Win32_error_category ().default_error_condition (HRESULT_CODE (ev));
46 virtual bool equivalent (
int ev,
const error_condition& cond)
const noexcept override
48 if (HRESULT_CODE (ev) or ev == 0) {
49 return Win32_error_category ().equivalent (HRESULT_CODE (ev), cond);
51 return error_category::equivalent (ev, cond);
53 virtual string message (
int hr)
const override
59 return "E_ACCESSDENIED";
61 return "E_INVALIDARG";
63 return "E_NOINTERFACE";
70 case DISP_E_TYPEMISMATCH:
71 return "DISP_E_TYPEMISMATCH";
72 case DISP_E_EXCEPTION:
73 return "DISP_E_EXCEPTION";
74 case INET_E_RESOURCE_NOT_FOUND:
75 return "INET_E_RESOURCE_NOT_FOUND";
76 case REGDB_E_CLASSNOTREG:
77 return "REGDB_E_CLASSNOTREG";
79 if (HRESULT_FACILITY (hr) == FACILITY_WIN32) {
80 return Win32_error_category ().message (HRESULT_CODE (hr));
82 if (HRESULT_FACILITY (hr) == FACILITY_INTERNET) {
83 unsigned int wCode = HRESULT_CODE (hr);
84 if (wCode < INTERNET_ERROR_BASE) {
85 wCode += INTERNET_ERROR_BASE;
88 return Win32_error_category ().message (HRESULT_CODE (wCode));
91 (void)::snprintf (buf, std::size (buf),
"HRESULT error code: 0x%x", hr);
104 return Common::Immortalize<HRESULT_error_category_> ();