Microsoft KB Archive/126708

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

HOWTO: Pass Large Memory Block Through Win32s Universal Thunk

Q126708



The information in this article applies to:


  • Microsoft Win32s versions 1.2, 1.3, 1.30a, 1.3c





SUMMARY

You can share memory between 32-bit code and 16-bit code under Win32s using either GlobalAlloc or passing a memory address to a Universal Thunk (UT) routine. For general information on how to share memory under Win32s, please refer to the following Knowledge Base article:

Q105762 HOWTO: Share Memory Between 32-Bit and 16-Bit Code on Win32s

When you pass a memory address to a thunk routine, the pointer address is translated via the universal thunk (UT). However, the translated pointer is only guaranteed for 32K due to performance reasons. For more information on this limitation, please refer to the following Knowledge Base article:

Q100833 INFO: Win32s Translated Pointers Guaranteed for 32K

This article describes ways to pass a larger memory block (including greater than 64K in size) through the Universal Thunk under Win32s.



MORE INFORMATION

GlobalAlloc()

You can call GlobalAlloc() to allocate a larger memory block on the 32-bit side of the thunk, copy the data into this memory block, send the handle to the 16-bit side, and lock the handle on the 16-bit side with GlobalLock(). With this method, you are not limited by the size of the block that can be passed across the thunk. If the memory block that you are passing is more than 64K in size, make sure to type cast the return value from GlobalLock() to a huge pointer on the 16-bit side.

VirtualAlloc()or HeapAlloc()

If you allocate the memory using VirtualAlloc(), it will be aligned on a 64K boundary, so that you can address the entire memory block. HeapAlloc() allocates large memory blocks using VirtualAlloc() as well. NOTE: You are still limited to 64K of memory, due to the selector tiling.

Allocate a selector

To use this method, get the 32-bit offset used by the Win32-based application and the selector base for the data selector returned by GetThreadSelectorEntry(), then calculate the linear address of the memory block. With this linear address, you can use AllocSelector(), SetSelectorBase(), and SetSelectorLimit() to access the memory block from the 16-bit side of the thunk.

For more information on converting the linear address to flat offset on Win32s, please refer to the following Knowledge Base article:

Q115080 HOWTO: Convert a Linear Address to a Flat Offset on Win32s

For more information on allocating and using a selector on the 16-bit side, please refer to the following Knowledge Base article:

Q132005 DOCERR: AllocSelector & FreeSelector Documentation Incomplete

NOTE: Sparse memory will cause problems in the general case. Make sure that the memory range has been not only reserved, but also committed.

Additional query words:

Keywords : kbprogramming kbOSWin32s
Issue type : kbhowto
Technology : kbWin32sSearch kbWin32s120 kbWin32s130 kbWin32s130a kbWin32s130c


Last Reviewed: January 16, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.