source: trunk/ab5.0/ablib/src/Classes/System/Runtime/InteropServices/GCHandle.ab@ 536

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

細かい修正。
Str$にStringを受け取る多重定義を追加した。
複数libを作るバッチで、コンパイルエラーが発生したら以後のビルドを行わないようにした。
Threadクラスの_beginthreadexをCreateThreadへ変更した。
ole2.abを全体が使える古い版へ戻した。
SendMessageCallback/SendMessageTimeoutを追加した。
GCHandleで登録が解除されない状態が起こる問題を直した。

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