GlobalHandle

 

Description

The GlobalHandle function retrieves the handle of the specified global memory object.

Syntax

HGLOBAL GlobalHandle( LPVOID pMem )

Parameters

pMem
[input] Handle to the global memory object.

Return

If the function succeeds, the return value is the Handle of the specified global memory object, in bytes.

Examples

EX1

void GlobalHandle_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 ;
        }
        
        HGLOBAL hDataTemp = GlobalHandle(pstr) ;
        
        if(0==GlobalUnlock(hDataTemp))
                out_str("the memory has been unlocked sucessfuly\n");
        
        GlobalFree(hDataTemp) ;
}

Remark

When the GlobalAlloc function allocates a memory object with GMEM_MOVEABLE, it returns a handle to the object. The GlobalLock function converts this handle into a pointer to the memory block, and GlobalHandle converts the pointer back into a handle.

See Also

GlobalReAlloc, GlobalReAlloc, GlobalFree, GlobalLock, GlobalUnlock

header to Include

origin.h

Reference