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.

316 lines
7.1 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * WCALL32.C
  8. * WOW32 16-bit resource support
  9. *
  10. * History:
  11. * Created 11-Mar-1991 by Jeff Parsons (jeffpar)
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. MODNAME(wcall32.c);
  16. //
  17. // the 16-bit local handles are treated as 32-bit quantities.
  18. // the low word contains the 16-bit handle and the high word
  19. // contains the data segment for the block.
  20. // when we do a callback to WOW16LocalAlloc it will
  21. // return the DS in the high word (which is normally unused).
  22. // on subsequent callbacks to realloc/lock/unlock/size/free
  23. // the 16-bit code sets the DS to this value.
  24. //
  25. HANDLE APIENTRY W32LocalAlloc(UINT dwFlags, UINT dwBytes, HANDLE hInstance)
  26. {
  27. //
  28. // If hInstance is not ours, then make Win32 call and return the
  29. // result to USER.
  30. //
  31. if (LOWORD (hInstance) == 0) {
  32. return (LocalAlloc(dwFlags, dwBytes));
  33. }
  34. #if !defined(i386)
  35. if (dwBytes != 0)
  36. dwBytes += 4;
  37. #endif
  38. return LocalAlloc16((WORD)dwFlags, (INT)dwBytes, hInstance);
  39. }
  40. // This api takes an extra pointer which is optional
  41. // In case of an edit control reallocating the memory inside apps memory
  42. // space it is used to update the thunk data (see wparam.c)
  43. HANDLE APIENTRY W32LocalReAlloc(
  44. HANDLE hMem, // memory to be reallocated
  45. UINT dwBytes, // size to reallocate to
  46. UINT dwFlags, // reallocation flags
  47. HANDLE hInstance, // Instance to identify ptr
  48. PVOID* ppv) // Pointer to the pointer that needs an update
  49. {
  50. //
  51. // If hInstance is not ours, then make Win32 call and return the
  52. // result to USER.
  53. //
  54. if (LOWORD (hInstance) == 0) {
  55. return (LocalReAlloc(hMem, dwBytes, dwFlags));
  56. }
  57. #if !defined(i386)
  58. if (dwBytes != 0)
  59. dwBytes += 4;
  60. #endif
  61. hMem = LocalReAlloc16(hMem, (INT)dwBytes, (WORD)dwFlags);
  62. // this code is used in User/Client (edit control) to realloc
  63. // memory for text storage
  64. // update what ppv points to using wparam.c
  65. if (NULL != ppv && NULL != *ppv) {
  66. *ppv = ParamMapUpdateNode((DWORD)*ppv, PARAM_32, NULL);
  67. }
  68. return hMem;
  69. }
  70. LPSTR APIENTRY W32LocalLock(HANDLE hMem, HANDLE hInstance)
  71. {
  72. VPVOID vp;
  73. //
  74. // If hInstance is not ours, then make Win32 call and return the
  75. // result to USER.
  76. //
  77. if (LOWORD (hInstance) == 0) {
  78. return (LocalLock(hMem));
  79. }
  80. if (vp = LocalLock16(hMem)) {
  81. return (LPSTR)VDMPTR(vp, 0);
  82. }
  83. else
  84. return NULL;
  85. }
  86. BOOL APIENTRY W32LocalUnlock(HANDLE hMem, HANDLE hInstance)
  87. {
  88. //
  89. // If hInstance is not ours, then make Win32 call and return the
  90. // result to USER.
  91. //
  92. if (LOWORD (hInstance) == 0) {
  93. return (LocalUnlock(hMem));
  94. }
  95. return LocalUnlock16(hMem);
  96. }
  97. DWORD APIENTRY W32LocalSize(HANDLE hMem, HANDLE hInstance)
  98. {
  99. DWORD dwSize;
  100. //
  101. // If hInstance is not ours, then make Win32 call and return the
  102. // result to USER.
  103. //
  104. if (LOWORD (hInstance) == 0) {
  105. return (LocalSize(hMem));
  106. }
  107. dwSize = LocalSize16(hMem);
  108. #if !defined(i386)
  109. if (dwSize >= 4)
  110. dwSize -= 4;
  111. #endif
  112. return dwSize;
  113. }
  114. HANDLE APIENTRY W32LocalFree(HANDLE hMem, HANDLE hInstance)
  115. {
  116. //
  117. // If hInstance is not ours, then make Win32 call and return the
  118. // result to USER.
  119. //
  120. if (LOWORD (hInstance) == 0) {
  121. return (LocalFree(hMem));
  122. }
  123. return LocalFree16(hMem);
  124. }
  125. ULONG APIENTRY W32GetExpWinVer(HANDLE hInst)
  126. {
  127. PARM16 Parm16;
  128. ULONG ul;
  129. // makes a direct call to krnl286:GetExpWinVer
  130. //
  131. if (LOWORD((DWORD)hInst) == (WORD) NULL) {
  132. //
  133. // Window is created by a 32 bit DLL, which is
  134. // linked to NTVDM process. So, we should not
  135. // passs it to the 16 bit kernel.
  136. //
  137. return (WOWRtlGetExpWinVer(hInst));
  138. }
  139. else {
  140. LPBYTE lpNewExeHdr;
  141. VPVOID vp = (DWORD)hInst & 0xffff0000;
  142. GETMISCPTR(vp, lpNewExeHdr);
  143. if (lpNewExeHdr) {
  144. ul = MAKELONG(*(PWORD16)&lpNewExeHdr[NE_LOWINVER_OFFSET],
  145. (*(PWORD16)&lpNewExeHdr[NE_HIWINVER_OFFSET] &
  146. FLAG_NE_PROPFONT));
  147. }
  148. else {
  149. Parm16.WndProc.wParam = LOWORD(hInst);
  150. CallBack16(RET_GETEXPWINVER, &Parm16, 0, &ul );
  151. }
  152. return ul;
  153. }
  154. }
  155. WORD APIENTRY W32GlobalAlloc16(UINT uFlags, DWORD dwBytes)
  156. {
  157. return HIWORD(GlobalAllocLock16((WORD)uFlags, dwBytes, NULL));
  158. }
  159. VOID APIENTRY W32GlobalFree16(WORD selector)
  160. {
  161. GlobalUnlockFree16(MAKELONG(0, selector));
  162. return;
  163. }
  164. int APIENTRY W32EditNextWord (LPSZ lpszEditText, int ichCurrentWord,
  165. int cbEditText, int action, DWORD dwProc16)
  166. {
  167. PARM16 Parm16;
  168. ULONG lReturn = 0;
  169. PBYTE lpstr16;
  170. VPVOID vpstr16;
  171. VPVOID vpfn;
  172. if (vpstr16 = malloc16 (cbEditText)) {
  173. GETMISCPTR (vpstr16, lpstr16);
  174. if (lpstr16) {
  175. lstrcpy (lpstr16, lpszEditText);
  176. // take out the marker bits and fix the RPL bits
  177. UnMarkWOWProc (dwProc16, vpfn);
  178. Parm16.WordBreakProc.action = GETINT16(action);
  179. Parm16.WordBreakProc.cbEditText = GETINT16(cbEditText);
  180. Parm16.WordBreakProc.ichCurrentWord = GETINT16(ichCurrentWord);
  181. Parm16.WordBreakProc.lpszEditText = vpstr16;
  182. CallBack16(RET_SETWORDBREAKPROC, &Parm16, vpfn, (PVPVOID)&lReturn);
  183. FREEMISCPTR (lpstr16);
  184. }
  185. free16(vpstr16);
  186. }
  187. return (INT32(LOWORD(lReturn)));
  188. }
  189. /***************************************************************************\
  190. * WOWRtlGetExpWinVer
  191. *
  192. * Returns the expected windows version, in the same format as Win3.1's
  193. * GetExpWinVer(). This takes it out of the module header.
  194. *
  195. * 09-9-92 ChandanC Created.
  196. \***************************************************************************/
  197. DWORD WOWRtlGetExpWinVer(
  198. HANDLE hmod)
  199. {
  200. PIMAGE_NT_HEADERS pnthdr;
  201. DWORD dwMajor = 3;
  202. DWORD dwMinor = 0xA;
  203. if (hmod != NULL) {
  204. try {
  205. pnthdr = (PIMAGE_NT_HEADERS)RtlImageNtHeader((PVOID)hmod);
  206. dwMajor = pnthdr->OptionalHeader.MajorSubsystemVersion;
  207. dwMinor = pnthdr->OptionalHeader.MinorSubsystemVersion;
  208. } except (EXCEPTION_EXECUTE_HANDLER) {
  209. dwMajor = 3; // just to be safe
  210. dwMinor = 0xA;
  211. }
  212. }
  213. // !!! HACK until linker is fixed!!! 05-Aug-1992 Bug #3211
  214. if (((dwMajor == 3) && (dwMinor == 1)) || (dwMajor == 1)) {
  215. dwMajor = 0x3;
  216. dwMinor = 0xA;
  217. }
  218. #ifdef FE_SB
  219. if (GetSystemDefaultLangID() == 0x411 &&
  220. CURRENTPTD()->dwWOWCompatFlagsFE & WOWCF_FE_BCW45J_COMMDLG &&
  221. dwMajor >= 4) {
  222. // When application display win3.x style DialogBox,
  223. // System requires return value of version 3.10
  224. dwMajor = 0x3;
  225. dwMinor = 0xA;
  226. }
  227. #endif // FE_SB
  228. /*
  229. * Return this is a win3.1 compatible format:
  230. *
  231. * 0x030A == win3.1
  232. * 0x0300 == win3.0
  233. * 0x0200 == win2.0, etc.
  234. *
  235. */
  236. return (DWORD)MAKELONG(MAKEWORD((BYTE)dwMinor, (BYTE)dwMajor), 0);
  237. }