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.

378 lines
14 KiB

  1. /*++ BUILD Version: 0001
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * WALIAS.H
  8. * WOW32 16-bit handle alias support
  9. *
  10. * History:
  11. * Created 27-Jan-1991 by Jeff Parsons (jeffpar)
  12. * Modified 12-May-1992 by Mike Tricker (miketri) to add MultiMedia support
  13. --*/
  14. typedef HANDLE HAND32;
  15. #define _WALIAS_
  16. #include "wspool.h"
  17. #include "wowuserp.h"
  18. //
  19. //
  20. // The WC structure is present in every CLS structure in the system,
  21. // although USER32 defines it as an array of 2 DWORDs. FindPWC(hwnd)
  22. // returns a read-only pointer to the WC structure for a given window's
  23. // class. Note that only classes registered by Win16 applications will
  24. // have meaningful values in the structure. To change elements of the
  25. // structure, use SETWC (== SetClassLong) with the appropriate GCL_WOW*
  26. // offset defined below.
  27. //
  28. #define SETWC(hwnd, nIndex, l) SetClassLong(hwnd, nIndex, l)
  29. #define SETWL(hwnd, nIndex, l) SetWindowLong(hwnd, nIndex, l)
  30. typedef struct _HDW {
  31. struct _HDW *Next; // pointer to next hDDE alias
  32. HANDLE hdwp32; // handle of WOW allocated 32 bit object
  33. } HDW, *PHDW;
  34. /* Handle mapping macros
  35. */
  36. //
  37. // The 32-bit hInstance for a 16-bit task will be hMod / hInst.
  38. // The hModule/hInstnace for a 32-bit entity will be xxxx / 0000.
  39. //
  40. // FritzS 8/13/92
  41. //
  42. #define HINSTRES32(h16) ((h16)?HMODINST32(h16):(HANDLE)NULL)
  43. //
  44. // The THREADID32 and HTASK32 macros are nearly equivalent, but the
  45. // WOWHandle mapping uses the one which will detect aliases (see WOLE2.C).
  46. // Most other functions don't need alias detection and it is too late
  47. // to test with the more general.
  48. //
  49. #ifdef DEBUG
  50. //
  51. // Check for task aliases that will cause us to fault if we dereference the NULL
  52. // pointer returned by SEGPTR(htask16,0).
  53. //
  54. #define THREADID32(htask16) \
  55. ((htask16) \
  56. ? (ISTASKALIAS(htask16) \
  57. ? (WOW32ASSERTMSGF(FALSE, \
  58. ("WOW32 ERROR %s line %d Task alias " \
  59. "to THREADID32, use HTASK32 instead.\n", \
  60. szModule, __LINE__)), 0) \
  61. : ((PTDB)SEGPTR((htask16),0))->TDB_ThreadID) \
  62. : 0)
  63. #else
  64. #define THREADID32(htask16) ((htask16) \
  65. ? ((PTDB)SEGPTR((htask16),0))->TDB_ThreadID \
  66. : 0)
  67. #endif
  68. #define HTASK32(htask16) (Htask16toThreadID32(htask16))
  69. #define GETHTASK16(htask32) (ThreadID32toHtask16((DWORD)htask32))
  70. #define ISINST16(h32) (((INT)(h32) & 0x0000fffe) != 0)
  71. #define HMODINST32(h16) ((HANDLE) MAKELONG(h16, GetExePtr16(h16)))
  72. #define GETHINST16(h32) ((HAND16)(INT)(h32))
  73. #define GETHMOD16(h32) ((HAND16)(INT)(HIWORD(h32)))
  74. #define ISMEM16(h32) (((INT)(h32) & 0xFFFF0000) == 0)
  75. #define HMEM32(h16) ((HANDLE)(INT)(h16))
  76. #define GETHMEM16(h32) ((HMEM16)(INT)(h32))
  77. #define ISRES16(h32) ((INT)(h32)&1)
  78. #define HRES32(p) ((p)?(HANDLE)((INT)(p)|1):(HANDLE)NULL)
  79. #define GETHRES16(h32) ((PRES)((INT)(h32)&~1))
  80. #define USER32(h16) ((HAND32)(INT)(SHORT)(h16))
  81. #define USER16(h32) ((HAND16)h32)
  82. #define HWND32(h16) USER32(h16)
  83. #define FULLHWND32(h16) (pfnOut.pfnGetFullUserHandle)(h16)
  84. #define GETHWND16(h32) USER16(h32)
  85. #define GETHWNDIA16(h32) GETHWND16(h32)
  86. #define HWNDIA32(h16) HWND32(h16)
  87. #define HMENU32(h16) USER32(h16)
  88. #define GETHMENU16(h32) USER16(h32)
  89. #define SERVERHANDLE(h) (HIWORD(h))
  90. #define GDI32(h16) (HANDLE) hConvert16to32(h16)
  91. #define GDI16(h32) ((HAND16) hConvert32to16((DWORD)h32))
  92. #define HGDI16(hobj32) GDI16((HAND32)(hobj32))
  93. #define HDC32(hdc16) GDI32((HAND16)(hdc16))
  94. #define GETHDC16(hdc32) GDI16((HAND32)(hdc32))
  95. #define HFONT32(hobj16) GDI32((HAND16)(hobj16))
  96. #define GETHFONT16(hobj32) GDI16((HAND32)(hobj32))
  97. #define HMETA32(hobj16) ((HANDLE)HMFFromWinMetaFile((HAND16)(hobj16),FALSE))
  98. #define GETHMETA16(hobj32) ((HAND16)WinMetaFileFromHMF((HMETAFILE)(hobj32),FALSE))
  99. #define HRGN32(hobj16) GDI32((HAND16)(hobj16))
  100. #define GETHRGN16(hobj32) GDI16((HAND32)(hobj32))
  101. #define HBITMAP32(hobj16) GDI32((HAND16)(hobj16))
  102. #define GETHBITMAP16(hobj32) GDI16((HAND32)(hobj32))
  103. #define HBRUSH32(hobj16) GDI32((HAND16)(hobj16))
  104. #define GETHBRUSH16(hobj32) GDI16((HAND32)(hobj32))
  105. #define HPALETTE32(hobj16) GDI32((HAND16)(hobj16))
  106. #define GETHPALETTE16(hobj32) GDI16((HAND32)(hobj32))
  107. #define HPEN32(hobj16) GDI32((HAND16)(hobj16))
  108. #define GETHPEN16(hobj32) GDI16((HAND32)(hobj32))
  109. #define HOBJ32(hobj16) GDI32((HAND16)(hobj16))
  110. #define GETHOBJ16(hobj32) GDI16((HAND32)(hobj32))
  111. #define HDROP32(hobj16) (HDROP)DropFilesHandler((HAND16)(hobj16), 0, HDROP_H16 | HDROP_ALLOCALIAS)
  112. #define GETHDROP16(hobj32) (HAND16)DropFilesHandler(0, (HAND32)(hobj32), HDROP_H32 | HDROP_ALLOCALIAS)
  113. #define FREEHDROP16(hobj16) (HDROP)DropFilesHandler((HAND16)(hobj16), 0, HDROP_H16 | HDROP_FREEALIAS)
  114. #define HMODULE32(h16) ((HANDLE)(h16)) // bogus
  115. #define GETHMODULE16(h32) ((HAND16)(h32)) // bogus
  116. #define HLOCAL32(h16) ((HANDLE)(h16)) // bogus
  117. #define GETHLOCAL16(h32) ((HAND16)(h32)) // bogus
  118. #define HANDLE32(h16) ((HANDLE)(h16)) // bogus (used in wucomm.c)
  119. #define GETHANDLE16(h32) ((HAND16)(h32)) // bogus (used in wucomm.c)
  120. #define BOGUSHANDLE32(h16) ((DWORD)(h16)) // bogus
  121. #define HDWP32(hdwp16) Prn32((HAND16)(hdwp16))
  122. #define GETHDWP16(hdwp32) GetPrn16((HAND32)(hdwp32))
  123. #define FREEHDWP16(h16) FreePrn((HAND16)(h16))
  124. #define COLOR32(clr) (COLORREF)( ( ((DWORD)(clr) >= 0x03000000) && \
  125. (HIWORD(clr) != 0x10ff) ) \
  126. ? ((clr) & 0xffffff) : (clr) )
  127. /*
  128. * MultiMedia handle mappings - MikeTri 12-May-1992
  129. *
  130. * change WOWCLASS_UNKNOWN to WOWCLASS_WIN16 MikeTri 210292
  131. */
  132. #define HDRVR32(hdrvr16) GetMMedia32((HAND16)(hdrvr16))
  133. #define GETHDRVR16(hdrvr32) GetMMedia16((HAND32)(hdrvr32), WOWCLASS_WIN16)
  134. #define FREEHDRVR16(hdrvr16) FreeMMedia16((HAND16)(hdrvr16))
  135. #define HMMIO32(hmmio16) GetMMedia32((HAND16)(hmmio16))
  136. #define GETHMMIO16(hmmio32) GetMMedia16((HAND32)(hmmio32), WOWCLASS_WIN16)
  137. #define FREEHMMIO16(hmmio16) FreeMMedia16((HAND16)(hmmio16))
  138. #define HMIDIIN32(hmidiin16) GetMMedia32((HAND16)(hmidiin16))
  139. #define GETHMIDIIN16(hmidiin32) GetMMedia16((HAND32)(hmidiin32), WOWCLASS_WIN16)
  140. #define FREEHMIDIIN16(hmidiin16) FreeMMedia16((HAND16)(hmidiin16))
  141. #define HMIDIOUT32(hmidiout16) GetMMedia32((HAND16)(hmidiout16))
  142. #define GETHMIDIOUT16(hmidiout32) GetMMedia16((HAND32)(hmidiout32), WOWCLASS_WIN16)
  143. #define FREEHMIDIOUT16(hmidiout16) FreeMMedia16((HAND16)(hmidiout16))
  144. #define HWAVEIN32(hwavein16) GetMMedia32((HAND16)(hwavein16))
  145. #define GETHWAVEIN16(hwavein32) GetMMedia16((HAND32)(hwavein32), WOWCLASS_WIN16)
  146. #define FREEHWAVEIN16(hwavein16) FreeMMedia16((HAND16)(hwavein16))
  147. #define HWAVEOUT32(hwaveout16) GetMMedia32((HAND16)(hwaveout16))
  148. #define GETHWAVEOUT16(hwaveout32) GetMMedia16((HAND32)(hwaveout32), WOWCLASS_WIN16)
  149. #define FREEHWAVEOUT16(hwaveout16) FreeMMedia16((HAND16)(hwaveout16))
  150. /* Function prototypes
  151. */
  152. INT GetStdClassNumber(PSZ pszClass);
  153. WNDPROC GetStdClassWndProc(DWORD iClass);
  154. DWORD GetStdClassThunkProc(INT iClass);
  155. PWC FindClass16 (LPCSTR pszClass, HINST16 hInst16);
  156. #define FindPWC(h32) (PWC) GetClassLong((h32), GCL_WOWWORDS)
  157. #define FindPWW(h32) (PWW) GetWindowLong((h32), GWL_WOWWORDS)
  158. HAND16 GetMMedia16 (HANDLE h32, INT iClass); //MultiMedia additions - MikeTri 12-May-1992
  159. HANDLE GetMMedia32 (HAND16 h16);
  160. VOID FreeMMedia16 (HAND16 h16);
  161. HAND16 GetWinsock16 (INT h32, INT iClass); //Winsock additions - DavidTr 4-Oct-1992
  162. DWORD GetWinsock32 (HAND16 h16);
  163. VOID FreeWinsock16 (HAND16 h16);
  164. BOOL MessageNeedsThunking (UINT uMsg);
  165. DWORD Htask16toThreadID32(HTASK16 htask16);
  166. /* Data structure used in thunking LB_GETTEXT special case
  167. */
  168. typedef struct _THUNKTEXTDWORD {
  169. BOOL fDWORD; // dword used or text
  170. DWORD dwDataItem; // dword
  171. } THUNKTEXTDWORD, *PTHUNKTEXTDWORD;
  172. typedef union _MSGTHUNKBUFFER {
  173. MSG msg;
  174. DRAWITEMSTRUCT ditem;
  175. MEASUREITEMSTRUCT mitem;
  176. DELETEITEMSTRUCT delitem;
  177. COMPAREITEMSTRUCT cmpitem;
  178. RECT rect;
  179. CREATESTRUCT cstruct;
  180. WINDOWPOS winpos;
  181. CLIENTCREATESTRUCT clcstruct;
  182. MDINEXTMENU mnm;
  183. MDICREATESTRUCT mdis;
  184. DROPSTRUCT dps;
  185. POINT pt[5]; // WM_GETMINMAXINFO
  186. UINT uinteger[2]; // SBM_GETRANGE
  187. BYTE cmdichild[sizeof(CREATESTRUCT) +
  188. sizeof(MDICREATESTRUCT)]; // FinishThunking...
  189. BYTE cmdiclient[sizeof(CREATESTRUCT) +
  190. sizeof(CLIENTCREATESTRUCT)]; // FinishThunking...
  191. BYTE calcsz[sizeof(NCCALCSIZE_PARAMS) +
  192. sizeof(WINDOWPOS)];
  193. THUNKTEXTDWORD thkdword; // LB_GETTEXT w/no HASSTRINGS
  194. } MSGTHUNKBUFFER, *LPMSGTHUNKBUFFER;
  195. typedef struct _MSGPARAMEX *LPMSGPARAMEX;
  196. typedef BOOL (FASTCALL *LPFNTHUNKMSG16)(LPMSGPARAMEX lpmpex);
  197. typedef VOID (FASTCALL *LPFNUNTHUNKMSG16)(LPMSGPARAMEX lpmpex);
  198. typedef struct _MSGPARAMEX {
  199. PARM16 Parm16;
  200. HWND hwnd;
  201. UINT uMsg;
  202. UINT uParam;
  203. LONG lParam;
  204. LONG lReturn;
  205. LPFNUNTHUNKMSG16 lpfnUnThunk16;
  206. PWW pww;
  207. INT iMsgThunkClass; // thunking aid
  208. INT iClass;
  209. MSGTHUNKBUFFER MsgBuffer[1];
  210. } MSGPARAMEX;
  211. #define MSG16NEEDSTHUNKING(lpmpex) ((lpmpex)->iClass != WOWCLASS_NOTHUNK)
  212. // Used for compatibility sake. If app gets The hInstance of a 32bit window
  213. // (the loword of 32bit hinstance is zero) then return a bogus gdt.
  214. //
  215. // Subsequently, if the app does a getmodulefilename on it we will return a
  216. // a fake 32bit modulename.
  217. //
  218. // This is required for a couple of HDC apps and 16bit recorder.
  219. //
  220. // - Nanduri
  221. //
  222. #define BOGUSGDT 0xfff0
  223. #define VALIDHMOD(h32) (((h32) && !(WORD)(h32)) ? BOGUSGDT : (WORD)(h32))
  224. // For DEVMODE struct handling
  225. // We add a little extra to devmode sizes that we return to 16-bit apps
  226. // including a signature "DM31" at the end of the driver extra stuff
  227. // See notes in wstruc.c
  228. typedef struct _WOWDM31 {
  229. DWORD dwWOWSig;
  230. WORD dmSpecVersion;
  231. WORD dmSize;
  232. WORD dmDriverExtra;
  233. WORD reserved; // pad to even DWORD (required for ptr arithmetic)
  234. } WOWDM31;
  235. typedef WOWDM31 UNALIGNED *PWOWDM31;
  236. // WOW DEVMODE magic signature
  237. #define WOW_DEVMODE31SIG 0x444d3331 // "DM31"
  238. // Win3.1 DEVMODE spec
  239. #define WOW_DEVMODE31SPEC 0x30A
  240. // Constant we add to Win3.1 DevMode->DriverExtra to account for the NT Devmode
  241. // fields not in the Win3.1 devmode & the WOW thunk info we add to the end
  242. #define WOW_DEVMODEEXTRA ((sizeof(DEVMODE)-sizeof(DEVMODE31))+sizeof(WOWDM31))
  243. extern WORD gUser16hInstance;
  244. ULONG GetGCL_HMODULE(HWND hwnd);
  245. #define ISFUNCID(dwcallid) (!((DWORD)(dwcallid) & 0xffff0000))
  246. #define POSTMSG(dwLocal) (ISFUNCID(dwLocal = \
  247. FRAMEPTR(CURRENTPTD()->vpStack)->wCallID) ? \
  248. (aw32WOW[dwLocal].lpfnW32 == WU32PostMessage) : \
  249. (dwLocal == (DWORD) WU32PostMessage))
  250. ULONG WOW32FaxHandler(UINT iFun, LPSTR lpIn);
  251. #define BAD_GDI32_HANDLE 0xFFFF // bad GDI32 handle
  252. #define END_OF_LIST 0 // end of free list
  253. // State flags
  254. #define SLOT_FREE 0x0000 // table index is free
  255. #define IN_USE 0x0001 // table index is in use
  256. #define H16_DELETED 0x0002 // marks index as candidate for being reclaimed
  257. #define GDI_STOCK_OBJECT 0x0003 // marks stock objects (non-deletable)
  258. // defines entries in the GDI16 handle mapping table
  259. typedef struct _tagGDIH16MAP {
  260. HANDLE h32; // store the full h32
  261. WORD State; // Either SLOT_FREE, IN_USE or H16_DELETED
  262. WORD NextFree; // points to next free index or END_OF_LIST
  263. } GDIH16MAP, *PGDIH16MAP;
  264. // defines entries in the GDI32 handle mapping table
  265. typedef struct _tagGDIH32MAP {
  266. WORD h16index;
  267. } GDIH32MAP, *PGDIH32MAP;
  268. void DeleteGdiHandleMappingTables(void);
  269. BOOL InitializeGdiHandleMappingTable(void);
  270. void RebuildGdiHandleMappingTables(void);
  271. void DeleteWOWGdiHandle(HANDLE h32, HAND16 h16);
  272. HAND16 GetWOWGdiHandleInfo(HANDLE h32);
  273. HAND16 IsGDIh32Mapped(HANDLE h32);
  274. INT GetIClass(PWW pww, HWND hwnd);
  275. /*
  276. //
  277. // if it's a standard class (fast method) ?
  278. // return it :
  279. // else if the window is initialized ?
  280. // we know it's a private app class : else get the class the hard way
  281. //
  282. // Note: GetiClassTheHardWay() may stiil return a standard class. See walias.c
  283. //
  284. #define GETICLASS(pww, hwnd) ( \
  285. (((((PWW)pww)->fnid & 0xfff) >= FNID_START) && \
  286. ((((PWW)pww)->fnid & 0xfff) <= FNID_END)) ? \
  287. (pfnOut.aiWowClass[(((PWW)pww)->fnid & 0xfff) - FNID_START]) : \
  288. ((((PWW)pww)->state2 & WINDOW_IS_INITIALIZED) ? \
  289. WOWCLASS_WIN16 : GetiClassTheHardWay(hwnd)) )
  290. */
  291. #define GETICLASS(pww, hwnd) GetIClass(pww, hwnd)