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.

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