The GlobalFree function frees the specified global memory object and invalidates its handle.
HGLOBAL GlobalFree( HGLOBAL hMem )
If the function succeeds, the return value is NULL.
If the function fails, the return value is equal to a handle to the global memory object.
EX1
void GlobalFree_Ex1() { string strTemp = "This is a test"; int nMemSize = strTemp.GetLength()+1 ; HANDLE hData = GlobalAlloc(GHND,nMemSize); if(!hData) { out_str("failed to alloc memory\n"); return ; } DWORD dSize = GlobalSize(hData); if(dSize != nMemSize) { out_str("memory is not enough\n"); return ; } LPSTR lpData = (LPSTR)GlobalLock(hData); lstrcpyn(lpData, strTemp, nMemSize); GlobalUnlock(hData); out_str(lpData); if(NULL != GlobalFree(hData)) { out_str("failed to free the allocated memory\n"); return ; } else { lpData = NULL; out_str("success to free the allocated memory"); } }
GlobalReAlloc, GlobalReAlloc, GlobalSize, GlobalLock, GlobalUnlock
origin.h