xphr.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 #ifndef __XPHR_H__
5 #define __XPHR_H__
6 
7 #include <assert.h>
8 
9 #ifdef _DEBUG
10  void AxDebugBreak(HRESULT hr);
11  #define AX_DEBUG_BREAK(hr) AxDebugBreak(hr)
12  #define AX_ASSERT assert
13  #define AX_VERIFY(f) AX_ASSERT(f)
14 #else
15  #define AX_DEBUG_BREAK(hr)
16  #define AX_ASSERT assert
17  #define AX_VERIFY(f) f
18 #endif
19 
20 #ifndef USES_HR
21  #define USES_HR HRESULT hr = S_OK; int nCleanupHandlerLineNumber = 0;
22  #define CLEANUP PseudoExceptionCleanup: nCleanupHandlerLineNumber = __LINE__;
23  #define E_JUMP() if( (0 == nCleanupHandlerLineNumber) || (__LINE__ < nCleanupHandlerLineNumber) ) {AX_DEBUG_BREAK(hr); goto PseudoExceptionCleanup;}
24  #define E_W32(Win32ReturnCode) {if(ERROR_SUCCESS != Win32ReturnCode){hr = HRESULT_FROM_WIN32(Win32ReturnCode); E_JUMP();}}
25  #define E_NULL(Expression) if(NULL == (Expression)) {E_W32(ERROR_INVALID_PARAMETER);}
26  #define E_MEM(Expression) if(NULL == (Expression)) {E_W32(ERROR_NOT_ENOUGH_MEMORY);}
27  #define E_HR(HresultExpression) {hr = HresultExpression; if(FAILED(hr)) {E_JUMP();}}
28  #define E_LW32() {const DWORD dwError = GetLastError(); if(ERROR_SUCCESS != dwError){hr = HRESULT_FROM_WIN32(dwError); E_JUMP()}}
29  #define E_BW32(BooleanWin32Call) if(!BooleanWin32Call){const DWORD dwError = GetLastError(); ASSERT(ERROR_SUCCESS != dwError); hr = HRESULT_FROM_WIN32(dwError); E_JUMP();}
30  #define HRESULT_TO_WIN32(HresultExpression) ((HRESULT_FACILITY(HresultExpression) == FACILITY_WIN32) ? HRESULT_CODE(HresultExpression) : (HresultExpression))
31 #endif //USES_HR
32 
33 #endif //__XPHR_H__

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.