The GlobalReAlloc function changes the size or attributes of a specified global memory object. The size can increase or decrease.
This function is provided only for compatibility with 16-bit versions of Windows.
HGLOBAL GlobalReAlloc(
HGLOBAL hMem, // handle to the global memory object
DWORD dwBytes, // new size of the block
UINT uFlags // how to reallocate object
);
The GMEM_MODIFY flag can be combined with either or both of the following flags:
Flag | Meaning |
---|---|
GMEM_DISCARDABLE | Ignored. This flag is provided only for compatibility with 16-bit Windows. In Win32, you must explicitly call the GlobalDiscard function to discard a block. In 16-bit Windows, allocates discardable memory, if the GMEM_MODIFY flag is also specified. This flag is ignored if the object was not previously allocated as movable or if the GMEM_MOVEABLE flag is not specified. |
GMEM_MOVEABLE | Changes a fixed memory object to a movable memory object, if the GMEM_MODIFY flag is also specified. |
If this parameter does not specify GMEM_MODIFY, it can also be any combination of the following flags:
Flag | Meaning |
---|---|
GMEM_NOCOMPACT | Ignored. This flag is provided only for compatibility with 16-bit Windows. |
GMEM_ZEROINIT | Causes the additional memory contents to be initialized to zero if the memory object is growing in size. |
If the function succeeds, the return value is a handle to the reallocated memory object.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
If GlobalReAlloc reallocates a movable object, the return value is a handle to the memory object. To convert the handle to a pointer, use the GlobalLock function.
If GlobalReAlloc reallocates a fixed object, the value of the handle returned is the address of the first byte of the memory block. To access the memory, a process can simply cast the return value to a pointer.
If GlobalReAlloc fails, the original memory is not freed, and the original handle and pointer are still valid.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Memory Management Overview, Memory Management Functions, GlobalAlloc, GlobalDiscard, GlobalLock