aboutsummaryrefslogtreecommitdiff
path: root/dxcommon/include
diff options
context:
space:
mode:
authormarsunet <marc.sunet@amd.com>2021-12-21 17:04:22 -0800
committermarsunet <marc.sunet@amd.com>2021-12-21 17:04:22 -0800
commitfba8184491e0b7ae6fab7ac01b4600d230dc4569 (patch)
treec13194764867a4ad8f46702356b22dccc1e56dd3 /dxcommon/include
parent8b1583b65d77188ef35a89e75f145f29c3e3b5d7 (diff)
Initial commit with window demo.HEADmain
Diffstat (limited to 'dxcommon/include')
-rw-r--r--dxcommon/include/dxcommon.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/dxcommon/include/dxcommon.h b/dxcommon/include/dxcommon.h
new file mode 100644
index 0000000..0270629
--- /dev/null
+++ b/dxcommon/include/dxcommon.h
@@ -0,0 +1,55 @@
1#pragma once
2
3#include <wrl.h>
4
5#include <stdexcept>
6
7//#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), static_cast<void**>(ppType)
8
9namespace dx {
10
11using Microsoft::WRL::ComPtr;
12
13class exception : public std::exception {
14public:
15 exception() noexcept {}
16
17 exception(HRESULT result, const char* file, int line) noexcept
18 {
19 sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X",
20 file, line, static_cast<unsigned int>(result));
21 }
22
23 exception(const char* error, const char* file, int line) noexcept
24 {
25 sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error);
26 }
27
28 const char* what() const noexcept
29 {
30 return m_error;
31 }
32
33private:
34 static char m_error[1024];
35};
36
37#define THROW(error) throw exception(error, __FILE__, __LINE__)
38
39#define ThrowIfFailed(result) {\
40 if (result != S_OK) {\
41 THROW(result);\
42 }\
43}
44
45template <typename T>
46void SafeRelease(ComPtr<T>& ptr)
47{
48 if (ptr)
49 {
50 ptr->Release();
51 ptr = nullptr;
52 }
53}
54
55} // dx