source: Include/com/bstring.ab@ 174

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

Environment, OperatingSystem, Versionの追加、Unicode対応修正ほか

File size: 2.0 KB
Line 
1' com/bstring.ab
2
3#require <ole2.ab>
4#require <oleauto.ab>
5
6Class BString
7Public
8 Sub BString()
9 bs = 0
10 End Sub
11
12 Sub BString(len As DWord)
13 bs = SysAllocStringLen(0, len)
14 End Sub
15
16 Sub BString(ByRef s As BString)
17 BString(s.bs, s.Length)
18 End Sub
19
20 Sub BString(s As LPCOLESTR)
21 bs = SysAllocString(s)
22 End Sub
23
24 Sub BString(s As LPCOLESTR, len As DWord)
25 bs = SysAllocStringLen(s, len)
26 End Sub
27
28 Sub BString(s As PCSTR)
29 BString(s, lstrlenA(s))
30 End Sub
31
32 Sub BString(s As PCSTR, len As DWord)
33 Dim lenBS = MultiByteToWideChar(CP_THREAD_ACP, 0, s, len, 0, 0)
34 bs = SysAllocStringLen(0, lenBS)
35 MultiByteToWideChar(CP_THREAD_ACP, 0, s, len, bs, lenBS)
36 End Sub
37
38 Sub BString(ByRef s As String)
39 BString(s.StrPtr, s.Length As DWord)
40 End Sub
41
42 Sub ~BString()
43 Clear()
44 End Sub
45
46 Sub Operator =(ByRef bstr As BString)
47 Clear()
48 BString(bstr)
49 End Sub
50
51 Sub Operator =(s As LPCOLESTR)
52 Clear()
53 BString(s)
54 End Sub
55
56 Sub Assign(ByRef bstr As BString)
57 Clear()
58 BString(bstr)
59 End Sub
60
61 Sub Assign(s As LPCOLESTR)
62 Clear()
63 BString(s)
64 End Sub
65
66 Sub AssignFromBStr(bstr As BSTR)
67 Clear()
68 BString(bstr)
69 End Sub
70
71 Sub Clear()
72 If bs <> 0 Then
73 SysFreeString(bs)
74 bs = 0
75 End If
76 End Sub
77
78 Sub Attach(bstr As BSTR)
79 Clear()
80 bs = bstr
81 End Sub
82
83 Function Detach() As BSTR
84 Detach = bs
85 bs = 0
86 End Function
87
88 Function BStr() As BSTR
89 BStr = bs
90 End Function
91
92 Const Function Length() As DWord
93 Length = SysStringLen(bs)
94 End Function
95
96 Const Function Operator [](i As SIZE_T) As OLECHAR
97#ifdef _DEBUG
98 If i > Length Then
99 'Throw OutOfRangeException
100 End If
101#endif
102 Return bs[i]
103 End Function
104
105 Sub Operator []=(i As SIZE_T, c As OLECHAR)
106#ifdef _DEBUG
107 If i > Length Then
108 'Throw OutOfRangeException
109 End If
110#endif
111 bs[i] = c
112 End Sub
113
114 Override Function ToString() As String
115 Dim s As String(bs, Length)
116 Return s
117 End Function
118
119Private
120 bs As BSTR
121End Class
122
Note: See TracBrowser for help on using the repository browser.