home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / MSINC.PAK / WOWNT32.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  10KB  |  263 lines

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