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.

216 lines
5.7 KiB

  1. /***************************************************************************
  2. * Baggage.h
  3. *
  4. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  5. *
  6. * File: pidi.h
  7. * Content: DirectInput PID internal include file
  8. *
  9. *@@BEGIN_MSINTERNAL
  10. * History:
  11. * Date By Reason
  12. * ==== == ======
  13. * 1999.01.04 OmSharma Lost a bet
  14. *
  15. *@@END_MSINTERNAL
  16. *
  17. ***************************************************************************/
  18. /***************************************************************************
  19. *
  20. * Debug / RDebug / Retail
  21. *
  22. * If either DEBUG or RDEBUG, set XDEBUG.
  23. *
  24. * Retail defines nothing.
  25. *
  26. ***************************************************************************/
  27. #if defined(DEBUG) || defined(RDEBUG) || defined(_DBG)
  28. #define XDEBUG
  29. #endif
  30. typedef LPUNKNOWN PUNK;
  31. typedef LPVOID PV, *PPV;
  32. typedef CONST VOID *PCV;
  33. typedef REFIID RIID;
  34. typedef CONST GUID *PCGUID;
  35. #define INTERNAL NTAPI /* Called only within a translation unit */
  36. #define EXTERNAL NTAPI /* Called from other translation units */
  37. #define INLINE static __inline
  38. #define INTERNAL NTAPI /* Called only within a translation unit */
  39. #define EXTERNAL NTAPI /* Called from other translation units */
  40. #define INLINE static __inline
  41. #define BEGIN_CONST_DATA data_seg(".text", "CODE")
  42. #define END_CONST_DATA data_seg(".data", "DATA")
  43. /*
  44. * Arithmetic on pointers.
  45. */
  46. #define pvSubPvCb(pv, cb) ((PV)((PBYTE)pv - (cb)))
  47. #define pvAddPvCb(pv, cb) ((PV)((PBYTE)pv + (cb)))
  48. #define cbSubPvPv(p1, p2) ((PBYTE)(p1) - (PBYTE)(p2))
  49. /*
  50. * Convert an object (X) to a count of bytes (cb).
  51. */
  52. #define cbX(X) sizeof(X)
  53. /*
  54. * Convert an array name (A) to a generic count (c).
  55. */
  56. #define cA(a) (cbX(a)/cbX(a[0]))
  57. /*
  58. * Convert a count of X's (cx) into a count of bytes
  59. * and vice versa.
  60. */
  61. #define cbCxX(cx, X) ((cx) * cbX(X))
  62. #define cxCbX(cb, X) ((cb) / cbX(X))
  63. /*
  64. * Convert a count of chars (cch), tchars (ctch), wchars (cwch),
  65. * or dwords (cdw) into a count of bytes, and vice versa.
  66. */
  67. #define cbCch(cch) cbCxX( cch, CHAR)
  68. #define cbCwch(cwch) cbCxX(cwch, WCHAR)
  69. #define cbCtch(ctch) cbCxX(ctch, TCHAR)
  70. #define cbCdw(cdw) cbCxX( cdw, DWORD)
  71. #define cchCb(cb) cxCbX(cb, CHAR)
  72. #define cwchCb(cb) cxCbX(cb, WCHAR)
  73. #define ctchCb(cb) cxCbX(cb, TCHAR)
  74. #define cdwCb(cb) cxCbX(cb, DWORD)
  75. /*
  76. * Zero an arbitrary buffer. It is a common error to get the second
  77. * and third parameters to memset backwards.
  78. */
  79. #define ZeroBuf(pv, cb) memset(pv, 0, cb)
  80. /*
  81. * Zero an arbitrary object.
  82. */
  83. #define ZeroX(x) ZeroBuf(&(x), cbX(x))
  84. /*
  85. * land -- Logical and. Evaluate the first. If the first is zero,
  86. * then return zero. Otherwise, return the second.
  87. */
  88. #define fLandFF(f1, f2) ((f1) ? (f2) : 0)
  89. /*
  90. * lor -- Logical or. Evaluate the first. If the first is nonzero,
  91. * return it. Otherwise, return the second.
  92. *
  93. * Unfortunately, due to the *nature* of the C language, this can
  94. * be implemented only with a GNU extension. In the non-GNU case,
  95. * we return 1 if the first is nonzero.
  96. */
  97. #if defined(__GNUC__)
  98. #define fLorFF(f1, f2) ((f1) ?: (f2))
  99. #else
  100. #define fLorFF(f1, f2) ((f1) ? 1 : (f2))
  101. #endif
  102. /*
  103. * limp - logical implication. True unless the first is nonzero and
  104. * the second is zero.
  105. */
  106. #define fLimpFF(f1, f2) (!(f1) || (f2))
  107. /*
  108. * leqv - logical equivalence. True if both are zero or both are nonzero.
  109. */
  110. #define fLeqvFF(f1, f2) (!(f1) == !(f2))
  111. /*
  112. * fInOrder - checks that i1 <= i2 < i3.
  113. */
  114. #define fInOrder(i1, i2, i3) ((unsigned)((i2)-(i1)) < (unsigned)((i3)-(i1)))
  115. /*
  116. * fHasAllBitsFlFl - checks that all bits in fl2 are set in fl1.
  117. */
  118. BOOL INLINE
  119. fHasAllBitsFlFl(DWORD fl1, DWORD fl2)
  120. {
  121. return (fl1 & fl2) == fl2;
  122. }
  123. /*
  124. * fEqualMask - checks that all masked bits are equal
  125. */
  126. BOOL INLINE
  127. fEqualMaskFlFl(DWORD flMask, DWORD fl1, DWORD fl2)
  128. {
  129. return ((fl1 ^ fl2) & flMask) == 0;
  130. }
  131. #define NEED_REALLOC
  132. STDMETHODIMP EXTERNAL ReallocCbPpv(UINT cb, PV ppvObj);
  133. STDMETHODIMP EXTERNAL AllocCbPpv(UINT cb, PV ppvObj);
  134. #ifdef NEED_REALLOC
  135. #define FreePpv(ppv) (void)ReallocCbPpv(0, ppv)
  136. #else
  137. void EXTERNAL FreePpv(PV ppv);
  138. #define FreePpv(ppv) FreePpv(ppv)
  139. #endif
  140. #define FreePv(pv) LocalFree((HLOCAL)(pv))
  141. HRESULT EXTERNAL hresDupPtszPptsz(LPCTSTR ptszSrc, LPTSTR *pptszDst);
  142. #define AToU(dst, cchDst, src) \
  143. MultiByteToWideChar(CP_ACP, 0, src, -1, dst, cchDst)
  144. #define UToA(dst, cchDst, src) \
  145. WideCharToMultiByte(CP_ACP, 0, src, -1, dst, cchDst, 0, 0)
  146. /***************************************************************************
  147. *
  148. * Debugging macros needed by inline functions
  149. *
  150. * The build of debugging goo is in debug.h
  151. *
  152. ***************************************************************************/
  153. int EXTERNAL AssertPtszPtszLn(LPCTSTR ptszExpr, LPCTSTR ptszFile, int iLine);
  154. #ifdef DEBUG
  155. #define AssertFPtsz(c, ptsz) \
  156. ((c) ? 0 : AssertPtszPtszLn(ptsz, TEXT(__FILE__), __LINE__))
  157. #define ValidateF(c, arg) \
  158. ((c) ? 0 : (RPF arg, ValidationException(), 0))
  159. #define ConfirmF(c) \
  160. ((c) ? 0 : AssertPtszPtszLn(TEXT(#c), TEXT(__FILE__), __LINE__))
  161. #else /* !DEBUG */
  162. #define AssertFPtsz(c, ptsz)
  163. #define ValidateF(c, arg)
  164. #define ConfirmF(c) (c)
  165. #endif
  166. /*
  167. * CAssertF - compile-time assertion.
  168. */
  169. #define CAssertF(c) switch(0) case c: case 0:
  170. #define AssertF(c) AssertFPtsz(c, TEXT(#c))
  171. #define Clamp( MIN_, VAL_, MAX_ ) ( (VAL_ < MIN_) ? MIN_ : ((VAL_ > MAX_) ? MAX_ : VAL_) )
  172. #define Clip( VAL_, MAX_) ( (VAL_ > MAX_) ? MAX_ : VAL_)