'************************************** ' 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, so I just wrote this API ' example test to verify it was what I tho ' ught, and able you provide the pointer, ' as to the effect of the flags. GPTR is d ' oing so with out the address memory pred ' isposition, as if, indicate newly provid ' ed. So here is just a simple global memo ' ry allocation, locking, reallocation, an ' d free of such with the cleanup. Example ' s of this API I've seen end up with anot ' her pointer address handle when locking ' occurs, I'm not sure how to handle that ' in freeing or unlocking. Maybe provided ' it's well to do so with two handle addre ' sses 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