Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: common.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __common_h
  11. #define __common_h
  12. //
  13. // ARRAYSIZE, SIZEOF, and ResultFromShort are defined in private shell
  14. // headers, but those headers tend to move around, change, and break.
  15. // Define the macros here so we don't have to include the headers only for
  16. // this purpose.
  17. //
  18. #ifndef ARRAYSIZE
  19. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  20. #define SIZEOF(a) sizeof(a)
  21. #endif
  22. #ifndef ResultFromShort
  23. #define ResultFromShort(i) MAKE_HRESULT(SEVERITY_SUCCESS, 0, (USHORT)(i))
  24. #endif
  25. //
  26. // Avoid bringing in C runtime code for NO reason
  27. //
  28. #if defined(__cplusplus)
  29. inline void * __cdecl operator new(size_t size) { return (void *)LocalAlloc(LPTR, size); }
  30. inline void __cdecl operator delete(void *ptr) { LocalFree(ptr); }
  31. extern "C" inline __cdecl _purecall(void) { return 0; }
  32. #endif // __cplusplus
  33. #include "debug.h"
  34. #include "unknown.h"
  35. #include "strings.h"
  36. #include "priv.h"
  37. #include "msgpopup.h"
  38. //
  39. //strsafe apis
  40. //
  41. #define STRSAFE_NO_DEPRECATE
  42. #include <strsafe.h>
  43. /*-----------------------------------------------------------------------------
  44. / Flags to control the trace output from parts of the common library
  45. /----------------------------------------------------------------------------*/
  46. #define TRACE_COMMON_STR 0x80000000
  47. #define TRACE_COMMON_ASSERT 0x40000000
  48. #define TRACE_COMMON_MISC 0x20000000
  49. /*-----------------------------------------------------------------------------
  50. / Misc functions (misc.cpp)
  51. /----------------------------------------------------------------------------*/
  52. HRESULT CallRegInstall(HMODULE hModule, LPCSTR pszSection);
  53. /*-----------------------------------------------------------------------------
  54. / Exit macros for macro
  55. / - these assume that a label "exit_gracefully:" prefixes the prolog
  56. / to your function
  57. /----------------------------------------------------------------------------*/
  58. #define ExitGracefully(hr, result, text) \
  59. { TraceMsg(text); hr = result; goto exit_gracefully; }
  60. #define FailGracefully(hr, text) \
  61. { if ( FAILED(hr) ) { TraceMsg(text); goto exit_gracefully; } }
  62. /*-----------------------------------------------------------------------------
  63. / Interface helper macros
  64. /----------------------------------------------------------------------------*/
  65. #define DoRelease(pInterface) \
  66. { if ( pInterface ) { pInterface->Release(); pInterface = NULL; } }
  67. /*-----------------------------------------------------------------------------
  68. / String helper macros
  69. /----------------------------------------------------------------------------*/
  70. #define StringByteCopy(pDest, iOffset, sz) \
  71. { memcpy(&(((LPBYTE)pDest)[iOffset]), sz, StringByteSize(sz)); }
  72. #define StringByteSize(sz) \
  73. ((lstrlen(sz)+1)*SIZEOF(TCHAR))
  74. /*-----------------------------------------------------------------------------
  75. / Other helpful macros
  76. /----------------------------------------------------------------------------*/
  77. #define ByteOffset(base, offset) \
  78. (((LPBYTE)base)+offset)
  79. // This wrapper function required to make prefast shut up when we are
  80. // initializing a critical section in a constructor.
  81. void ExceptionPropagatingInitializeCriticalSection(LPCRITICAL_SECTION critsec);
  82. #endif