GlobalLock

 

Description

The GlobalLock function locks a global memory object and returns a pointer to the first byte of the object's memory block.

Syntax

LPVOID GlobalLock( HGLOBAL hMem )

Parameters

hMem
[input] Handle to the global memory object.

Return

If the function succeeds, the return value is a pointer to the first byte of the memory block.

If the function fails, the return value is NULL.

Examples

EX1

void GlobalLock_Ex1()
{
        int nBytes = 200; 
        HGLOBAL hData = GlobalAlloc(GHND,nBytes);
        
        char* pstr = (char *)GlobalLock(hData) ;
                

        if(NULL==pstr)
        {
                out_str("failed to Lock the memory\n");
                return ;
        }
        else
                printf("the first byte of the object's memory address: (0x)%x",pstr);

        GlobalUnlock(hData);
        
        GlobalFree(hData);
}

Remark

See Also

GlobalReAlloc, GlobalReAlloc, GlobalFree, GlobalSize, GlobalUnlock

header to Include

origin.h

Reference