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.

413 lines
12 KiB

  1. //
  2. // DC Groupware Common stuff
  3. //
  4. #ifndef _H_DCG
  5. #define _H_DCG
  6. #include <stddef.h>
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <ctype.h>
  11. #include <string.h>
  12. #include <time.h>
  13. #include <memory.h>
  14. #ifdef DLL_DISP
  15. #ifdef IS_16
  16. //
  17. // Win16 Display Driver
  18. //
  19. #define STRICT
  20. #define UNALIGNED
  21. #include <windows.h>
  22. #include <windowsx.h>
  23. #include <winddi.h>
  24. #define abs(A) (((A) < 0)? -(A) : (A))
  25. #define FIELD_OFFSET(type, field) FIELDOFFSET(type, field)
  26. #else
  27. //
  28. // Windows NT DDK include files (used to replace standard windows.h)
  29. //
  30. // The display driver runs in the Kernel space and so MUST NOT access any
  31. // Win32 functions or data. Instead we can only use the Win32k functions
  32. // as described in the DDK.
  33. //
  34. // NOTE ALSO: OUR DRIVER MUST WORK ON NT4 AND WIN2K, so we use NT4
  35. // versions of headers.
  36. //
  37. #include <ntddk.h>
  38. #include <windef.h>
  39. #include <wingdi.h>
  40. #include <ntddvd40.h>
  41. #include <winddi40.h>
  42. #endif // IS_16
  43. // Debugging Macros
  44. #include <drvdbg.h>
  45. #else
  46. #ifndef STRICT
  47. #define STRICT
  48. #endif
  49. #define OEMRESOURCE
  50. #include <windows.h>
  51. #include <windowsx.h>
  52. #include <commctrl.h>
  53. #include <winable.h>
  54. #include <mlzdbg.h> // multi-level zone debug header file
  55. #include <memtrack.h>
  56. #include <strutil.h>
  57. #endif // DLL_DISP
  58. //
  59. // DC_DATA macros to generate extern declarations.
  60. // NOTE: Keep this section in ssync with datainit.h, the header included
  61. // by a file to actually generate storage for variables declared using the
  62. // DC_DATA macros
  63. //
  64. #define DC_DATA(TYPE, Name) \
  65. extern TYPE Name
  66. #define DC_DATA_VAL(TYPE, Name, Value) \
  67. extern TYPE Name
  68. #define DC_CONST_DATA(TYPE, Name, Value) \
  69. extern const TYPE Name
  70. #define DC_DATA_ARRAY(TYPE, Name, Size) \
  71. extern TYPE Name[Size]
  72. #define DC_CONST_DATA_ARRAY(TYPE, Name, Size, Value) \
  73. extern const TYPE Name[Size]
  74. #define DC_DATA_2D_ARRAY(TYPE, Name, Size1, Size2) \
  75. extern TYPE Name[Size1][Size2]
  76. #define DC_CONST_DATA_2D_ARRAY(TYPE, Name, Size1, Size2, Value) \
  77. extern const TYPE Name[Size1][Size2]
  78. typedef UINT FAR* LPUINT;
  79. typedef UINT MCSID;
  80. #define MCSID_NULL ((MCSID)0)
  81. //
  82. // T.128 PROTOCOL STRUCTURES
  83. // These are defined in a way that keeps the offsets and total sizes the
  84. // same, regardless of whether this header is included in 32-bit code,
  85. // 16-bit code, big-endian code, etc.
  86. //
  87. // We make special types to avoid inadvertenly altering something else and
  88. // breaking the structure. The TSHR_ prefix helps make this clear.
  89. //
  90. #include <t_share.h>
  91. //
  92. // Defines the maximum number of BYTES allowed in a translated "shared by "
  93. // string.
  94. //
  95. #define DC_MAX_SHARED_BY_BUFFER 64
  96. #define DC_MAX_SHAREDDESKTOP_BUFFER 64
  97. //
  98. // Registry prefix.
  99. //
  100. #define DC_REG_PREFIX TEXT("SOFTWARE\\Microsoft\\Conferencing\\AppSharing\\")
  101. //
  102. // Limits
  103. //
  104. #define MAX_TSHR_UINT16 65535
  105. //
  106. // Return codes
  107. //
  108. #define UT_BASE_RC 0x0000
  109. #define OM_BASE_RC 0x0200
  110. #define OM_LAST_RC 0x02FF
  111. #define WB_BASE_RC 0x0300
  112. #define WB_LAST_RC 0x03FF
  113. #define NET_BASE_RC 0x0700
  114. #define NET_LAST_RC 0x07FF
  115. #define CM_BASE_RC 0x0800
  116. #define CM_LAST_RC 0x08FF
  117. #define AL_BASE_RC 0x0a00
  118. #define AL_LAST_RC 0x0aFF
  119. //
  120. // Events
  121. // ======
  122. // This section lists the ranges available for each component when defining
  123. // its events. A component must not define events outside its permitted
  124. // range.
  125. //
  126. #define UT_BASE_EVENT (0x0600) // Utility service events
  127. #define UT_LAST_EVENT (0x06FF) // are in this range
  128. #define OM_BASE_EVENT (0x0700) // Object Manager events
  129. #define OM_LAST_EVENT (0x07FF) // are in this range
  130. #define NET_BASE_EVENT (0x0800) // Network layer events
  131. #define NET_LAST_EVENT (0x08FF) // are in this range
  132. #define CM_BASE_EVENT (0x0900) // Call Manager events
  133. #define CM_LAST_EVENT (0x09FF) // are in this range
  134. #define AL_BASE_EVENT (0x0A00) // Application Loader evts
  135. #define AL_LAST_EVENT (0x0AFF) // are in this range
  136. #define SPI_BASE_EVENT (0x0B00) // SPI event numbers
  137. #define SPI_LAST_EVENT (0x0BFF)
  138. #define S20_BASE_EVENT (0x0C00) // S20 event numbers
  139. #define S20_LAST_EVENT (0x0CFF)
  140. //
  141. // NOTE: Keep this above WM_USER; WB reposts the events using the event
  142. // as the message. So it CANNOT conflict with an existing Win message.
  143. //
  144. #define WB_BASE_EVENT (0x0D00) // Whiteboard events
  145. #define WB_LAST_EVENT (0x0DFF) // are in this range
  146. #define SC_BASE_EVENT (0x0E00) // SC event numbers
  147. #define SC_LAST_EVENT (0x0EFF)
  148. #define DBG_INI_SECTION_NAME "Debug"
  149. //
  150. // The GCC channel keys used with MG_ChannelJoinByKey. They must be
  151. // unique.
  152. //
  153. // SFR6043: Modified these values from 41-43 to 421-423. These values now
  154. // represent the default static channel numbers used.
  155. //
  156. // FT (potentially) uses all key numbers in the range 600-1100. If you add
  157. // a new channel key, do not use a number in that range.
  158. //
  159. #define GCC_OBMAN_CHANNEL_KEY 421
  160. #define GCC_AS_CHANNEL_KEY 422
  161. //
  162. // GCC Token keys
  163. //
  164. #define GCC_OBMAN_TOKEN_KEY 500
  165. //
  166. //
  167. // MACROS
  168. //
  169. //
  170. #define DC_QUIT goto DC_EXIT_POINT
  171. //
  172. // DEBUG structure type stamps, to help us track memory leaks
  173. //
  174. #ifdef _DEBUG
  175. typedef struct tagDBGSTAMP
  176. {
  177. char idStamp[8];
  178. }
  179. DBGSTAMP;
  180. #define STRUCTURE_STAMP DBGSTAMP stamp;
  181. #define SET_STAMP(lpv, st) lstrcpyn((lpv)->stamp.idStamp, "AS"#st, sizeof(DBGSTAMP))
  182. #else
  183. #define STRUCTURE_STAMP
  184. #define SET_STAMP(lpv, st)
  185. #endif // _DEBUG
  186. //
  187. // Cousin of the the FIELD macros supplied by 16-bit windows.h.
  188. //
  189. #define FIELD_SIZE(type, field) (sizeof(((type FAR *)0L)->field))
  190. //
  191. // Macro to round up a number to the nearest multiple of four.
  192. //
  193. #define DC_ROUND_UP_4(x) (((x) + 3L) & ~(3L))
  194. //
  195. // Unaligned pointer access macros -- first macros to extract an integer
  196. // from an UNALIGNED pointer. Note that these macros assume that the
  197. // integer is in local byte order
  198. //
  199. #ifndef DC_NO_UNALIGNED
  200. #define EXTRACT_TSHR_UINT16_UA(pA) (*(LPTSHR_UINT16_UA)(pA))
  201. #define EXTRACT_TSHR_INT16_UA(pA) (*(LPTSHR_INT16_UA)(pA))
  202. #define EXTRACT_TSHR_UINT32_UA(pA) (*(LPTSHR_UINT32_UA)(pA))
  203. #define EXTRACT_TSHR_INT32_UA(pA) (*(LPTSHR_INT32_UA)(pA))
  204. #define INSERT_TSHR_UINT16_UA(pA,V) (*(LPTSHR_UINT16_UA)(pA)) = (V)
  205. #define INSERT_TSHR_INT16_UA(pA,V) (*(LPTSHR_INT16_UA)(pA)) = (V)
  206. #define INSERT_TSHR_UINT32_UA(pA,V) (*(LPTSHR_UINT32_UA)(pA)) = (V)
  207. #define INSERT_TSHR_INT32_UA(pA,V) (*(LPTSHR_INT32_UA)(pA)) = (V)
  208. #else
  209. #define EXTRACT_TSHR_UINT16_UA(pA) ((TSHR_UINT16) (((LPBYTE)(pA))[0]) | \
  210. (TSHR_UINT16) ((((LPBYTE)(pA))[1]) << 8) )
  211. #define EXTRACT_TSHR_INT16_UA(pA) ((TSHR_INT16) (((LPBYTE)(pA))[0]) | \
  212. (TSHR_INT16) ((((LPBYTE)(pA))[1]) << 8) )
  213. #define EXTRACT_TSHR_UINT32_UA(pA) ((TSHR_UINT32) (((LPBYTE)(pA))[0]) | \
  214. (TSHR_UINT32) ((((LPBYTE)(pA))[1]) << 8) | \
  215. (TSHR_UINT32) ((((LPBYTE)(pA))[2]) << 16) | \
  216. (TSHR_UINT32) ((((LPBYTE)(pA))[3]) << 24) )
  217. #define EXTRACT_TSHR_INT32_UA(pA) ((TSHR_INT32) (((LPBYTE)(pA))[0]) | \
  218. (TSHR_INT32) ((((LPBYTE)(pA))[1]) << 8) | \
  219. (TSHR_INT32) ((((LPBYTE)(pA))[2]) << 16) | \
  220. (TSHR_INT32) ((((LPBYTE)(pA))[3]) << 24) )
  221. #define INSERT_TSHR_UINT16_UA(pA,V) \
  222. { \
  223. (((LPBYTE)(pA))[0]) = (BYTE)( (V) & 0x00FF); \
  224. (((LPBYTE)(pA))[1]) = (BYTE)(((V)>>8) & 0x00FF); \
  225. }
  226. #define INSERT_TSHR_INT16_UA(pA,V) INSERT_TSHR_UINT16_UA(pA,V)
  227. #define INSERT_TSHR_UINT32_UA(pA,V) \
  228. { \
  229. (((LPBYTE)(pA))[0]) = (BYTE)( (V) & 0x000000FF); \
  230. (((LPBYTE)(pA))[1]) = (BYTE)(((V)>>8) & 0x000000FF); \
  231. (((LPBYTE)(pA))[2]) = (BYTE)(((V)>>16) & 0x000000FF); \
  232. (((LPBYTE)(pA))[3]) = (BYTE)(((V)>>24) & 0x000000FF); \
  233. }
  234. #define INSERT_TSHR_INT32_UA(pA,V) INSERT_TSHR_UINT32_UA(pA,V)
  235. #endif
  236. //
  237. // Stamp type and macro: each module should use these when stamping its
  238. // data structures.
  239. //
  240. typedef TSHR_UINT32 DC_ID_STAMP;
  241. #define DC_MAKE_ID_STAMP(X1, X2, X3, X4) \
  242. ((DC_ID_STAMP) (((DC_ID_STAMP) X4) << 24) | \
  243. (((DC_ID_STAMP) X3) << 16) | \
  244. (((DC_ID_STAMP) X2) << 8) | \
  245. (((DC_ID_STAMP) X1) << 0) )
  246. //
  247. // BOGUS LAURABU!
  248. // COM_SIZEOF_RECT() was the old name of COM_SIZEOF_RECT_EXCLUSIVE(). But
  249. // it was being used in the display driver on INCLUSIVE rects. I fixed this,
  250. // I changed it to use COM_SIZEOF_RECT_INCLUSIVE. But this may uncover
  251. // other bugs. The reason I found this--my 16-bit display driver generates
  252. // no orders yet, all the DDI calls just add screen data. So each little
  253. // patblted strip, one pixel wide/high, gets sent via draw bounds as screen
  254. // data.
  255. //
  256. __inline DWORD COM_SizeOfRectInclusive(LPRECT prc)
  257. {
  258. return((DWORD)(prc->right+1-prc->left) * (DWORD)(prc->bottom+1-prc->top));
  259. }
  260. __inline DWORD COM_SizeOfRectExclusive(LPRECT prc)
  261. {
  262. return((DWORD)(prc->right-prc->left) * (DWORD)(prc->bottom-prc->top));
  263. }
  264. //
  265. // NORMAL rect<->rectl conversions
  266. //
  267. __inline void RECTL_TO_RECT(const RECTL FAR* lprclSrc, LPRECT lprcDst)
  268. {
  269. lprcDst->left = lprclSrc->left;
  270. lprcDst->top = lprclSrc->top;
  271. lprcDst->right = lprclSrc->right;
  272. lprcDst->bottom = lprclSrc->bottom;
  273. }
  274. __inline void RECT_TO_RECTL(const RECT FAR* lprcSrc, LPRECTL lprclDst)
  275. {
  276. lprclDst->left = lprcSrc->left;
  277. lprclDst->top = lprcSrc->top;
  278. lprclDst->right = lprcSrc->right;
  279. lprclDst->bottom = lprcSrc->bottom;
  280. }
  281. //
  282. // This macro works on 32 bit unsigned ticks and returns TRUE if TIME is
  283. // between BEGIN and END (both inclusive) allowing for the wraparound.
  284. //
  285. #define IN_TIME_RANGE(BEGIN, END, TIME) \
  286. (((BEGIN) < (END)) ? \
  287. (((TIME) >= (BEGIN)) && ((TIME) <= (END))) : \
  288. (((TIME) >= (BEGIN)) || ((TIME) <= (END))))
  289. //
  290. // Convert BPP to number of colors.
  291. //
  292. #define COLORS_FOR_BPP(BPP) (((BPP) > 8) ? 0 : (1 << (BPP)))
  293. #define MAX_ITOA_LENGTH 18
  294. #endif // _H_DCG