#pragma once #if defined(_WIN32) # include # include # include # include # include namespace MFUtils { template using TComPtr = Microsoft::WRL::ComPtr<_Ty>; template inline TComPtr<_Ty> MakeComPtr() { TComPtr<_Ty> obj; _Ty** ppv = &obj; *ppv = new _Ty(); return obj; } template inline TComPtr<_Ty> MakeComPtr(_Types&&... args) { TComPtr<_Ty> obj; _Ty** ppv = &obj; *ppv = new _Ty(std::forward<_Types>(args)...); return obj; } template inline TComPtr<_Ty> ReferencedPtrToComPtr(_Ty* ptr) { TComPtr<_Ty> obj; _Ty** ppv = &obj; *ppv = ptr; return obj; } template inline HRESULT CreateInstance(REFCLSID clsid, Microsoft::WRL::ComPtr& ptr) { // ASSERT(!ptr); return CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, __uuidof(T), reinterpret_cast(ptr.GetAddressOf())); } HRESULT InitializeMFOnce(); std::string_view GetVideoTypeName(const GUID& SubType); } // namespace MFUtils namespace DX { // Helper class for COM exceptions class com_exception : public std::exception { public: com_exception(HRESULT hr) noexcept : result(hr) {} const char* what() const override { static char s_str[64] = {}; sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast(result)); return s_str; } private: HRESULT result; }; // Helper utility converts D3D API failures into exceptions. inline void ThrowIfFailed(HRESULT hr) { if (FAILED(hr)) { throw com_exception(hr); } } } // namespace DX #endif