Leaderboard
Popular Content
Showing content with the highest reputation on 09/27/2021 in all areas
-
Convert GetRef function from VBScript to AutoIt
WilliamasKumeliukas and one other reacted to Danyfirex for a topic
Hello. It's me again. Just to leave a whole example. #RequireAdmin #include <WinAPICom.au3> #include <Debug.au3> #include <Array.au3> Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global Const $sIID_ISearchCompletedCallback = "{88AEE058-D4B0-4725-A2F1-814A67AE964C}" Global Const $sIID_IDownloadCompletedCallback = "{77254866-9F5B-4C8E-B9E2-C77A8530D64B}" Global Const $sIID_IDownloadProgressChangedCallback = "{8C3F1CDD-6173-4591-AEBD-A56A53CA77C1}" 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") Global $g_aSelectedRows = 0 _Test() Exit Func _Test() _WinAPI_CoInitialize($COINIT_APARTMENTTHREADED) Local Const $sCriteria = "Type='Software' and IsInstalled=0" Local $oMUS = ObjCreate("Microsoft.Update.Session") Local $oSearcher = $oMUS.CreateUpdateSearcher() Local $oCompleted, $tCompleted, $dtagISearchCompletedCallback = "InvokeSCC hresult(idispatch;ptr);" $oCompleted = __ObjectFromTag("__MyInterface_", $dtagISearchCompletedCallback, $tCompleted) ;Create Cast Tag IUpdateSearcher Local $sTagSearcher = $tagIDispatch & _Dummy("A", "", 8) & "BeginSearch hresult(bstr;ptr;variant;idispatch*);" & "EndSearch hresult(idispatch;idispatch*);" Local $oSearcherCast = ObjCreateInterface($oSearcher, "{8F45ABF1-F9AE-4B95-A933-F0F66E5056EA}", $sTagSearcher, False) Local $AsyncState = "Danyfirex Loves AutoIt" Local $oJob = 0 ;~ $oJob = $oSearcher.BeginSearch($sCriteria, $oCompleted, $Variant) ;this will not work $oSearcherCast.BeginSearch($sCriteria, $oCompleted(), $AsyncState, $oJob) ;casted to make it work While Not $oJob.IsCompleted ;wait search Sleep(100) WEnd Local $oSearchResult = 0 $oSearcherCast.EndSearch($oJob, $oSearchResult) Local $aUpdates[$oSearchResult.Updates.Count][5] Local $oCustomUpdateCollection = $oSearchResult.Updates.Copy $oCustomUpdateCollection.Clear Local $iCount = 0 For $oUpdate In $oSearchResult.Updates $aUpdates[$iCount][0] = $oUpdate.Title $aUpdates[$iCount][1] = $oUpdate.Description $aUpdates[$iCount][2] = ByteSuffix($oUpdate.MaxDownloadSize) $aUpdates[$iCount][3] = $oUpdate.MaxDownloadSize $aUpdates[$iCount][4] = $oUpdate $iCount += 1 Next _ArraySort($aUpdates, 0, 0, 0, 3) _DebugArrayDisplay($aUpdates, "Select Some Updates for Download Click ""Run User Func""", "|0:3", 0, Default, "Title|Description|Size|Size Bytes", Default, _GetSelected) If $g_aSelectedRows[0] = 0 Then Return MsgBox(0, "Info", "No Updates Selected. Script will Exit...") EndIf ;Create Update Collection For $i = 1 To $g_aSelectedRows[0] ConsoleWrite("Add Update: " & $aUpdates[$g_aSelectedRows[$i]][0] & @CRLF) $oCustomUpdateCollection.Add($aUpdates[$g_aSelectedRows[$i]][4]) Next Local $oDownloader = $oMUS.CreateUpdateDownloader() $oDownloader.Updates = $oCustomUpdateCollection Local $sTagDownloader = $tagIDispatch & _Dummy("A", "", 8) & "BeginDownload hresult(ptr;ptr;variant;idispatch*);Download hresult();EndDownload hresult(idispatch;idispatch*);" Local $oDownloaderCast = ObjCreateInterface($oDownloader, "{68F1C6F9-7ECC-4666-A464-247FE12496C3}", $sTagDownloader, False) Local $oDownloadProgress, $tDownloadProgress, $dtagIDownloadProgressChangedCallback = "Invoke_DPCC hresult(idispatch;idispatch);" $oDownloadProgress = __ObjectFromTag("__MyInterface_", $dtagIDownloadProgressChangedCallback, $tDownloadProgress) Local $oDownloadCompleted, $tDownloadCompleted, $dtagIDownloadCompletedCallback = "Invoke_DCC hresult(idispatch;ptr);" $oDownloadCompleted = __ObjectFromTag("__MyInterface_", $dtagIDownloadCompletedCallback, $tDownloadCompleted) Local $AsyncState = "Danyfirex Loves AutoIt Download" Local $oDownloadJob = 0 ;~ $oDownloader.BeginDownload($oDownloadProgress(), $oDownloadCompleted(), $AsyncState, $oDownloadJob) ;this will not work $oDownloaderCast.BeginDownload($oDownloadProgress(), $oDownloadCompleted(), $AsyncState, $oDownloadJob) ;casted to make it work ProgressOn("Downloading Updates", "Download Started...") While Not $oDownloadJob.IsCompleted Sleep(100) WEnd Sleep(2000) ProgressOff() Local $oDownloadResult = 0 $oDownloaderCast.EndDownload($oDownloadJob, $oDownloadResult) If $oDownloadResult.ResultCode = 2 Then MsgBox(0, "Info", "Download Completed.") Else MsgBox(0, "Info", "Download Failed.") EndIf $oDownloader = 0 $oDownloaderCast = 0 $oSearcherCast = 0 $oSearcher = 0 $oMUS = 0 EndFunc ;==>_Test Func _GetSelected($aArray, $aSelected) $g_aSelectedRows = $aSelected If $g_aSelectedRows[0] = 0 Then MsgBox(0, "", "Select one/more items. Click ""Run User Func""") Else Send("{ESC}") EndIf EndFunc ;==>_GetSelected Func ByteSuffix($iBytes) Local $iIndex = 0, $aArray = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'] While $iBytes > 1023 $iIndex += 1 $iBytes /= 1024 WEnd Return Round($iBytes) & $aArray[$iIndex] EndFunc ;==>ByteSuffix 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_ISearchCompletedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK ElseIf $sIID = $sIID_IDownloadCompletedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK ElseIf $sIID = $sIID_IDownloadProgressChangedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK Else Return $E_NOINTERFACE EndIf EndFunc ;==>__MyInterface_QueryInterface Func __MyInterface_AddRef($pSelf) Return 1 EndFunc ;==>__MyInterface_AddRef Func __MyInterface_Release($pSelf) Return 1 EndFunc ;==>__MyInterface_Release Volatile Func __MyInterface_Invoke_SCC($pSelf, $oSearchJob, $pISearchCompletedCallbackArgs) ;~ ConsoleWrite("InvokeSCC - oSearchJob.AsyncState: " & $oSearchJob.AsyncState & @CRLF) Return $S_OK EndFunc ;==>__MyInterface_Invoke_SCC Volatile Func __MyInterface_Invoke_DCC($pSelf, $oDownloadJob, $pIDownloadCompletedCallbackArgs) ;~ ConsoleWrite("InvokeDCC - $oDownloadJob.AsyncState: " & $oDownloadJob.AsyncState & @CRLF) ProgressSet(100, "Download Completed...", "Download Completed.") Return $S_OK EndFunc ;==>__MyInterface_Invoke_DCC Volatile Func __MyInterface_Invoke_DPCC($pSelf, $oDownloadJob, $oDownloadProgressChangedCallbackArgs) ;~ ConsoleWrite("InvokeDPCC" & @CRLF) Local $iCurrentPercent = $oDownloadProgressChangedCallbackArgs.Progress.CurrentUpdatePercentComplete ProgressSet($iCurrentPercent, "(" & $iCurrentPercent & "%) " & $oDownloadJob.Updates($oDownloadProgressChangedCallbackArgs.Progress.CurrentUpdateIndex).Title, _ "Downloading Updates (" & $oDownloadProgressChangedCallbackArgs.Progress.CurrentUpdateIndex + 1 & "/" & $oDownloadJob.Updates.Count & ")") Return $S_OK EndFunc ;==>__MyInterface_Invoke_DPCC 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 ; 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 -
Reuse function variables in other function without Global
seadoggie01 and one other reacted to JockoDundee for a topic
Looking back at the initial problem posted by the OP, I don’t think it takes much more than: Func main() Local $var1, $var2 web_extraction($var1, $var2) StringStripWS($var1, 3) EndFunc Func web_extraction(ByRef $var1, ByRef $var2) $var1 = "extracted info 1" $var2 = "extracted info 2" EndFunc2 points -
[BUGFIX VERSION] - 6 Apr 24 Fixed: UDF failed if header colours were initialised but not specifically set. New UDF in the zip below. -------------------------------------------------------------------------------------- Note: This is a new recoded and expanded version of my earlier UDF of the same name. If you move to this new version there might well be several script-breaking changes, particularly when setting which columns are to be editable. Please read the "Beginner's Guide" and look at the included example scripts to see where things have changed. -------------------------------------------------------------------------------------- This UDF allows you to do much more with ListView controls (either native or UDF created): Edit the content with plain text, combos or date-time pickers - and edit the headers too Move rows within the ListView Drag rows both within the ListView and to other ListViews in the same GUI (or not as required) Insert and delete columns and rows Sort columns by simply clicking the header Colour individual ListView items and headers Only select a single cell rather then the entire row Save and load entire ListViews For the advanced user: If you use certain Windows message handlers (In particular WM_NOTIFY) in your script, please read the function headers for the equivalent handlers within the UDF. Here is the UDF, with 6 examples and the guide, in zip format: GUIListViewEx.zip Credit to: martin (basic drag code), Array.au3 authors (array functions), KaFu and ProgAndy (font function), LarsJ (colouring code) Happy to take compliments or criticism - preferably the former! M231 point
-
Peace Equalizer shows power of AutoIt
Zedna reacted to PeterVerbeek for a topic
In this post I take the opportunity to show the awesome capabilities of AutoIt and its libraries. My open source project Peace is a long running AutoIt based app located on SourceForge. It provides users with a system-wide equalizer and effects machine. It's an interface using the power of Equalizer APO, an audio processing object software. Peace has been download over 2,600,000 times by various kind of users. Amongst others it gives them possibilities like these: Hearing impaired - Amplify the gain of frequencies which are impaired. Home Theatre - Create Equalizer presets for watching movies and listening to music. Music lovers & audiophiles - Create presets for listening to music on their high quality speakers and headphones. Gamers - Enhance frequencies to get an edge over other gamers. Headphones - Improve the sound quality of cheap headphones and get the max out of expensive ones. Bass lovers - Boost low frequencies for extra bass. Voice - Make a microphone sound better and improve the voice, for instance for YouTube usage. Low audio - Boost low audio of an input source to a comfortable level. This list covers the main needs of the Peace user. Many people have contacted me over the years asking for new features and telling me how they use Peace for their (sometimes specific) needs. I was able to use AutoIt and its libraries for all of their needs. So what are the main features of Peace? Equalize your computer audio by using up to 31 sliders. Support of equalizing 9 speakers : left/right, center, subwoofer, left/right rear, left/right side. Per slider a filter can be chosen such as peak, low/high pass, shelving. The graph windows shows your equalization so you see exactly what you're doing. Apply an effect such as crossfeed simple/Jan Meier/Chu Moy, stereo balance, bass/treble, upmix/downmix, channel routing. Save presets (called configurations) and activate by mouse click, hotkey, desktop shortcut or Peace system tray. Select a target device to equalize, microphone as input can also be equalized. Automate: you can let Peace automatically activate presets on a switch to another device and another process. Peace is available in these languages: English, Czech, Deutsch, Français, Italiano, Nederlands, Pусский, Українська So who am I? I'm a Dutch programmer who happens the stumble upon AutoIt 5 years ago and created a small Equalizer interface app of less than 400 program lines with it. Nowadays Peace has grown to more than 18,000 lines as many features were added. Although Peace is open source, the program code isn't of the best possible quality. The reason being that I didn't expect it to become so popular. It caught me by supprise. I've created a Library of functions called Pal (link to forum post) which quality is up to the AutoIt community standard as counterpart to the Peace program code. I want to state here that AutoIt is a mature program language as Peace obviously shows. I wish it to be used more extensively for professional or semi-professional apps. In my view AutoIt deserves a place amongst the major programming languages for Windows computers. Regards, Peter Verbeek1 point -
Convert GetRef function from VBScript to AutoIt
Danyfirex reacted to WilliamasKumeliukas for a topic
here my little modification which solve the issue: If IsArray($g_aSelectedRows) = 0 Or $g_aSelectedRows[0] = 0 Then Return MsgBox(0, "Info", "No Updates Selected. Script will Exit...") EndIf Best Regards, WilliamasKumeliukas1 point -
Convert GetRef function from VBScript to AutoIt
Danyfirex reacted to WilliamasKumeliukas for a topic
Omg @Danyfirex, your incredible! I cannot thank you enough for this great help! @mLipok, this is a normal bug from Microsoft, I most of the time get this 100gb update for each culmulative updates (via microsoft update session), this is a miscalculation which is not actually downloading 103gb for real1 point -
Here is little modified script (compatibility with Au3Check) : ;~ https://www.autoitscript.com/forum/topic/206615-convert-getref-function-from-vbscript-to-autoit/?tab=comments#comment-1489832 #RequireAdmin #include <WinAPICom.au3> #include <Debug.au3> #include <Array.au3> Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global Const $sIID_ISearchCompletedCallback = "{88AEE058-D4B0-4725-A2F1-814A67AE964C}" Global Const $sIID_IDownloadCompletedCallback = "{77254866-9F5B-4C8E-B9E2-C77A8530D64B}" Global Const $sIID_IDownloadProgressChangedCallback = "{8C3F1CDD-6173-4591-AEBD-A56A53CA77C1}" 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") Global $g_aSelectedRows = 0 _Test() Exit Func _Test() _WinAPI_CoInitialize($COINIT_APARTMENTTHREADED) Local Const $sCriteria = "Type='Software' and IsInstalled=0" Local $oMUS = ObjCreate("Microsoft.Update.Session") Local $oSearcher = $oMUS.CreateUpdateSearcher() Local $oCompleted, $tCompleted, $dtagISearchCompletedCallback = "InvokeSCC hresult(idispatch;ptr);" $oCompleted = __ObjectFromTag("__MyInterface_", $dtagISearchCompletedCallback, $tCompleted) ;Create Cast Tag IUpdateSearcher Local $sTagSearcher = $tagIDispatch & _Dummy("A", "", 8) & "BeginSearch hresult(bstr;ptr;variant;idispatch*);" & "EndSearch hresult(idispatch;idispatch*);" Local $oSearcherCast = ObjCreateInterface($oSearcher, "{8F45ABF1-F9AE-4B95-A933-F0F66E5056EA}", $sTagSearcher, False) Local $AsyncState = "Danyfirex Loves AutoIt" Local $oJob = 0 ;~ $oJob = $oSearcher.BeginSearch($sCriteria, $oCompleted, $Variant) ;this will not work $oSearcherCast.BeginSearch($sCriteria, $oCompleted(), $AsyncState, $oJob) ;casted to make it work While Not $oJob.IsCompleted ;wait search Sleep(100) WEnd Local $oSearchResult = 0 $oSearcherCast.EndSearch($oJob, $oSearchResult) Local $aUpdates[$oSearchResult.Updates.Count][5] Local $oCustomUpdateCollection = $oSearchResult.Updates.Copy $oCustomUpdateCollection.Clear Local $iCount = 0 For $oUpdate In $oSearchResult.Updates $aUpdates[$iCount][0] = $oUpdate.Title $aUpdates[$iCount][1] = $oUpdate.Description $aUpdates[$iCount][2] = ByteSuffix($oUpdate.MaxDownloadSize) $aUpdates[$iCount][3] = $oUpdate.MaxDownloadSize $aUpdates[$iCount][4] = $oUpdate $iCount += 1 Next _ArraySort($aUpdates, 0, 0, 0, 3) _DebugArrayDisplay($aUpdates, "Select Some Updates for Download Click ""Run User Func""", "|0:3", 0, Default, "Title|Description|Size|Size Bytes", Default, _GetSelected) If $g_aSelectedRows[0] = 0 Then Return MsgBox(0, "Info", "No Updates Selected. Script will Exit...") EndIf ;Create Update Collection For $i = 1 To $g_aSelectedRows[0] ConsoleWrite("Add Update: " & $aUpdates[$g_aSelectedRows[$i]][0] & @CRLF) $oCustomUpdateCollection.Add($aUpdates[$g_aSelectedRows[$i]][4]) Next Local $oDownloader = $oMUS.CreateUpdateDownloader() $oDownloader.Updates = $oCustomUpdateCollection Local $sTagDownloader = $tagIDispatch & _Dummy("A", "", 8) & "BeginDownload hresult(ptr;ptr;variant;idispatch*);Download hresult();EndDownload hresult(idispatch;idispatch*);" Local $oDownloaderCast = ObjCreateInterface($oDownloader, "{68F1C6F9-7ECC-4666-A464-247FE12496C3}", $sTagDownloader, False) Local $oDownloadProgress, $tDownloadProgress, $dtagIDownloadProgressChangedCallback = "Invoke_DPCC hresult(idispatch;idispatch);" $oDownloadProgress = __ObjectFromTag("__MyInterface_", $dtagIDownloadProgressChangedCallback, $tDownloadProgress) Local $oDownloadCompleted, $tDownloadCompleted, $dtagIDownloadCompletedCallback = "Invoke_DCC hresult(idispatch;ptr);" $oDownloadCompleted = __ObjectFromTag("__MyInterface_", $dtagIDownloadCompletedCallback, $tDownloadCompleted) $AsyncState = "Danyfirex Loves AutoIt Download" Local $oDownloadJob = 0 ;~ $oDownloader.BeginDownload($oDownloadProgress(), $oDownloadCompleted(), $AsyncState, $oDownloadJob) ;this will not work $oDownloaderCast.BeginDownload($oDownloadProgress(), $oDownloadCompleted(), $AsyncState, $oDownloadJob) ;casted to make it work ProgressOn("Downloading Updates", "Download Started...") While Not $oDownloadJob.IsCompleted Sleep(100) WEnd Sleep(2000) ProgressOff() Local $oDownloadResult = 0 $oDownloaderCast.EndDownload($oDownloadJob, $oDownloadResult) If $oDownloadResult.ResultCode = 2 Then MsgBox(0, "Info", "Download Completed.") Else MsgBox(0, "Info", "Download Failed.") EndIf $oDownloader = 0 $oDownloaderCast = 0 $oSearcherCast = 0 $oSearcher = 0 $oMUS = 0 EndFunc ;==>_Test Func _GetSelected($aArray, $aSelected) #forceref $aArray $g_aSelectedRows = $aSelected If $g_aSelectedRows[0] = 0 Then MsgBox(0, "", "Select one/more items. Click ""Run User Func""") Else Send("{ESC}") EndIf EndFunc ;==>_GetSelected Func ByteSuffix($iBytes) Local $iIndex = 0, $aArray = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'] While $iBytes > 1023 $iIndex += 1 $iBytes /= 1024 WEnd Return Round($iBytes) & $aArray[$iIndex] EndFunc ;==>ByteSuffix 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_ISearchCompletedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK ElseIf $sIID = $sIID_IDownloadCompletedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK ElseIf $sIID = $sIID_IDownloadProgressChangedCallback Then DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf) Return $S_OK Else Return $E_NOINTERFACE EndIf EndFunc ;==>__MyInterface_QueryInterface Func __MyInterface_AddRef($pSelf) #forceref $pSelf Return 1 EndFunc ;==>__MyInterface_AddRef Func __MyInterface_Release($pSelf) #forceref $pSelf Return 1 EndFunc ;==>__MyInterface_Release Volatile Func __MyInterface_Invoke_SCC($pSelf, $oSearchJob, $pISearchCompletedCallbackArgs) #forceref $pSelf, $oSearchJob, $pISearchCompletedCallbackArgs ;~ ConsoleWrite("InvokeSCC - oSearchJob.AsyncState: " & $oSearchJob.AsyncState & @CRLF) Return $S_OK EndFunc ;==>__MyInterface_Invoke_SCC Volatile Func __MyInterface_Invoke_DCC($pSelf, $oDownloadJob, $pIDownloadCompletedCallbackArgs) #forceref $pSelf, $oDownloadJob, $pIDownloadCompletedCallbackArgs ;~ ConsoleWrite("InvokeDCC - $oDownloadJob.AsyncState: " & $oDownloadJob.AsyncState & @CRLF) ProgressSet(100, "Download Completed...", "Download Completed.") Return $S_OK EndFunc ;==>__MyInterface_Invoke_DCC Volatile Func __MyInterface_Invoke_DPCC($pSelf, $oDownloadJob, $oDownloadProgressChangedCallbackArgs) #forceref $pSelf ;~ ConsoleWrite("InvokeDPCC" & @CRLF) Local $iCurrentPercent = $oDownloadProgressChangedCallbackArgs.Progress.CurrentUpdatePercentComplete ProgressSet($iCurrentPercent, "(" & $iCurrentPercent & "%) " & $oDownloadJob.Updates($oDownloadProgressChangedCallbackArgs.Progress.CurrentUpdateIndex).Title, _ "Downloading Updates (" & $oDownloadProgressChangedCallbackArgs.Progress.CurrentUpdateIndex + 1 & "/" & $oDownloadJob.Updates.Count & ")") Return $S_OK EndFunc ;==>__MyInterface_Invoke_DPCC 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 ; 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 Even after my mod, I still get: related to this: If $g_aSelectedRows[0] = 0 Then Return MsgBox(0, "Info", "No Updates Selected. Script will Exit...") EndIf1 point
-
Updated example that starts up Excel and a second application (could be Spark). It brings Excel to the front and waits. When the user selects a new cell function oExcel_Events_SelectionChange is called. This function displays the selected cell, checks if the address is within the valid range. If yes, the value of the cell is read and displayed on the Console. Then the function switches to Notepad (could be Spark), waits 2 seconds and then switches back to Excel. #include <Excel.au3> Run("notepad.exe") ; Start a second application Global $oExcel = _Excel_Open() ; Start up or connect to Excel Global $oWorkbook = _Excel_BookNew($oExcel, 1) ; Create a new empty workbook with a single worksheet WinActivate($oExcel.Caption) ; Activate Excel Global $oWorksheet = $oWorkbook.Sheets(1) ; Access this worksheet Global $oRangeValid = $oWorksheet.Range("A1:B2" ) ; Range the user can select from _Excel_RangeWrite($oWorkbook, 1, "111", "A1") ; Write example data to this worksheet _Excel_RangeWrite($oWorkbook, 1, "222", "A2") _Excel_RangeWrite($oWorkbook, 1, "333", "B1") ; ***************************************************************************** ; Example Script ; Handle Worksheet SelectionChange event when the user selects a new cell. ; This script loops until Shift-Alt-E is pressed to exit. ; ***************************************************************************** HotKeySet("+!e", "_Exit") ;Shift-Alt-E to Exit the script MsgBox(64, "Excel Example Script", "Hotkey to exit the script: 'Shift-Alt-E'!") Global $oEvent = ObjEvent($oWorksheet, "oExcel_Events_") While 1 Sleep(10) WEnd ; Worksheet SelectionChange event. See: https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet.selectionchange Func oExcel_Events_SelectionChange($oRange) Local $sAddress = $oRange.Address ; Get the selected address ConsoleWrite("User selected Cell: " & $sAddress & @CRLF) If IsObj($oExcel.Intersect($oRangeValid, $oRange)) Then ; Check if the selected cell is inside the valid range ConsoleWrite("Cell value is: : " & $oRange.Value & @CRLF) WinActivate("[CLASS:Notepad]", "") ; Activate Notepad Sleep(2000) ; Sleep 2 seconds WinActivate($oExcel.Caption) ; Activate Excel Else ConsoleWrite("The selected cell is outside the valid range!" & @CRLF) EndIf EndFunc ;==>oExcel_Events_SelectionChange Func _Exit() Exit EndFunc ;==>_Exit1 point
-
CarlD, Glad you find the UDF useful. The text is indeed displaced to the right when an icon is used - just as in the standard MS MsgBox dialog. Here is a short script to show this: #include <MsgBoxConstants.au3> #include "ExtMsgBox.au3" MsgBox($MB_SYSTEMMODAL, "No icon", "Here is a bit of longish text to display!") MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "With icon", "Here is a bit of longish text to display!") _ExtMsgBox(0, "OK", "With icon", "Here is a bit of longish text to display!") _ExtMsgBox($MB_ICONINFORMATION, "OK", "With icon", "Here is a bit of longish text to display!") As you can see (I hope!) both the standard and UDF dialogs widen and shift the text to the right when there is an icon displayed. So if you really, really want the text to be absolutely centered in the dialog when an icon is used, you need to pad the text as you mention, although it will take a degree of experimentation in sizing the additional blank space to get it perfect. Personally i would just leave it as it is - MS seem happy to do so! M231 point
-
AutoIt v3.3.15.4 Beta
JockoDundee reacted to argumentum for a topic
Is there any compiler that forces you to such ?. As far as I know, all compilers compile and signing a file is another thing altogether, not forced, nor enforced by any compiler, as is not compiler related. Unless an IDE gives you an interface with settings/options to enforce it. Now, if I'm right ( and often am ), what you like is an interface/GUI/wrapper with settings to enforce such. And that, could be coded if needed. By you if you have a clear understanding of how it would function. And shared here in the forum for the rest of us1 point -
Convert GetRef function from VBScript to AutoIt
WilliamasKumeliukas 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 Saludos1 point