home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / wownt32.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  10KB  |  255 lines

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