#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