Source code of Windows XP (NT5)
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.

110 lines
3.8 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. / Flags to control the trace output from parts of the common library
  40. /----------------------------------------------------------------------------*/
  41. #define TRACE_COMMON_STR 0x80000000
  42. #define TRACE_COMMON_ASSERT 0x40000000
  43. #define TRACE_COMMON_MISC 0x20000000
  44. /*-----------------------------------------------------------------------------
  45. / Misc functions (misc.cpp)
  46. /----------------------------------------------------------------------------*/
  47. HRESULT CallRegInstall(HMODULE hModule, LPCSTR pszSection);
  48. #if(_WIN32_WINNT < 0x0500)
  49. typedef int (CALLBACK *_PFNDPAENUMCALLBACK)(LPVOID p, LPVOID pData);
  50. void DPA_DestroyCallback(LPVOID, _PFNDPAENUMCALLBACK, LPVOID);
  51. #ifndef DA_LAST
  52. #define DA_LAST (0x7FFFFFFF)
  53. #endif
  54. #ifndef DPA_AppendPtr
  55. #define DPA_AppendPtr(hdpa, pitem) DPA_InsertPtr(hdpa, DA_LAST, pitem)
  56. #endif
  57. #endif
  58. /*-----------------------------------------------------------------------------
  59. / Exit macros for macro
  60. / - these assume that a label "exit_gracefully:" prefixes the prolog
  61. / to your function
  62. /----------------------------------------------------------------------------*/
  63. #define ExitGracefully(hr, result, text) \
  64. { TraceMsg(text); hr = result; goto exit_gracefully; }
  65. #define FailGracefully(hr, text) \
  66. { if ( FAILED(hr) ) { TraceMsg(text); goto exit_gracefully; } }
  67. /*-----------------------------------------------------------------------------
  68. / Interface helper macros
  69. /----------------------------------------------------------------------------*/
  70. #define DoRelease(pInterface) \
  71. { if ( pInterface ) { pInterface->Release(); pInterface = NULL; } }
  72. /*-----------------------------------------------------------------------------
  73. / String helper macros
  74. /----------------------------------------------------------------------------*/
  75. #define StringByteCopy(pDest, iOffset, sz) \
  76. { memcpy(&(((LPBYTE)pDest)[iOffset]), sz, StringByteSize(sz)); }
  77. #define StringByteSize(sz) \
  78. ((lstrlen(sz)+1)*SIZEOF(TCHAR))
  79. /*-----------------------------------------------------------------------------
  80. / Other helpful macros
  81. /----------------------------------------------------------------------------*/
  82. #define ByteOffset(base, offset) \
  83. (((LPBYTE)base)+offset)
  84. // This wrapper function required to make prefast shut up when we are
  85. // initializing a critical section in a constructor.
  86. void ExceptionPropagatingInitializeCriticalSection(LPCRITICAL_SECTION critsec);
  87. #endif