1010
1111Global Const $IID_IUnknown = " {00000000-0000-0000-C000-000000000046}"
1212Global Const $IID_IDispatch = " {00020400-0000-0000-C000-000000000046}"
13+ Global Const $IID_IConnectionPointContainer = " {B196B284-BAB4-101A-B69C-00AA00341D07}"
1314
1415Global Const $DISPATCH_METHOD = 1
1516Global Const $DISPATCH_PROPERTYGET = 2
@@ -90,6 +91,7 @@ Func IDispatch($QueryInterface=QueryInterface, $AddRef=AddRef, $Release=Release,
9091EndFunc
9192
9293Func QueryInterface($pSelf , $pRIID , $pObj )
94+ If $pObj = 0 Then Return $E_POINTER
9395 Local $sGUID = DllCall (" ole32.dll" , " int" , " StringFromGUID2" , " PTR" , $pRIID , " wstr" , " " , " int" , 40 )[2 ]
9496 If (Not ($sGUID = $IID_IDispatch )) And (Not ($sGUID = $IID_IUnknown )) Then Return $E_NOINTERFACE
9597 Local $tStruct = DllStructCreate (" ptr" , $pObj )
@@ -104,11 +106,13 @@ Func AddRef($pSelf)
104106EndFunc
105107
106108Func Release($pSelf )
109+ Local $i
107110 Local $tStruct = DllStructCreate (" int Ref" , $pSelf - 8 )
108111 $tStruct .Ref -= 1
109112 If $tStruct .Ref == 0 Then
113+ ; initiate garbage collection
110114 Local $pDescructor = DllStructGetData (DllStructCreate (" PTR" , $pSelf + (@AutoItX64 ?8 :4 ) + ((@AutoItX64 ?8 :4 )* 7 * 2 ) + (@AutoItX64 ?8 :4 ) + 1 ),1 )
111- $tVARIANT = DllStructCreate ($tagVARIANT , $pDescructor )
115+ Local $tVARIANT = DllStructCreate ($tagVARIANT , $pDescructor )
112116 If Not ($pDescructor = 0 ) Then
113117 DllStructSetData (DllStructCreate (" PTR" , $pSelf + (@AutoItX64 ?8 :4 ) + ((@AutoItX64 ?8 :4 )* 7 * 2 ) + (@AutoItX64 ?8 :4 ) + 1 ),1 ,0 )
114118 Local $IDispatch = IDispatch()
@@ -128,12 +132,12 @@ Func Release($pSelf)
128132 $IDispatch = 0
129133 EndIf
130134 DllStructSetData (DllStructCreate (" BYTE" , $pSelf + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 + (@AutoItX64 ?8 :4 )),1 ,1 ); lock
131- $pProperty = DllStructGetData (DllStructCreate (" ptr" , $pSelf + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 ),1 ); get first property
135+ Local $pProperty = DllStructGetData (DllStructCreate (" ptr" , $pSelf + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 ),1 ); get first property
132136 DllStructSetData (DllStructCreate (" ptr" , $pSelf + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 ),1 ,0 ); detatch properties from object
133137 While 1 ; releases all properties
134138 If $pProperty = 0 Then ExitLoop
135- $tProperty = DllStructCreate ($tagProperty , $pProperty )
136- $_pProperty = $pProperty
139+ Local $tProperty = DllStructCreate ($tagProperty , $pProperty )
140+ Local $_pProperty = $pProperty
137141 $pProperty = $tProperty .Next
138142 If Not ($tProperty .__getter= 0 ) Then
139143 VariantClear($tProperty .__getter)
@@ -149,7 +153,14 @@ Func Release($pSelf)
149153 $tProperty = 0
150154 _MemGlobalFree(GlobalHandle($_pProperty ))
151155 WEnd
156+ Local $pMethods = $pSelf + (@AutoItX64 ?8 :4 )
157+ #cs
158+ For $i=0 To DllStructGetData(DllStructCreate("INT", $pSelf-4),1)-1
159+ DllStructSetData(DllStructCreate("PTR",$pMethods), 1, 0)
160+ $pMethods+=(@AutoItX64?8:4)
161+ Next
152162 Local $pCallbacks = $pSelf + (@AutoItX64?8:4) + ((@AutoItX64?8:4)*7)
163+ #ce
153164 #cs
154165 ;Cannot Free callback while in progress i guess... makes some sense
155166 For $i=0 To DllStructGetData(DllStructCreate("INT", $pSelf-4),1)-1
@@ -160,7 +171,7 @@ Func Release($pSelf)
160171 _MemGlobalFree(GlobalHandle($pSelf - 8 ))
161172 Return 0
162173 EndIf
163- Return $tStruct .Ref
174+ Return $tStruct .Ref
164175EndFunc
165176
166177Func GetIDsOfNames($pSelf , $riid , $rgszNames , $cNames , $lcid , $rgDispId )
@@ -192,6 +203,12 @@ Func GetIDsOfNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId)
192203 ElseIf $s_rgszName == " __destructor" Then
193204 DllStructSetData ($tIds , 1 , - 7 )
194205 Return $S_OK
206+ ElseIf $s_rgszName == " __register" Then
207+ DllStructSetData ($tIds , 1 , - 8 )
208+ Return $S_OK
209+ ElseIf $s_rgszName == " __unregister" Then
210+ DllStructSetData ($tIds , 1 , - 9 )
211+ Return $S_OK
195212 EndIf
196213
197214 Local $iID = - 1
@@ -211,7 +228,6 @@ Func GetIDsOfNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId)
211228 Local $tProp , $pData , $tVARIANT , $pVARIANT
212229
213230 Local $iLock = DllStructGetData (DllStructCreate (" BYTE" , $pSelf + (@AutoItX64 ?8 :4 ) + ((@AutoItX64 ?8 :4 )* 7 * 2 ) + (@AutoItX64 ?8 :4 )),1 )
214-
215231 If ($iID == - 1 ) And $iLock = 0 Then
216232 $tProp = DllStructCreate ($tagProperty )
217233 $pData = MemCloneGlob($tProp )
@@ -237,11 +253,28 @@ Func GetIDsOfNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId)
237253EndFunc
238254
239255Func GetTypeInfo($pSelf , $iTInfo , $lcid , $ppTInfo )
240- Return $E_NOTIMPL
256+ If $iTInfo <> 0 Then Return $DISP_E_BADINDEX
257+ If $ppTInfo = 0 Then Return $E_INVALIDARG
258+ Return $E_NOTIMPL
259+ If DllStructGetData (DllStructCreate (" UINT" , $iTInfo ),1 )<> 0 Then Return $DISP_E_BADINDEX
260+ ; ~ Local $IID_ITypeInfo = "{00020401-0000-0000-C000-000000000046}"
261+ ; ~ ConsoleWrite("$iTInfo: "&DllStructGetData(DllStructCreate("UINT", $iTInfo),1)&@CRLF)
262+ ; ~ ConsoleWrite("$lcid: "&$lcid&@CRLF)
263+ ; ~ Local $ITypeInfo=DllCall("OleAut32.dll","LONG","CreateDispTypeInfo","PTR",0,"UINT",$lcid,"PTR*",0)
264+ ; ~ $ITypeInfo=ObjCreateInterface($ITypeInfo[3], $IID_IUnknown)
265+ ; ~ $ITypeInfo=ObjCreateInterface($ITypeInfo[3], $IID_ITypeInfo, "GetTypeAttr;GetTypeComp;GetFuncDesc;GetVarDesc;GetNames;GetRefTypeOfImplType;GetImplTypeFlags;GetIDsOfNames;Invoke;GetDocumentation;GetDllEntry;GetRefTypeInfo;AddressOfMember;CreateInstance;GetMops;GetContainingTypeLib;ReleaseTypeAttr;ReleaseFuncDesc;ReleaseVarDesc")
266+ ; ~ ConsoleWrite($ITypeInfo[3]&@CRLF)
267+ ; ~ ConsoleWrite(DllStructSetData(DllStructCreate("PTR",$ppTInfo),1)&@CRLF)
268+ ; ~ DllStructSetData(DllStructCreate("PTR",$ppTInfo),1,Ptr($ITypeInfo))
269+ ; ~ $ITypeInfo=0
270+ Return $S_OK
241271EndFunc
242272
243273Func GetTypeInfoCount($pSelf , $pctinfo )
244- Return $E_NOTIMPL
274+ ; ~ DllStructSetData(DllStructCreate("UINT",$pctinfo),1, 1)
275+ DllStructSetData (DllStructCreate (" UINT" ,$pctinfo ),1 , 0 )
276+ Return $S_OK
277+ ; ~ Return $E_NOTIMPL
245278EndFunc
246279
247280Func Invoke($pSelf , $dispIdMember , $riid , $lcid , $wFlags , $pDispParams , $pVarResult , $pExcepInfo , $puArgErr )
@@ -357,11 +390,11 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
357390 $tProperty = DllStructCreate ($tagProperty , $pProperty )
358391 Next
359392 If ($tProperty .__getter= 0 ) Then
360- $tVARIANT_Getter = DllStructCreate ($tagVARIANT )
393+ Local $tVARIANT_Getter = DllStructCreate ($tagVARIANT )
361394 $pVARIANT_Getter = MemCloneGlob($tVARIANT_Getter )
362395 VariantInit($pVARIANT_Getter )
363396 Else
364- $pVARIANT_Getter = $tProperty .__getter
397+ Local $pVARIANT_Getter = $tProperty .__getter
365398 VariantClear($pVARIANT_Getter )
366399 EndIf
367400 VariantCopy($pVARIANT_Getter , $tVARIANT )
@@ -396,11 +429,11 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
396429 $tProperty = DllStructCreate ($tagProperty , $pProperty )
397430 Next
398431 If ($tProperty .__setter= 0 ) Then
399- $tVARIANT_Setter = DllStructCreate ($tagVARIANT )
400- $pVARIANT_Setter = MemCloneGlob($tVARIANT_Setter )
432+ Local $tVARIANT_Setter = DllStructCreate ($tagVARIANT )
433+ Local $pVARIANT_Setter = MemCloneGlob($tVARIANT_Setter )
401434 VariantInit($pVARIANT_Setter )
402435 Else
403- $pVARIANT_Setter = $tProperty .__setter
436+ Local $pVARIANT_Setter = $tProperty .__setter
404437 VariantClear($pVARIANT_Setter )
405438 EndIf
406439 VariantCopy($pVARIANT_Setter , $tVARIANT )
@@ -427,7 +460,7 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
427460 $oIDispatch .ret = 0
428461 DllStructSetData (DllStructCreate (" INT" , $pSelf - 4 - 4 ), 1 , DllStructGetData (DllStructCreate (" INT" , $pSelf - 4 - 4 ), 1 )+ 1 )
429462 $oIDispatch .parent = 0
430- $tProperty02 = DllStructCreate ($tagProperty , DllStructGetData (DllStructCreate (" ptr" , ptr ($oIDispatch ) + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 ),1 ))
463+ Local $tProperty02 = DllStructCreate ($tagProperty , DllStructGetData (DllStructCreate (" ptr" , ptr ($oIDispatch ) + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 ),1 ))
431464 $tProperty02 = DllStructCreate ($tagProperty , $tProperty02 .Next )
432465 $tProperty02 = DllStructCreate ($tagProperty , $tProperty02 .Next )
433466 $tVARIANT = DllStructCreate ($tagVARIANT , $tProperty02 .Variant)
@@ -474,7 +507,7 @@ Func Invoke($pSelf, $dispIdMember, $riid, $lcid, $wFlags, $pDispParams, $pVarRes
474507 $oIDispatch .ret = 0
475508 DllStructSetData (DllStructCreate (" INT" , $pSelf - 4 - 4 ), 1 , DllStructGetData (DllStructCreate (" INT" , $pSelf - 4 - 4 ), 1 )+ 1 )
476509 $oIDispatch .parent = 0
477- $tProperty02 = DllStructCreate ($tagProperty , DllStructGetData (DllStructCreate (" ptr" , ptr ($oIDispatch ) + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 ),1 ))
510+ Local $tProperty02 = DllStructCreate ($tagProperty , DllStructGetData (DllStructCreate (" ptr" , ptr ($oIDispatch ) + (@AutoItX64 ?8 :4 ) + (@AutoItX64 ?8 :4 )* 7 * 2 ),1 ))
478511 $tProperty02 = DllStructCreate ($tagProperty , $tProperty02 .Next )
479512 $tProperty02 = DllStructCreate ($tagProperty , $tProperty02 .Next )
480513 $tVARIANT = DllStructCreate ($tagVARIANT , $tProperty02 .Variant)
0 commit comments