Attribute VB_Name = "PtrObj" ' PtrObj Function ' ' This function (PtrObj) is the reverse of the undocumented ObjPtr ' function. PtrObj converts a long integer into an object reference. ' Copyright David Pinch; http://www.thoughtproject.com Option Explicit ' =================================================================== ' Win32: RtlMoveMemory ' =================================================================== Private Declare Sub RtlMoveMemory _ Lib "kernel32" _ (ByRef Target As Any, _ ByRef Source As Any, _ ByVal Length As Long) ' =================================================================== ' PtrObj ' =================================================================== Public Function PtrObj(ByVal Pointer As Long) As Object Dim SoftRef As Object ' Exit immediately it the Pointer is Null. The function ' will return the default value of Nothing. If Pointer = 0 Then Exit Function End If ' Get a soft reference to the object RtlMoveMemory SoftRef, Pointer, 4 ' Get a legal reference to the object Set PtrObj = SoftRef ' Destroy the illegal reference RtlMoveMemory SoftRef, 0&, 4 FunctionExit: Exit Function FunctionError: Set PtrObj = Nothing Resume FunctionExit End Function