-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathStream.ahk
199 lines (165 loc) · 6.41 KB
/
Stream.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
class: Stream
wraps the *IStream* interface and lets you read and write data to stream objects.
Authors:
- maul.esel (https://github.com/maul-esel)
License:
- *LGPL* (http://www.gnu.org/licenses/lgpl-2.1.txt)
Documentation:
- *class documentation* (http://maul-esel.github.com/COM-Classes/master/Stream)
- *msdn* (http://msdn.microsoft.com/en-us/library/windows/desktop/aa380034)
Requirements:
AutoHotkey - AHK v2 alpha
OS - Windows 2000 Professional, Windows 2000 Server or higher
Base classes - _CCF_Error_Handler_, Unknown, SequentialStream
Constant classes - STGC, LOCKTYPE, STATFLAG, STREAM_SEEK
Structure classes - STATSTG
*/
class Stream extends SequentialStream
{
/*
Field: ThrowOnCreation
indicates that attempting to create an instance of this class without supplying a valid pointer should throw an exception.
*/
static ThrowOnCreation := true
/*
Field: IID
This is IID_IStream. It is required to create an instance.
*/
static IID := "{0000000c-0000-0000-C000-000000000046}"
/*
group: constructors
Method: FromHGlobal
As this class does not support direct creation, you can use this method to create an instance from a handle, e.g. a HICON.
Parameters:
UPTR handle - the handle to create a stream from
[opt] BOOL autoRelease - indicates whether the underlying handle provided should be freed automatically if the object is released.
Returns:
Stream stream - the created instance
*/
FromHGlobal(handle, autoRelease := true)
{
local ptr
this._Error(DllCall("Ole32.dll\CreateStreamOnHGlobal", "UPtr", handle, "UInt", autoRelease, "ptr*", ptr))
return new Stream(ptr)
}
/*
Method: Seek
changes the seek pointer to a new location. The new location is relative to either the beginning of the stream, the end of the stream, or the current seek pointer.
Parameters:
INT64 move - the displacement to be added to the location indicated by the dwOrigin parameter.
UINT dwOrigin - The origin for the displacement specified in move. You can use the fields of the STREAM_SEEK class for convenience.
Returns:
UINT64 newPos - the location where this method writes the value of the new seek pointer from the beginning of the stream.
*/
Seek(move, dwOrigin)
{
local pos
this._Error(DllCall(NumGet(this.vt+05*A_PtrSize), "ptr", this.ptr, "int64", move, "uint", dwOrigin, "Uint64*", pos))
return pos
}
/*
Method: SetSize
changes the size of the stream object.
Parameters:
UINT64 newsize - Specifies the new size of the stream as a number of bytes.
Returns:
BOOL success - true on success, false otherwise.
*/
SetSize(newsize)
{
return this._Error(DllCall(NumGet(this.vt+06*A_PtrSize), "ptr", this.ptr, "uint64", newsize))
}
/*
Method: CopyTo
copies a specified number of bytes from the current seek pointer in the stream to the current seek pointer in another stream.
Parameters:
Stream destination - either a Stream instance or a pointer to the IStream instance to copy the bytes to.
UINT64 byteCount - The number of bytes to copy from the source stream.
[opt] byRef UINT64 bytesRead - receives the number of bytes actually read from the source stream
[opt] byRef UINT64 bytesWritten - receives the number of byteCount actually written to the destination
Returns:
BOOL success - true on success, false otherwise.
*/
CopyTo(destination, byteCount, byRef bytesRead := "", byRef bytesWritten := "")
{
return this._Error(DllCall(NumGet(this.vt+07*A_PtrSize), "ptr", this.ptr, "uptr", (IsObject(destination) ? destination.ptr : destination), "uint64", byteCount, "uint64*", bytesRead, "uint64*", bytesWritten))
}
/*
Method: Commit
ensures that any changes made to a stream object open in transacted mode are reflected in the parent storage.
Parameters:
UINT flags - Controls how the changes for the stream object are committed. You may use the fields of the STGC enumeration class for convenience.
Returns:
BOOL success - true on success, false otherwise.
*/
Commit(flags)
{
return this._Error(DllCall(NumGet(this.vt+08*A_PtrSize), "ptr", this.ptr, "uint", flags))
}
/*
Method: Revert
This method has no effect.
Returns:
BOOL success - true on success, false otherwise.
*/
Revert()
{
return this._Error(DllCall(NumGet(this.vt+09*A_PtrSize), "ptr", this.ptr))
}
/*
Method: LockRegion
restricts access to a specified range of bytes in the stream.
Parameters:
UINT64 offset - specifies the byte offset for the beginning of the range.
UINT64 byteCount - specifies the length of the range, in bytes, to be restricted.
UINT lockType - specifies the restrictions being requested on accessing the range. You may use the fields of the LOCKTYPE enumeration class for convenience.
Returns:
BOOL success - true on success, false otherwise.
*/
LockRegion(offset, byteCount, lockType)
{
return this._Error(DllCall(NumGet(this.vt+10*A_PtrSize), "ptr", this.ptr, "uint64", offset, "uint64", byteCount, "uint", lockType))
}
/*
Method: UnlockRegion
removes the access restriction on a range of bytes previously restricted with IStream::LockRegion.
Parameters:
UINT64 offset - specifies the byte offset for the beginning of the range.
UINT64 byteCount - specifies the length of the range, in bytes, to be restricted.
UINT lockType - specifies the access restrictions previously placed on the range. You may use the fields of the LOCKTYPE enumeration class for convenience.
Returns:
BOOL success - true on success, false otherwise.
*/
UnlockRegion(offset, byteCount, lockType)
{
return this._Error(DllCall(NumGet(this.vt+11*A_PtrSize), "ptr", this.ptr, "uint64", offset, "uint64", byteCount, "uint", lockType))
}
/*
Method: Stat
retrieves the STATSTG structure for this stream.
Parameters:
[opt] UINT flag - indicates certain members to omit from the structure. You can use the fields of the STATFLAG enumeration class for convenience.
Returns:
STATSTG info - the STATSTG instance for the stream
*/
Stat(flag := 0)
{
static stat_size := STATSTG.GetRequiredSize()
local struct := CCFramework.AllocateMemory(stat_size)
this._Error(DllCall(NumGet(this.vt+12*A_PtrSize), "ptr", this.ptr, "ptr", struct, "uint", flag))
return STATSTG.FromStructPtr(struct)
}
/*
Method: Clone
creates a new stream object with its own seek pointer that references the same bytes as the original stream.
Returns:
Stream clone - the cloned stream instance
*/
Clone()
{
local ptr
this._Error(DllCall(NumGet(this.vt+13*A_PtrSize), "ptr", this.ptr, "ptr*", ptr))
return new Stream(ptr)
}
}