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.

372 lines
11 KiB

  1. /*
  2. Copyright 1991-1993 Microsoft Corporation. All rights reserved.
  3. Microsoft Confidential.
  4. Common macros - internal use only; subincludes several .h files
  5. */
  6. #ifndef _INCLUDE_SHDSYSH
  7. #define _INCLUDE_SHDSYSH
  8. /******************* Controlling Defines ************************************/
  9. // define DEBUG unless explicitly asked not to:
  10. #ifndef NONDEBUG
  11. #ifndef DEBUG
  12. #define DEBUG
  13. #endif //DEBUG
  14. #endif //NONDEBUG
  15. #define VSZDD // add vszDDxx strings in DDErr
  16. /******************* Includes ***********************************************/
  17. #ifndef _INC_WINDOWS
  18. #include <windows.h>
  19. #endif //_INC_WINDOWS
  20. #include <stdlib.h>
  21. #include <string.h> // for string macros
  22. #include <limits.h> // implementation dependent values
  23. /******************* Defines ************************************************/
  24. #define cbSzTMax 256 // size of temp string buffers
  25. #define cbSzRcMax 256 // max size of RC strings
  26. #define cbSzNameMax 32 // max size of app name, class names, etc
  27. #ifdef CHICAGO
  28. #define cbSzFileMax 260 // max size of file names for Chicago
  29. #else // WIN31
  30. #define cbSzFileMax 128 // max size of file names
  31. #endif //CHICAGO
  32. #ifndef TRUE
  33. #define TRUE 1
  34. #endif //TRUE
  35. #ifndef FALSE
  36. #define FALSE 0
  37. #endif //FALSE
  38. #define fTrue TRUE // alias
  39. #define fFalse FALSE // alias
  40. #define wDontCare 1
  41. #define lDontCare 1L
  42. #define lpszNull ((LPSTR)NULL)
  43. /******************* Calling Conventions ************************************/
  44. /* Exported functions: FAR PASCAL, LOADDS if BUILDDLL is defined
  45. WINAPI Documented API (see windows.h)
  46. CALLBACK DlgProc, WndProc, DriverProc, ResultsFunction (see windows.h)
  47. EXPORT Internal system entry point (e.g. PenAboutBoxFn)
  48. */
  49. #define EXPORT WINAPI
  50. /* Internal functions, not exported:
  51. PUBLIC FAR PASCAL (NEAR if SMALL)
  52. Called internally from several functional areas
  53. FASTPUBLIC FAR _fastcall (NEAR if SMALL)
  54. Called internally from several functional areas;
  55. few arguments, no far ptrs, NOT exported
  56. FARPRIVATE FAR PASCAL
  57. Called internally from one or few functional areas
  58. PRIVATE NEAR PASCAL
  59. Called internally from same file
  60. FASTPRIVATE NEAR _fastcall
  61. Called internally from same file;
  62. few arguments, no far ptrs, NOT exported
  63. IWINAPI FAR PASCAL [LOADDS]
  64. For exclusive use by parameter validation layer;
  65. this is NOT exported (e.g. ITPtoDP)
  66. */
  67. #ifdef SMALL
  68. #ifndef PUBLIC
  69. #define PUBLIC NEAR PASCAL
  70. #endif
  71. #define FASTPUBLIC NEAR _fastcall
  72. #else // !SMALL
  73. #ifndef PUBLIC
  74. #define PUBLIC FAR PASCAL
  75. #endif
  76. #define FASTPUBLIC FAR _fastcall
  77. #endif //SMALL
  78. #define FARPRIVATE FAR PASCAL
  79. #ifndef PRIVATE
  80. #define PRIVATE NEAR PASCAL
  81. #endif
  82. #define FASTPRIVATE NEAR _fastcall
  83. #define IWINAPI WINAPI
  84. // for compatability only, in DLLs compiled without -Gw:
  85. #define DLLEXPORT FAR PASCAL _loadds
  86. /******************* Generic Macros *****************************************/
  87. #ifndef RC_INVOKED // BLOCK is used in .rc version stamping
  88. #define BLOCK
  89. #endif //!RC_INVOKED
  90. #define NOREF
  91. #define Unref(var) var;
  92. #undef SetFlag
  93. #undef ToggleFlag
  94. #undef ResetFlag
  95. // flag setting and testing (multiple flags ok):
  96. #define SetFlag(w, flags) do {(w) |= (flags);} while (0)
  97. #define ToggleFlag(w, flags) do {(w) ^= (flags);} while (0)
  98. #define ResetFlag(w, flags) do {(w) &= ~(flags);} while (0)
  99. // tests: FFlag is common (T if any flag), FExactFlag is rare (all flags req):
  100. #define FFlag(w, flags) (BOOL)(((w) & (flags)) != 0)
  101. #define FExactFlag(w, flags) (BOOL)(((w) & (flags)) == (flags))
  102. /******************* User Macros ********************************************/
  103. /******************* Mem Macros *********************************************/
  104. #define SG(x) _based(_segname("_" #x))
  105. #define CODECONST SG(CODE)
  106. // extra debug info: local name of function
  107. #ifdef DEBUG
  108. #define ThisFnIs(sz)\
  109. static char CODECONST szThisFn[] = sz;\
  110. static LPCSTR CODECONST lpszThisFn = szThisFn
  111. #else
  112. #define ThisFnIs(sz) // nothing
  113. #define lpszThisFn NULL
  114. #endif //DEBUG
  115. #ifdef DEBUG
  116. #define AssertSameSeg(x1,x2) (HIWORD((LPVOID)(x1))==HIWORD((LPVOID)(x2)))
  117. #else
  118. #define AssertSameSeg(x1, x2)
  119. #endif //DEBUG
  120. // handle from ptr (from windowsx.h):
  121. #ifndef GlobalPtrHandle
  122. #define GlobalPtrHandle(lp)\
  123. ((HGLOBAL)LOWORD(GlobalHandle(SELECTOROF(lp))))
  124. #endif
  125. #define LocalUnlockFree(hMem) \
  126. do {\
  127. BOOL fErr = LocalUnlock(hMem);\
  128. HLOCAL h = LocalFree(hMem);\
  129. Assert(!fErr && !h);\
  130. hMem = (HLOCAL)NULL;\
  131. } while (0)
  132. #define GlobalUnlockFree(hMem) do {\
  133. BOOL fErr = GlobalUnlock(hMem);\
  134. HGLOBAL h = GlobalFree(hMem);\
  135. Assert(!fErr && !h);\
  136. hMem = (HGLOBAL)NULL;\
  137. } while (0)
  138. // mX macros return BOOL success of operation (and put dbg sz);
  139. // for example: if (!mGlobalFree(hMem)) goto endFn;
  140. #ifdef DEBUG
  141. #define mGlobalAlloc(hglb, fuAlloc, cbAlloc) \
  142. (((HGLOBAL)hglb = GlobalAlloc(fuAlloc, cbAlloc)) != NULL \
  143. || OOMSz(vszDDGlobalAlloc))
  144. #define mGlobalReAlloc(hglbNew, hglb, cbNewSize, fuAlloc) \
  145. (((HGLOBAL)hglbNew = GlobalReAlloc((HGLOBAL)(hglb), cbNewSize, fuAlloc)) != NULL \
  146. || OOMSz(vszDDGlobalReAlloc))
  147. #define mGlobalLock(lpv, hglb) \
  148. (((LPVOID)lpv = GlobalLock((HGLOBAL)(hglb))) != NULL \
  149. || PanicSz(vszDDGlobalLock))
  150. #define mGlobalUnlock(hglb) \
  151. (!GlobalUnlock((HGLOBAL)(hglb)) || DbgSz(vszDDGlobalUnlock))
  152. #define mGlobalFree(hglb) \
  153. (GlobalFree((HGLOBAL)(hglb)) == NULL || DbgSz(vszDDGlobalFree))
  154. #define mLocalAlloc(hloc, fuAlloc, cbAlloc) \
  155. (((HLOCAL)hloc = LocalAlloc(fuAlloc, cbAlloc)) != NULL \
  156. || OOMSz(vszDDLocalAlloc))
  157. #define mLocalReAlloc(hlocNew, hloc, cbNewSize, fuAlloc) \
  158. (((HLOCAL)hlocNew = LocalReAlloc((HLOCAL)(hloc), cbNewSize, fuAlloc)) != NULL \
  159. || OOMSz(vszDDLocalReAlloc))
  160. #define mLocalLock(lpv, hloc) \
  161. (((LPVOID)lpv = LocalLock((HLOCAL)(hloc))) != NULL \
  162. || PanicSz(vszDDLocalLock))
  163. #define mLocalUnlock(hloc) \
  164. (!LocalUnlock((HLOCAL)(hloc)) || DbgSz(vszDDLocalUnlock))
  165. #define mLocalFree(hloc) \
  166. (LocalFree((HLOCAL)(hloc)) == NULL)
  167. #else
  168. #define mGlobalAlloc(hglb, fuAlloc, cbAlloc) \
  169. (((HGLOBAL)hglb = GlobalAlloc(fuAlloc, cbAlloc)) != NULL)
  170. #define mGlobalReAlloc(hglbNew, hglb, cbNewSize, fuAlloc) \
  171. (((HGLOBAL)hglbNew = GlobalReAlloc((HGLOBAL)(hglb), cbNewSize, fuAlloc)) != NULL)
  172. #define mGlobalLock(lpv, hglb) \
  173. (((LPVOID)lpv = GlobalLock((HGLOBAL)(hglb))) != NULL)
  174. #define mGlobalUnlock(hglb) \
  175. (!GlobalUnlock((HGLOBAL)(hglb)))
  176. #define mGlobalFree(hglb) \
  177. (GlobalFree((HGLOBAL)(hglb)) == NULL)
  178. #define mLocalAlloc(hloc, fuAlloc, cbAlloc) \
  179. (((HLOCAL)hloc = LocalAlloc(fuAlloc, cbAlloc)) != NULL)
  180. #define mLocalReAlloc(hlocNew, hloc, cbNewSize, fuAlloc) \
  181. (((HLOCAL)hlocNew = LocalReAlloc((HLOCAL)(hloc), cbNewSize, fuAlloc)) != NULL)
  182. #define mLocalLock(lpv, hloc) \
  183. (((LPVOID)lpv = LocalLock((HLOCAL)(hloc))) != NULL)
  184. #define mLocalUnlock(hloc) \
  185. (!LocalUnlock((HLOCAL)(hloc)))
  186. #define mLocalFree(hloc) \
  187. (LocalFree((HLOCAL)(hloc)) == NULL)
  188. #endif //DEBUG
  189. /******************* Gdi Macros *********************************************/
  190. // delete GDI object if non NULL:
  191. #define AssertDelObj(hobj) \
  192. do {\
  193. if (hobj && IsGDIObject(hobj)) {\
  194. BOOL fOk = DeleteObject(hobj);\
  195. Assert(fOk);\
  196. }\
  197. hobj = (HANDLE)0;\
  198. } while (0)
  199. #define IsValidRect(lpr) \
  200. ((lpr) \
  201. && sizeof(*(lpr))==sizeof(RECT) \
  202. && (lpr)->right >= (lpr)->left \
  203. && (lpr)->bottom >= (lpr)->top)
  204. #define IsValidNonemptyRect(lpr) \
  205. (IsValidRect(lpr) && !IsRectEmpty((CONST LPRECT)lpr))
  206. /******************* String Macros ******************************************/
  207. /* String macros. */
  208. // If compiling an app small/medium model, then should use more efficient
  209. // near pointer version of
  210. // this hack err... software innovation works quite well with models
  211. // and National Language support to reduce duplication
  212. #ifdef JAPAN
  213. #define StrNlsPrefix() j
  214. #else
  215. #define StrNlsPrefix()
  216. #endif //JAPAN
  217. #ifdef SMALLSTRING
  218. #define StrModelPrefix()
  219. #else
  220. #define StrModelPrefix() _f
  221. #endif //SMALLSTRING
  222. /* These are the macros which have to have different implementations
  223. based on language (at least for DBCS) and model.
  224. These macros can be replaced transparently to deal with DBCS
  225. (without any changes in an app and without breaking any assuptions
  226. made by an app). Others such as strlen and strncmp have 2 flavors
  227. byte-oriented and logical character oriented. There will have
  228. to be new macro names defined for logical charcters since the apps
  229. currently assume byte orientation.
  230. */
  231. #define SzStrStr(sz1,sz2) StrModelPrefix() ## \
  232. StrNlsPrefix() ## strstr(sz1, sz2)
  233. #define SzStrCh(sz1,ch) StrModelPrefix() ## \
  234. StrNlsPrefix() ## strchr(sz1, ch)
  235. #define SzStrTok(sz1,sz2) StrModelPrefix() ## \
  236. StrNlsPrefix() ## strtok(sz1,sz2)
  237. /* These macros are currently independent of language do not
  238. understand DBCS and are byte oriented. Refer above.
  239. StrModelPrefix is used here to create a single definition for
  240. multiple models.
  241. */
  242. #define CbSizeSz(sz) StrModelPrefix() ## strlen(sz)
  243. #define SzCat(sz1,sz2) StrModelPrefix() ## strcat(sz1,sz2)
  244. #define SzNCat(sz1,sz2,n) StrModelPrefix() ## strncat(sz1,sz2,n)
  245. #define SzCopy(sz1,sz2) StrModelPrefix() ## strcpy(sz2,sz1)
  246. #define SzNCopy(sz1,sz2,n) StrModelPrefix() ## strncpy(sz2,sz1,n)
  247. #define FillBuf(sz,ch,c) StrModelPrefix() ## memset(sz,ch,c)
  248. #define FIsLpvEqualLpv(lpv1,lpv2,cb) (BOOL)(StrModelPrefix() ## \
  249. memcmp((LPVOID)(lpv1), (LPVOID)(lpv2), cb) == 0)
  250. #define FIsSzEqualSzN(sz1,sz2,n) (BOOL)(StrModelPrefix() ## \
  251. strnicmp(sz1,sz2,n) == 0)
  252. #define Bltbyte(rgbSrc,rgbDest,cb) StrModelPrefix() ## \
  253. memmove(rgbDest, rgbSrc, cb)
  254. #define PvFindCharInBuf(pv,ch,cb) StrModelPrefix() ## memchr(pv, ch, cb)
  255. // model independent, language-independent (DBCS aware) macros
  256. #define FIsSzEqualSz(sz1,sz2) (BOOL)(lstrcmpi(sz1,sz2) == 0)
  257. #define FIsSz1LessThanSz2(sz1,sz2) (BOOL)(lstrcmpi(sz1,sz2) < 0)
  258. #define FIsCaseSzEqualSz(sz1,sz2) (BOOL)(lstrcmp(sz1,sz2) == 0)
  259. #define SzFromInt(sz,w) (wsprintf((LPSTR)sz, (LPSTR)"%d", w), (LPSTR)sz)
  260. #define FLenSzLessThanCb(sz, cb) (BOOL)(PvFindCharInBuf(sz, 0, cb) != NULL)
  261. #ifdef SMALLSTRING
  262. #define IntFromSz(sz) atoi(sz)
  263. #endif //SMALLSTRING
  264. /******************* Typedefs ***********************************************/
  265. typedef int INT; // alias
  266. typedef int RS; // Resource String
  267. typedef unsigned long ulong;
  268. typedef unsigned short ushort;
  269. #ifndef VXD
  270. typedef LPSTR LPPATH;
  271. #endif
  272. #endif //_INCLUDE_SHDSYSH