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.

195 lines
6.7 KiB

  1. //
  2. // utils.h: Declares data, defines and struct types for common code
  3. // module.
  4. //
  5. //
  6. #ifndef __UTILS_H__
  7. #define __UTILS_H__
  8. ///////////////////////////////////////////////////// DEFINES
  9. #define BLOCK
  10. #define Unref(x) x
  11. #ifdef DEBUG
  12. #define INLINE
  13. #define DEBUG_CODE(x) x
  14. #else
  15. #define INLINE __inline
  16. #define DEBUG_CODE(x)
  17. #endif
  18. ///////////////////////////////////////////////////// MACROS
  19. // Zero-initialize data-item
  20. //
  21. #define ZeroInit(pobj, type) lmemset((LPTSTR)pobj, 0, sizeof(type))
  22. // Copy chunk of memory
  23. //
  24. #define BltByte(pdest, psrc, cb) lmemmove((LPTSTR)pdest, (LPTSTR)psrc, cb)
  25. // General flag macros
  26. //
  27. #define SetFlag(obj, f) do {obj |= (f);} while (0)
  28. #define ToggleFlag(obj, f) do {obj ^= (f);} while (0)
  29. #define ClearFlag(obj, f) do {obj &= ~(f);} while (0)
  30. #define IsFlagSet(obj, f) (BOOL)(((obj) & (f)) == (f))
  31. #define IsFlagClear(obj, f) (BOOL)(((obj) & (f)) != (f))
  32. // void * GAlloc(DWORD cbBytes)
  33. // Alloc a chunk of memory, quickly, with no 64k limit on size of
  34. // individual objects or total object size. Initialize to zero.
  35. //
  36. #define GAlloc(cbBytes) GlobalAlloc(GPTR, cbBytes)
  37. // void * GReAlloc(void * pv, DWORD cbNewSize)
  38. // Realloc one of above. If pv is NULL, then this function will do
  39. // an alloc for you. Initializes new portion to zero.
  40. //
  41. #define GReAlloc(pv, cbNewSize) GlobalReAlloc(pv, GMEM_MOVEABLE | GMEM_ZEROINIT, cbNewSize)
  42. // void GFree(void *pv)
  43. // Free pv if it is nonzero. Set pv to zero.
  44. //
  45. #define GFree(pv) do { (pv) ? GlobalFree(pv) : (void)0; pv = NULL; } while (0)
  46. // DWORD GGetSize(void *pv)
  47. // Get the size of a block allocated by Alloc()
  48. //
  49. #define GGetSize(pv) GlobalSize(pv)
  50. // type * GAllocType(type); (macro)
  51. // Alloc some memory the size of <type> and return pointer to <type>.
  52. //
  53. #define GAllocType(type) (type *)GAlloc(sizeof(type))
  54. // type * GAllocArray(type, int cNum); (macro)
  55. // Alloc an array of data the size of <type>.
  56. //
  57. #define GAllocArray(type, cNum) (type *)GAlloc(sizeof(type) * (cNum))
  58. // type * GReAllocArray(type, void * pb, int cNum);
  59. //
  60. #define GReAllocArray(type, pb, cNum) (type *)GReAlloc(pb, sizeof(type) * (cNum))
  61. // void Free(void _huge * pb); (macro)
  62. // Free pb if it is nonzero. Set pb to zero. (Overrides Free above.)
  63. //
  64. #define Free(pb) do { (pb) ? Free(pb) : (void)0; pb = NULL; } while (0)
  65. // Color macros
  66. //
  67. #define ColorText(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)
  68. #define ColorBk(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_WINDOW)
  69. #define ColorMenuText(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT)
  70. #define ColorMenuBk(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU)
  71. #define GetImageDrawStyle(nState) (((nState) & ODS_SELECTED) ? ILD_SELECTED : ILD_NORMAL)
  72. // Sets the dialog handle in the given data struct on first
  73. // message that the dialog gets (WM_SETFONT).
  74. //
  75. #define SetDlgHandle(hwnd, msg, lp) if((msg)==WM_SETFONT) (lp)->hdlg=(hwnd);
  76. #endif // __UTILS_H__
  77. #ifndef __STRING_H__
  78. #define __STRING_H__
  79. ///////////////////////////////////////////////////// INCLUDES
  80. ///////////////////////////////////////////////////// MACROS
  81. #define Bltbyte(rgbSrc,rgbDest,cb) _fmemmove(rgbDest, rgbSrc, cb)
  82. // Model independent, language-independent (DBCS aware) macros
  83. // taken from rcsys.h in Pen project and modified.
  84. //
  85. #define IsSzEqual(sz1, sz2) (BOOL)(lstrcmpi(sz1, sz2) == 0)
  86. #define IsCaseSzEqual(sz1, sz2) (BOOL)(lstrcmp(sz1, sz2) == 0)
  87. #define SzFromInt(sz, n) (wsprintf((LPTSTR)sz, (LPTSTR)TEXT("%d"), n), (LPTSTR)sz)
  88. #define IsLink(sz, szLnk) (!lstrcmpi((LPTSTR)(sz+lstrlen(sz)-4), szLnk))
  89. ///////////////////////////////////////////////////// PROTOTYPES
  90. LPTSTR PUBLIC SzStrTok(LPTSTR string, LPCTSTR control);
  91. LPCTSTR PUBLIC SzStrCh(LPCTSTR string, char ch);
  92. LPTSTR PUBLIC SzFromIDS (UINT ids, LPTSTR pszBuf, int cbBuf);
  93. ///////////////////////////////////////////////////// MORE INCLUDES
  94. #endif // __STRING_H__
  95. typedef struct _PROC_INFO
  96. {
  97. LPCSTR Name;
  98. FARPROC Address;
  99. }
  100. PROC_INFO, *PPROC_INFO;
  101. #define PROCS_LOADED( pProcInfo ) ( (pProcInfo)[0].Address != NULL )
  102. #define LOAD_IF_NEEDED( Library, ProcInfo ) ( PROCS_LOADED( ProcInfo ) || \
  103. LoadLibraryAndProcs( Library, ProcInfo ) )
  104. extern PROC_INFO ACMProcs[];
  105. extern PROC_INFO VFWProcs[];
  106. extern PROC_INFO AVIProcs[];
  107. extern PROC_INFO VERSIONProcs[];
  108. BOOL LoadACM();
  109. BOOL FreeACM();
  110. BOOL LoadAVI();
  111. BOOL FreeAVI();
  112. BOOL LoadVFW();
  113. BOOL FreeVFW();
  114. BOOL LoadVERSION();
  115. BOOL FreeVERSION();
  116. //#define DEBUG_BUILT_LINKED
  117. #ifndef DEBUG_BUILT_LINKED
  118. #define acmFormatDetailsW (*ACMProcs[0].Address)
  119. #define acmFormatTagDetailsW (*ACMProcs[1].Address)
  120. #define acmDriverDetailsW (*ACMProcs[2].Address)
  121. #define acmDriverMessage (*ACMProcs[3].Address)
  122. #define acmDriverAddW (*ACMProcs[4].Address)
  123. #define acmDriverEnum (*ACMProcs[5].Address)
  124. #define acmDriverPriority (*ACMProcs[6].Address)
  125. #define acmDriverRemove (*ACMProcs[7].Address)
  126. #define acmMetrics (*ACMProcs[8].Address)
  127. #define acmFormatChooseW (*ACMProcs[9].Address)
  128. #define ICClose (*VFWProcs[0].Address)
  129. #define ICGetInfo (*VFWProcs[1].Address)
  130. #define ICLocate (*VFWProcs[2].Address)
  131. #define MCIWndCreateW (*VFWProcs[3].Address)
  132. #define AVIFileRelease (*AVIProcs[0].Address)
  133. #define AVIStreamRelease (*AVIProcs[1].Address)
  134. #define AVIStreamSampleToTime (*AVIProcs[2].Address)
  135. #define AVIStreamStart (*AVIProcs[3].Address)
  136. #define AVIStreamLength (*AVIProcs[4].Address)
  137. #define AVIStreamReadFormat (*AVIProcs[5].Address)
  138. #define AVIStreamInfoW (*AVIProcs[6].Address)
  139. #define AVIFileGetStream (*AVIProcs[7].Address)
  140. #define AVIFileOpenW (*AVIProcs[8].Address)
  141. #define AVIFileInit (*AVIProcs[9].Address)
  142. #define AVIFileExit (*AVIProcs[10].Address)
  143. #define VerQueryValueW (*VERSIONProcs[0].Address)
  144. #define GetFileVersionInfoW (*VERSIONProcs[1].Address)
  145. #define GetFileVersionInfoSizeW (*VERSIONProcs[2].Address)
  146. #endif