Code:
'PB 5/9 .02 'GlobalMem.inc ' 'allocate global memory ' #If Not %Def(%WINAPI) #Include Once "WIN32API.INC" #EndIf #Include Once "C:\PBINC\Error.inc" ' Function GMem_Alloc(ByVal memSize As Long, e As ErrT) As Long 'allocate memory If e.err = %false Then If memSize Then Local hMem As Long hMem = GlobalAlloc(ByVal %GPTR, ByVal memSize) If hMem Then Function = hMem Else Err_Set e, %ErrUndefined, "GlobalMem.inc", "", "", "GMem_Alloc", "memory allocation fail" End If End If End If End Function ' Function GMem_Free(ByVal hMem As Long, e As ErrT) As Long 'free allocated memory If hMem Then GlobalFree(ByVal hMem) Function = %NULL End Function ' Function GMem_ReAlloc(ByVal hMem As Long, ByVal newSize As Long, e As ErrT) As Long 'reallocate block of memory 'USE: hMem = GMemReAlloc(hMem, newSize) Local h As Long If newSize = 0 Then If hMem Then GlobalFree(ByVal hMem) Function = %NULL Else If hMem Then h = GlobalReAlloc(ByVal hMem, ByVal newSize, ByVal %GMEM_MOVEABLE Or %GMEM_ZEROINIT) Else h = GlobalAlloc(ByVal %GPTR, ByVal newSize) End If If h Then Function = h Else Err_Set e, %ErrUndefined, "GlobalMem.inc", "", "", "GMem_ReAlloc", "memory allocation fail" End If End If End Function ' Sub GMem_Copy(ByVal copyTo As Long, ByVal copyFrom As Long, ByVal byteCount As Long, e As ErrT) 'copy/move block of memory If e.err = %false Then If copyTo = %null Or copyFrom = %null Then Err_Set e, %ErrUndefined, "GlobalMem.inc", "", "", "GMem_Copy", "null memory handle" End If MoveMemory(ByVal copyTo, ByVal copyFrom, ByVal byteCount) End If End Sub
Leave a comment: