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.

321 lines
14 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: wowuserp.h *
  3. * *
  4. * Declarations of USER services provided to WOW. *
  5. * *
  6. * Created: 03-Mar-1993 *
  7. * Author: John Colleran [johnc] *
  8. * *
  9. * Copyright (c) 1993-1998 Microsoft Corporation *
  10. \**************************************************************************/
  11. #include "w32w64.h"
  12. #pragma pack(1)
  13. typedef struct _NE_MODULE_SEG {
  14. USHORT ns_sector;
  15. USHORT ns_cbseg;
  16. USHORT ns_flags;
  17. USHORT ns_minalloc;
  18. USHORT ns_handle;
  19. } NEMODULESEG;
  20. typedef struct _NE_MODULE_SEG UNALIGNED *PNEMODULESEG;
  21. #pragma pack()
  22. // Shared WOW32 prototypes called by USER32.
  23. typedef HLOCAL (WINAPI *PFNLALLOC)(UINT dwFlags, UINT dwBytes, HANDLE hInstance);
  24. typedef HLOCAL (WINAPI *PFNLREALLOC)(HLOCAL hMem, UINT dwBytes, UINT dwFlags, HANDLE hInstance, PVOID* ppv);
  25. typedef LPVOID (WINAPI *PFNLLOCK)(HLOCAL hMem, HANDLE hInstance);
  26. typedef BOOL (WINAPI *PFNLUNLOCK)(HLOCAL hMem, HANDLE hInstance);
  27. typedef UINT (WINAPI *PFNLSIZE)(HLOCAL hMem, HANDLE hInstance);
  28. typedef HLOCAL (WINAPI *PFNLFREE)(HLOCAL hMem, HANDLE hInstance);
  29. typedef WORD (WINAPI *PFN16GALLOC)(UINT flags, DWORD cb);
  30. typedef VOID (WINAPI *PFN16GFREE)(WORD h16Mem);
  31. typedef DWORD (WINAPI *PFNGETMODFNAME)(HANDLE hModule, LPTSTR lpszPath, DWORD cchPath);
  32. typedef VOID (WINAPI *PFNEMPTYCB)(VOID);
  33. typedef DWORD (WINAPI *PFNGETEXPWINVER)(HANDLE hModule);
  34. typedef HANDLE (WINAPI *PFNFINDA)(HANDLE hModule, LPCSTR lpName, LPCSTR lpType, WORD wLang);
  35. typedef HANDLE (WINAPI *PFNFINDW)(HANDLE hModule, LPCWSTR lpName, LPCWSTR lpType, WORD wLang);
  36. typedef HANDLE (WINAPI *PFNLOAD)(HANDLE hModule, HANDLE hResInfo);
  37. typedef BOOL (WINAPI *PFNFREE)(HANDLE hResData, HANDLE hModule);
  38. typedef LPSTR (WINAPI *PFNLOCK)(HANDLE hResData, HANDLE hModule);
  39. typedef BOOL (WINAPI *PFNUNLOCK)(HANDLE hResData, HANDLE hModule);
  40. typedef DWORD (WINAPI *PFNSIZEOF)(HANDLE hModule, HANDLE hResInfo);
  41. typedef DWORD (WINAPI *PFNWOWWNDPROCEX)(HWND hwnd, UINT uMsg, WPARAM uParam, LPARAM lParam, DWORD dw, PVOID adwWOW);
  42. typedef BOOL (WINAPI *PFNWOWDLGPROCEX)(HWND hwnd, UINT uMsg, WPARAM uParam, LPARAM lParam, DWORD dw, PVOID adwWOW);
  43. typedef int (WINAPI *PFNWOWEDITNEXTWORD)(LPSTR lpch, int ichCurrent, int cch, int code, DWORD dwProc16);
  44. typedef VOID (WINAPI *PFNWOWCBSTOREHANDLE)(WORD wFmt, WORD h16);
  45. typedef WORD (FASTCALL *PFNGETPROCMODULE16)(DWORD vpfn);
  46. typedef VOID (FASTCALL *PFNWOWMSGBOXINDIRECTCALLBACK)(DWORD vpfnCallback, LPHELPINFO lpHelpInfo);
  47. typedef int (WINAPI *PFNWOWILSTRCMP)(LPCWSTR lpString1, LPCWSTR lpString2);
  48. typedef VOID (FASTCALL *PFNWOWTELLWOWTHEHDLG)(HWND hDlg);
  49. // Shared USER32 prototypes called by WOW32
  50. typedef HWND (WINAPI *PFNCSCREATEWINDOWEX)(DWORD dwExStyle, LPCTSTR lpClassName,
  51. LPCTSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HANDLE hInstance, LPVOID lpParam, DWORD Flags);
  52. typedef VOID (WINAPI *PFNDIRECTEDYIELD)(DWORD ThreadId);
  53. typedef VOID (WINAPI *PFNFREEDDEDATA)(HANDLE hDDE, BOOL fIgnorefRelease, BOOL fFreeTruelyGlobalObjects);
  54. typedef LONG (WINAPI *PFNGETCLASSWOWWORDS)(HINSTANCE hInstance, LPCTSTR pString);
  55. typedef BOOL (WINAPI *PFNINITTASK)(UINT dwExpWinVer, DWORD dwAppCompatFlags, LPCSTR lpszModName, LPCSTR lpszBaseFileName, DWORD hTaskWow, DWORD dwHotkey, DWORD idTask, DWORD dwX, DWORD dwY, DWORD dwXSize, DWORD dwYSize);
  56. typedef ATOM (WINAPI *PFNREGISTERCLASSWOWA)(PVOID lpWndClass, LPDWORD pdwWOWstuff);
  57. typedef BOOL (WINAPI *PFNREGISTERUSERHUNGAPPHANDLERS)(PFNW32ET pfnW32EndTask, HANDLE hEventWowExec);
  58. typedef HWND (WINAPI *PFNSERVERCREATEDIALOG)(HANDLE hmod, LPDLGTEMPLATE lpDlgTemplate, DWORD cb, HWND hwndOwner , DLGPROC pfnWndProc, LPARAM dwInitParam, UINT fFlags);
  59. typedef HCURSOR (WINAPI *PFNSERVERLOADCREATECURSORICON)(HANDLE hmod, LPTSTR lpModName, DWORD dwExpWinVer, LPCTSTR lpName, DWORD cb, PVOID pcur, LPTSTR lpType, BOOL fClient);
  60. typedef HMENU (WINAPI *PFNSERVERLOADCREATEMENU)(HANDLE hMod, LPTSTR lpName, CONST LPMENUTEMPLATE pmt, DWORD cb, BOOL fCallClient);
  61. typedef BOOL (WINAPI *PFNWOWCLEANUP)(HANDLE hInstance, DWORD hTaskWow);
  62. typedef BOOL (WINAPI *PFNWOWMODULEUNLOAD)(HANDLE hModule);
  63. typedef HWND (WINAPI *PFNWOWFINDWINDOW)(LPCSTR lpClassName, LPCSTR lpWindowName);
  64. typedef HBITMAP (WINAPI *PFNWOWLOADBITMAPA)(HINSTANCE hmod, LPCSTR lpName, LPBYTE pResData, DWORD cbResData);
  65. typedef BOOL (WINAPI *PFNWOWWAITFORMSGANDEVENT)(HANDLE hevent);
  66. typedef BOOL (WINAPI *PFNYIELDTASK)(VOID);
  67. typedef DWORD (WINAPI *PFNGETFULLUSERHANDLE)(WORD wHandle);
  68. typedef DWORD (WINAPI *PFNGETMENUINDEX)(HMENU hMenu, HMENU hSubMenu);
  69. typedef WORD (WINAPI *PFNWOWGETDEFWINDOWPROCBITS)(PBYTE pDefWindowProcBits, WORD cbDefWindowProcBits);
  70. typedef VOID (WINAPI *PFNFILLWINDOW)(HWND hwndParent, HWND hwnd, HDC hdc, HANDLE hBrush);
  71. // other prototypes
  72. typedef BOOL (WINAPI *PFNWOWGLOBALFREEHOOK)(HGLOBAL hMem);
  73. /*
  74. * MEASUREITEMSTRUCT itemWidth tag telling wow the itemData is a flat pointer
  75. */
  76. #define MIFLAG_FLAT 0x464C4154
  77. /*
  78. * CallWindowProc Bits
  79. */
  80. #define WOWCLASS_RPL_MASK 0x00060000 // the LDT bits that store the 2 high bits
  81. #define WNDPROC_WOWPROC 0xC0000000 // These bits for WOW Window Procs
  82. #define WNDPROC_WOWMASK 0x3fffffff // To mask off wow bits
  83. #define WNDPROC_HANDLE 0xFFFF // HIWORD(x) == 0xFFFF for handle
  84. // USER needs a way to distinguish between a WOW and a Win32 window proc. We
  85. // used to achieve this by always setting the MSB of a 16:16 address as 1 (and
  86. // storing the MSB in the Table indicator bit of the LDT which is always 1). The
  87. // MSB of a user mode flat address was guranteed to be never 1 as the user mode
  88. // address space was limited to 2GB. Starting with NT 5.0, user mode address
  89. // space is being increased to 3GB. This change breaks the above assumption
  90. // that a 32bit user mode flat address will never have the MSB as 1.
  91. // To work around this problem, WOW is going to use the two bits of a
  92. // 16:16 address instead of just one. We will set both these bits as 1 because
  93. // with 3GB address space, the user mode flat addresses cannot have 11 as the
  94. // first two bits. To achieve this, we will save the 2 most significant bits of
  95. // the selector in the bit 1 and bit 2. We are able to do this because for WOW
  96. // because both these bits have fixed values.
  97. //
  98. // SudeepB 21-Nov-1996
  99. #ifndef _WIN64
  100. // MarkWOWProc
  101. // zero out the RPL bits
  102. // get the high two bit in position where they have to be saved
  103. // save the high bits and mark it a wow proc
  104. #define MarkWOWProc(vpfnProc,result) \
  105. { \
  106. ULONG temp1,temp2; \
  107. temp1 = (ULONG)vpfnProc & ~WOWCLASS_RPL_MASK; \
  108. temp2 = ((ULONG)vpfnProc & WNDPROC_WOWPROC) >> 13; \
  109. (ULONG)result = temp1 | temp2 | WNDPROC_WOWPROC; \
  110. }
  111. // UnMarkWOWProc
  112. // mask off the marker bits
  113. // get the saved bits to right places
  114. // restore the saved bits and set the RPL field correctly
  115. #define UnMarkWOWProc(vpfnProc,result) \
  116. { \
  117. ULONG temp1,temp2; \
  118. temp1 = (ULONG)vpfnProc & WNDPROC_WOWMASK; \
  119. temp2 = ((ULONG)vpfnProc & WOWCLASS_RPL_MASK) << 13; \
  120. result = temp1 | temp2 | WOWCLASS_RPL_MASK; \
  121. }
  122. #define IsWOWProc(vpfnProc) (((ULONG)vpfnProc & WNDPROC_WOWPROC) == WNDPROC_WOWPROC)
  123. #else
  124. #define MarkWOWProc(vpfnProc,result) DBG_UNREFERENCED_PARAMETER(vpfnProc)
  125. #define UnMarkWOWProc(vpfnProc,result) DBG_UNREFERENCED_PARAMETER(vpfnProc)
  126. #define IsWOWProc(vpfnProc) (FALSE)
  127. #endif
  128. /*
  129. * CreateWindow flags
  130. */
  131. #define CW_FLAGS_ANSI 0x00000001
  132. typedef struct tagAPFNWOWHANDLERSIN
  133. {
  134. // In'ees - passed from WOW32 to USER32 and called by USER32
  135. PFNLALLOC pfnLocalAlloc;
  136. PFNLREALLOC pfnLocalReAlloc;
  137. PFNLLOCK pfnLocalLock;
  138. PFNLUNLOCK pfnLocalUnlock;
  139. PFNLSIZE pfnLocalSize;
  140. PFNLFREE pfnLocalFree;
  141. PFNGETEXPWINVER pfnGetExpWinVer;
  142. PFN16GALLOC pfn16GlobalAlloc;
  143. PFN16GFREE pfn16GlobalFree;
  144. PFNEMPTYCB pfnEmptyCB;
  145. PFNFINDA pfnFindResourceEx;
  146. PFNLOAD pfnLoadResource;
  147. PFNFREE pfnFreeResource;
  148. PFNLOCK pfnLockResource;
  149. PFNUNLOCK pfnUnlockResource;
  150. PFNSIZEOF pfnSizeofResource;
  151. PFNWOWWNDPROCEX pfnWowWndProcEx;
  152. PFNWOWDLGPROCEX pfnWowDlgProcEx;
  153. PFNWOWEDITNEXTWORD pfnWowEditNextWord;
  154. PFNWOWCBSTOREHANDLE pfnWowCBStoreHandle;
  155. PFNGETPROCMODULE16 pfnGetProcModule16;
  156. PFNWOWMSGBOXINDIRECTCALLBACK pfnWowMsgBoxIndirectCallback;
  157. PFNWOWILSTRCMP pfnWowIlstrsmp;
  158. PFNWOWTELLWOWTHEHDLG pfnWOWTellWOWThehDlg;
  159. } PFNWOWHANDLERSIN, * APFNWOWHANDLERSIN;
  160. typedef struct tagAPFNWOWHANDLERSOUT
  161. {
  162. // Out'ees - passed from USER32 to WOW32 and called/used by WOW32
  163. DWORD dwBldInfo;
  164. PFNCSCREATEWINDOWEX pfnCsCreateWindowEx;
  165. PFNDIRECTEDYIELD pfnDirectedYield;
  166. PFNFREEDDEDATA pfnFreeDDEData;
  167. PFNGETCLASSWOWWORDS pfnGetClassWOWWords;
  168. PFNINITTASK pfnInitTask;
  169. PFNREGISTERCLASSWOWA pfnRegisterClassWOWA;
  170. PFNREGISTERUSERHUNGAPPHANDLERS pfnRegisterUserHungAppHandlers;
  171. PFNSERVERCREATEDIALOG pfnServerCreateDialog;
  172. PFNSERVERLOADCREATECURSORICON pfnServerLoadCreateCursorIcon;
  173. PFNSERVERLOADCREATEMENU pfnServerLoadCreateMenu;
  174. PFNWOWCLEANUP pfnWOWCleanup;
  175. PFNWOWMODULEUNLOAD pfnWOWModuleUnload;
  176. PFNWOWFINDWINDOW pfnWOWFindWindow;
  177. PFNWOWLOADBITMAPA pfnWOWLoadBitmapA;
  178. PFNWOWWAITFORMSGANDEVENT pfnWowWaitForMsgAndEvent;
  179. PFNYIELDTASK pfnYieldTask;
  180. PFNGETFULLUSERHANDLE pfnGetFullUserHandle;
  181. PFNGETMENUINDEX pfnGetMenuIndex;
  182. PFNWOWGETDEFWINDOWPROCBITS pfnWowGetDefWindowProcBits;
  183. PFNFILLWINDOW pfnFillWindow;
  184. INT * aiWowClass;
  185. } PFNWOWHANDLERSOUT, * APFNWOWHANDLERSOUT;
  186. //
  187. // The WW structure is embedded at the end of USER's WND structure.
  188. // However, WOW and USER use different names to access the WW
  189. // fields. So this structure is defined as a union of two structures,
  190. // WHICH MUST HAVE THE SAME SIZE, just different field names.
  191. //
  192. // Make sure that WND_CNT_WOWDWORDS matches the number of DWORDs
  193. // used by the WOW only fields.
  194. //
  195. // FindPWW(hwnd) returns a read-only pointer to this structure for
  196. // a given window. To change elements of this structure, use
  197. // SETWW (== SetWindowLong) with the appropriate GWL_WOW* offset
  198. // defined below.
  199. //
  200. /* WOW class/handle type identifiers (see WARNING below)
  201. */
  202. #define FNID_START 0x0000029A
  203. #define FNID_END 0x000002B4
  204. #define WOWCLASS_UNKNOWN 0 // here begin our "window handle" classes
  205. #define WOWCLASS_WIN16 1
  206. #define WOWCLASS_BUTTON 2
  207. #define WOWCLASS_COMBOBOX 3
  208. #define WOWCLASS_EDIT 4
  209. #define WOWCLASS_LISTBOX 5
  210. #define WOWCLASS_MDICLIENT 6
  211. #define WOWCLASS_SCROLLBAR 7
  212. #define WOWCLASS_STATIC 8
  213. #define WOWCLASS_DESKTOP 9
  214. #define WOWCLASS_DIALOG 10
  215. #define WOWCLASS_ICONTITLE 11
  216. #define WOWCLASS_MENU 12
  217. #define WOWCLASS_SWITCHWND 13
  218. #define WOWCLASS_COMBOLBOX 14
  219. #define WOWCLASS_MAX 14 // Always equal to the last value used.
  220. #define WOWCLASS_NOTHUNK 0xFF // not an actual class index
  221. //
  222. // WARNING! The above sequence and values must be maintained otherwise the
  223. // table in WMSG16.C for message thunking must be changed. Same goes for
  224. // table in WALIAS.C.
  225. //
  226. //
  227. // When including this from USER, VPWNDPROC is undefined
  228. //
  229. #ifndef _WALIAS_
  230. typedef DWORD VPWNDPROC;
  231. typedef DWORD VPSZ;
  232. #endif
  233. typedef struct tagWOWCLS {
  234. VPSZ vpszMenu;
  235. WORD iClsExtra; // app's value for class extra
  236. WORD hMod16;
  237. } WC;
  238. typedef WC UNALIGNED *PWC;
  239. typedef struct _WW { /* ww */
  240. /*
  241. *
  242. * WOW/USER fields
  243. * NOTE: The order and size of the following 4 fields is assumed
  244. * by the SetWF, ClrWF, TestWF, MaskWF macros.
  245. * Specifically, state must remain the first field in this structure.
  246. *
  247. */
  248. DWORD state; // State flags
  249. DWORD state2; //
  250. DWORD ExStyle; // Extended Style
  251. DWORD style; // Style flags
  252. KHANDLE hModule; // Handle to module instance data (32-bit).
  253. WORD hMod16; // WOW only -- hMod of wndproc
  254. WORD fnid; // record window proc used by this hwnd
  255. // access through GETFNID
  256. } WW, *PWW, **PPWW;
  257. // this is tied to WFISINITIALIZED in ntuser\inc\user.h
  258. #define WINDOW_IS_INITIALIZED 0x80000000
  259. ULONG_PTR UserRegisterWowHandlers(APFNWOWHANDLERSIN apfnWowIn, APFNWOWHANDLERSOUT apfnWowOut);
  260. VOID WINAPI RegisterWowBaseHandlers(PFNWOWGLOBALFREEHOOK pfn);
  261. BOOL
  262. InitTask(
  263. UINT dwExpWinVer,
  264. DWORD dwAppCompatFlags,
  265. LPCSTR lpszModName,
  266. LPCSTR lpszBaseFileName,
  267. DWORD hTaskWow,
  268. DWORD dwHotkey,
  269. DWORD idTask,
  270. DWORD dwX,
  271. DWORD dwY,
  272. DWORD dwXSize,
  273. DWORD dwYSize);
  274. BOOL YieldTask(VOID);
  275. #define DY_OLDYIELD ((DWORD)-1)
  276. VOID DirectedYield(DWORD ThreadId);
  277. DWORD UserGetInt16State(void);