source: Include/Classes/System/Runtime/InteropServices/GCHandle.ab@ 282

Last change on this file since 282 was 282, checked in by イグトランス (egtra), 17 years ago

#121対応、Classes/System/Windows/Forms以下を名前空間に入れた。

File size: 1.5 KB
Line 
1' Classes/System/Runtime/InteropServices/GCHandle.ab
2
3#require <Classes/System/Collections/ArrayList.ab>
4
5Namespace System
6Namespace Runtime
7Namespace InteropServices
8
9Class GCHandle
10Public
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)
18 handle = ObjPtr(obj)
19 End Sub
20
21 Const Function IsAllocated() As Boolean
22 Return handle <> 0
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
36 Return h.handle As LONG_PTR
37 End Function
38
39 Static Function FromIntPtr(ip As LONG_PTR) As GCHandle
40 FromIntPtr = New GCHandle
41 FromIntPtr.handle = ip As VoidPtr
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
52 Function Operator == (y As GCHandle) As Boolean
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
60 Override Function ToString() As String
61 Return "System.Runtime.InteropServices.GCHandle"
62 End Function
63
64'Private
65 Sub GCHandle()
66 End Sub
67
68Private
69 handle As VoidPtr
70
71 Static allocated As /*System.Collections.*/ArrayList
72End Class
73
74End Namespace 'System
75End Namespace 'Runtime
76End Namespace 'InteropServices
Note: See TracBrowser for help on using the repository browser.