common.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 2k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #ifndef __common_h
  2. #define __common_h
  3. /*-----------------------------------------------------------------------------
  4. / Exit macros for macro
  5. /   - these assume that a label "exit_gracefully:" prefixes the prolog
  6. /     to your function
  7. /----------------------------------------------------------------------------*/
  8. #if !DSUI_DEBUG
  9. #define ExitGracefully(hr, result, text)            
  10.             {  hr = result; goto exit_gracefully; }
  11. #define FailGracefully(hr, text)                    
  12.     { if ( FAILED(hr) ) { goto exit_gracefully; } }
  13. #else
  14. #define ExitGracefully(hr, result, text)            
  15.             { OutputDebugString(TEXT(text)); hr = result; goto exit_gracefully; }
  16. #define FailGracefully(hr, text)                    
  17.     { if ( FAILED(hr) ) { OutputDebugString(TEXT(text)); goto exit_gracefully; } }
  18. #endif
  19. /*-----------------------------------------------------------------------------
  20. / Interface helper macros
  21. /----------------------------------------------------------------------------*/
  22. #define DoRelease(pInterface)                       
  23.         { if ( pInterface ) { pInterface->Release(); pInterface = NULL; } }
  24. /*-----------------------------------------------------------------------------
  25. / String helper macros
  26. /----------------------------------------------------------------------------*/
  27. #define StringByteCopy(pDest, iOffset, sz)          
  28.         { memcpy(&(((LPBYTE)pDest)[iOffset]), sz, StringByteSize(sz)); }
  29.        
  30. #define StringByteSize(sz)                          
  31.         ((lstrlen(sz)+1)*sizeof(TCHAR))
  32. /*-----------------------------------------------------------------------------
  33. / Other helpful macros
  34. /----------------------------------------------------------------------------*/
  35. #define ByteOffset(base, offset)                    
  36.         (((LPBYTE)base)+offset)
  37. #ifndef ARRAYSIZE
  38. #define ARRAYSIZE(a)                (sizeof(a)/sizeof(a[0]))
  39. #endif
  40. #endif