Exception - { HRESULT hr;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#pragma once # #define WIN32_LEAN_AND_MEAN #include <exception> #include <windows.h> #include <dxerr9.h> #include <string> # #define WIDEN2(x) L ## x #define WIDEN(x) WIDEN2(x) #define __WIDE_FILE__ WIDEN(__FILE__) # #ifndef __TFILE__ #ifdef UNICODE #define __TFILE__ __WIDE_FILE__ #else #define __TFILE__ __FILE__ #endif #endif # // Get the library #pragma comment(lib, "dxerr9.lib") # /* Macro: HRE Checks HRESULT values for success, and throws <DirectX::Exception> on failure. C Usage: HRE(device->DrawPrimitive(. ..)); */ #define HRE(expression) DirectX::CheckHr<>::Test((expression), __TFILE__, __LINE__, #expression) # /* Macro: HREX Checks HRESULT values for success, and throws an exception of a type specified by the caller. t Usage: HREX(DirectX::Exception, device->DrawPrimitive(. ..)); */ #define HREX(exceptionType, expression) \ DirectX::CheckHr<exceptionType>::Test((expression), __TFILE__, __LINE__, #expression) # namespace DirectX { struct Exception : public std::exception
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { HRESULT hr; std::basic_string&lt;TCHAR&gt; hrString, hrDescription; std::basic_string&lt;TCHAR&gt; fileName; DWORD line; std::string expression; s Exception(const char* what) : std::exception(what), hr(S_OK), line(0) { } }; } /* Struct: CheckHr We actually want a function, but default template parameters are allowed on classes/structs only. We'll use a static function inside the structure. */ template&lt;typename T = Exception&gt; struct CheckHr { /* Checks the given HRESULT for success, and throws an exception of the specified type if the HR indicates failure. */ static void Test( HRESULT hr, const TCHAR* fileName, long line, const char* expression) { if(FAILED(hr)) { T ex(DXGetErrorDescription9A(hr)); ex.hr = hr; ex.hrString = DXGetErrorString9(hr); ex.hrDescription = DXGetErrorDescription9(hr); ex.fileName = fileName; ex.line = line; if(expression) ex.expression = expression; throw ex; } } }; }...
View Full Document

This note was uploaded on 01/31/2011 for the course CS 302 taught by Professor J.parker during the Spring '08 term at University of Texas at Austin.

Page1 / 2

Exception - { HRESULT hr;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online