GlobalReAlloc

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
);
 

Parameters

hMem
Handle to the global memory object to be reallocated. This handle is returned by either the GlobalAlloc or GlobalReAlloc function.
dwBytes
Specifies the new size, in bytes, of the memory block. If uFlags specifies the GMEM_MODIFY flag, this parameter is ignored.
uFlags
Specifies how to reallocate the global memory object. If the GMEM_MODIFY flag is specified, this parameter modifies the attributes of the memory object, and the dwBytes parameter is ignored. Otherwise, this parameter controls the reallocation of the memory 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.

Return Values

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.

Remarks

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.

QuickInfo

  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.

See Also

Memory Management Overview, Memory Management Functions, GlobalAlloc, GlobalDiscard, GlobalLock