Plasma Engine  2.0
Loading...
Searching...
No Matches
HResultUtils.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Basics/Platform/Win/MinWindows.h>
5#include <Foundation/Strings/String.h>
6
8PL_FOUNDATION_DLL plString plHRESULTtoString(plMinWindows::HRESULT result);
9
11PL_ALWAYS_INLINE plResult plToResult(plMinWindows::HRESULT result)
12{
13 return result >= 0 ? PL_SUCCESS : PL_FAILURE;
14}
15
16#define PL_HRESULT_TO_FAILURE(code) \
17 do \
18 { \
19 plMinWindows::HRESULT s = (code); \
20 if (s < 0) \
21 return PL_FAILURE; \
22 } while (false)
23
24#define PL_HRESULT_TO_FAILURE_LOG(code) \
25 do \
26 { \
27 plMinWindows::HRESULT s = (code); \
28 if (s < 0) \
29 { \
30 plLog::Error("Call '{0}' failed with: {1}", PL_PP_STRINGIFY(code), plHRESULTtoString(s)); \
31 return PL_FAILURE; \
32 } \
33 } while (false)
34
35#define PL_HRESULT_TO_LOG(code) \
36 do \
37 { \
38 plMinWindows::HRESULT s = (code); \
39 if (s < 0) \
40 { \
41 plLog::Error("Call '{0}' failed with: {1}", PL_PP_STRINGIFY(code), plHRESULTtoString(s)); \
42 } \
43 } while (false)
44
45#define PL_NO_RETURNVALUE
46
47#define PL_HRESULT_TO_LOG_RET(code, ret) \
48 do \
49 { \
50 plMinWindows::HRESULT s = (code); \
51 if (s < 0) \
52 { \
53 plLog::Error("Call '{0}' failed with: {1}", PL_PP_STRINGIFY(code), plHRESULTtoString(s)); \
54 return ret; \
55 } \
56 } while (false)
57
58#define PL_HRESULT_TO_ASSERT(code) \
59 do \
60 { \
61 plMinWindows::HRESULT s = (code); \
62 PL_ASSERT_DEV(s >= 0, "Call '{0}' failed with: {1}", PL_PP_STRINGIFY(code), plHRESULTtoString(s)); \
63 } while (false)
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54