Leaked source code of windows server 2003
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.

1829 lines
58 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * WSTRUC.C
  8. * WOW32 16-bit structure conversion support
  9. *
  10. * History:
  11. * Created 27-Jan-1991 by Jeff Parsons (jeffpar)
  12. * Wrote DDE data conversion routines, etc Chandan CHauhan (ChandanC)
  13. *
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. #include "wowshlp.h"
  18. #ifdef FE_IME
  19. #include "ime.h"
  20. #endif // FE_IME
  21. MODNAME(wstruc.c);
  22. /* Structure copying functions
  23. *
  24. * For input structures, there are GETxxxx16 macros; for output structures
  25. * there are PUTxxxx16 macros. Most or all of these macros will simply call
  26. * the corresponding function below. Nothing magical here....
  27. */
  28. VOID getstr16(VPSZ vpszSrc, LPSZ lpszDst, INT cb)
  29. {
  30. PSZ pszSrc;
  31. if (cb == 0)
  32. return;
  33. if (cb != -1)
  34. GETVDMPTR(vpszSrc, cb, pszSrc);
  35. else {
  36. GETPSZPTR(vpszSrc, pszSrc);
  37. if(pszSrc) {
  38. cb = strlen(pszSrc)+1;
  39. }
  40. }
  41. if(lpszDst && pszSrc) {
  42. RtlCopyMemory(lpszDst, pszSrc, cb);
  43. }
  44. FREEVDMPTR(pszSrc);
  45. RETURN(NOTHING);
  46. }
  47. VOID putstr16(VPSZ vpszDst, LPCSTR lpszSrc, INT cb)
  48. {
  49. PSZ pszDst;
  50. if (cb == 0)
  51. return;
  52. if (cb == -1)
  53. cb = strlen(lpszSrc)+1;
  54. GETVDMPTR(vpszDst, cb, pszDst);
  55. RtlCopyMemory(pszDst, lpszSrc, cb);
  56. FLUSHVDMPTR(vpszDst, cb, pszDst);
  57. FREEVDMPTR(pszDst);
  58. RETURN(NOTHING);
  59. }
  60. LPRECT getrect16(VPRECT16 vpRect, LPRECT lpRect)
  61. {
  62. register PRECT16 pRect16;
  63. // Some APIs (eg, InvalidateRect) have OPTIONAL input pointers -JTP
  64. if (vpRect) {
  65. GETVDMPTR(vpRect, sizeof(RECT16), pRect16);
  66. lpRect->left = FETCHSHORT(pRect16->left);
  67. lpRect->top = FETCHSHORT(pRect16->top);
  68. lpRect->right = FETCHSHORT(pRect16->right);
  69. lpRect->bottom = FETCHSHORT(pRect16->bottom);
  70. FREEVDMPTR(pRect16);
  71. } else {
  72. lpRect = NULL;
  73. }
  74. return lpRect;
  75. }
  76. VOID putrect16(VPRECT16 vpRect, LPRECT lpRect)
  77. {
  78. register PRECT16 pRect16;
  79. // Some APIs (ScrollDC may be the only one) have OPTIONAL output pointers
  80. if (vpRect) {
  81. GETVDMPTR(vpRect, sizeof(RECT16), pRect16);
  82. STORESHORT(pRect16->left, (SHORT)lpRect->left);
  83. STORESHORT(pRect16->top, (SHORT)lpRect->top);
  84. STORESHORT(pRect16->right, (SHORT)lpRect->right);
  85. STORESHORT(pRect16->bottom, (SHORT)lpRect->bottom);
  86. FLUSHVDMPTR(vpRect, sizeof(RECT16), pRect16);
  87. FREEVDMPTR(pRect16);
  88. }
  89. }
  90. VOID getpoint16(VPPOINT16 vpPoint, INT c, LPPOINT lpPoint)
  91. {
  92. register PPOINT16 pPoint16;
  93. // The assumption here is that no APIs have OPTIONAL POINT pointers
  94. // (regardless of whether they're input or output) -JTP
  95. WOW32ASSERT(vpPoint);
  96. if (lpPoint) {
  97. GETVDMPTR(vpPoint, sizeof(POINT16), pPoint16);
  98. while (c--) {
  99. lpPoint->x = pPoint16->x;
  100. lpPoint->y = pPoint16->y;
  101. lpPoint++;
  102. pPoint16++; // ZOWIE Batman, you wouldn't be able to increment
  103. } // this pointer if FREEVDMPTR wasn't a no-op! -JTP
  104. FREEVDMPTR(pPoint16);
  105. }
  106. }
  107. VOID putpoint16(VPPOINT16 vpPoint, INT c, LPPOINT lpPoint)
  108. {
  109. INT cb;
  110. PPOINT16 pPoint16ptr;
  111. register PPOINT16 pPoint16;
  112. // The assumption here is that no APIs have OPTIONAL POINT pointers
  113. // (regardless of whether they're input or output) -JTP
  114. WOW32ASSERT(vpPoint);
  115. if (lpPoint) {
  116. GETVDMPTR(vpPoint, sizeof(POINT16), pPoint16);
  117. cb = c;
  118. pPoint16ptr = pPoint16;
  119. while (c--) {
  120. if (lpPoint->x > (LONG)0x7fff)
  121. pPoint16->x = (SHORT)0x7fff;
  122. else if (lpPoint->x < (LONG)0xffff8000)
  123. pPoint16->x = (SHORT)0x8000;
  124. else
  125. pPoint16->x = (SHORT)lpPoint->x;
  126. if (lpPoint->y > (LONG)0x7fff)
  127. pPoint16->y = (SHORT)0x7fff;
  128. else if (lpPoint->y < (LONG)0xffff8000)
  129. pPoint16->y = (SHORT)0x8000;
  130. else
  131. pPoint16->y = (SHORT)lpPoint->y;
  132. lpPoint++;
  133. pPoint16++;
  134. }
  135. FLUSHVDMPTR(vpPoint, cb*sizeof(POINT16), pPoint16ptr);
  136. FREEVDMPTR(pPoint16ptr);
  137. }
  138. }
  139. VOID getintarray16(VPINT16 vpInt, INT c, LPINT lpInt)
  140. {
  141. INT i;
  142. register INT16 *pInt16;
  143. if (lpInt && GETVDMPTR(vpInt, sizeof(INT16)*c, pInt16)) {
  144. for (i=0; i < c; i++) {
  145. lpInt[i] = FETCHSHORT(pInt16[i]);
  146. }
  147. }
  148. FREEVDMPTR(pInt16);
  149. }
  150. //
  151. // getuintarray16
  152. //
  153. // copies an array of 16-bit unsigned words to an array of 32-bit unsigned
  154. // words. the pointer to 32-bit array must be freed by the caller.
  155. //
  156. VOID getuintarray16(VPWORD vp, INT c, PUINT pu)
  157. {
  158. register WORD *pW16;
  159. if (pu && GETVDMPTR(vp, sizeof(WORD)*c, pW16)) {
  160. while (c--) {
  161. pu[c] = FETCHWORD(pW16[c]);
  162. }
  163. FREEVDMPTR(pW16);
  164. }
  165. }
  166. VOID putintarray16(VPINT16 vpInt, INT c, LPINT lpInt)
  167. {
  168. INT i;
  169. register INT16 *pInt16;
  170. if (lpInt && GETVDMPTR(vpInt, sizeof(INT16)*c, pInt16)) {
  171. for (i=0; i < c; i++) {
  172. STOREWORD(pInt16[i], lpInt[i]);
  173. }
  174. FLUSHVDMPTR(vpInt, sizeof(INT16)*c, pInt16);
  175. FREEVDMPTR(pInt16);
  176. }
  177. }
  178. VOID putkerningpairs16(VPKERNINGPAIR16 vpKrn, UINT c, LPKERNINGPAIR lpKrn)
  179. {
  180. UINT i;
  181. register PKERNINGPAIR16 pKrn16;
  182. WOW32ASSERT(vpKrn);
  183. GETVDMPTR(vpKrn, sizeof(KERNINGPAIR16), pKrn16);
  184. for (i=0; i < c; i++) {
  185. pKrn16[i].wFirst = (WORD) lpKrn[i].wFirst;
  186. pKrn16[i].wSecond = (WORD) lpKrn[i].wSecond;
  187. pKrn16[i].iKernAmount = (INT16) lpKrn[i].iKernAmount;
  188. }
  189. FLUSHVDMPTR(vpKrn, sizeof(KERNINGPAIR16), pKrn16);
  190. FREEVDMPTR(pKrn16);
  191. }
  192. // Fill in a 32 bit DRAWITEMSTRUCT from a 16 bit one
  193. VOID getdrawitem16(VPDRAWITEMSTRUCT16 vpDI16, LPDRAWITEMSTRUCT lpDI)
  194. {
  195. register PDRAWITEMSTRUCT16 pDI16;
  196. GETVDMPTR(vpDI16, sizeof(DRAWITEMSTRUCT16), pDI16);
  197. lpDI->CtlType = FETCHWORD(pDI16->CtlType);
  198. lpDI->CtlID = FETCHWORD(pDI16->CtlID);
  199. if ((SHORT)(lpDI->itemID = FETCHWORD(pDI16->itemID)) == -1) {
  200. lpDI->itemID = (UINT)-1;
  201. }
  202. lpDI->itemAction = FETCHWORD(pDI16->itemAction);
  203. lpDI->itemState = FETCHWORD(pDI16->itemState);
  204. lpDI->hwndItem = HWND32(FETCHWORD(pDI16->hwndItem));
  205. lpDI->hDC = HDC32(FETCHWORD(pDI16->hDC));
  206. lpDI->rcItem.left = (SHORT)pDI16->rcItem.left;
  207. lpDI->rcItem.top = (SHORT)pDI16->rcItem.top;
  208. lpDI->rcItem.right = (SHORT)pDI16->rcItem.right;
  209. lpDI->rcItem.bottom = (SHORT)pDI16->rcItem.bottom;
  210. lpDI->itemData = FETCHDWORD(pDI16->itemData);
  211. FREEVDMPTR(pDI16);
  212. return;
  213. }
  214. // Fill in a 16 bit DRAWITEMSTRUCT from a 32 bit one
  215. HAND16 putdrawitem16(VPDRAWITEMSTRUCT16 vpDI16, LPDRAWITEMSTRUCT lpDI)
  216. {
  217. HAND16 hdc16;
  218. register PDRAWITEMSTRUCT16 pDI16;
  219. GETVDMPTR(vpDI16, sizeof(DRAWITEMSTRUCT16), pDI16);
  220. STOREWORD(pDI16->CtlType, lpDI->CtlType);
  221. STOREWORD(pDI16->CtlID, lpDI->CtlID);
  222. STOREWORD(pDI16->itemID, lpDI->itemID);
  223. STOREWORD(pDI16->itemAction, lpDI->itemAction);
  224. STOREWORD(pDI16->itemState, lpDI->itemState);
  225. STOREWORD(pDI16->hwndItem, GETHWND16(lpDI->hwndItem));
  226. hdc16 = GETHDC16(lpDI->hDC);
  227. STOREWORD(pDI16->hDC, hdc16);
  228. pDI16->rcItem.left = (SHORT)lpDI->rcItem.left;
  229. pDI16->rcItem.top = (SHORT)lpDI->rcItem.top;
  230. pDI16->rcItem.right = (SHORT)lpDI->rcItem.right;
  231. pDI16->rcItem.bottom = (SHORT)lpDI->rcItem.bottom;
  232. STOREDWORD(pDI16->itemData, lpDI->itemData);
  233. FREEVDMPTR(pDI16);
  234. return(hdc16);
  235. }
  236. #ifdef NOTUSED
  237. //
  238. // Allocate and fill a 32bit DropFileStruct based on a 16bit one.
  239. // 16 bit structure is not freed.
  240. //
  241. BOOL getdropfilestruct16(HAND16 hand16, PHANDLE phand32)
  242. {
  243. PDROPFILESTRUCT16 lpdfs16;
  244. LPDROPFILESTRUCT lpdfs32;
  245. VPVOID vp;
  246. INT cb;
  247. vp = GlobalLock16(hand16, &cb);
  248. if (vp) {
  249. GETMISCPTR(vp, lpdfs16);
  250. *phand32 = WOWGLOBALALLOC(GMEM_DDESHARE,
  251. cb-sizeof(DROPFILESTRUCT16)+
  252. sizeof(DROPFILESTRUCT));
  253. if (*phand32) {
  254. lpdfs32 = GlobalLock(*phand32);
  255. lpdfs32->pFiles = sizeof(DROPFILESTRUCT);
  256. lpdfs32->pt.x = lpdfs16->x;
  257. lpdfs32->pt.y = lpdfs16->y;
  258. lpdfs32->fNC = lpdfs16->fNC;
  259. lpdfs32->fWide = FALSE;
  260. RtlCopyMemory((LPBYTE)lpdfs32+lpdfs32->pFiles,
  261. (LPBYTE)lpdfs16+lpdfs16->pFiles,
  262. cb-sizeof(DROPFILESTRUCT16));
  263. FREEMISCPTR(lpdfs16);
  264. GlobalUnlock16(hand16);
  265. GlobalUnlock(*phand32);
  266. return TRUE;
  267. } else {
  268. FREEMISCPTR(lpdfs16);
  269. GlobalUnlock16(hand16);
  270. return FALSE;
  271. }
  272. } else {
  273. *phand32 = NULL;
  274. }
  275. return FALSE;
  276. }
  277. #endif
  278. INT GetBMI16Size(PVPVOID vpbmi16, WORD fuColorUse, LPDWORD lpdwClrUsed)
  279. {
  280. int nHdrSize;
  281. int nEntSize;
  282. int nEntries;
  283. int nBitCount;
  284. int nClrUsed = 0;
  285. register PBITMAPINFOHEADER16 pbmi16;
  286. GETVDMPTR(vpbmi16, sizeof(BITMAPINFO16), pbmi16);
  287. nHdrSize = (int) FETCHDWORD(pbmi16->biSize);
  288. if ( fuColorUse == DIB_RGB_COLORS ) {
  289. nEntSize = sizeof(RGBQUAD);
  290. if ( nHdrSize == sizeof(BITMAPCOREHEADER) ) {
  291. nEntSize = sizeof(RGBTRIPLE);
  292. }
  293. }
  294. else {
  295. nEntSize = sizeof(USHORT);
  296. }
  297. if( nHdrSize == sizeof(BITMAPINFOHEADER) ) {
  298. nBitCount = FETCHWORD (pbmi16->biBitCount);
  299. nClrUsed = FETCHDWORD(pbmi16->biClrUsed);
  300. *lpdwClrUsed = nClrUsed;
  301. }
  302. else {
  303. nBitCount = FETCHWORD(((LPBITMAPCOREHEADER)pbmi16)->bcBitCount);
  304. *lpdwClrUsed = 0;
  305. }
  306. /* the following block of code should be this:
  307. *
  308. * if ( nBitCount >= 9 ) { // this is how Win3.1 code says == 24
  309. * nEntries = 1;
  310. * }
  311. * else if ( dwClrUsed ) {
  312. * nEntries = dwClrUsed;
  313. * }
  314. * else {
  315. * nEntries = 1 << nBitCount;
  316. * }
  317. *
  318. * but due to the fact that many apps don't initialize the biBitCount &
  319. * biClrUsed fields (especially biClrUsed) we have to do the following
  320. * sanity checking instead. cmjones
  321. */
  322. if ( nBitCount <= 8 ) {
  323. nEntries = 1 << nBitCount;
  324. // for selected apps ? What apps will be broken by this ?
  325. if (nClrUsed > 0 && nClrUsed < nEntries)
  326. nEntries = nClrUsed;
  327. }
  328. else if (( nBitCount == 16 ) || ( nBitCount == 32)) {
  329. nEntries = 3;
  330. }
  331. // everything else including (nBitCount == 24)
  332. else {
  333. nEntries = 0;
  334. }
  335. // if this asserts it's an app bug
  336. // Changed assert to warning at Craig's request - DaveHart
  337. #ifdef DEBUG
  338. if (!(nEntries > 1) && !(nBitCount == 24)) {
  339. LOGDEBUG(LOG_ALWAYS, ("WOW::GetBMI16Size:bad BitCount:cmjones\n"));
  340. }
  341. #endif
  342. // this will never be true for a CORE type DIB
  343. if(*lpdwClrUsed > (DWORD)nEntries) {
  344. *lpdwClrUsed = nEntries;
  345. }
  346. FREEVDMPTR(pbmi16);
  347. return ( nHdrSize + (nEntries * nEntSize) );
  348. }
  349. INT GetBMI32Size(LPBITMAPINFO lpbmi32, WORD fuColorUse)
  350. {
  351. int nHdrSize;
  352. int nEntSize;
  353. int nEntries;
  354. int nBitCount;
  355. DWORD dwClrUsed;
  356. nHdrSize = (int)((LPBITMAPINFOHEADER)lpbmi32)->biSize;
  357. if ( fuColorUse == DIB_RGB_COLORS ) {
  358. nEntSize = sizeof(RGBQUAD);
  359. if ( nHdrSize == sizeof(BITMAPCOREHEADER) ) {
  360. nEntSize = sizeof(RGBTRIPLE);
  361. }
  362. }
  363. else {
  364. nEntSize = sizeof(USHORT);
  365. }
  366. if( nHdrSize == sizeof(BITMAPINFOHEADER) ) {
  367. nBitCount = ((LPBITMAPINFOHEADER)lpbmi32)->biBitCount;
  368. dwClrUsed = ((LPBITMAPINFOHEADER)lpbmi32)->biClrUsed;
  369. }
  370. else {
  371. nBitCount = (int)((LPBITMAPCOREHEADER)lpbmi32)->bcBitCount;
  372. dwClrUsed = 0;
  373. }
  374. nEntries = 0;
  375. if ( nBitCount < 9 ) {
  376. if((nBitCount == 4) || (nBitCount == 8) || (nBitCount == 1)) {
  377. nEntries = 1 << nBitCount;
  378. }
  379. else if (( nBitCount == 16 ) || ( nBitCount == 32)) {
  380. nEntries = 3;
  381. }
  382. // if this asserts it's an app bug -- we'll try to salvage things
  383. WOW32ASSERTMSG((nEntries > 1),
  384. ("WOW::GetBMI32Size:bad BitCount: cmjones\n"));
  385. // sanity check for apps (lots) that don't init the dwClrUsed field
  386. if(dwClrUsed) {
  387. nEntries = (int)min((DWORD)nEntries, dwClrUsed);
  388. }
  389. }
  390. return ( nHdrSize + (nEntries * nEntSize) );
  391. }
  392. LPBITMAPINFO CopyBMI16ToBMI32(PVPVOID vpbmi16, LPBITMAPINFO lpbmi32, WORD fuColorUse)
  393. {
  394. INT nbmiSize = 0;
  395. DWORD dwClrUsed;
  396. register LPVOID pbmi16;
  397. if(vpbmi16) {
  398. if((nbmiSize = GetBMI16Size(vpbmi16, fuColorUse, &dwClrUsed)) != 0) {
  399. GETVDMPTR(vpbmi16, nbmiSize, pbmi16);
  400. // We can't trust the size we get since apps don't fill in the
  401. // structure correctly so we do a try except around the copy
  402. // to the 32 bit structure. That way if we go off the end of
  403. // memory it doesn't matter, we continue going. - mattfe june 93
  404. try {
  405. RtlCopyMemory ((VOID *)lpbmi32, (CONST VOID *)pbmi16, nbmiSize);
  406. } except (TRUE) {
  407. // Continue if we wen't off the end of 16 bit memory
  408. }
  409. // patch color use field in 32-bit BMIH
  410. // INFO headers only - CORE headers will have dwClrUsed == 0
  411. if(dwClrUsed) {
  412. ((LPBITMAPINFOHEADER)lpbmi32)->biClrUsed = dwClrUsed;
  413. }
  414. FREEVDMPTR(pbmi16);
  415. return (lpbmi32);
  416. }
  417. }
  418. return (NULL);
  419. }
  420. LPBITMAPINFOHEADER CopyBMIH16ToBMIH32(PVPVOID vpbmih16, LPBITMAPINFOHEADER lpbmih32)
  421. {
  422. DWORD dwHeaderSize = 0L;
  423. register PBITMAPINFOHEADER16 pbmih16;
  424. if(vpbmih16) {
  425. GETVDMPTR(vpbmih16, sizeof(BITMAPINFOHEADER16), pbmih16);
  426. dwHeaderSize = FETCHDWORD(pbmih16->biSize);
  427. RtlCopyMemory((VOID *)lpbmih32,(CONST VOID *)pbmih16,(int)dwHeaderSize);
  428. FREEVDMPTR(pbmih16);
  429. return(lpbmih32);
  430. }
  431. return(NULL);
  432. }
  433. // Fill in a 32 bit MEASUREITEMSTRUCT from a 16 bit one
  434. VOID getmeasureitem16(VPMEASUREITEMSTRUCT16 vpMI16, LPMEASUREITEMSTRUCT lpMI, HWND16 hwnd16 )
  435. {
  436. register PMEASUREITEMSTRUCT16 pMI16;
  437. DWORD dw;
  438. BOOL fHasStrings;
  439. GETVDMPTR(vpMI16, sizeof(MEASUREITEMSTRUCT16), pMI16);
  440. lpMI->CtlType = FETCHWORD(pMI16->CtlType);
  441. lpMI->CtlID = FETCHWORD(pMI16->CtlID);
  442. lpMI->itemID = FETCHWORD(pMI16->itemID);
  443. lpMI->itemWidth = FETCHWORD(pMI16->itemWidth);
  444. lpMI->itemHeight = FETCHWORD(pMI16->itemHeight);
  445. fHasStrings = FALSE;
  446. if ( lpMI->CtlType == ODT_COMBOBOX ) {
  447. dw = GetWindowLong( GetDlgItem(HWND32(hwnd16),lpMI->CtlID), GWL_STYLE );
  448. fHasStrings = (dw & CBS_HASSTRINGS);
  449. }
  450. if ( lpMI->CtlType == ODT_LISTBOX ) {
  451. dw = GetWindowLong( GetDlgItem(HWND32(hwnd16),lpMI->CtlID), GWL_STYLE );
  452. fHasStrings = (dw & LBS_HASSTRINGS);
  453. }
  454. if ( fHasStrings ) {
  455. GETPSZPTR(pMI16->itemData, (PVOID)lpMI->itemData);
  456. } else {
  457. lpMI->itemData = FETCHDWORD(pMI16->itemData);
  458. }
  459. FREEVDMPTR(pMI16);
  460. return;
  461. }
  462. // Fill in a 16 bit MEASUREITEMSTRUCT from a 32 bit one
  463. VOID putmeasureitem16(VPMEASUREITEMSTRUCT16 vpMI16, LPMEASUREITEMSTRUCT lpMI)
  464. {
  465. register PMEASUREITEMSTRUCT16 pMI16;
  466. GETVDMPTR(vpMI16, sizeof(MEASUREITEMSTRUCT16), pMI16);
  467. STOREWORD(pMI16->CtlType, lpMI->CtlType);
  468. STOREWORD(pMI16->CtlID, lpMI->CtlID);
  469. STOREWORD(pMI16->itemID, lpMI->itemID);
  470. STOREWORD(pMI16->itemWidth, lpMI->itemWidth);
  471. STOREWORD(pMI16->itemHeight, lpMI->itemHeight);
  472. STOREDWORD(pMI16->itemData, lpMI->itemData);
  473. FREEVDMPTR(pMI16);
  474. return;
  475. }
  476. // Fill in a 32 bit DELETEITEMSTRUCT from a 16 bit one
  477. VOID getdeleteitem16(VPDELETEITEMSTRUCT16 vpDI16, LPDELETEITEMSTRUCT lpDI)
  478. {
  479. register PDELETEITEMSTRUCT16 pDI16;
  480. GETVDMPTR(vpDI16, sizeof(DELETEITEMSTRUCT16), pDI16);
  481. lpDI->CtlType = FETCHWORD(pDI16->CtlType);
  482. lpDI->CtlID = FETCHWORD(pDI16->CtlID);
  483. lpDI->itemID = FETCHWORD(pDI16->itemID);
  484. lpDI->hwndItem = HWND32(FETCHWORD(pDI16->hwndItem));
  485. lpDI->itemData = FETCHDWORD(pDI16->itemData);
  486. FREEVDMPTR(pDI16);
  487. return;
  488. }
  489. // Fill in a 16 bit DELETEITEMSTRUCT from a 32 bit one
  490. VOID putdeleteitem16(VPDELETEITEMSTRUCT16 vpDI16, LPDELETEITEMSTRUCT lpDI)
  491. {
  492. register PDELETEITEMSTRUCT16 pDI16;
  493. GETVDMPTR(vpDI16, sizeof(DELETEITEMSTRUCT16), pDI16);
  494. STOREWORD(pDI16->CtlType, lpDI->CtlType);
  495. STOREWORD(pDI16->CtlID, lpDI->CtlID);
  496. STOREWORD(pDI16->itemID, lpDI->itemID);
  497. STOREWORD(pDI16->hwndItem, GETHWND16(lpDI->hwndItem));
  498. FLUSHVDMPTR(vpDI16, sizeof(DELETEITEMSTRUCT16), pDI16);
  499. FREEVDMPTR(pDI16);
  500. return;
  501. }
  502. // Fill in a 32 bit COMPAREITEMSTRUCT from a 16 bit one
  503. VOID getcompareitem16(VPCOMPAREITEMSTRUCT16 vpCI16, LPCOMPAREITEMSTRUCT lpCI)
  504. {
  505. register PCOMPAREITEMSTRUCT16 pCI16;
  506. GETVDMPTR(vpCI16, sizeof(COMPAREITEMSTRUCT16), pCI16);
  507. lpCI->CtlType = FETCHWORD (pCI16->CtlType);
  508. lpCI->CtlID = FETCHWORD (pCI16->CtlID);
  509. lpCI->hwndItem = HWND32(pCI16->hwndItem);
  510. lpCI->itemID1 = FETCHWORD (pCI16->itemID1);
  511. lpCI->itemID2 = FETCHWORD (pCI16->itemID2);
  512. lpCI->itemData1 = FETCHDWORD(pCI16->itemData1);
  513. lpCI->itemData2 = FETCHDWORD(pCI16->itemData2);
  514. FREEVDMPTR(pCI16);
  515. return;
  516. }
  517. // Fill in a 16 bit COMPAREITEMSTRUCT from a 32 bit one
  518. VOID putcompareitem16(VPCOMPAREITEMSTRUCT16 vpCI16, LPCOMPAREITEMSTRUCT lpCI)
  519. {
  520. register PCOMPAREITEMSTRUCT16 pCI16;
  521. GETVDMPTR(vpCI16, sizeof(COMPAREITEMSTRUCT16), pCI16);
  522. STOREWORD (pCI16->CtlType, (lpCI)->CtlType);
  523. STOREWORD (pCI16->CtlID, (lpCI)->CtlID);
  524. STOREWORD (pCI16->hwndItem, GETHWND16((lpCI)->hwndItem));
  525. STOREWORD (pCI16->itemID1, (lpCI)->itemID1);
  526. STOREWORD (pCI16->itemID2, (lpCI)->itemID2);
  527. STOREDWORD(pCI16->itemData1, (lpCI)->itemData1);
  528. STOREDWORD(pCI16->itemData2, (lpCI)->itemData2);
  529. FLUSHVDMPTR(vpCI16, sizeof(COMPAREITEMSTRUCT16), pCI16);
  530. FREEVDMPTR(pCI16);
  531. return;
  532. }
  533. // NOTE: The below two routines are useful to changing a simple 16-bit message
  534. // into a 32-bit message and vice-versa. The routines take into account only
  535. // those messages which can be returned from GetMessage(), or passed to
  536. // DispatchMessage(), etc. Normally these are only input messages (all other
  537. // messages are sent rather than posted. This type of message has been
  538. // extended to include DDE messages (they are posted too) and WM_TIMER messages.
  539. // If you question this ability, please talk with me. -BobDay
  540. // These routines should only be called from these routines:
  541. // CallMsgFilter
  542. // DispatchMessage
  543. // GetMessage
  544. // IsDialogMessage
  545. // TranslateAccelerator
  546. // TranslateMDISysAccel
  547. // TranslateMessage
  548. // PeekMessage
  549. // WM32GetDlgCode
  550. // ThunkWMMsg16
  551. // Don't call them from any other function!
  552. //
  553. // WARNING: May cause 16-bit memory movement, invalidating flat pointers.
  554. // Fill in a 32 bit MSG from a 16 bit one
  555. // See NOTE above!
  556. VOID getmsg16(VPMSG16 vpmsg16, LPMSG lpmsg, LPMSGPARAMEX lpmpex)
  557. {
  558. register PMSG16 pmsg16;
  559. UINT message;
  560. HWND16 hwnd16;
  561. WPARAM wParam;
  562. LPARAM lParam;
  563. WPARAM uParam;
  564. GETVDMPTR(vpmsg16, sizeof(MSG16), pmsg16);
  565. hwnd16 = FETCHWORD(pmsg16->hwnd);
  566. message = FETCHWORD(pmsg16->message);
  567. wParam = FETCHWORD(pmsg16->wParam);
  568. lParam = FETCHLONG(pmsg16->lParam);
  569. uParam = INT32(wParam); // default thunking - sign extend
  570. #ifdef DEBUG
  571. if (HIWORD(wParam) &&
  572. !((message == WM_TIMER ||
  573. message == WM_COMMAND ||
  574. message == WM_DROPFILES ||
  575. message == WM_HSCROLL ||
  576. message == WM_VSCROLL ||
  577. message == WM_MENUSELECT ||
  578. message == WM_MENUCHAR ||
  579. message == WM_ACTIVATEAPP ||
  580. message == WM_ACTIVATE) ||
  581. (message >= WM_DDE_FIRST && message <= WM_DDE_LAST))) {
  582. LOGDEBUG(LOG_ALWAYS,("WOW: getmsg16 - losing HIWORD(wParam)!"));
  583. WOW32ASSERT(FALSE);
  584. }
  585. #endif
  586. if ( message == WM_TIMER ) {
  587. HAND16 htask16;
  588. PTMR ptmr;
  589. WORD wIDEvent;
  590. htask16 = CURRENTPTD()->htask16;
  591. wIDEvent = (WORD)wParam;
  592. ptmr = FindTimer16( hwnd16, htask16, wIDEvent );
  593. if ( !ptmr ) {
  594. LOGDEBUG(LOG_TRACE,(" getmsg16 WARNING: cannot find timer %04x\n", wIDEvent));
  595. } else {
  596. uParam = (WPARAM)wIDEvent; // wParam is unsigned word
  597. lParam = ptmr->dwTimerProc32; // 32-bit proc or NULL
  598. }
  599. } else if ((message == WM_SYSCOMMAND ||
  600. message == WM_COMMAND ||
  601. message == WM_DROPFILES ||
  602. message == WM_HSCROLL ||
  603. message == WM_VSCROLL ||
  604. message == WM_MENUSELECT ||
  605. message == WM_MENUCHAR ||
  606. message == WM_ACTIVATEAPP ||
  607. message == WM_ACTIVATE) ||
  608. (message >= WM_DDE_FIRST && message <= WM_DDE_LAST)) {
  609. HWND hwnd32;
  610. lpmpex->Parm16.WndProc.hwnd = hwnd16;
  611. lpmpex->Parm16.WndProc.wMsg = (WORD)message;
  612. lpmpex->Parm16.WndProc.wParam = (WORD)wParam;
  613. lpmpex->Parm16.WndProc.lParam = lParam;
  614. lpmpex->iMsgThunkClass = WOWCLASS_WIN16;
  615. hwnd32 = ThunkMsg16(lpmpex);
  616. // memory may have moved
  617. FREEVDMPTR(pmsg16);
  618. GETVDMPTR(vpmsg16, sizeof(MSG16), pmsg16);
  619. lParam = lpmpex->lParam;
  620. lpmsg->hwnd = hwnd32;
  621. lpmsg->message = lpmpex->uMsg;
  622. lpmsg->wParam = lpmpex->uParam;
  623. if (message == WM_DDE_INITIATE) {
  624. LOGDEBUG(LOG_ALWAYS,("WOW::getmsg16:*** ERROR: saw WM_DDE_INITIATE message %04x\n", message));
  625. WI32DDEDeleteInitiator((HAND16) FETCHWORD(pmsg16->wParam));
  626. }
  627. goto finish_up;
  628. } else if (message == WM_SYSTIMER) {
  629. uParam = UINT32(wParam); // un-sign extend this
  630. } else if (message == WM_SETTEXT) {
  631. LONG lParamMap;
  632. LOGDEBUG(LOG_ALWAYS, ("WOW::Warning::getmsg16 processing WM_SETTEXT\n"));
  633. LOGDEBUG(LOG_ALWAYS, ("WOW::Check for possible rogue PostMessage\n"));
  634. // this is thy meaning: we have a message that comes from the 32-bit world
  635. // yet carries 16-bit payload. We have an option of converting this
  636. // to 32-bits at this very point via the param tracking mechanism
  637. GETPSZPTR(lParam, (LPSZ)lParamMap);
  638. lParam = (LPARAM)AddParamMap(lParamMap, lParam);
  639. if (lParam != lParamMap) {
  640. FREEPSZPTR((LPSZ)lParamMap);
  641. }
  642. //
  643. // now lParam is a "normal" 32-bit lParam with a map entry and
  644. // a ref count of "0" (meaning undead) so it could be deleted
  645. // later (during the thunking)
  646. //
  647. SetParamRefCount(lParam, PARAM_32, 0);
  648. }
  649. lpmsg->hwnd = HWND32(hwnd16);
  650. lpmsg->message = message;
  651. lpmsg->wParam = uParam;
  652. finish_up:
  653. lpmsg->lParam = lParam;
  654. lpmsg->time = FETCHLONG(pmsg16->time);
  655. lpmsg->pt.x = FETCHSHORT(pmsg16->pt.x);
  656. lpmsg->pt.y = FETCHSHORT(pmsg16->pt.y);
  657. FREEVDMPTR(pmsg16);
  658. return;
  659. }
  660. /*
  661. * Int 16 state key state bits (in order of Int 16 flags)
  662. */
  663. BYTE abStateVK[] = { VK_RSHIFT,
  664. VK_LSHIFT,
  665. VK_CONTROL,
  666. VK_MENU} ;
  667. /*
  668. * Int 16 state key toggle bits (in order of Int 16 flags)
  669. */
  670. BYTE abToggleVK[] = { VK_SCROLL,
  671. VK_NUMLOCK,
  672. VK_CAPITAL,
  673. VK_INSERT};
  674. // Updates the Int16 bios shift key state info
  675. // (uses "synchronous" key state)
  676. // GetKeyState is a very fast call (GetAsyncKeyState is not)
  677. void UpdateInt16State(void)
  678. {
  679. BYTE bInt16State = 0;
  680. LPBYTE lpbInt16Data;
  681. int iBit;
  682. /*
  683. * Get the toggled keys and OR in their toggle state
  684. */
  685. for( iBit = sizeof(abToggleVK)/sizeof(abToggleVK[0])-1;
  686. iBit >= 0; iBit--) {
  687. bInt16State = bInt16State << 1;
  688. if (GetKeyState(abToggleVK[iBit]) & 1)
  689. bInt16State |= 1;
  690. }
  691. /*
  692. * Get the state keys and OR in their current state
  693. */
  694. for( iBit = sizeof(abStateVK)/sizeof(abStateVK[0])-1;
  695. iBit >= 0; iBit--) {
  696. bInt16State = bInt16State << 1;
  697. if (GetKeyState(abStateVK[iBit]) & 0x8000)
  698. bInt16State |= 1;
  699. }
  700. // Int 16 keyboard state is at 40:17
  701. //
  702. // We need to update this address with the current state of
  703. // the keyboard buffer.
  704. lpbInt16Data = (LPBYTE)GetRModeVDMPointer(0x400017);
  705. *lpbInt16Data = bInt16State;
  706. }
  707. // Fill in a 16 bit MSG from a 32 bit one
  708. // See NOTE above!
  709. ULONG putmsg16(VPMSG16 vpmsg16, LPMSG lpmsg)
  710. {
  711. register PMSG16 pmsg16;
  712. UINT message;
  713. WPARAM wParam;
  714. LPARAM lParam;
  715. WM32MSGPARAMEX wm32mpex;
  716. ULONG ulReturn = 0;
  717. message = lpmsg->message;
  718. wParam = lpmsg->wParam;
  719. lParam = lpmsg->lParam;
  720. if (message == WM_TIMER) {
  721. PTMR ptmr;
  722. ptmr = FindTimer32((HWND16)(GETHWND16(lpmsg->hwnd)), (DWORD)wParam);
  723. if ( !ptmr ) {
  724. LOGDEBUG(LOG_TRACE,(" putmsg16 ERROR: cannot find timer %08x\n", lpmsg->wParam));
  725. } else {
  726. lParam = ptmr->vpfnTimerProc; // 16-bit address or NULL
  727. }
  728. }
  729. else if ((message == WM_COMMAND ||
  730. message == WM_DROPFILES ||
  731. message == WM_HSCROLL ||
  732. message == WM_VSCROLL ||
  733. message == WM_MENUSELECT ||
  734. message == WM_MENUCHAR ||
  735. message == WM_ACTIVATEAPP ||
  736. message == WM_ACTIVATE) ||
  737. (message >= WM_DDE_FIRST && message <= WM_DDE_LAST)) {
  738. WORD wParamNew = (WORD)wParam;
  739. LONG lParamNew = (LONG)lParam;
  740. wm32mpex.Parm16.WndProc.wParam = (WORD)wParam;
  741. wm32mpex.Parm16.WndProc.lParam = (LONG)lParam;
  742. wm32mpex.fThunk = THUNKMSG;
  743. wm32mpex.hwnd = lpmsg->hwnd;
  744. wm32mpex.uMsg = message;
  745. wm32mpex.uParam = wParam;
  746. wm32mpex.lParam = lParam;
  747. wm32mpex.pww = (PWW)NULL;
  748. wm32mpex.fFree = FALSE;
  749. wm32mpex.lpfnM32 = aw32Msg[message].lpfnM32;
  750. ulReturn = (wm32mpex.lpfnM32)(&wm32mpex);
  751. if (ulReturn) {
  752. wParam = (WPARAM) wm32mpex.Parm16.WndProc.wParam;
  753. lParam = (LPARAM) wm32mpex.Parm16.WndProc.lParam;
  754. }
  755. else {
  756. if ((message == WM_DDE_DATA) || (message == WM_DDE_POKE)) {
  757. wParam = (WPARAM) wm32mpex.Parm16.WndProc.wParam;
  758. lParam = (LPARAM) wm32mpex.Parm16.WndProc.lParam;
  759. }
  760. }
  761. } else if (message >= WM_KEYFIRST && message <= WM_KEYLAST) {
  762. UpdateInt16State();
  763. #ifdef FE_IME
  764. // WM_IMEKEYDOWN & WM_IMEKEYUP 32 -> 16
  765. // 32bit:wParam HIWORD charactor code, LOWORD virtual key
  766. // 16bit:wParam HIBYTE charactor code, LOBYTE virtual key
  767. // kksuzuka:#4281 1994.11.19 MSKK V-HIDEKK
  768. } else if (message >= WM_IMEKEYDOWN && message <= WM_IMEKEYUP) {
  769. LONG wParamNew = wParam;
  770. wParamNew >>= 8;
  771. wParamNew |= (0xffff & wParam);
  772. wParam = wParamNew;
  773. #endif // FE_IME
  774. } else if (message & WOWPRIVATEMSG) {
  775. LOGDEBUG(LOG_ALWAYS, ("WOW::Warning::putmsg16 caught private message 0x%lx\n", message));
  776. message &= ~WOWPRIVATEMSG; // clear the private bit...
  777. /* If we had some special processing to do for private msgs sent with
  778. a WOWPRIVATEMSG flag the code here would look like
  779. if (WM_SETTEXT == message) {
  780. //
  781. // this message is already equipped with 16-bit lParam
  782. //
  783. }
  784. */
  785. }
  786. GETVDMPTR(vpmsg16, sizeof(MSG16), pmsg16);
  787. STOREWORD(pmsg16->hwnd, GETHWND16(lpmsg->hwnd));
  788. STOREWORD(pmsg16->message, message);
  789. STOREWORD(pmsg16->wParam, wParam);
  790. STORELONG(pmsg16->lParam, lParam);
  791. STORELONG(pmsg16->time, lpmsg->time);
  792. STOREWORD(pmsg16->pt.x, lpmsg->pt.x);
  793. STOREWORD(pmsg16->pt.y, lpmsg->pt.y);
  794. FLUSHVDMPTR(vpmsg16, sizeof(MSG16), pmsg16);
  795. FREEVDMPTR(pmsg16);
  796. return (ulReturn);
  797. }
  798. // Fill in a 32 bit LOGFONT from a 16 bit LOGFONT
  799. VOID getlogfont16(VPLOGFONT16 vplf, LPLOGFONT lplf)
  800. {
  801. register PLOGFONT16 plf16;
  802. // PBYTE p1, p2;
  803. // The assumption here is that no APIs have OPTIONAL LOGFONT pointers
  804. WOW32WARNMSG((vplf),("WOW:getlogfont16: NULL 16:16 logfont ptr\n"));
  805. GETVDMPTR(vplf, sizeof(LOGFONT16), plf16);
  806. if(plf16) {
  807. lplf->lfHeight = FETCHSHORT(plf16->lfHeight);
  808. lplf->lfWidth = FETCHSHORT(plf16->lfWidth);
  809. lplf->lfEscapement = FETCHSHORT(plf16->lfEscapement);
  810. lplf->lfOrientation = FETCHSHORT(plf16->lfOrientation);
  811. lplf->lfWeight = FETCHSHORT(plf16->lfWeight);
  812. lplf->lfItalic = plf16->lfItalic;
  813. lplf->lfUnderline = plf16->lfUnderline;
  814. lplf->lfStrikeOut = plf16->lfStrikeOut;
  815. lplf->lfCharSet = plf16->lfCharSet;
  816. lplf->lfOutPrecision = plf16->lfOutPrecision;
  817. lplf->lfClipPrecision = plf16->lfClipPrecision;
  818. lplf->lfQuality = plf16->lfQuality;
  819. lplf->lfPitchAndFamily = plf16->lfPitchAndFamily;
  820. #if 0
  821. //
  822. // can't do it this way, an app can have an unitialized lfFaceName
  823. // that's a looong stream of non-null chars, in which case we blow
  824. // out our stack.
  825. //
  826. p1 = lplf->lfFaceName;
  827. p2 = plf16->lfFaceName;
  828. while (*p1++ = *p2++);
  829. #else
  830. #if (LF_FACESIZE != 32)
  831. #error Win16/Win32 LF_FACESIZE constants differ
  832. #endif
  833. WOW32_strncpy(lplf->lfFaceName, (const char *)plf16->lfFaceName, LF_FACESIZE);
  834. lplf->lfFaceName[LF_FACESIZE-1] = '\0';
  835. #endif
  836. // if (*p2) {
  837. // i = 0;
  838. // while ((i < LF_FACESIZE) && (*p2)) {
  839. // *p1++ = *p2++;
  840. // i++;
  841. // }
  842. // *p1 = *p2;
  843. //
  844. // } else {
  845. // lstrcpy(lplf->lfFaceName, "System");
  846. // }
  847. FREEVDMPTR(plf16);
  848. }
  849. }
  850. // Fill in a 16 bit LOGFONT from a 32 bit LOGFONT
  851. VOID putlogfont16(VPLOGFONT16 vplf, INT cb, LPLOGFONT lplf)
  852. {
  853. register PLOGFONT16 plf16;
  854. PBYTE p1, p2;
  855. INT cbCopied;
  856. // The assumption here is that no APIs have OPTIONAL LOGFONT pointers
  857. WOW32WARNMSG((vplf),("WOW:putlogfont16: NULL 16:16 logfont ptr\n"));
  858. GETVDMPTR(vplf, sizeof(LOGFONT16), plf16);
  859. if(plf16) {
  860. switch (cb)
  861. {
  862. default:
  863. plf16->lfPitchAndFamily = lplf->lfPitchAndFamily;
  864. case 17:
  865. plf16->lfQuality = lplf->lfQuality;
  866. case 16:
  867. plf16->lfClipPrecision = lplf->lfClipPrecision;
  868. case 15:
  869. plf16->lfOutPrecision = lplf->lfOutPrecision;
  870. case 14:
  871. plf16->lfCharSet = lplf->lfCharSet;
  872. case 13:
  873. plf16->lfStrikeOut = lplf->lfStrikeOut;
  874. case 12:
  875. plf16->lfUnderline = lplf->lfUnderline;
  876. case 11:
  877. plf16->lfItalic = lplf->lfItalic;
  878. case 10:
  879. STORESHORT(plf16->lfWeight, lplf->lfWeight);
  880. case 9:
  881. case 8:
  882. STORESHORT(plf16->lfOrientation,lplf->lfOrientation);
  883. case 7:
  884. case 6:
  885. STORESHORT(plf16->lfEscapement, lplf->lfEscapement);
  886. case 5:
  887. case 4:
  888. STORESHORT(plf16->lfWidth, lplf->lfWidth);
  889. case 3:
  890. case 2:
  891. STORESHORT(plf16->lfHeight, lplf->lfHeight);
  892. case 1:
  893. break;
  894. }
  895. p1 = lplf->lfFaceName;
  896. p2 = (PBYTE)plf16->lfFaceName;
  897. cbCopied = 18;
  898. while ((++cbCopied <= cb) && (*p2++ = *p1++));
  899. FLUSHVDMPTR(vplf, sizeof(LOGFONT16), plf16);
  900. FREEVDMPTR(plf16);
  901. }
  902. }
  903. // Fill in a 16 bit ENUMLOGFONT from a 32 bit ENUMLOGFONT
  904. VOID putenumlogfont16(VPENUMLOGFONT16 vpelf, LPENUMLOGFONT lpelf)
  905. {
  906. register PENUMLOGFONT16 pelf16;
  907. PBYTE p1, p2;
  908. // The assumption here is that no APIs have OPTIONAL ENUMLOGFONT pointers
  909. WOW32ASSERT(vpelf);
  910. GETVDMPTR(vpelf, sizeof(ENUMLOGFONT16), pelf16);
  911. STORESHORT(pelf16->elfLogFont.lfHeight, lpelf->elfLogFont.lfHeight);
  912. STORESHORT(pelf16->elfLogFont.lfWidth, lpelf->elfLogFont.lfWidth);
  913. STORESHORT(pelf16->elfLogFont.lfEscapement, lpelf->elfLogFont.lfEscapement);
  914. STORESHORT(pelf16->elfLogFont.lfOrientation,lpelf->elfLogFont.lfOrientation);
  915. STORESHORT(pelf16->elfLogFont.lfWeight, lpelf->elfLogFont.lfWeight);
  916. pelf16->elfLogFont.lfItalic = lpelf->elfLogFont.lfItalic;
  917. pelf16->elfLogFont.lfUnderline = lpelf->elfLogFont.lfUnderline;
  918. pelf16->elfLogFont.lfStrikeOut = lpelf->elfLogFont.lfStrikeOut;
  919. pelf16->elfLogFont.lfCharSet = lpelf->elfLogFont.lfCharSet;
  920. pelf16->elfLogFont.lfOutPrecision = lpelf->elfLogFont.lfOutPrecision;
  921. pelf16->elfLogFont.lfClipPrecision = lpelf->elfLogFont.lfClipPrecision;
  922. pelf16->elfLogFont.lfQuality = lpelf->elfLogFont.lfQuality;
  923. pelf16->elfLogFont.lfPitchAndFamily = lpelf->elfLogFont.lfPitchAndFamily;
  924. p1 = lpelf->elfLogFont.lfFaceName;
  925. p2 = (PBYTE)pelf16->elfLogFont.lfFaceName;
  926. while ((*p2++ = *p1++) != '\0');
  927. p1 = lpelf->elfFullName;
  928. p2 = (PBYTE)pelf16->elfFullName;
  929. while ((*p2++ = *p1++) != '\0');
  930. p1 = lpelf->elfStyle;
  931. p2 = (PBYTE)pelf16->elfStyle;
  932. while ((*p2++ = *p1++) != '\0');
  933. FLUSHVDMPTR(vpelf, sizeof(ENUMLOGFONT16), pelf16);
  934. FREEVDMPTR(pelf16);
  935. }
  936. VOID puttextmetric16(VPTEXTMETRIC16 vptm, LPTEXTMETRIC lptm)
  937. {
  938. register PTEXTMETRIC16 ptm16;
  939. // The assumption here is that no APIs have OPTIONAL TEXTMETRIC pointers
  940. WOW32ASSERT(vptm);
  941. GETVDMPTR(vptm, sizeof(TEXTMETRIC16), ptm16);
  942. STORESHORT(ptm16->tmHeight, (lptm)->tmHeight);
  943. STORESHORT(ptm16->tmAscent, (lptm)->tmAscent);
  944. STORESHORT(ptm16->tmDescent, (lptm)->tmDescent);
  945. STORESHORT(ptm16->tmInternalLeading,(lptm)->tmInternalLeading);
  946. STORESHORT(ptm16->tmExternalLeading,(lptm)->tmExternalLeading);
  947. STORESHORT(ptm16->tmAveCharWidth, (lptm)->tmAveCharWidth);
  948. STORESHORT(ptm16->tmMaxCharWidth, (lptm)->tmMaxCharWidth);
  949. STORESHORT(ptm16->tmWeight, (lptm)->tmWeight);
  950. ptm16->tmItalic = (lptm)->tmItalic;
  951. ptm16->tmUnderlined = (lptm)->tmUnderlined;
  952. ptm16->tmStruckOut = (lptm)->tmStruckOut;
  953. ptm16->tmFirstChar = (lptm)->tmFirstChar;
  954. ptm16->tmLastChar = (lptm)->tmLastChar;
  955. ptm16->tmDefaultChar = (lptm)->tmDefaultChar;
  956. ptm16->tmBreakChar = (lptm)->tmBreakChar;
  957. ptm16->tmPitchAndFamily = (lptm)->tmPitchAndFamily;
  958. ptm16->tmCharSet = (lptm)->tmCharSet;
  959. STORESHORT(ptm16->tmOverhang, (lptm)->tmOverhang);
  960. STORESHORT(ptm16->tmDigitizedAspectX,(lptm)->tmDigitizedAspectX);
  961. STORESHORT(ptm16->tmDigitizedAspectY,(lptm)->tmDigitizedAspectY);
  962. FLUSHVDMPTR(vptm, sizeof(TEXTMETRIC16), ptm16);
  963. FREEVDMPTR(ptm16);
  964. }
  965. VOID putnewtextmetric16(VPNEWTEXTMETRIC16 vpntm, LPNEWTEXTMETRIC lpntm)
  966. {
  967. register PNEWTEXTMETRIC16 pntm16;
  968. // The assumption here is that no APIs have OPTIONAL TEXTMETRIC pointers
  969. WOW32ASSERT(vpntm);
  970. GETVDMPTR(vpntm, sizeof(NEWTEXTMETRIC16), pntm16);
  971. STORESHORT(pntm16->tmHeight, (lpntm)->tmHeight);
  972. STORESHORT(pntm16->tmAscent, (lpntm)->tmAscent);
  973. STORESHORT(pntm16->tmDescent, (lpntm)->tmDescent);
  974. STORESHORT(pntm16->tmInternalLeading, (lpntm)->tmInternalLeading);
  975. STORESHORT(pntm16->tmExternalLeading, (lpntm)->tmExternalLeading);
  976. STORESHORT(pntm16->tmAveCharWidth, (lpntm)->tmAveCharWidth);
  977. STORESHORT(pntm16->tmMaxCharWidth, (lpntm)->tmMaxCharWidth);
  978. STORESHORT(pntm16->tmWeight, (lpntm)->tmWeight);
  979. pntm16->tmItalic = (lpntm)->tmItalic;
  980. pntm16->tmUnderlined = (lpntm)->tmUnderlined;
  981. pntm16->tmStruckOut = (lpntm)->tmStruckOut;
  982. pntm16->tmFirstChar = (lpntm)->tmFirstChar;
  983. pntm16->tmLastChar = (lpntm)->tmLastChar;
  984. pntm16->tmDefaultChar = (lpntm)->tmDefaultChar;
  985. pntm16->tmBreakChar = (lpntm)->tmBreakChar;
  986. pntm16->tmPitchAndFamily = (lpntm)->tmPitchAndFamily;
  987. pntm16->tmCharSet = (lpntm)->tmCharSet;
  988. STORESHORT(pntm16->tmOverhang, (lpntm)->tmOverhang);
  989. STORESHORT(pntm16->tmDigitizedAspectX, (lpntm)->tmDigitizedAspectX);
  990. STORESHORT(pntm16->tmDigitizedAspectY, (lpntm)->tmDigitizedAspectY);
  991. STOREDWORD(pntm16->ntmFlags, (lpntm)->ntmFlags);
  992. STOREWORD( pntm16->ntmSizeEM, (WORD)((lpntm)->ntmSizeEM));
  993. STOREWORD( pntm16->ntmCellHeight, (WORD)((lpntm)->ntmCellHeight));
  994. STOREWORD( pntm16->ntmAvgWidth, (WORD)((lpntm)->ntmAvgWidth));
  995. FLUSHVDMPTR(vpntm, sizeof(NEWTEXTMETRIC16), pntm16);
  996. FREEVDMPTR(pntm16);
  997. }
  998. VOID putoutlinetextmetric16(VPOUTLINETEXTMETRIC16 vpotm, INT cb, LPOUTLINETEXTMETRIC lpotm)
  999. {
  1000. register POUTLINETEXTMETRIC16 potm16;
  1001. OUTLINETEXTMETRIC16 otm16;
  1002. int count;
  1003. GETVDMPTR(vpotm, cb, potm16);
  1004. otm16.otmSize = (WORD)lpotm->otmSize;
  1005. /*
  1006. ** Copy the TEXTMETRIC structure
  1007. */
  1008. otm16.otmTextMetrics.tmHeight = (SHORT)lpotm->otmTextMetrics.tmHeight;
  1009. otm16.otmTextMetrics.tmAscent = (SHORT)lpotm->otmTextMetrics.tmAscent;
  1010. otm16.otmTextMetrics.tmDescent = (SHORT)lpotm->otmTextMetrics.tmDescent;
  1011. otm16.otmTextMetrics.tmInternalLeading = (SHORT)lpotm->otmTextMetrics.tmInternalLeading;
  1012. otm16.otmTextMetrics.tmExternalLeading = (SHORT)lpotm->otmTextMetrics.tmExternalLeading;
  1013. otm16.otmTextMetrics.tmAveCharWidth = (SHORT)lpotm->otmTextMetrics.tmAveCharWidth;
  1014. otm16.otmTextMetrics.tmMaxCharWidth = (SHORT)lpotm->otmTextMetrics.tmMaxCharWidth;
  1015. otm16.otmTextMetrics.tmWeight = (SHORT)lpotm->otmTextMetrics.tmWeight;
  1016. otm16.otmTextMetrics.tmItalic = lpotm->otmTextMetrics.tmItalic;
  1017. otm16.otmTextMetrics.tmUnderlined = lpotm->otmTextMetrics.tmUnderlined;
  1018. otm16.otmTextMetrics.tmStruckOut = lpotm->otmTextMetrics.tmStruckOut;
  1019. otm16.otmTextMetrics.tmFirstChar = lpotm->otmTextMetrics.tmFirstChar;
  1020. otm16.otmTextMetrics.tmLastChar = lpotm->otmTextMetrics.tmLastChar;
  1021. otm16.otmTextMetrics.tmDefaultChar = lpotm->otmTextMetrics.tmDefaultChar;
  1022. otm16.otmTextMetrics.tmBreakChar = lpotm->otmTextMetrics.tmBreakChar;
  1023. otm16.otmTextMetrics.tmPitchAndFamily = lpotm->otmTextMetrics.tmPitchAndFamily;
  1024. otm16.otmTextMetrics.tmCharSet = lpotm->otmTextMetrics.tmCharSet;
  1025. otm16.otmTextMetrics.tmOverhang = (SHORT)lpotm->otmTextMetrics.tmOverhang;
  1026. otm16.otmTextMetrics.tmDigitizedAspectX = (SHORT)lpotm->otmTextMetrics.tmDigitizedAspectX;
  1027. otm16.otmTextMetrics.tmDigitizedAspectY = (SHORT)lpotm->otmTextMetrics.tmDigitizedAspectY;
  1028. otm16.otmFiller = lpotm->otmFiller;
  1029. /*
  1030. ** Panose
  1031. */
  1032. otm16.otmPanoseNumber.bFamilyType = lpotm->otmPanoseNumber.bFamilyType;
  1033. otm16.otmPanoseNumber.bSerifStyle = lpotm->otmPanoseNumber.bSerifStyle;
  1034. otm16.otmPanoseNumber.bWeight = lpotm->otmPanoseNumber.bWeight;
  1035. otm16.otmPanoseNumber.bProportion = lpotm->otmPanoseNumber.bProportion;
  1036. otm16.otmPanoseNumber.bContrast = lpotm->otmPanoseNumber.bContrast;
  1037. otm16.otmPanoseNumber.bStrokeVariation = lpotm->otmPanoseNumber.bStrokeVariation;
  1038. otm16.otmPanoseNumber.bArmStyle = lpotm->otmPanoseNumber.bArmStyle;
  1039. otm16.otmPanoseNumber.bMidline = lpotm->otmPanoseNumber.bMidline;
  1040. otm16.otmPanoseNumber.bXHeight = lpotm->otmPanoseNumber.bXHeight;
  1041. otm16.otmfsSelection = (WORD)lpotm->otmfsSelection;
  1042. otm16.otmfsType = (WORD)lpotm->otmfsType;
  1043. otm16.otmsCharSlopeRise = (SHORT)lpotm->otmsCharSlopeRise;
  1044. otm16.otmsCharSlopeRun = (SHORT)lpotm->otmsCharSlopeRun;
  1045. otm16.otmItalicAngle = (SHORT)lpotm->otmItalicAngle;
  1046. otm16.otmEMSquare = (WORD)lpotm->otmEMSquare;
  1047. otm16.otmAscent = (SHORT)lpotm->otmAscent;
  1048. otm16.otmDescent = (SHORT)lpotm->otmDescent;
  1049. otm16.otmLineGap = (WORD)lpotm->otmLineGap;
  1050. otm16.otmsCapEmHeight = (WORD)lpotm->otmsCapEmHeight;
  1051. otm16.otmsXHeight = (WORD)lpotm->otmsXHeight;
  1052. /*
  1053. ** Font Box Rectangle (ZOWIE!, I sure wish I could use putrect16 but alas!)
  1054. */
  1055. otm16.otmrcFontBox.left = (SHORT)lpotm->otmrcFontBox.left;
  1056. otm16.otmrcFontBox.top = (SHORT)lpotm->otmrcFontBox.top;
  1057. otm16.otmrcFontBox.right = (SHORT)lpotm->otmrcFontBox.right;
  1058. otm16.otmrcFontBox.bottom = (SHORT)lpotm->otmrcFontBox.bottom;
  1059. otm16.otmMacAscent = (SHORT)lpotm->otmMacAscent;
  1060. otm16.otmMacDescent = (SHORT)lpotm->otmMacDescent;
  1061. otm16.otmMacLineGap = (WORD)lpotm->otmMacLineGap;
  1062. otm16.otmusMinimumPPEM = (WORD)lpotm->otmusMinimumPPEM;
  1063. otm16.otmptSubscriptSize.x = (SHORT)lpotm->otmptSubscriptSize.x;
  1064. otm16.otmptSubscriptSize.y = (SHORT)lpotm->otmptSubscriptSize.y;
  1065. otm16.otmptSubscriptOffset.x = (SHORT)lpotm->otmptSubscriptOffset.x;
  1066. otm16.otmptSubscriptOffset.y = (SHORT)lpotm->otmptSubscriptOffset.y;
  1067. otm16.otmptSuperscriptSize.x = (SHORT)lpotm->otmptSuperscriptSize.x;
  1068. otm16.otmptSuperscriptSize.y = (SHORT)lpotm->otmptSuperscriptSize.y;
  1069. otm16.otmptSuperscriptOffset.x = (SHORT)lpotm->otmptSuperscriptOffset.x;
  1070. otm16.otmptSuperscriptOffset.y = (SHORT)lpotm->otmptSuperscriptOffset.y;
  1071. otm16.otmsStrikeoutSize = (WORD)lpotm->otmsStrikeoutSize;
  1072. otm16.otmsStrikeoutPosition = (SHORT)lpotm->otmsStrikeoutPosition;
  1073. otm16.otmsUnderscorePosition = (SHORT)lpotm->otmsUnderscorePosition;
  1074. otm16.otmsUnderscoreSize = (SHORT)lpotm->otmsUnderscoreSize;
  1075. otm16.otmpFamilyName = (WORD) (lpotm->otmpFamilyName -
  1076. sizeof(OUTLINETEXTMETRIC) + sizeof(OUTLINETEXTMETRIC16));
  1077. otm16.otmpFaceName = (WORD) (lpotm->otmpFaceName -
  1078. sizeof(OUTLINETEXTMETRIC) + sizeof(OUTLINETEXTMETRIC16));
  1079. otm16.otmpStyleName = (WORD) (lpotm->otmpStyleName -
  1080. sizeof(OUTLINETEXTMETRIC) + sizeof(OUTLINETEXTMETRIC16));
  1081. otm16.otmpFullName = (WORD) (lpotm->otmpFullName -
  1082. sizeof(OUTLINETEXTMETRIC) + sizeof(OUTLINETEXTMETRIC16));
  1083. count = sizeof(OUTLINETEXTMETRIC16);
  1084. if ( cb <= count ) {
  1085. count = cb;
  1086. } else {
  1087. /*
  1088. ** Copy the rest of the buffer (strings, etc.) over verbatim.
  1089. */
  1090. RtlCopyMemory( (LPSTR)potm16 + sizeof(OUTLINETEXTMETRIC16),
  1091. (LPSTR)lpotm + sizeof(OUTLINETEXTMETRIC),
  1092. cb - sizeof(OUTLINETEXTMETRIC16) );
  1093. }
  1094. /*
  1095. ** Now really copy it (the structure portion) into the 16-bit memory
  1096. */
  1097. RtlCopyMemory((VOID *)potm16, (CONST VOID *)&otm16, count );
  1098. FLUSHVDMPTR(vpotm, cb, potm16);
  1099. FREEVDMPTR(potm16);
  1100. }
  1101. // Converts a 16 bit handle table to 32 bit
  1102. VOID gethandletable16(VPWORD vpht, UINT c, LPHANDLETABLE lpht)
  1103. {
  1104. PHANDLETABLE16 pht16;
  1105. WORD w;
  1106. GETVDMPTR(vpht, sizeof(HAND16)*c, pht16);
  1107. // be careful, we need to get the correct 32 obj handle from alias
  1108. while (c--)
  1109. {
  1110. w = FETCHWORD(pht16->objectHandle[c]);
  1111. if (w)
  1112. lpht->objectHandle[c] = HOBJ32(w);
  1113. else
  1114. lpht->objectHandle[c] = (HANDLE)NULL;
  1115. }
  1116. FREEVDMPTR(pht16);
  1117. }
  1118. // Converts a 32 bit handle table to 16 bit
  1119. VOID puthandletable16(VPWORD vpht, UINT c, LPHANDLETABLE lpht)
  1120. {
  1121. PHANDLETABLE16 pht16;
  1122. DWORD dw;
  1123. GETVDMPTR(vpht, sizeof(HAND16)*c, pht16);
  1124. // be careful, we need to get the correct 16 alias the 32 obj handle
  1125. while (c--) {
  1126. dw = FETCHDWORD(lpht->objectHandle[c]);
  1127. if (dw) {
  1128. pht16->objectHandle[c] = GETHOBJ16((HAND32)dw);
  1129. }
  1130. else {
  1131. pht16->objectHandle[c] = (HAND16)NULL;
  1132. }
  1133. }
  1134. FREEVDMPTR(pht16);
  1135. }
  1136. /*
  1137. * To solve a ton of devmode compatibility issues we are now going to return
  1138. * Win3.1 devmodes to 16-bit apps instead of NT devmodes.
  1139. *
  1140. * The most common problem we encounter is that apps determine the size to
  1141. * allocate for a DEVMODE buffer by: sizeof(DEVMODE) + dm->dmDriverExtra
  1142. * Apps seem to handle the DriverExtra stuff pretty well but there is a wide-
  1143. * spread belief that the public DEVMODE structure is a fixed size.
  1144. * We hide the NT specific DEVMODE stuff and the WOW devmode thunk info in
  1145. * what the app thinks is the DriverExtra part of the devmode:
  1146. *
  1147. * ____________________________ _____
  1148. * | Win 3.1 DEVMODE | |
  1149. * | dmSize = sizeof(DEVMODE31) | |
  1150. * | dmDriverExtra = | |
  1151. * ___|__/ (sizeof(DEVMODENT) - | Win 3.1 DEVMODE
  1152. * | | \ sizeof(DEVMODE31)) + | |
  1153. * -|---|--- original DriverExtra + | |
  1154. * | | _|__/ sizeof(DWORD) + | |
  1155. * | | | | \ (sizeof(WORD) * 3) | |
  1156. * | | | |____________________________| _____| <-- where app thinks driver
  1157. * | | | | NT DEVMODE stuff not in | | extra starts
  1158. * | `-->| the Win3.1 DEVMODE struct | NT specific DEVMODE stuff
  1159. * | | |____________________________| _____| <-- where driver extra really
  1160. * `---->| actual NT driver extra | starts
  1161. * | |____________________________| <-- where WOWDM31 struct starts
  1162. * | | DWORD with "DM31" | <--- WOW DEVMODE31 signature
  1163. * ->| WORD original dmSpecVersion|\
  1164. * | WORD original dmSize | <--- values returned by the driver
  1165. * | WORD original dmDriverExtra|/
  1166. * | WORD to pad to even DWORD | <--- requried for ptr arithmetic
  1167. * |____________________________|
  1168. *
  1169. * NOTE: We may see Win3.0 & Win3.1 DevModes that are returned by 16-bit fax
  1170. * drivers.
  1171. *
  1172. */
  1173. LPDEVMODE ThunkDevMode16to32(VPDEVMODE31 vpdm16)
  1174. {
  1175. INT nSize, nDriverExtra;
  1176. LPDEVMODE lpdm32;
  1177. PDEVMODE31 pdm16;
  1178. PWOWDM31 pWOWDM31;
  1179. if(FETCHDWORD(vpdm16) == 0L) {
  1180. return(NULL);
  1181. }
  1182. GETVDMPTR(vpdm16, sizeof(DEVMODE31), pdm16);
  1183. // we will generally see only Win3.1 DevMode's here but 16-bit fax
  1184. // drivers can return a Win3.0 DevMode.
  1185. nSize = FETCHWORD(pdm16->dmSize);
  1186. WOW32WARNMSGF((nSize==sizeof(DEVMODE31)),
  1187. ("ThunkDevMode16to32: Unexpected dmSize(16) = %d\n", nSize));
  1188. // check for bad DEVMODE (PageMaker & MSProfit are known culprits)
  1189. // (PageMaker 5.0a passes a 16:16 ptr to NULL!!)
  1190. // this test taken from gdi\client\object.c!bConvertToDevmodeW
  1191. if ( (nSize < (offsetof(DEVMODE, dmDriverExtra) + sizeof(WORD))) ||
  1192. (nSize > sizeof(DEVMODE)) ) {
  1193. LOGDEBUG(LOG_ALWAYS,("WOW::ThunkDevMode16to32:Bail out case!!\n"));
  1194. return(NULL);
  1195. }
  1196. // note this might include the "extra" DriverExtra we added in
  1197. // ThunkDevMode32to16()
  1198. nDriverExtra = FETCHWORD(pdm16->dmDriverExtra);
  1199. // allocate 32-bit DEVMODE -- don't worry if we alloc a little too much due
  1200. // to the WOW stuff we added to the end of the driver extra
  1201. if(lpdm32 = malloc_w(nSize + nDriverExtra)) {
  1202. // fill in the 32-bit devmode
  1203. RtlCopyMemory((VOID *)lpdm32,(CONST VOID *)pdm16, nSize + nDriverExtra);
  1204. // if this is a Win3.1 size DEVMODE, it may be one of our special ones
  1205. if(nSize == sizeof(DEVMODE31)) {
  1206. // see if it has our "DM31" signature at the end of the DEVMODE
  1207. pWOWDM31 = (PWOWDM31)((PBYTE)lpdm32 +
  1208. sizeof(DEVMODE31) +
  1209. nDriverExtra -
  1210. sizeof(WOWDM31));
  1211. // if it does, adjust the dmSpecVersion, dmSize & dmDriverExtra
  1212. // back to the values we got from the driver
  1213. if(pWOWDM31->dwWOWSig == WOW_DEVMODE31SIG) {
  1214. lpdm32->dmSpecVersion = pWOWDM31->dmSpecVersion;
  1215. lpdm32->dmSize = pWOWDM31->dmSize;
  1216. lpdm32->dmDriverExtra = pWOWDM31->dmDriverExtra;
  1217. }
  1218. #ifdef DEBUG
  1219. // somehow the app got a DEVMODE and either lost our thunking info
  1220. // or threw it away (#205327)
  1221. else {
  1222. LOGDEBUG(LOG_ALWAYS, ("WOW::ThunkDevMode16to32: Signature missing from DEVMODE!!\n"));
  1223. }
  1224. #endif
  1225. }
  1226. }
  1227. FREEVDMPTR(pdm16);
  1228. return(lpdm32);
  1229. }
  1230. BOOL ThunkDevMode32to16(VPDEVMODE31 vpdm16, LPDEVMODE lpdm32, UINT nBytes)
  1231. {
  1232. WORD nSize, nDriverExtra;
  1233. PDEVMODE31 pdm16;
  1234. PWOWDM31 pWOWDM31;
  1235. GETVDMPTR(vpdm16, sizeof(DEVMODE31), pdm16);
  1236. if((FETCHDWORD(vpdm16) == 0L) || (!lpdm32) || (!pdm16)) {
  1237. return(FALSE);
  1238. }
  1239. nSize = lpdm32->dmSize;
  1240. // We should only see DevModes of the current NT size because the spooler
  1241. // converts all devmodes to the current version
  1242. WOW32WARNMSGF((nSize==sizeof(DEVMODE)),
  1243. ("ThunkDevMode32to16: Unexpected devmode size = %d\n",nSize));
  1244. nDriverExtra = lpdm32->dmDriverExtra;
  1245. // fill in the 16-bit devmode
  1246. RtlCopyMemory((VOID *)pdm16,
  1247. (CONST VOID *)lpdm32,
  1248. min((nSize + nDriverExtra), (WORD)nBytes));
  1249. // Convert NT sized devmodes to Win3.1 devmodes.
  1250. // Note: Winfax.drv passes back an NT size DevMode with dmSpecVersion=0x300
  1251. // also it passes a hard coded 0xa9 to GetEnvironment() as the max
  1252. // size of its buffer (see GetEnvironment() notes in wgdi.c)
  1253. // If there is a buffer constraint, we'll just have to be satisfied
  1254. // with copying the nBytes worth of the devmode which should work
  1255. // in the case of WinFax.
  1256. if((nSize == sizeof(DEVMODE)) && ((nSize + nDriverExtra) <= (WORD)nBytes)) {
  1257. // save our signature along with the original dmSpecVersion, dmSize,
  1258. // and dmDriverExtra at the end of the DriverExtra memory
  1259. pWOWDM31 = (PWOWDM31)((PBYTE)pdm16 +
  1260. sizeof(DEVMODE) +
  1261. nDriverExtra);
  1262. pWOWDM31->dwWOWSig = WOW_DEVMODE31SIG;
  1263. pWOWDM31->dmSpecVersion = lpdm32->dmSpecVersion;
  1264. pWOWDM31->dmSize = nSize;
  1265. pWOWDM31->dmDriverExtra = nDriverExtra;
  1266. // Make our special adjustments to the public devmode stuff.
  1267. // We can't tell an app a Win3.0 DevMode is a Win3.1 version or it might
  1268. // try to write to the new Win3.1 fields
  1269. if(lpdm32->dmSpecVersion > WOW_DEVMODE31SPEC) {
  1270. pdm16->dmSpecVersion = WOW_DEVMODE31SPEC;
  1271. }
  1272. pdm16->dmSize = sizeof(DEVMODE31);
  1273. pdm16->dmDriverExtra += WOW_DEVMODEEXTRA;
  1274. }
  1275. FLUSHVDMPTR(vpdm16, sizeof(DEVMODE31), pdm16);
  1276. FREEVDMPTR(pdm16);
  1277. return(TRUE);
  1278. }
  1279. VOID getwindowpos16( VPWINDOWPOS16 vpwp, LPWINDOWPOS lpwp )
  1280. {
  1281. register PWINDOWPOS16 pwp16;
  1282. GETVDMPTR(vpwp, sizeof(WINDOWPOS16), pwp16);
  1283. lpwp->hwnd = HWND32(pwp16->hwnd);
  1284. lpwp->hwndInsertAfter = HWNDIA32(pwp16->hwndInsertAfter);
  1285. lpwp->x = (INT) FETCHSHORT(pwp16->x);
  1286. lpwp->y = (INT) FETCHSHORT(pwp16->y);
  1287. lpwp->cx = (INT) FETCHSHORT(pwp16->cx);
  1288. lpwp->cy = (INT) FETCHSHORT(pwp16->cy);
  1289. lpwp->flags = (WORD) FETCHWORD(pwp16->flags);
  1290. FREEVDMPTR(pwp16);
  1291. }
  1292. VOID putwindowpos16( VPWINDOWPOS16 vpwp, LPWINDOWPOS lpwp )
  1293. {
  1294. register PWINDOWPOS16 pwp16;
  1295. GETVDMPTR(vpwp, sizeof(WINDOWPOS16), pwp16);
  1296. STOREWORD(pwp16->hwnd, GETHWND16(lpwp->hwnd));
  1297. STOREWORD(pwp16->hwndInsertAfter, GETHWNDIA16(lpwp->hwndInsertAfter));
  1298. STORESHORT(pwp16->x, lpwp->x);
  1299. STORESHORT(pwp16->y, lpwp->y);
  1300. STORESHORT(pwp16->cx, lpwp->cx);
  1301. STORESHORT(pwp16->cy, lpwp->cy);
  1302. STOREWORD(pwp16->flags, lpwp->flags);
  1303. FLUSHVDMPTR(vpwp, sizeof(WINDOWPOS16), pwp16);
  1304. FREEVDMPTR(pwp16);
  1305. }
  1306. VOID W32CopyMsgStruct(VPMSG16 vpmsg16, LPMSG lpmsg, BOOL fThunk16To32)
  1307. {
  1308. register PMSG16 pmsg16;
  1309. GETVDMPTR(vpmsg16, sizeof(MSG16), pmsg16);
  1310. if (fThunk16To32) {
  1311. lpmsg->hwnd = HWND32(pmsg16->hwnd);
  1312. lpmsg->message = pmsg16->message;
  1313. lpmsg->wParam = pmsg16->wParam;
  1314. lpmsg->lParam = pmsg16->lParam;
  1315. lpmsg->time = pmsg16->time;
  1316. lpmsg->pt.x = pmsg16->pt.x;
  1317. lpmsg->pt.y = pmsg16->pt.y;
  1318. }
  1319. else {
  1320. // for later use.
  1321. }
  1322. FREEVDMPTR(pmsg16);
  1323. return;
  1324. }
  1325. HAND16 getpaintstruct16(VPVOID vp, LPPAINTSTRUCT lp)
  1326. {
  1327. HAND16 hdc16;
  1328. PPAINTSTRUCT16 pps16;
  1329. GETVDMPTR(vp, sizeof(PAINTSTRUCT16), pps16);
  1330. hdc16 = FETCHWORD(pps16->hdc);
  1331. (lp)->hdc = HDC32(hdc16);
  1332. (lp)->fErase = FETCHSHORT(pps16->fErase);
  1333. (lp)->rcPaint.left = FETCHSHORT(pps16->rcPaint.left);
  1334. (lp)->rcPaint.top = FETCHSHORT(pps16->rcPaint.top);
  1335. (lp)->rcPaint.right = FETCHSHORT(pps16->rcPaint.right);
  1336. (lp)->rcPaint.bottom= FETCHSHORT(pps16->rcPaint.bottom);
  1337. (lp)->fRestore = FETCHSHORT(pps16->fRestore);
  1338. (lp)->fIncUpdate = FETCHSHORT(pps16->fIncUpdate);
  1339. RtlCopyMemory((lp)->rgbReserved,
  1340. pps16->rgbReserved, sizeof(pps16->rgbReserved));
  1341. FREEVDMPTR(pps16);
  1342. return(hdc16);
  1343. }
  1344. HAND16 putpaintstruct16(VPVOID vp, LPPAINTSTRUCT lp)
  1345. {
  1346. HAND16 hdc16;
  1347. PPAINTSTRUCT16 pps16;
  1348. GETVDMPTR(vp, sizeof(PAINTSTRUCT16), pps16);
  1349. hdc16 = GETHDC16((lp)->hdc);
  1350. STOREWORD(pps16->hdc, hdc16);
  1351. STORESHORT(pps16->fErase, (lp)->fErase);
  1352. STORESHORT(pps16->rcPaint.left, (lp)->rcPaint.left);
  1353. STORESHORT(pps16->rcPaint.top, (lp)->rcPaint.top);
  1354. STORESHORT(pps16->rcPaint.right, (lp)->rcPaint.right);
  1355. STORESHORT(pps16->rcPaint.bottom, (lp)->rcPaint.bottom);
  1356. STORESHORT(pps16->fRestore, (lp)->fRestore);
  1357. STORESHORT(pps16->fIncUpdate, (lp)->fIncUpdate);
  1358. RtlCopyMemory(pps16->rgbReserved,
  1359. (lp)->rgbReserved, sizeof(pps16->rgbReserved));
  1360. FLUSHVDMPTR(vp, sizeof(PAINTSTRUCT16), pps16);
  1361. FREEVDMPTR(pps16);
  1362. return(hdc16);
  1363. }
  1364. VOID FASTCALL getmenuiteminfo16(VPVOID vp, LPMENUITEMINFO pmii32)
  1365. {
  1366. PMENUITEMINFO16 pmii16;
  1367. GETVDMPTR(vp, sizeof(*pmii16), pmii16);
  1368. pmii32->cbSize = sizeof(*pmii32);
  1369. pmii32->fMask = pmii16->fMask;
  1370. if (pmii32->fMask & MIIM_CHECKMARKS) {
  1371. pmii32->hbmpChecked = HBITMAP32(pmii16->hbmpChecked);
  1372. pmii32->hbmpUnchecked = HBITMAP32(pmii16->hbmpUnchecked);
  1373. } else {
  1374. pmii32->hbmpChecked = pmii32->hbmpUnchecked = NULL;
  1375. }
  1376. pmii32->dwItemData = (pmii32->fMask & MIIM_DATA)
  1377. ? pmii16->dwItemData
  1378. : 0;
  1379. pmii32->wID = (pmii32->fMask & MIIM_ID)
  1380. ? pmii16->wID
  1381. : 0;
  1382. pmii32->fState = (pmii32->fMask & MIIM_STATE)
  1383. ? pmii16->fState
  1384. : 0;
  1385. pmii32->hSubMenu = (pmii32->fMask & MIIM_SUBMENU)
  1386. ? HMENU32(pmii16->hSubMenu)
  1387. : NULL;
  1388. if (pmii32->fMask & MIIM_TYPE) {
  1389. pmii32->fType = pmii16->fType;
  1390. if (pmii32->fType & MFT_BITMAP) {
  1391. pmii32->dwTypeData = (LPTSTR) HBITMAP32(pmii16->dwTypeData);
  1392. } else if (!(pmii32->fType & MFT_NONSTRING)) { // like (pmii32->fType & MFT_STRING) but MFT_STRING is zero
  1393. GETPSZPTR(pmii16->dwTypeData, pmii32->dwTypeData);
  1394. AddParamMap( (DWORD) pmii32->dwTypeData, pmii16->dwTypeData);
  1395. } else {
  1396. pmii32->dwTypeData = (LPTSTR) pmii16->dwTypeData;
  1397. }
  1398. } else {
  1399. pmii32->dwTypeData = (LPSTR) pmii32->fType = 0;
  1400. }
  1401. pmii32->cch = pmii16->cch;
  1402. FREEVDMPTR(pmii16);
  1403. }
  1404. VOID FASTCALL putmenuiteminfo16(VPVOID vp, LPMENUITEMINFO pmii32)
  1405. {
  1406. PMENUITEMINFO16 pmii16;
  1407. GETVDMPTR(vp, sizeof(*pmii16), pmii16);
  1408. pmii16->cbSize = sizeof(*pmii16);
  1409. pmii16->fMask = (WORD) pmii32->fMask;
  1410. if (pmii32->fMask & MIIM_CHECKMARKS) {
  1411. pmii16->hbmpChecked = GETHBITMAP16(pmii32->hbmpChecked);
  1412. pmii16->hbmpUnchecked = GETHBITMAP16(pmii32->hbmpUnchecked);
  1413. }
  1414. if (pmii32->fMask & MIIM_DATA) {
  1415. pmii16->dwItemData = pmii32->dwItemData;
  1416. }
  1417. if (pmii32->fMask & MIIM_ID) {
  1418. pmii16->wID = (WORD) pmii32->wID;
  1419. }
  1420. if (pmii32->fMask & MIIM_STATE) {
  1421. pmii16->fState = (WORD) pmii32->fState;
  1422. }
  1423. if (pmii32->fMask & MIIM_SUBMENU) {
  1424. pmii16->hSubMenu = GETHMENU16(pmii32->hSubMenu);
  1425. }
  1426. if (pmii32->fMask & MIIM_TYPE) {
  1427. pmii16->fType = (WORD) pmii32->fType;
  1428. if (pmii32->fType & MFT_BITMAP) {
  1429. pmii16->dwTypeData = GETHBITMAP16(pmii32->dwTypeData);
  1430. } else if (!(pmii32->fType & MFT_NONSTRING)) { // like (pmii32->fType & MFT_STRING) but MFT_STRING is zero
  1431. pmii16->dwTypeData = GetParam16( (DWORD) pmii32->dwTypeData);
  1432. } else {
  1433. pmii16->dwTypeData = (VPSTR) pmii32->dwTypeData;
  1434. }
  1435. }
  1436. FREEVDMPTR(pmii16);
  1437. }