home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / wownt32.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  9.7 KB  |  263 lines

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