Leaderboard
Popular Content
Showing content with the highest reputation on 09/24/2021 in all areas
-
Convert GetRef function from VBScript to AutoIt
WilliamasKumeliukas and one other reacted to Danyfirex for a topic
Hello. Here is the Implementation of ISearchCompletedCallback If You understand how it works you will be able to implement BeginDownload required Interface callbacks. #include <WinAPICom.au3> Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global Const $sIID_SearchCompletedCallback = "{88AEE058-D4B0-4725-A2F1-814A67AE964C}" Global Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" Global Const $tagIDispatch = $tagIUnknown & _ "GetTypeInfoCount hresult(dword*);" & _ "GetTypeInfo hresult(dword;dword;ptr*);" & _ "GetIDsOfNames hresult(struct*;struct*;dword;dword;struct*);" & _ "Invoke hresult(uint;struct*;dword;word;struct*;struct*;ptr;uint*);" Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _Test() Exit Func _Test() _WinAPI_CoInitialize($COINIT_APARTMENTTHREADED) Local $oMUS = ObjCreate("Microsoft.Update.Session") Local $oSearch = $oMUS.CreateUpdateSearcher() Local $oCompleted, $tCompleted Local $dtagISearchCompletedCallback = "Invoke hresult(idispatch;ptr);" $oCompleted = __ObjectFromTag("__MyInterface_", $dtagISearchCompletedCallback, $tCompleted, Default, $sIID_SearchCompletedCallback) ;~ $oCompleted = __ObjectFromTag("__MyInterface_", $dtagISearchCompletedCallback, $tCompleted) Local $AsyncState = "Danyfirex Loves AutoIt" Local $sCriteria = "IsInstalled=0 or IsHidden=1 or IsPresent=1" ;Create Cast ObjectTag IUpdateSearcher Local $sTagSearch = $tagIDispatch & _Dummy("A", "", 8) & "BeginSearch hresult(bstr;ptr;variant;idispatch*);" & "EndSearch hresult(idispatch;idispatch*);" Local $oSearchCast = ObjCreateInterface($oSearch, "{8f45abf1-f9ae-4b95-a933-f0f66e5056ea}", $sTagSearch, False) Local $oJob = 0 ;~ $oJob = $oSearch.BeginSearch($sCriteria, $oCompleted, $Variant) ;this will not work $oSearchCast.BeginSearch($sCriteria, $oCompleted(), $AsyncState, $oJob) ;casted to make it work ConsoleWrite("$oJob.AsyncState: " & $oJob.AsyncState & @CRLF) While Not $oJob.IsCompleted Sleep(100) WEnd MsgBox(0, "ISearchCompletedCallback Invoke Reached", "Print Updates Title & Exit") Local $oSearchResult = 0 $oSearchCast.EndSearch($oJob, $oSearchResult) For $oUpdate In $oSearchResult.Updates ConsoleWrite(">" & $oUpdate.Title & @CRLF) Next $oSearchCast = 0 $oSearch = 0 $oMUS = 0 EndFunc ;==>_Test Func _Dummy($Name, $Parameters = "", $iTimes = 1) Local $sTag = "" For $i = 1 To $iTimes $sTag &= "DM_" & $Name & $i & " hresult(" & $Parameters & ");" Next Return $sTag EndFunc ;==>_Dummy Func __ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default If $bIsUnknown = Default Then $bIsUnknown = True Local $sInterface = $tagInterface ; copy interface description Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention Local $aMethods = StringSplit(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback ; Allocation $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] ; Replace COM types by matching dllcallback types $sTagPart = StringReplace(StringReplace(StringReplace(StringReplace($aSplit[1], "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr") $sMethod = $sFunctionPrefix & $sNamePart $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle Next DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1 DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object EndFunc ;==>__ObjectFromTag Func __DeleteObjectFromTag(ByRef $tInterface) For $i = 1 To DllStructGetData($tInterface, "Size") DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i)) Next $tInterface = 0 EndFunc ;==>__DeleteObjectFromTag Func __MyInterface_QueryInterface($pSelf, $pRIID, $pObj) ; Ret: long Par: ptr;ptr* Local $sIID = StringFromGUID2($pRIID) If $sIID = $sIID_IUnknown Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK ElseIf $sIID = $sIID_SearchCompletedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK Else Return $E_NOINTERFACE EndIf EndFunc ;==>__MyInterface_QueryInterface Func StringFromGUID2($pGUID) Local $aReturn = DllCall('ole32.dll', 'int', 'StringFromGUID2', 'struct*', $pGUID, 'wstr', '', 'int', 65536) If @error Or Not $aReturn[0] Then Return SetError(@error + 20, @extended, '') Return SetExtended($aReturn[0], $aReturn[2]) EndFunc ;==>StringFromGUID2 Func __MyInterface_AddRef($pSelf) Return 1 EndFunc ;==>__MyInterface_AddRef Func __MyInterface_Release($pSelf) Return 1 EndFunc ;==>__MyInterface_Release Volatile Func __MyInterface_Invoke($pSelf, $oSearchJob, $pISearchCompletedCallbackArgs) ConsoleWrite("Invoke" & @CRLF) ConsoleWrite("Invoke - oSearchJob.AsyncState: " & $oSearchJob.AsyncState & @CRLF) Return $S_OK EndFunc ;==>__MyInterface_Invoke ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc Saludos2 points -
Scratch doubt and replace that with a definite NO WAY!2 points
-
Reuse function variables in other function without Global
Leendert-Jan reacted to diff for a topic
Hello, feeling dumb that I can't resolve my issue, my point is to not use Global variables in bigger projects at all. So I have 2 functions, the first is main function and the second searching for information from websites and attaches the extracted information to variables. Func main() ...does some code... ..then later i have some code which need to use variables from web_extraction() function.. example: StringStripWS($var1, 3) Of course I get here error that variable $var1 possibly not declared EndFunc Func web_extraction() ..does some code... ...extracts information from websites.. $var1 = "extracted info 1" $var2 = "extracted info 2" etc etc. EndFunc Of course I can write at the beginning Global $var1, $var2 and this will work, but how I can use $var1, $var2 which kill itself after function ends in main function? I have read a lot of information about $params in function and etc. tried everything and still receive that the variables are possibly not declared and just stay blank inside. Any examples how correctly to write this?1 point -
SplashOff and Tooltip("") not working in toggle function
WhaleJesus reacted to mikell for a topic
I suppose you meant this Func ToggleST() $TooltipToggle = Not $TooltipToggle1 point -
Since there is good integration between VBScript and AutoIt, why not run the VBScript code directly (as a VBScript), and then pass data between VBScript and an AutoIt script as needed through ROT objects.1 point
-
[Solved]Close Multiple GUI
abdulrahmanok reacted to spudw2k for a topic
The AutoIt help file has a very helpful article for using it. Enum I use it particularly when working with arrays to help myself keep the indexes straight in my mind.1 point -
Not a real GUI but a front-end but it works for what I'm using it for. Newer versions of SignTool and MakeCert can be downloaded as part of Windows SDK. Newer versions of OpenSSL can be downloaded from FireDaemon. Download all the files needed from OneDrive 03.07.2021. - had to make some modifications. Newer version uploaded. 03.06.2023. - added OneDrive path for all the files needed. DigitalSign.au31 point