Rev | Line | |
---|
[203] | 1 | ' Classes/System/Runtime/InteropServices/GCHandle.ab
|
---|
| 2 |
|
---|
| 3 | #require <Classes/System/Collections/ArrayList.ab>
|
---|
| 4 |
|
---|
[282] | 5 | Namespace System
|
---|
| 6 | Namespace Runtime
|
---|
| 7 | Namespace InteropServices
|
---|
| 8 |
|
---|
[203] | 9 | Class GCHandle
|
---|
| 10 | Public
|
---|
| 11 | Function Target() As Object
|
---|
| 12 | Dim pobj = VarPtr(handle) As *Object
|
---|
| 13 | Return pobj[0]
|
---|
| 14 | End Function
|
---|
| 15 |
|
---|
| 16 | Sub Target(obj As Object)
|
---|
| 17 | allocated.Add(obj)
|
---|
[257] | 18 | handle = ObjPtr(obj)
|
---|
[203] | 19 | End Sub
|
---|
| 20 |
|
---|
| 21 | Const Function IsAllocated() As Boolean
|
---|
[233] | 22 | Return handle <> 0
|
---|
[203] | 23 | End Function
|
---|
| 24 |
|
---|
| 25 | Static Function Alloc(obj As Object) As GCHandle
|
---|
| 26 | Alloc = New GCHandle
|
---|
| 27 | Alloc.Target = obj
|
---|
| 28 | End Function
|
---|
| 29 |
|
---|
| 30 | Sub Free()
|
---|
| 31 | allocated.Remove(Target)
|
---|
| 32 | handle = 0
|
---|
| 33 | End Sub
|
---|
| 34 |
|
---|
| 35 | Static Function ToIntPtr(h As GCHandle) As LONG_PTR
|
---|
[223] | 36 | Return h.handle As LONG_PTR
|
---|
[203] | 37 | End Function
|
---|
| 38 |
|
---|
| 39 | Static Function FromIntPtr(ip As LONG_PTR) As GCHandle
|
---|
| 40 | FromIntPtr = New GCHandle
|
---|
[223] | 41 | FromIntPtr.handle = ip As VoidPtr
|
---|
[203] | 42 | End Function
|
---|
| 43 |
|
---|
| 44 | Override Function GetHashCode() As Long
|
---|
| 45 | Return _System_HashFromPtr(handle)
|
---|
| 46 | End Function
|
---|
| 47 |
|
---|
| 48 | Function Equals(y As GCHandle) As Boolean
|
---|
| 49 | Return handle = y.handle
|
---|
| 50 | End Function
|
---|
| 51 |
|
---|
[208] | 52 | Function Operator == (y As GCHandle) As Boolean
|
---|
[203] | 53 | Return Equals(y)
|
---|
| 54 | End Function
|
---|
| 55 |
|
---|
| 56 | Function Operator <> (y As GCHandle) As Boolean
|
---|
| 57 | Return Not Equals(y)
|
---|
| 58 | End Function
|
---|
| 59 |
|
---|
[208] | 60 | Override Function ToString() As String
|
---|
| 61 | Return "System.Runtime.InteropServices.GCHandle"
|
---|
| 62 | End Function
|
---|
| 63 |
|
---|
[203] | 64 | 'Private
|
---|
| 65 | Sub GCHandle()
|
---|
| 66 | End Sub
|
---|
| 67 |
|
---|
| 68 | Private
|
---|
| 69 | handle As VoidPtr
|
---|
| 70 |
|
---|
[282] | 71 | Static allocated As /*System.Collections.*/ArrayList
|
---|
[203] | 72 | End Class
|
---|
[282] | 73 |
|
---|
| 74 | End Namespace 'System
|
---|
| 75 | End Namespace 'Runtime
|
---|
| 76 | End Namespace 'InteropServices
|
---|
Note:
See
TracBrowser
for help on using the repository browser.