Using Near and Far Pointers with C Run-Time FunctionsLast reviewed: July 22, 1997Article ID: Q74788 |
3.00 3.10
WINDOWS
kbprg
The information in this article applies to:
In an application designed for the Microsoft Windows graphical environment, many C run-time functions do not work with memory allocated by the GlobalAlloc() function when the application is developed in the small or medium memory model. MS-DOS (non-Windows) applications written in the small or medium memory model assume the presence of only one data segment (DS). Therefore, the C Run-time functions assume that DS will not change. However, an application can store data in a block of memory allocated with the GlobalAlloc() function and locked with the GlobalLock() function. The segment returned from GlobalLock() will be different from the application's data segment. Specifying the alternate data segment in a C run-time function that assumes a near pointer results in the following C compiler warning:
WARNING: Segment Lost in ConversionFor example, the following code passes far pointers to a Run-time function incorrectly:
hMem = GlobalAlloc (...); lpMem = GlobalLock (hMem); strcpy (szBuffer, lpMem); GlobalUnlock (hMem);This section of incorrect code produces one of two results.
strcpy (lpMem, szBuffer);Four ways to work around this situation are:
|
Additional reference words: 3.00 3.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |