Skip to content

Commit 62dbee4

Browse files
committed
v1.0.2
1 parent 7eb40d1 commit 62dbee4

1 file changed

Lines changed: 47 additions & 135 deletions

File tree

AutoItObject_Internal.au3

Lines changed: 47 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#cs ----------------------------------------------------------------------------
22
AutoIt Version : 3.3.14.2
33
Author.........: genius257
4-
Version........: 1.0.1
4+
Version........: 1.0.2
55
#ce ----------------------------------------------------------------------------
66

77
#include-once
@@ -10,7 +10,6 @@
1010

1111
Global Const $IID_IUnknown = "{00000000-0000-0000-C000-000000000046}"
1212
Global Const $IID_IDispatch = "{00020400-0000-0000-C000-000000000046}"
13-
Global Const $IID_IRecordInfo = "{0000002F-0000-0000-C000-000000000046}"
1413

1514
Global Const $DISPATCH_METHOD = 1
1615
Global Const $DISPATCH_PROPERTYGET = 2
@@ -47,70 +46,35 @@ Global Enum $VT_EMPTY,$VT_NULL,$VT_I2,$VT_I4,$VT_R4,$VT_R8,$VT_CY,$VT_DATE,$VT_B
4746

4847
Global Const $tagProperty = "ptr Name;ptr Variant;ptr __getter;ptr __setter;ptr Next"
4948

50-
Func IUnknown()
51-
Local $tagObject = "int RefCount;int Size;ptr Object;ptr Methods[3];int_ptr Callbacks[3];ulong_ptr Slots[16]" ; 16 pointer sized elements more to create space for possible private props
52-
Local $tObject = DllStructCreate($tagObject)
53-
54-
$proc = DllCallbackRegister(QueryInterface, "LONG", "ptr;ptr;ptr")
55-
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($proc), 1)
56-
DllStructSetData($tObject, "Callbacks", $proc, 1)
57-
58-
$proc = DllCallbackRegister(AddRef, "dword", "PTR")
59-
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($proc), 2)
60-
DllStructSetData($tObject, "Callbacks", $proc, 2)
61-
62-
$proc = DllCallbackRegister(Release, "dword", "PTR")
63-
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($proc), 3)
64-
DllStructSetData($tObject, "Callbacks", $proc, 3)
65-
66-
DllStructSetData($tObject, "RefCount", 2) ; initial ref count is 1
67-
DllStructSetData($tObject, "Size", 3) ; number of interface methods
68-
69-
$pData = MemCloneGlob($tObject)
70-
71-
$tObject = DllStructCreate($tagObject, $pData)
72-
73-
DllStructSetData($tObject, "Object", DllStructGetPtr($tObject, "Methods")) ; Interface method pointers
74-
Return ObjCreateInterface(DllStructGetPtr($tObject, "Object"), $IID_IUnknown, Default, True) ; pointer that's wrapped into object
75-
EndFunc
76-
77-
Func IDispatch()
49+
Func IDispatch($QueryInterface=QueryInterface, $AddRef=AddRef, $Release=Release, $GetTypeInfoCount=GetTypeInfoCount, $GetTypeInfo=GetTypeInfo, $GetIDsOfNames=GetIDsOfNames, $Invoke=Invoke)
7850
Local $tagObject = "int RefCount;int Size;ptr Object;ptr Methods[7];int_ptr Callbacks[7];ptr Properties;BYTE lock;"
7951
Local $tObject = DllStructCreate($tagObject)
80-
Local $proc
81-
Local Static $QueryInterface = 0
82-
Local Static $AddRef = 0
83-
Local Static $Release = 0
84-
Local Static $GetTypeInfoCount = 0
85-
Local Static $GetTypeInfo = 0
86-
Local Static $GetIDsOfNames = 0
87-
Local Static $Invoke = 0
88-
89-
If $QueryInterface==0 Then $QueryInterface = DllCallbackRegister(QueryInterface, "LONG", "ptr;ptr;ptr")
52+
53+
$QueryInterface = DllCallbackRegister($QueryInterface, "LONG", "ptr;ptr;ptr")
9054
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($QueryInterface), 1)
9155
DllStructSetData($tObject, "Callbacks", $QueryInterface, 1)
9256

93-
If $AddRef==0 Then $AddRef = DllCallbackRegister(AddRef, "dword", "PTR")
57+
$AddRef = DllCallbackRegister($AddRef, "dword", "PTR")
9458
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($AddRef), 2)
9559
DllStructSetData($tObject, "Callbacks", $AddRef, 2)
9660

97-
If $Release==0 Then $Release = DllCallbackRegister(Release, "dword", "PTR")
61+
$Release = DllCallbackRegister($Release, "dword", "PTR")
9862
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($Release), 3)
9963
DllStructSetData($tObject, "Callbacks", $Release, 3)
10064

101-
If $GetTypeInfoCount==0 Then $GetTypeInfoCount = DllCallbackRegister(GetTypeInfoCount, "long", "ptr;ptr")
65+
$GetTypeInfoCount = DllCallbackRegister($GetTypeInfoCount, "long", "ptr;ptr")
10266
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($GetTypeInfoCount), 4)
10367
DllStructSetData($tObject, "Callbacks", $GetTypeInfoCount, 4)
10468

105-
If $GetTypeInfo==0 Then $GetTypeInfo = DllCallbackRegister(GetTypeInfo, "long", "ptr;uint;int;ptr")
69+
$GetTypeInfo = DllCallbackRegister($GetTypeInfo, "long", "ptr;uint;int;ptr")
10670
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($GetTypeInfo), 5)
10771
DllStructSetData($tObject, "Callbacks", $GetTypeInfo, 5)
10872

109-
If $GetIDsOfNames==0 Then $GetIDsOfNames = DllCallbackRegister(GetIDsOfNames, "long", "ptr;ptr;ptr;uint;int;ptr")
73+
$GetIDsOfNames = DllCallbackRegister($GetIDsOfNames, "long", "ptr;ptr;ptr;uint;int;ptr")
11074
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($GetIDsOfNames), 6)
11175
DllStructSetData($tObject, "Callbacks", $GetIDsOfNames, 6)
11276

113-
If $Invoke==0 Then $Invoke = DllCallbackRegister(Invoke, "long", "ptr;int;ptr;int;ushort;ptr;ptr;ptr;ptr")
77+
$Invoke = DllCallbackRegister($Invoke, "long", "ptr;int;ptr;int;ushort;ptr;ptr;ptr;ptr")
11478
DllStructSetData($tObject, "Methods", DllCallbackGetPtr($Invoke), 7)
11579
DllStructSetData($tObject, "Callbacks", $Invoke, 7)
11680

@@ -125,26 +89,6 @@ Func IDispatch()
12589
Return ObjCreateInterface(DllStructGetPtr($tObject, "Object"), $IID_IDispatch, Default, True) ; pointer that's wrapped into object
12690
EndFunc
12791

128-
Func __IDispatch();create IDispatch object and alter core functions to specialized debug alternets
129-
Local $oIDispatch = IDispatch()
130-
Local $tPtr = DllStructCreate("ptr")
131-
DllStructSetData($tPtr, 1, $oIDispatch)
132-
Local $pIDispatch = DllStructGetData($tPtr, 1)
133-
Local $_tIDispatch = DllStructCreate("ptr Object;ptr Methods[7];int_ptr Callbacks[7]", $pIDispatch)
134-
135-
Local Static $_GetIDsOfNames = 0
136-
Local Static $_Invoke = 0
137-
138-
If $_GetIDsOfNames==0 Then $_GetIDsOfNames = DllCallbackRegister(__GetIDsOfNames, "long", "ptr;ptr;ptr;uint;int;ptr")
139-
DllStructSetData($_tIDispatch, "Methods", DllCallbackGetPtr($_GetIDsOfNames), 6)
140-
DllStructSetData($_tIDispatch, "Callbacks", $_GetIDsOfNames, 6)
141-
If $_Invoke==0 Then $_Invoke = DllCallbackRegister(__Invoke, "long", "ptr;int;ptr;int;ushort;ptr;ptr;ptr;ptr")
142-
DllStructSetData($_tIDispatch, "Methods", DllCallbackGetPtr($_Invoke), 7)
143-
DllStructSetData($_tIDispatch, "Callbacks", $_Invoke, 7)
144-
145-
Return $oIDispatch
146-
EndFunc
147-
14892
Func QueryInterface($pSelf, $pRIID, $pObj)
14993
Local $sGUID=DllCall("ole32.dll", "int", "StringFromGUID2", "PTR", $pRIID, "wstr", "", "int", 40)[2]
15094
If (Not ($sGUID=$IID_IDispatch)) And (Not ($sGUID=$IID_IUnknown)) Then Return $E_NOINTERFACE
@@ -171,30 +115,8 @@ Func Release($pSelf)
171115
Return $tStruct.Ref
172116
EndFunc
173117

174-
Func __GetIDsOfNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId)
175-
Local $tIds = DllStructCreate("long", $rgDispId)
176-
;~ Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + DllStructGetSize(DllStructCreate("ptr Object;ptr Methods[7];int_ptr Callbacks[7]"))),1)
177-
Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + (@AutoItX64?8:4) + (@AutoItX64?8:4)*7*2),1)
178-
If $pProperty=0 Then
179-
$tProp = DllStructCreate($tagProperty)
180-
$pData = MemCloneGlob($tProp)
181-
$tProp = DllStructCreate($tagProperty, $pData)
182-
$tProp.Name = 0;no reason to waste memory on a string in this object
183-
$tVARIANT = DllStructCreate($tagVARIANT)
184-
$pVARIANT = MemCloneGlob($tVARIANT)
185-
$tVARIANT = DllStructCreate($tagVARIANT, $pVARIANT)
186-
;~ $tVARIANT.vt = $VT_EMPTY
187-
VariantInit($tVARIANT)
188-
$tProp.Variant = $pVARIANT
189-
DllStructSetData(DllStructCreate("ptr", $pSelf + DllStructGetSize(DllStructCreate("ptr Object;ptr Methods[7];int_ptr Callbacks[7]"))), 1, $pData)
190-
EndIf
191-
192-
DllStructSetData($tIds, 1, 0)
193-
EndFunc; __GetIDsOfNames
194-
195118
Func GetIDsOfNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId)
196119
Local $tIds = DllStructCreate("long", $rgDispId)
197-
;~ Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + DllStructGetSize(DllStructCreate("ptr Object;ptr Methods[7];int_ptr Callbacks[7]"))),1)
198120
Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + (@AutoItX64?8:4) + (@AutoItX64?8:4)*7*2),1)
199121
Local $tProperty = 0
200122
Local $iSize2
@@ -210,7 +132,7 @@ Func GetIDsOfNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId)
210132
ElseIf $s_rgszName=="__defineSetter" Then
211133
DllStructSetData($tIds, 1, -3)
212134
Return $S_OK
213-
ElseIf $s_rgszName=="__defineMethod" Then
135+
ElseIf $s_rgszName=="__keys" Then
214136
DllStructSetData($tIds, 1, -4)
215137
Return $S_OK
216138
ElseIf $s_rgszName=="__unset" Then
@@ -271,32 +193,12 @@ Func GetTypeInfoCount($pSelf, $pctinfo)
271193
Return $E_NOTIMPL
272194
EndFunc
273195

