source: Include/com/bstring.ab@ 270

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

COM関係を名前空間に入れた

File size: 2.8 KB
RevLine 
[138]1' com/bstring.ab
2
3#require <ole2.ab>
4#require <oleauto.ab>
5
[267]6Namespace ActiveBasic
7Namespace COM
8
[138]9Class BString
[226]10 Sub Init(s As PCSTR, len As DWord)
11 Dim lenBS = MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, 0, 0)
12 bs = SysAllocStringLen(0, lenBS)
13 MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, bs, lenBS)
14 End Sub
[138]15Public
16 Sub BString()
17 bs = 0
18 End Sub
19
20 Sub BString(len As DWord)
[142]21 bs = SysAllocStringLen(0, len)
[138]22 End Sub
23
24 Sub BString(ByRef s As BString)
[226]25 Init(s.bs, s.Length)
[138]26 End Sub
27
28 Sub BString(s As LPCOLESTR)
29 bs = SysAllocString(s)
30 End Sub
31
32 Sub BString(s As LPCOLESTR, len As DWord)
33 bs = SysAllocStringLen(s, len)
34 End Sub
35
36 Sub BString(s As PCSTR)
[226]37 Init(s, lstrlenA(s))
[138]38 End Sub
39
40 Sub BString(s As PCSTR, len As DWord)
[208]41 Dim lenBS = MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, 0, 0)
[138]42 bs = SysAllocStringLen(0, lenBS)
[208]43 MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, bs, lenBS)
[138]44 End Sub
45
46 Sub BString(ByRef s As String)
[226]47 Init(s.StrPtr, s.Length As DWord)
[138]48 End Sub
49
[142]50 Sub ~BString()
51 Clear()
52 End Sub
53
54 Sub Assign(ByRef bstr As BString)
55 Clear()
[226]56 Init(bstr, bstr.Length)
[142]57 End Sub
58
59 Sub Assign(s As LPCOLESTR)
60 Clear()
[226]61 Init(s, lstrlenW(s))
[142]62 End Sub
63
64 Sub AssignFromBStr(bstr As BSTR)
65 Clear()
[175]66 String.Copy(bs, bstr)
[142]67 End Sub
68
[175]69 Const Function Copy() As BSTR
70 BString.Copy(Copy, bs)
71 End Function
72
[138]73 Sub Clear()
74 If bs <> 0 Then
75 SysFreeString(bs)
76 bs = 0
77 End If
78 End Sub
79
[192]80 Sub Attach(ByRef bstr As BSTR)
[138]81 Clear()
[175]82 BString.Move(bs, bstr)
[138]83 End Sub
84
85 Function Detach() As BSTR
[175]86 BString.Move(Detach, bs)
[138]87 End Function
88
89 Function BStr() As BSTR
90 BStr = bs
91 End Function
[208]92/*
93 Static Function Assgin(bs As BSTR) As BString
94 Assgin = New BString
95 Assgin.Assgin(bs)
96 End Function
[138]97
[208]98 Static Function Attach(bs As BSTR) As BString
99 Attach = New BString
100 Attach.Attach(bs)
101 End Function
102*/
[138]103 Const Function Length() As DWord
104 Length = SysStringLen(bs)
105 End Function
106
[142]107 Const Function Operator [](i As SIZE_T) As OLECHAR
[138]108#ifdef _DEBUG
109 If i > Length Then
110 'Throw OutOfRangeException
111 End If
112#endif
113 Return bs[i]
114 End Function
115
116 Sub Operator []=(i As SIZE_T, c As OLECHAR)
117#ifdef _DEBUG
118 If i > Length Then
119 'Throw OutOfRangeException
120 End If
121#endif
122 bs[i] = c
123 End Sub
124
125 Override Function ToString() As String
[208]126 Return New String(bs As PCWSTR, Length As Long)
[138]127 End Function
128
[175]129 Override Function GetHashCode() As Long
130 Return _System_GetHashFromWordArray(bs, Length)
131 End Function
132
[138]133Private
134 bs As BSTR
[175]135
136 Static Sub Copy(ByRef dst As BSTR, ByVal src As BSTR)
137 dst = SysAllocStringLen(src, SysStringLen(src))
138 End Sub
139
140 Static Sub Move(ByRef dst As BSTR, ByRef src As BSTR)
141 dst = src
142 src = 0
143 End Sub
[138]144End Class
145
[267]146End Namespace 'COM
147End Namespace 'ActiveBasic
Note: See TracBrowser for help on using the repository browser.