'************************************** ' Name: Global Memory ' Description:I could not find documenta ' tion or anything on the net to which wha ' t I had a hunch was true with Global mem ' ory allocation (or even Local memory, be ' cause Global flags occur across all memo ' ry), so I just wrote this API example te ' st to verify it was what I thought, and ' able you provide the pointer, as to the ' effect of the flags. GPTR is doing so wi ' th out the address memory predisposition ' , as if, indicate newly provided. So her ' e is just a simple global memory allocat ' ion, locking, reallocation, and free of ' such with the cleanup. Examples of this ' API I've seen end up with another pointe ' r address handle when locking occurs, I' ' m not sure how to handle that in freeing ' or unlocking. Maybe provided it's well t ' o do so with two handle addresses also. ' By: Nicholas Forystek ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None '************************************** Private Const GPTR = &H40 Private Const GHND = &H42 Private Const GMEM_FIXED = &H0 Private Const GMEM_MOVEABLE = &H2 Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long Private Declare Function GlobalReAlloc Lib "kernel32" (ByVal hMem As Long, ByVal dwBytes As Long, ByVal wFlags As Long) As Long Private Declare Sub RtlMoveMemory Lib "kernel32" (Left As Any, Pass As Any, ByVal Right As Long) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public Sub Main() Dim hMem As Long 'print the size, address and value of th ' e memory Debug.Print "1- (" & GlobalSize(hMem) & ":" & VarPtr(hMem) & ")=" & hMem 'moveable container of address as the GP ' TR flag hMem = GlobalAlloc(GMEM_MOVEABLE And VarPtr(hMem), 64) 'make sure there is no errors If hMem = 0 Then Debug.Print "Alloc Error" 'print the size, address and value of th ' e memory Debug.Print "2- (" & GlobalSize(hMem) & ":" & VarPtr(hMem) & ")=" & hMem 'lock the memory scope, checking for err ' ors If GlobalLock(hMem) <> hMem Then Debug.Print "Lock Error" 'print the size, address and value of th ' e memory Debug.Print "3- (" & GlobalSize(hMem) & ":" & VarPtr(hMem) & ")=" & hMem 'reallocate the GPTR to be twice the siz ' e hMem = GlobalReAlloc(hMem, 128, GMEM_MOVEABLE Or GPTR) 'print the size, address and value of th ' e memory Debug.Print "4- (" & GlobalSize(hMem) & ":" & VarPtr(hMem) & ")=" & hMem 'unlock the memory scope, checking for e ' rrors If GlobalUnlock(hMem) <> 1 Then Debug.Print "Unlock Error" 'print the size, address and value of th ' e memory Debug.Print "5- (" & GlobalSize(hMem) & ":" & VarPtr(hMem) & ")=" & hMem 'free up the memory, checking for errors ' If GlobalFree(hMem) <> 0 Then Debug.Print "Free Error" End Sub