GlobalFree
API
Imports System.Runtime.InteropServices
Module MemoryManagement
' Declare the GlobalFree function from the user32.dll (instead of gdi32.dll or kernel32.dll)
<DllImport("kernel32.dll", SetLastError:=True)>
Public Function GlobalFree(ByVal hMem As IntPtr) As IntPtr
End Function
Sub Main()
' Example usage of GlobalFree
Dim hMem As IntPtr ' Assume this points to some allocated global memory
' Call GlobalFree to free the memory
Dim result As IntPtr = GlobalFree(hMem)
If result = IntPtr.Zero Then
Console.WriteLine("Memory successfully freed.")
Else
' Handle the error
Dim err As Integer = Marshal.GetLastWin32Error()
Console.WriteLine($"Error freeing memory: {err}")
End If
End Sub
End Module