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

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

Stringなどで例外を投げるようにした。
#147の解決。
CType ASCII文字判定関数群の追加。

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