GlobalReAlloc

  HGLOBAL GlobalReAlloc(hglb, cbNewSize, fuAlloc)    
  HGLOBAL hglb; /* handle of memory block to reallocate */
  DWORD cbNewSize; /* new size of block */
  UINT fuAlloc; /* how block is reallocated */

The GlobalReAlloc function changes the size or attributes of the specified global memory block.

Parameters

hglb

Identifies the global memory block to be reallocated.

cbNewSize

Specifies the new size of the memory block in bytes.

fuAlloc

Specifies how to reallocate the global block. If this parameter includes GMEM_MODIFY, GlobalReAlloc ignores the cbNewSize parameter.

Value Meaning

GMEM_DISCARDABLE  
  Causes a previously movable block to become discardable. This flag can be used only with GMEM_MODIFY.
GMEM_MODIFY  
  Use to modify the memory flags of a block without changing its size. Use GMEM_DISCARDABLE and GMEM_MOVEABLE to select the new flags.
GMEM_MOVEABLE  
  If cbNewSize is zero, this flag causes a previously movable and discardable block to be discarded (if the block's lock count is zero). If cbNewSize is zero and the block is not movable and discardable, this flag causes GlobalReAlloc to fail.
  If cbNewSize is nonzero and the memory block identified by hglb is fixed, this flag allows the reallocated block to be moved to a new fixed location.
  If a movable block is locked, this flag allows the block to be moved to a new locked location without invalidating the handle. This may occur even if the block is currently locked by a previous call to GlobalLock. (Note that in this case the handle returned by the GlobalReAlloc function may be different from the handle passed to the function.)
  If this flag is used with GMEM_MODIFY, GlobalReAlloc changes a fixed memory block to a movable memory block.
GMEM_NODISCARD  
  Prevents memory from being discarded to satisfy the allocation request. This flag cannot be used with GMEM_MODIFY.
GMEM_ZEROINIT  
  If the block is growing, this flag causes the additional memory to be initialized to zero. This flag cannot be used with GMEM_MODIFY.

Return Value

If the function is successful, the return value is the handle of the reallocated global memory. It is NULL if the block cannot be reallocated as specified. Use the GetLastError function to obtain extended error information.

Comments

If GlobalReAlloc reallocates a movable block, the return value is a handle to the memory. To access the memory, an application must use the GlobalLock function to convert the handle to a pointer.

If GlobalReAlloc reallocates a fixed block, the return value is a pointer to the memory. To access the memory, an application can simply cast the return value to a pointer.

See Also

GlobalAlloc, GlobalFree, GlobalLock