From fba8184491e0b7ae6fab7ac01b4600d230dc4569 Mon Sep 17 00:00:00 2001 From: marsunet Date: Tue, 21 Dec 2021 17:04:22 -0800 Subject: Initial commit with window demo. --- dxcommon/include/dxcommon.h | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 dxcommon/include/dxcommon.h (limited to 'dxcommon/include') 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 @@ +#pragma once + +#include + +#include + +//#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), static_cast(ppType) + +namespace dx { + +using Microsoft::WRL::ComPtr; + +class exception : public std::exception { +public: + exception() noexcept {} + + exception(HRESULT result, const char* file, int line) noexcept + { + sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X", + file, line, static_cast(result)); + } + + exception(const char* error, const char* file, int line) noexcept + { + sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error); + } + + const char* what() const noexcept + { + return m_error; + } + +private: + static char m_error[1024]; +}; + +#define THROW(error) throw exception(error, __FILE__, __LINE__) + +#define ThrowIfFailed(result) {\ + if (result != S_OK) {\ + THROW(result);\ + }\ +} + +template +void SafeRelease(ComPtr& ptr) +{ + if (ptr) + { + ptr->Release(); + ptr = nullptr; + } +} + +} // dx -- cgit v1.2.3