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.

260 lines
9.3 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1995-1999, Microsoft Corporation
  3. Module Name:
  4. wownt32.h
  5. Abstract:
  6. Procedure declarations for functions in WOW32.DLL callable by
  7. 3rd-party 32-bit thunking code.
  8. --*/
  9. #ifndef _WOWNT32_
  10. #define _WOWNT32_
  11. #if defined(_MSC_VER)
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #endif
  16. //
  17. // 16:16 -> 0:32 Pointer translation.
  18. //
  19. // WOWGetVDMPointer will convert the passed in 16-bit address
  20. // to the equivalent 32-bit flat pointer. If fProtectedMode
  21. // is TRUE, the function treats the upper 16 bits as a selector
  22. // in the local descriptor table. If fProtectedMode is FALSE,
  23. // the upper 16 bits are treated as a real-mode segment value.
  24. // In either case the lower 16 bits are treated as the offset.
  25. //
  26. // The return value is NULL if the selector is invalid.
  27. //
  28. // NOTE: Limit checking is not performed in the retail build
  29. // of Windows NT. It is performed in the checked (debug) build
  30. // of WOW32.DLL, which will cause NULL to be returned when the
  31. // limit is exceeded by the supplied offset.
  32. //
  33. LPVOID WINAPI WOWGetVDMPointer(DWORD vp, DWORD dwBytes,
  34. BOOL fProtectedMode);
  35. //
  36. // The following two functions are here for compatibility with
  37. // Windows 95. On Win95, the global heap can be rearranged,
  38. // invalidating flat pointers returned by WOWGetVDMPointer, while
  39. // a thunk is executing. On Windows NT, the 16-bit VDM is completely
  40. // halted while a thunk executes, so the only way the heap will
  41. // be rearranged is if a callback is made to Win16 code.
  42. //
  43. // The Win95 versions of these functions call GlobalFix to
  44. // lock down a segment's flat address, and GlobalUnfix to
  45. // release the segment.
  46. //
  47. // The Windows NT implementations of these functions do *not*
  48. // call GlobalFix/GlobalUnfix on the segment, because there
  49. // will not be any heap motion unless a callback occurs.
  50. // If your thunk does callback to the 16-bit side, be sure
  51. // to discard flat pointers and call WOWGetVDMPointer again
  52. // to be sure the flat address is correct.
  53. //
  54. LPVOID WINAPI WOWGetVDMPointerFix(DWORD vp, DWORD dwBytes,
  55. BOOL fProtectedMode);
  56. VOID WINAPI WOWGetVDMPointerUnfix(DWORD vp);
  57. //
  58. // Win16 memory management.
  59. //
  60. // These functions can be used to manage memory in the Win16
  61. // heap. The following four functions are identical to their
  62. // Win16 counterparts, except that they are called from Win32
  63. // code.
  64. //
  65. WORD WINAPI WOWGlobalAlloc16(WORD wFlags, DWORD cb);
  66. WORD WINAPI WOWGlobalFree16(WORD hMem);
  67. DWORD WINAPI WOWGlobalLock16(WORD hMem);
  68. BOOL WINAPI WOWGlobalUnlock16(WORD hMem);
  69. //
  70. // The following three functions combine two common operations in
  71. // one switch to 16-bit mode.
  72. //
  73. DWORD WINAPI WOWGlobalAllocLock16(WORD wFlags, DWORD cb, WORD *phMem);
  74. WORD WINAPI WOWGlobalUnlockFree16(DWORD vpMem);
  75. DWORD WINAPI WOWGlobalLockSize16(WORD hMem, PDWORD pcb);
  76. //
  77. // Yielding the Win16 nonpreemptive scheduler
  78. //
  79. // The following two functions are provided for Win32 code called
  80. // via Generic Thunks which needs to yield the Win16 scheduler so
  81. // that tasks in that VDM can execute while the thunk waits for
  82. // something to complete. These two functions are functionally
  83. // identical to calling back to 16-bit code which calls Yield or
  84. // DirectedYield.
  85. //
  86. VOID WINAPI WOWYield16(VOID);
  87. VOID WINAPI WOWDirectedYield16(WORD htask16);
  88. //
  89. // 16 <--> 32 Handle mapping functions.
  90. //
  91. // NOTE: While some of these functions perform trivial
  92. // conversions, these functions must be used to maintain
  93. // compatibility with future versions of Windows NT which
  94. // may require different handle mapping.
  95. //
  96. typedef enum _WOW_HANDLE_TYPE { /* WOW */
  97. WOW_TYPE_HWND,
  98. WOW_TYPE_HMENU,
  99. WOW_TYPE_HDWP,
  100. WOW_TYPE_HDROP,
  101. WOW_TYPE_HDC,
  102. WOW_TYPE_HFONT,
  103. WOW_TYPE_HMETAFILE,
  104. WOW_TYPE_HRGN,
  105. WOW_TYPE_HBITMAP,
  106. WOW_TYPE_HBRUSH,
  107. WOW_TYPE_HPALETTE,
  108. WOW_TYPE_HPEN,
  109. WOW_TYPE_HACCEL,
  110. WOW_TYPE_HTASK,
  111. WOW_TYPE_FULLHWND
  112. } WOW_HANDLE_TYPE;
  113. HANDLE WINAPI WOWHandle32 (WORD, WOW_HANDLE_TYPE);
  114. WORD WINAPI WOWHandle16 (HANDLE, WOW_HANDLE_TYPE);
  115. #define HWND_32(h16) ((HWND) (WOWHandle32(h16, WOW_TYPE_HWND)))
  116. #define HMENU_32(h16) ((HMENU) (WOWHandle32(h16, WOW_TYPE_HMENU)))
  117. #define HDWP_32(h16) ((HDWP) (WOWHandle32(h16, WOW_TYPE_HDWP)))
  118. #define HDROP_32(h16) ((HDROP) (WOWHandle32(h16, WOW_TYPE_HDROP)))
  119. #define HDC_32(h16) ((HDC) (WOWHandle32(h16, WOW_TYPE_HDC)))
  120. #define HFONT_32(h16) ((HFONT) (WOWHandle32(h16, WOW_TYPE_HFONT)))
  121. #define HMETAFILE_32(h16) ((HMETAFILE) (WOWHandle32(h16, WOW_TYPE_HMETAFILE)))
  122. #define HRGN_32(h16) ((HRGN) (WOWHandle32(h16, WOW_TYPE_HRGN)))
  123. #define HBITMAP_32(h16) ((HBITMAP) (WOWHandle32(h16, WOW_TYPE_HBITMAP)))
  124. #define HBRUSH_32(h16) ((HBRUSH) (WOWHandle32(h16, WOW_TYPE_HBRUSH)))
  125. #define HPALETTE_32(h16) ((HPALETTE) (WOWHandle32(h16, WOW_TYPE_HPALETTE)))
  126. #define HPEN_32(h16) ((HPEN) (WOWHandle32(h16, WOW_TYPE_HPEN)))
  127. #define HACCEL_32(h16) ((HACCEL) (WOWHandle32(h16, WOW_TYPE_HACCEL)))
  128. #define HTASK_32(h16) ((DWORD) (WOWHandle32(h16, WOW_TYPE_HTASK)))
  129. #define FULLHWND_32(h16) ((HWND) (WOWHandle32(h16, WOW_TYPE_FULLHWND)))
  130. #define HWND_16(h32) (WOWHandle16(h32, WOW_TYPE_HWND))
  131. #define HMENU_16(h32) (WOWHandle16(h32, WOW_TYPE_HMENU))
  132. #define HDWP_16(h32) (WOWHandle16(h32, WOW_TYPE_HDWP))
  133. #define HDROP_16(h32) (WOWHandle16(h32, WOW_TYPE_HDROP))
  134. #define HDC_16(h32) (WOWHandle16(h32, WOW_TYPE_HDC))
  135. #define HFONT_16(h32) (WOWHandle16(h32, WOW_TYPE_HFONT))
  136. #define HMETAFILE_16(h32) (WOWHandle16(h32, WOW_TYPE_HMETAFILE))
  137. #define HRGN_16(h32) (WOWHandle16(h32, WOW_TYPE_HRGN))
  138. #define HBITMAP_16(h32) (WOWHandle16(h32, WOW_TYPE_HBITMAP))
  139. #define HBRUSH_16(h32) (WOWHandle16(h32, WOW_TYPE_HBRUSH))
  140. #define HPALETTE_16(h32) (WOWHandle16(h32, WOW_TYPE_HPALETTE))
  141. #define HPEN_16(h32) (WOWHandle16(h32, WOW_TYPE_HPEN))
  142. #define HACCEL_16(h32) (WOWHandle16(h32, WOW_TYPE_HACCEL))
  143. #define HTASK_16(h32) (WOWHandle16(h32, WOW_TYPE_HTASK))
  144. //
  145. // Generic Callbacks.
  146. //
  147. // WOWCallback16 can be used in Win32 code called
  148. // from 16-bit (such as by using Generic Thunks) to call back to
  149. // the 16-bit side. The function called must be declared similarly
  150. // to the following:
  151. //
  152. // LONG FAR PASCAL CallbackRoutine(DWORD dwParam);
  153. //
  154. // If you are passing a pointer, declare the parameter as such:
  155. //
  156. // LONG FAR PASCAL CallbackRoutine(VOID FAR *vp);
  157. //
  158. // NOTE: If you are passing a pointer, you'll need to get the
  159. // pointer using WOWGlobalAlloc16 or WOWGlobalAllocLock16
  160. //
  161. // If the function called returns a WORD instead of a DWORD, the
  162. // upper 16 bits of the return value is undefined. Similarly, if
  163. // the function called has no return value, the entire return value
  164. // is undefined.
  165. //
  166. // WOWCallback16Ex allows any combination of arguments up to
  167. // WCB16_MAX_CBARGS bytes total to be passed to the 16-bit routine.
  168. // cbArgs is used to properly clean up the 16-bit stack after calling
  169. // the routine. Regardless of the value of cbArgs, WCB16_MAX_CBARGS
  170. // bytes will always be copied from pArgs to the 16-bit stack. If
  171. // pArgs is less than WCB16_MAX_CBARGS bytes from the end of a page,
  172. // and the next page is inaccessible, WOWCallback16Ex will incur an
  173. // access violation.
  174. //
  175. // If cbArgs is larger than the WCB16_MAX_ARGS which the running
  176. // system supports, the function returns FALSE and GetLastError
  177. // returns ERROR_INVALID_PARAMETER. Otherwise the function
  178. // returns TRUE and the DWORD pointed to by pdwRetCode contains
  179. // the return code from the callback routine. If the callback
  180. // routine returns a WORD, the HIWORD of the return code is
  181. // undefined and should be ignored using LOWORD(dwRetCode).
  182. //
  183. // WOWCallback16Ex can call routines using the PASCAL and CDECL
  184. // calling conventions. The default is to use the PASCAL
  185. // calling convention. To use CDECL, pass WCB16_CDECL in the
  186. // dwFlags parameter.
  187. //
  188. // The arguments pointed to by pArgs must be in the correct
  189. // order for the callback routine's calling convention.
  190. // To call the PASCAL routine SetWindowText,
  191. //
  192. // LONG FAR PASCAL SetWindowText(HWND hwnd, LPCSTR lpsz);
  193. //
  194. // pArgs would point to an array of words:
  195. //
  196. // WORD SetWindowTextArgs[] = {OFFSETOF(lpsz), SELECTOROF(lpsz), hwnd};
  197. //
  198. // In other words, the arguments are placed in the array in reverse
  199. // order with the least significant word first for DWORDs and offset
  200. // first for FAR pointers.
  201. //
  202. // To call the CDECL routine wsprintf, for example
  203. //
  204. // LPSTR lpszFormat = "%d %s";
  205. // int _cdecl wsprintf(lpsz, lpszFormat, nValue. lpszString);
  206. //
  207. // pArgs would point to the array:
  208. //
  209. // WORD wsprintfArgs[] = {OFFSETOF(lpsz), SELECTOROF(lpsz),
  210. // OFFSETOF(lpszFormat), SELECTOROF(lpszFormat),
  211. // nValue,
  212. // OFFSETOF(lpszString), SELECTOROF(lpszString)};
  213. //
  214. // In other words, the arguments are placed in the array in the order
  215. // listed in the function prototype with the least significant word
  216. // first for DWORDs and offset first for FAR pointers.
  217. //
  218. DWORD WINAPI WOWCallback16(DWORD vpfn16, DWORD dwParam);
  219. #define WCB16_MAX_CBARGS (16)
  220. #define WCB16_PASCAL (0x0)
  221. #define WCB16_CDECL (0x1)
  222. BOOL WINAPI WOWCallback16Ex(
  223. DWORD vpfn16,
  224. DWORD dwFlags,
  225. DWORD cbArgs,
  226. PVOID pArgs,
  227. PDWORD pdwRetCode
  228. );
  229. #endif /* !_WOWNT32_ */