274-
Func __Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarResult, $pExcepInfo, $puArgErr)
275-
If $dispIdMember<>0 Then Return $DISP_E_MEMBERNOTFOUND
276-
Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + DllStructGetSize(DllStructCreate("ptr Object;ptr Methods[7];int_ptr Callbacks[7]"))),1)
277-
Local $tProperty = DllStructCreate($tagProperty, $pProperty)
278-
279-
Local $tVARIANT = DllStructCreate($tagVARIANT, $tProperty.Variant)
280-
281-
;~ If (Not(BitAND($wFlags, $DISPATCH_PROPERTYGET)==0)) And (Not(BitAND($wFlags, $DISPATCH_METHOD)==0)) Then
282-
If (Not(BitAND($wFlags, $DISPATCH_PROPERTYGET)==0)) Then
283-
VariantCopy($pVarResult, $tVARIANT)
284-
Return $S_OK
285-
Else
286-
$tDISPPARAMS = DllStructCreate($tagDISPPARAMS, $pDispParams)
287-
$_tVARIANT = DllStructCreate($tagVARIANT, $tDISPPARAMS.rgvargs)
288-
VariantClear($tVARIANT)
289-
VariantCopy($tVARIANT, $_tVARIANT)
290-
EndIf
291-
EndFunc
292-
293196
Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarResult, $pExcepInfo, $puArgErr)
294197
If $dispIdMember=-1 Then Return $DISP_E_MEMBERNOTFOUND
295198
Local $tVARIANT, $_tVARIANT, $tDISPPARAMS
296199
Local $t
297200
Local $i
298201

299-
;~ Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + DllStructGetSize(DllStructCreate("ptr Object;ptr Methods[7];int_ptr Callbacks[7]"))),1)
300202
Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + (@AutoItX64?8:4) + (@AutoItX64?8:4)*7*2),1)
301203
Local $tProperty = DllStructCreate($tagProperty, $pProperty)
302204

@@ -342,8 +244,24 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
342244
Return $DISP_E_MEMBERNOTFOUND
343245
EndIf
344246

345-
If ($dispIdMember=-4) Then;__defineMethod (deprecated)
346-
Return $DISP_E_EXCEPTION
247+
If ($dispIdMember=-4) Then;__keys
248+
Local $aKeys[1]
249+
Local $pProperty = DllStructGetData(DllStructCreate("ptr", $pSelf + (@AutoItX64?8:4) + (@AutoItX64?8:4)*7*2),1)
250+
While 1
251+
If $pProperty=0 Then ExitLoop
252+
Local $tProperty = DllStructCreate($tagProperty, $pProperty)
253+
$aKeys[UBound($aKeys,1)-1] = DllStructGetData(DllStructCreate("WCHAR["&_WinAPI_StrLen($tProperty.Name)&"]", $tProperty.Name), 1)
254+
If $tProperty.next=0 Then ExitLoop
255+
ReDim $aKeys[UBound($aKeys,1)+1]
256+
$pProperty = $tProperty.next
257+
WEnd
258+
If $pProperty=0 Then Return $S_OK
259+
Local $oIDispatch = IDispatch()
260+
$oIDispatch.a=$aKeys
261+
VariantClear($pVarResult)
262+
VariantCopy($pVarResult, DllStructGetData(DllStructCreate($tagProperty, DllStructGetData(DllStructCreate("ptr", Ptr($oIDispatch) + (@AutoItX64?8:4) + (@AutoItX64?8:4)*7*2),1)), "Variant"))
263+
$oIDispatch=0
264+
Return $S_OK
347265
EndIf
348266

