' Classes/System/Runtime/InteropServices/GCHandle.ab Namespace System Namespace Runtime Namespace InteropServices Class GCHandle Public Function Target() As Object Target = ActiveBasic.GetObjectFromHandle(handle) End Function Sub Target(obj As Object) If handle <> 0 Then ActiveBasic.ReleaseObjectHandle(handle) End If handle = ActiveBasic.AllocObjectHandle(obj) End Sub Const Function IsAllocated() As Boolean Return handle <> 0 End Function Static Function Alloc(obj As Object) As GCHandle Alloc = New GCHandle Alloc.Target = obj End Function Sub Free() If handle = 0 Then Throw New InvalidOperationException End If ActiveBasic.ReleaseObjectHandle(handle) handle = 0 End Sub Static Function ToIntPtr(h As GCHandle) As LONG_PTR Return h.handle End Function Static Function FromIntPtr(ip As LONG_PTR) As GCHandle If ip = 0 Then Throw New InvalidOperationException("GCHandle.FromIntPtr: ip is 0.") End If FromIntPtr = New GCHandle FromIntPtr.handle = ip End Function Override Function GetHashCode() As Long Return _System_HashFromPtr(handle As VoidPtr) End Function Function Equals(y As GCHandle) As Boolean Return handle = y.handle End Function Function Operator == (y As GCHandle) As Boolean Return Equals(y) End Function Function Operator <> (y As GCHandle) As Boolean Return Not Equals(y) End Function Override Function ToString() As String Return "System.Runtime.InteropServices.GCHandle" End Function Private Sub GCHandle() End Sub Private handle As LONG_PTR End Class End Namespace 'System End Namespace 'Runtime End Namespace 'InteropServices