VB - VarPtr for .NET

By , 11/10/2007
(1 ratings)
The VarPtr function will return an offset where a given object is located in the memory.

In VB6 this function already exists but not in VB.NET, so I build a .NET Version of the VarPtr function.
Public Function VarPtr(ByVal e As Object) As Integer
    Dim GC As GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)
    Dim GC2 As Integer = GC.AddrOfPinnedObject.ToInt32
    Return GC2
End Function

Tagged with VarPtr.



Log in, to comment!