349267
If ($dispIdMember=-2) Then;__defineGetter
@@ -385,9 +303,7 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
385303
VariantCopy($pVARIANT_Getter, $tVARIANT)
386304
$tProperty.__getter = $pVARIANT_Getter
387305
Return $S_OK
388-
EndIf
389-
390-
If ($dispIdMember=-3) Then;defineSetter
306+
ElseIf ($dispIdMember=-3) Then;defineSetter
391307
If DllStructGetData(DllStructCreate("BYTE", $pSelf + (@AutoItX64?8:4) + ((@AutoItX64?8:4)*7*2) + (@AutoItX64?8:4)),1)>0 Then
392308
Return $DISP_E_EXCEPTION
393309
EndIf
@@ -441,12 +357,24 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
441357
If (Not(BitAND($wFlags, $DISPATCH_PROPERTYGET)=0)) Then
442358
$_tVARIANT = DllStructCreate($tagVARIANT, $pVarResult)
443359
If Not($tProperty.__getter = 0) Then
360+
$tDISPPARAMS = DllStructCreate($tagDISPPARAMS, $pDispParams)
444361
Local $oIDispatch = IDispatch()
445362
$oIDispatch.val = 0
446363
$oIDispatch.ret = 0
447364
$oIDispatch.parent = ObjCreateInterface($pSelf,$IID_IDispatch)
365+
$oIDispatch.arguments = IDispatch();
366+
$oIDispatch.arguments.length=$tDISPPARAMS.cArgs
367+
Local $aArguments[$tDISPPARAMS.cArgs], $iArguments=$tDISPPARAMS.cArgs-1
448368
Local $_pProperty = DllStructGetData(DllStructCreate("ptr", Ptr($oIDispatch) + (@AutoItX64?8:4) + (@AutoItX64?8:4)*7*2),1)
449369
Local $_tProperty = DllStructCreate($tagProperty, $_pProperty)
370+
For $i=0 To $iArguments
371+
VariantClear($_tProperty.Variant)
372+
VariantCopy($_tProperty.Variant, $tDISPPARAMS.rgvargs+(($iArguments-$i)*DllStructGetSize($_tVARIANT)))
373+
$aArguments[$i]=$oIDispatch.val
374+
Next
375+
$oIDispatch.arguments.values=$aArguments
376+
$oIDispatch.arguments.__lock()
377+
$oIDispatch.__defineSetter("parent", PrivateProperty)
450378
VariantClear($_tProperty.Variant)
451379
VariantCopy($_tProperty.Variant, $tProperty.__getter)
452380
Local $fGetter = $oIDispatch.val
@@ -467,7 +395,7 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
467395

468396
VariantCopy($pVarResult, $tVARIANT)
469397
Return $S_OK
470-
Else
398+
Else; ~ $DISPATCH_PROPERTYPUT
471399
$tDISPPARAMS = DllStructCreate($tagDISPPARAMS, $pDispParams)
472400
If Not ($tProperty.__setter=0) Then
473401
Local $oIDispatch = IDispatch()
@@ -547,26 +475,6 @@ Func GetProcessHeap()
547475
Return $aRet[0]
548476
EndFunc
549477

550-
Func SysAllocString($psz)
551-
;~ Local $aRet = DllCall("OleAut32.dll","PTR","SysAllocString","WSTR",$psz)
552-
Local $aRet = DllCall("OleAut32.dll","PTR","SysAllocString","PTR",$psz)
553-
If @error<>0 Then Return SetError(@error, @extended, 0)
554-
If $aRet[0]=0 Then Return SetError(-1, @extended, $aRet[0])
555-
Return $aRet[0]
556-
EndFunc
557-
558-
Func SysFreeString($bstrString)
559-
Local $aRet = DllCall("OleAut32.dll","NONE","SysFreeString","PTR",$bstrString)
560-
If @error<>0 Then Return SetError(@error, @extended, 0)
561-
Return $aRet[0]
562-
EndFunc
563-
564-
Func SysAddRefString($bstrString)
565-
Local $aRet = DllCall("Oleaut32.dll","LONG","SysAddRefString","PTR",$bstrString)
566-
If @error<>0 Then Return SetError(@error, @extended, 0)
567-
Return $aRet[0]
568-
EndFunc
569-
570478
Func VariantInit($tVARIANT)
571479
Local $aRet=DllCall("OleAut32.dll","LONG","VariantInit",IsDllStruct($tVARIANT)?"struct*":"PTR",$tVARIANT)
572480
If @error<>0 Then Return SetError(-1, @error, 0)
@@ -594,4 +502,8 @@ EndFunc
594502

595503
Func VariantChangeTypeEx()
596504
;TODO
505+
EndFunc
506+
507+
Func PrivateProperty()
508+
Return SetError(1, 1, 0)
597509
EndFunc

0 commit comments

Comments
 (0)