-
Notifications
You must be signed in to change notification settings - Fork 71
/
Unknown.ahk
175 lines (144 loc) · 4.22 KB
/
Unknown.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
/*
class: Unknown
wraps the *IUnknown* interface and provides meta-functions and helper methods for inherited classes.
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/Unknown)
- *msdn* (http://msdn.microsoft.com/en-us/library/windows/desktop/ms680509)
Requirements:
AutoHotkey - AHK v2 alpha
Base classes - _CCF_Error_Handler_
Other classes - CCFramework
*/
class Unknown extends _CCF_Error_Handler_
{
/*
Field: IID_IUnknown
This is IID_IUnknown. It may be used by inherited classes.
*/
static IID_IUnknown := "{00000000-0000-0000-C000-000000000046}"
/*
Field: Error
an object holding the last error code and its description
Fields:
HRESULT code - the HRESULT error code
STR description - the error description string in the system's language
BOOL isError - a shortcut to define whether an error occured or not
Remarks:
This field is updated by the internal helper method <_Error>, which should be called by almost all methods in inherited classes.
*/
Error := { "code" : 0, "description" : "", "isError" : false }
/*
Field: ThrowOnCreation
determines whether the creation of a new instance, without a given pointer, should throw an exception. False by default.
Developer remarks:
Inherited classes may override this and set it to TRUE if they can't provide a direct creation of a class by calling ComObjCreate().
This causes an exception to be thrown. You should document this in your class.
*/
static ThrowOnCreation := false
/*
group: meta-functions
Method: __New
constructor for all inherited classes
Parameters:
[opt] UPTR ptr - a pointer to an already created instance of the COM class.
Remarks:
If ptr is not given, a new instance is created using the class' IID and CLSID fields, passing them to ComObjCreate().
Developer remarks:
To make this working, you must define the correct IID and CLSID in your class.
This makes available 2 instance fields:
UPTR ptr - the pointer to the object
UPTR vt - the pointer to the object's vTable
*/
__New(ptr := 0)
{
if (!ptr)
{
if (this.base.ThrowOnCreation)
{
throw Exception("This class does not support direct creation: " . this.base.__class, -1)
}
else
{
this.ptr := ComObjCreate(this.base.CLSID, this.base.IID)
}
}
else
{
this.ptr := ptr
}
this.vt := NumGet(this.ptr + 0)
}
/*
Method: __Delete
deconstructor for all inherited classes.
Remarks:
In most cases, you don't call this from your code.
*/
__Delete()
{
return ObjRelease(this.ptr)
}
/*
group: builtin method overrides
Method: _Clone
an override for the internal method _Clone() to make it also increase the underlying COM instance's reference count
*/
_Clone()
{
this.AddRef() ; no matter if called on "this" or the new clone - same COM pointer
return ObjClone(this)
}
/*
group: internal functions
Method: _Error
internal helper function for inherited classes that updates the instance's <Error> object.
Parameters:
HRESULT error - the error code to work on
Returns:
BOOL success - a bool indicating success (true = success, false otherwise)
Developer remarks:
Pass any HRESULT return values to this function to update the Error field.
In most cases, you should also return this function's return value.
In case your method doesn't return a HRESULT, call this method with error code 0 to clear the object.
*/
_Error(error)
{
this.Error.code := error, this.Error.description := CCFramework.FormatError(error)
return this.Error.isError := error >= 0x00
}
/*
group: IUnknown
Method: QueryInterface
Queries the COM object for an interface.
Parameters:
IID iid - the string representation of or raw interface pointer to the queried interface
Returns:
UPTR pointer - a pointer to the interface or zero.
*/
QueryInterface(iid)
{
if CCFramework.isInteger(iid)
iid := CCFramework.GUID2String(iid)
return ComObjQuery(this.ptr, iid)
}
/*
Method: AddRef
Increment's the object's reference count.
*/
AddRef()
{
return ObjAddRef(this.ptr)
}
/*
Function: Release
Decrements the object's reference count.
*/
Release()
{
return ObjRelease(this.ptr)
}
}