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

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

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

File size: 1.6 KB
RevLine 
[203]1' Classes/System/Runtime/InteropServices/GCHandle.ab
2
[282]3Namespace System
4Namespace Runtime
5Namespace InteropServices
6
[203]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)
[257]16 handle = ObjPtr(obj)
[203]17 End Sub
18
19 Const Function IsAllocated() As Boolean
[233]20 Return handle <> 0
[203]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
[223]34 Return h.handle As LONG_PTR
[203]35 End Function
36
37 Static Function FromIntPtr(ip As LONG_PTR) As GCHandle
[388]38 If ip = 0 Then
39 Throw New InvalidOperationException("GCHandle.FromIntPtr: ip is 0.")
40 End If
[203]41 FromIntPtr = New GCHandle
[223]42 FromIntPtr.handle = ip As VoidPtr
[203]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
[208]53 Function Operator == (y As GCHandle) As Boolean
[203]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
[208]61 Override Function ToString() As String
62 Return "System.Runtime.InteropServices.GCHandle"
63 End Function
64
[203]65'Private
66 Sub GCHandle()
67 End Sub
68
69Private
70 handle As VoidPtr
71
[340]72 Static allocated = New System.Collections.Generic.List<Object>
[203]73End Class
[282]74
75End Namespace 'System
76End Namespace 'Runtime
77End Namespace 'InteropServices
Note: See TracBrowser for help on using the repository browser.