GlobalReAlloc

 

Description

The GlobalReAlloc function changes the size or attributes of a specified global memory object. The size can increase or decrease.

Syntax

HGLOBAL GlobalReAlloc( HGLOBAL hMem, DWORD dwBytes, UINT uFlags )

Parameters

hMem
[input] Handle to the global memory object to be reallocated.
dwBytes
[input] New size of the memory block, in bytes. If uFlags specifies GMEM_MODIFY, this parameter is ignored.
uFlags
[input] Reallocation options.

Return

If the function succeeds, the return value is a handle to the reallocated memory object.

If the function fails, the return value is NULL.

Examples

EX1

void GlobalReAlloc_Ex1()
{
        
        DWORD nMemSize =200 ;
        HGLOBAL hData = GlobalAlloc(GHND,nMemSize);
        
        if(!hData)
        {
                out_str("failed to allocate memory\n");
                return ;
        }
        
        if(NULL == GlobalReAlloc(hData, nMemSize*2, GMEM_MOVEABLE))
        {
                out_str("failed to Reallocate memory\n");
                return ;
        }
        else
        {
                printf("The memory resized to : %d BYTES",GlobalSize(hData)) ;
        }
        
        GlobalFree(hData) ;      
}

Remark

See Also

GlobalAlloc, GlobalFree, GlobalSize, GlobalLock, GlobalUnlock

Header to Include

origin.h

Reference