Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 11/19/2025 in Posts

  1. I was before retiring in Basic software development as Windows Core So I can tell you that the solution comes with generating an assembly code based on a run time implementing the AutoIt builtin functions That need to defined something as as C compiler, that's a tremending job at least for me Today Autoit is based on a interpreting byte code corresponding to AutoIt builtin functions which is not too bad from my point of view Cheers
    3 points
  2. Hello! Just letting everyone know that I'm still hard at work on this. Decided to make some major changes to the structure once again. Now I can continue to lay out the GUI. Now it is based on an event queue. Any time an action is performed or information is requested, the object pushes it to a queue which announces to other objects that have subscribed to the queue. I'm hoping this will allow me to implement an undo/redo!
    3 points
  3. Wow, that looks wild. To be honest, I haven't delved deep enough into your script to really understand how the path strings for _JSON_Get() are constructed there. As I understand it, you want to map this highly hierarchical structure to a 2D array—is that correct? From my point of view, neither manual fixed loops nor the use of _JSON_Get() are the ideal way to do this. Instead of manual nested loops, the format here literally cries out for recursion. And since _JSON_Get starts from the beginning again with each call and you can quickly get confused with the path string, you don't really need it here. You have the structure available as AutoIt data structures. So you can also process it directly to access it – you don't need _JSON_Get() for that. That is more for conveniently accessing certain values whose path you know in advance. On the other hand, first putting together a path and then using _JSON_Get to retrieve the element is artificially cumbersome, since you basically already have the element when you put the path together. So I simply implemented the whole thing recursively, and from my point of view, it seems to make sense: #include <JSON.au3> #include <Array.au3> ; extract array of devices from the json structure Global $aDevices = _extractDevices(_JSON_Parse(FileRead('Argumentum.json'))) ; display the result _ArrayDisplay($aDevices, "Devices", "", 64, "|", "Index|JSON-Path|ID|Text|Min|Value|Max|SensorID|Type|ImageURL") Func _extractDevices($mDevice, $bMaster = True, $sIndex = 0) Local Static $aDevices[0][0], $iElements Local Enum $eIdx, $ePath, $eID, $eText, $eMin, $eValue, $eMax, $eSensorID, $eType, $eImg ; check Input validity If Not IsMap($mDevice) Then Return SetError(1, 0, Null) ; first recursion level has to initialize things If $bMaster Then Redim $aDevices[8][$eImg + 1] $iElements = 0 EndIf ; add current device to result array If UBound($aDevices) <= $iElements Then Redim $aDevices[UBound($aDevices) * 2][$eImg + 1] ; resize array if necessary $aDevices[$iElements][$eIdx] = $sIndex $aDevices[$iElements][$ePath] = StringReplace(StringRegExpReplace(StringTrimLeft($sIndex, 2), "(\d+)", 'Children[$1]'), ',', '.') $aDevices[$iElements][$eID] = $mDevice["id"] $aDevices[$iElements][$eText] = $mDevice["Text"] $aDevices[$iElements][$eMin] = $mDevice["Min"] $aDevices[$iElements][$eValue] = $mDevice["Value"] $aDevices[$iElements][$eMax] = $mDevice["Max"] $aDevices[$iElements][$eSensorID] = $mDevice["SensorId"] $aDevices[$iElements][$eType] = $mDevice["Type"] $aDevices[$iElements][$eImg] = $mDevice["ImageURL"] $iElements += 1 ; process the childrens Local $aChildren = $mDevice["Children"] If IsArray($aChildren) And UBound($aChildren, 1) > 0 And UBound($aChildren, 0) = 1 Then For $i = 0 To UBound($aChildren) - 1 _extractDevices($aChildren[$i], False, $sIndex & "," & $i) Next EndIf If $bMaster Then Redim $aDevices[$iElements][$eImg + 1] Return $aDevices EndIf EndFunc I am therefore unable to assess where the problem lies in your script or whether there may even be a bug in the JSON UDF. In my script, I have therefore generated the query string for _JSON_Get() for each element in parallel, and when I use these with _JSON_Get(), it works as desired. Yes, that was highly unprofessional of me - I agree with you there. To me, it seemed logical to adjust the function to return a null instead of an empty string in the event of an error, so I simply changed it without further ado. Of course, I completely ignored the fact that this was a script-breaking change and didn't even mention it in the commit message. That's really not acceptable - sorry! I have therefore rolled it back in the GitHub repo.
    3 points
  4. But you could hack the NM_CUSTOMDRAW. Not so great but it is working : ; From Nine #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <WinAPI.au3> #include <FrameConstants.au3> Global Const $tagNMCUSTOMDRAWINFO = $tagNMHDR & ";dword DrawStage;handle hdc;" & $tagRECT & ";dword_ptr ItemSpec;uint ItemState;lparam lItemParam;" Global $idBut Example() Func Example() Local $hGUI = GUICreate("Example") $idBut = GUICtrlCreateButton("Test", 10, 10, 100, 30) GUICtrlCreateButton("Standard", 10, 50, 100, 30) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBut ConsoleWrite("Button was pressed" & @CRLF) EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tInfo = DllStructCreate($tagNMCUSTOMDRAWINFO, $lParam) If $tInfo.IDFrom = $idBut And $tInfo.Code = $NM_CUSTOMDRAW Then Local $tRECT = DllStructCreate($tagRECT, DllStructGetPtr($tInfo, "left")) Switch $tInfo.DrawStage Case $CDDS_PREPAINT _WinAPI_DrawFrameControl($tInfo.hDC, $tRECT, $DFC_BUTTON, (BitAND($tInfo.ItemState, $CDIS_SELECTED) ? $DFCS_PUSHED : 0) + $DFCS_BUTTONPUSH) _WinAPI_InflateRect($tRECT, -3, -3) Local $hBrush = _WinAPI_CreateSolidBrush(BitAND($tInfo.ItemState, $CDIS_HOT) ? 0xCDEF : 0xAAAA) _WinAPI_FillRect($tInfo.hDC, $tRECT, $hBrush) _WinAPI_DeleteObject($hBrush) Return $CDRF_NOTIFYPOSTPAINT Case $CDDS_POSTPAINT _WinAPI_InflateRect($tRECT, -6, -6) _WinAPI_SetTextColor($tInfo.hDC, 0xFFFFFF) _WinAPI_SetBkColor($tInfo.hDC, BitAND($tInfo.ItemState, $CDIS_HOT) ? 0xCDEF : 0xAAAA) _WinAPI_DrawText($tInfo.hDC, GUICtrlRead($tInfo.IDFrom), $tRECT, BitOR($DT_CENTER, $DT_VCENTER)) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
    2 points
  5. The displayed error msg suggests that your test script does not contain required #include MCFinclude.au3 (anymore). Without it, CodeCrypter cannot produce an encrypted version. If you have not edited helloworld.au3 yourself, then your files may be corrupted; delete everything and re-download the package from the official Autoit repository (various idiots have posted copies elsewhere; I cannot vouch for that content). I did test the helloworld example again just now, which can be encrypted without any issues, and runs normally.
    1 point
  6. Guys, I have a sincere question: AutoIt has ceased to be a purely automation language, given that many relatively large projects are written today. Why isn't the interpreter optimized? This is especially true when compared to other interpreted languages that are optimizing interpreter speed. (I'm not dissatisfied or complaining, I just had this question.)
    1 point
  7. WildByDesign, Sounds possible - I will take a look over the next few days to see how it could be done. M23
    1 point
  8. Ok, I'll give it a try: 1: Thanks 2: No it really hasn't. But did open doors to have a beautiful range of UDFs. 3: Yes, am one of those that stretch the limits with IPC, forking and creative ways to stay within just AutoIt. 4: Is basically one guy's side project. Open sourced it one but people wanted to take over and... closed sourced it out of... what else could he do. And lucky us that he didn't just close shop ( so to say ). Not nice when you share your vision and people start dreaming of "I would" left and right disregarding you ( the "inventor" and director of the thing ). It is optimized as much as possible for a single threaded design. Is as good as it is. There are teams of people in many languages and it is a job of it's own. You ( or anyone ) can code in any of a myriad of coding languages out there. At times am like, screw PHP, I'll code it in AutoIt
    1 point
  9. from the help file The destination directory path must already exist before this function is called, or the FileInstall() will fail, returning 0 and not creating the file, nor path. See DirCreate() for information about creating the directory path. I didn't see anywhere to check If Not FileExists(@TempDir& "\Meteora") Then DirCreate(@TempDir& "\Meteora") Edit: e.g. #AutoIt3Wrapper_icon=Install.ico #AutoIt3Wrapper_UseUpx=n #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> #include <File.au3> #RequireAdmin Local $sSetUpDir = @TempDir & "\MySetUp" DirRemove($sSetUpDir, 1) DirCreate($sSetUpDir) ; === FILE PRINCIPALI === DirCreate($sSetUpDir & "\Meteora") FileInstall("C:\MeteoraBuild\Alert_FXBLUE_V3.exe", $sSetUpDir & "\Meteora\Alert_FXBLUE_V3.exe", 1) FileInstall("C:\MeteoraBuild\Cockpit_FXBLUE_V3.exe", $sSetUpDir & "\Meteora\Cockpit_FXBLUE_V3.exe", 1) FileInstall("C:\MeteoraBuild\CopyTrade_ExchangeTG.exe", $sSetUpDir & "\Meteora\CopyTrade_ExchangeTG.exe", 1) FileInstall("C:\MeteoraBuild\MarketWatch_BAR_FXBLUE_V3.exe", $sSetUpDir & "\Meteora\MarketWatch_BAR_FXBLUE_V3.exe", 1) FileInstall("C:\MeteoraBuild\NtoN.exe", $sSetUpDir & "\Meteora\NtoN.exe", 1) FileInstall("C:\MeteoraBuild\Starter_V3.exe", $sSetUpDir & "\Meteora\Starter_V3.exe", 1) FileInstall("C:\MeteoraBuild\TerminalGui_FXBLUE_V3.exe", $sSetUpDir & "\Meteora\TerminalGui_FXBLUE_V3.exe", 1) FileInstall("C:\MeteoraBuild\CopyTradeV4.exe", $sSetUpDir & "\Meteora\CopyTradeV4.exe", 1) FileInstall("C:\MeteoraBuild\FXBlueQuickChannel64.dll", $sSetUpDir & "\Meteora\FXBlueQuickChannel64.dll", 1) FileInstall("C:\MeteoraBuild\sqlite3_x64.dll", $sSetUpDir & "\Meteora\sqlite3_x64.dll", 1) FileInstall("C:\MeteoraBuild\Config.ini", $sSetUpDir & "\Meteora\Config.ini", 1) FileInstall("C:\MeteoraBuild\ConfigTelegram.ini", $sSetUpDir & "\Meteora\ConfigTelegram.ini", 1) FileInstall("C:\MeteoraBuild\MarketWatchConfig.ini", $sSetUpDir & "\Meteora\MarketWatchConfig.ini", 1) ; === LANGUAGE === DirCreate($sSetUpDir & "\Meteora\Language") FileInstall("C:\MeteoraBuild\Language\Italiano.lang", $sSetUpDir & "\Meteora\Language\Italiano.lang", 1) FileInstall("C:\MeteoraBuild\Language\English.lang", $sSetUpDir & "\Meteora\Language\English.lang", 1) ; === COPYTRADE === DirCreate($sSetUpDir & "\Meteora\CopyTrade") FileInstall("C:\MeteoraBuild\CopyTrade\Italiano.lang", $sSetUpDir & "\Meteora\CopyTrade\Italiano.lang", 1) FileInstall("C:\MeteoraBuild\CopyTrade\English.lang", $sSetUpDir & "\Meteora\CopyTrade\English.lang", 1) ; === SOUND === DirCreate($sSetUpDir & "\Meteora\Sound") FileInstall("C:\MeteoraBuild\Sound\alert-33762.mp3", $sSetUpDir & "\Meteora\Sound\alert-33762.mp3", 1) ; ... (continua con tutti i file audio) ... ...
    1 point
  10. I personally don't know anything about AutoIt's internal source code. However, I am always 100% of the belief that if there is room for optimization, optimize it. Now this is really more toward the developer(s) of AutoIt. I am also quite pleased with the performance of AutoIt. I have no complaints either. But if there is room to optimize, it would certainly be appreciated. From my own perspective, I always try to get scripts and things working the way that I want first. Then I go through several rounds of finding ways to do parts of it more efficiently. Optimizing for performance and efficiency. As far as the AutoIt interpreter goes, that is beyond me of course. I do want to say one extra thing though. The "community" here surrounding AutoIt is by far one of the best I've ever seen. I would really love to see AutoIt continue to grow, thrive and expand. I came to the AutoIt scene quite late. But I love it and would be absolutely devastated if it were to cease one day. That is actually something that I've pondered over the past half-year or so. I never brought it up or anything because I feel like I am still very new here. I know that the development team is very small. But I've often wondered, what would happen if that small development team one day became unable to continue? By that, I mean like some sort of sickness, disability, passing away, etc. It's a difficult thing to talk about which is why I never brought it up. Could there be plans that, for example, if the main development team did one day become unable to continue, that possibly the source code for AutoIt could then be passed on to the community to continue the development team's dreams? Maybe that is already part of an unspoken plan in legal documents or something. It's not easy or pleasant to discuss, of course. Anyway, I've got such tremendous respect for this community. ❤️
    1 point
  11. Here my take on it : ; From Nine #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <WinAPI.au3> #include <FrameConstants.au3> Global Const $tagNMCUSTOMDRAWINFO = $tagNMHDR & ";dword DrawStage;handle hdc;" & $tagRECT & ";dword_ptr ItemSpec;uint ItemState;lparam lItemParam;" Example() Func Example() Local $hGUI = GUICreate("Example") Local $idBut = GUICtrlCreateButton("Test1", 10, 10, 100, 30) GUICtrlCreateButton("Test2", 10, 50, 100, 30) GUICtrlCreateRadio("Radio", 10, 90, 100, 30) GUICtrlCreateCheckbox("Check", 10, 130, 100, 30) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBut ConsoleWrite("Button was pressed" & @CRLF) EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tInfo = DllStructCreate($tagNMCUSTOMDRAWINFO, $lParam) If _WinAPI_GetClassName($tInfo.hWndFrom) = "Button" And IsString(GUICtrlRead($tInfo.IDFrom)) And $tInfo.Code = $NM_CUSTOMDRAW Then Local $tRECT = DllStructCreate($tagRECT, DllStructGetPtr($tInfo, "left")) Switch $tInfo.DrawStage Case $CDDS_PREPAINT _WinAPI_DrawFrameControl($tInfo.hDC, $tRECT, $DFC_BUTTON, (BitAND($tInfo.ItemState, $CDIS_SELECTED) ? $DFCS_PUSHED : 0) + $DFCS_BUTTONPUSH) _WinAPI_InflateRect($tRECT, -3, -3) Local $hBrush = _WinAPI_CreateSolidBrush(BitAND($tInfo.ItemState, $CDIS_HOT) ? 0xDEAD : 0xBEEF) _WinAPI_FillRect($tInfo.hDC, $tRECT, $hBrush) _WinAPI_DeleteObject($hBrush) Return $CDRF_NOTIFYPOSTPAINT Case $CDDS_POSTPAINT _WinAPI_InflateRect($tRECT, -6, -6) _WinAPI_SetTextColor($tInfo.hDC, 0xFFFFFF) _WinAPI_SetBkColor($tInfo.hDC, BitAND($tInfo.ItemState, $CDIS_HOT) ? 0xDEAD : 0xBEEF) _WinAPI_DrawText($tInfo.hDC, GUICtrlRead($tInfo.IDFrom), $tRECT, BitOR($DT_CENTER, $DT_VCENTER)) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
    1 point
  12. This is a UDF to use a Listview or Treeview as a File/Folder Explorer. You can also fine the TreeListExplorer UDF on Github. It allows to create a system, where a root folder can be set and that synchronizes all attached Tree or Listviews. So it is possible to attach multiple views to one system. Additionally, it is possible to add an Input Control as a View to show the current folder. When pressing {ENTER}, the system opens the path provided by the input. The following functions are available: ; #CURRENT# ===================================================================================================================== ; __TreeListExplorer_StartUp ; __TreeListExplorer_Shutdown ; __TreeListExplorer_CreateSystem ; __TreeListExplorer_DeleteSystem ; __TreeListExplorer_AddView ; __TreeListExplorer_RemoveView ; __TreeListExplorer_OpenPath ; __TreeListExplorer_Reload ; __TreeListExplorer_GetPath ; __TreeListExplorer_GetRoot ; __TreeListExplorer_GetSelected ; __TreeListExplorer_SetRoot ; =============================================================================================================================== When creating a System, a callback function can be provided to be called, when the root folder or the current folder changes. When adding a View, callback functions for single/double click at an item as well as a loading callback can be added. Example view: The Code for the Example to get a quick overview: If you like it, please leave me a comment, also if you have any suggestions to make it better or if you found bugs. I did a complete rework of this UDF (2025/03/02). Now it is easier to use and does not need external UDFs anymore. This also removes a lot of bugs, that were in the old version. It is also possible to freely select if folders and/or files should be visible in any view. Changelog: Version 1.0.0 (Old Version) Version 2.0.0 (New Version after rework) Version 2.1.0 - Rename $sCallbackOnSelect to $sCallbackOnClick - Add an additional callback $sCallbackOnSelectionChange, that is called whenever the Tree-/ListView item selection changes Version 2.2.0 - Improve loading speed for TreeView folders when expanding Version 2.3.0 - Fix some bugs where folders did not correctly expand/collapse when clicking them (when the root folder is not "" => shows all drives) - Fix some documentation - Add a method for reloading (__TreeListExplorer_Reload) the current folder (ListView/TreeView) or all folders (TreeView) - Remove the reload parameter from the __TreeListExplorer_OpenPath method (Replaced with __TreeListExplorer_Reload). - Other small internal changes Version 2.4.0 - Add the possibility to handle file/folder selections better - Files/Folders keep selected when reloading - The currently selected File/Folder can be checked with __TreeListExplorer_GetSelected - File selection is synchronized between all Tree-/Listviews, Folder selection only between ListViews (TreeView folder selection changes the current folder and expands it) - fixed minor issues Version 2.5.0 - Disabled TreeList expand with a single click and changed it to a double click - Selection is now synchronized for all files/folders between all views (Tree-/ListView) - The Selection callback is now moved from __TreeListExplorer_AddView to __TreeListExplorer_CreateSystem and only fires ones per change for the system and not for every view (as it was before) - All callbacks were changed to pass the selected folder and some additional information is now provided (clicked index/item, the loading path,...) - Small performance improvements - Some internal restructuring Version 2.5.1 - Fixed: selection not working for drives Version 2.6.0 - Added support for icons of all file extensions for TreeViews and ListViews. Version 2.7.0 - Input controls are now possible as a view. They show the current folder and when pressing {ENTER} inside, the system tries to open the path show in the input. - Changed the behavior of the treeview when clicking items. They now change the current folder, but are not expanded. This changes the folder in the ListView, when clicking a folder in the TreeView. Version 2.7.1 - Clicking on the Bitmap of a TreeView item is now registered as a click (not just the text like before) - Fixed a missing selection update when clicking on a TreeView item Version 2.7.2 - Add parameter for setting the (file-/folder-)icon size on startup Version 2.8.0 - TreeView selection is now triggering the select event and the $sSelect corresponds to the selected folder/file. NOTE: __TreeViewExplorer_GetSelected will be empty, if the selection is a folder in a treeview - Selection handling was improved, especially the synchronization between TreeView and ListView - Add keyboard navigation to the listview - Fixed a bug, where the icon index was sent as event (GuIGetMsg), when an item was clicked (happens without the udf message handling, so it needed a workaround: suppress the default autoit handler for mouseclicks) Version 2.8.1 - Fixed a bug, where the select callback was sometimes not send correctly Version 2.9.0 - Fixed bug for TreeViews, where folders were shown as expandable, when having only files but no folders, even if showing files was turned of - rework how treeviews are filled/updated/expanded (folders that are expanded will stay expanded on reload) - add the possibility to set a depth limit for the treeview (Example: Drive selection with $sRoot="" and $iMaxDepth=0) - Fixed bug for Arrow selection in the ListView to not trigger a click event anymore - When the open folder or the selection changed, the TreeView checks, if it still exists (=> treeview updates, if a folder was deleted) Version 2.9.1 - Workaround for a Bug in the GuiTreeView UDF (until it is fixed), causing random control deletions instead of TreeView item deletions Version 2.9.3 - Fixed custom icon size when extracting icons Version 2.9.4 - Improved display quality for some icons (Thanks WildByDesign for the work on that) - Fixed an issue, where cached file icons for individual files were shown as a folder Version 2.9.5 - Improved display quality for some icons (When resource files are defined in the registry, the one with the size greater or equal to the required icon size will be choosen) Version 2.10.0 - Added the possibility to filter ListViews/TreeViews with a callback function. This callbackfunction is called for every file/folder and only if it returns True, will they be added to the view. - Added the possibility to set $bNavigate for ListViews when adding them. This enables or disables the possibility to navigate through folders with doubleclicks in a ListView (and add/removes the ".." folder at the top, which enables the user to navigate to the parent folder) Version 2.10.1 - Added the WinAPIConstants.au3 include to fix missing constants due to changes with the new AutoIt-Version (v3.3.18.0) Special thanks to @WildByDesign for a lot of testing to help improving this UDF. TreeListExplorer.au3 TreeListExplorer-Example.au3
    1 point
  13. Thank you for following up. I am likely going to start another project with your UDF, so I figured that I should mention the discussion about the map bug. For what it’s worth, my previous large project that uses your UDF has not experienced any problems at all. And you are right, it makes sense to wait until a fix in AutoIt.
    1 point
  14. Since I first posted I've seen the menu working correctly and then not. I think it's alright for a while after each reboot.
    1 point
  15. Hi, yes, I saw that and it may impact this UDF. But to the best of my knowledge, the probability should be rather slim. The Integer/String mixup is not happening, because I am using one data type per map (as key) and the hashes are not simple/short numbers, but larger/more complex (CtrlIDs/Strings/...) The more concerning part would be the sharing of memory between multiple maps, because I use the same Map keys rather often... but I did not see any problems until now, so it is probably not affected. Overall, I do not really see a way for me to address this without a complete rewrite with DllStructs or something (I used maps instead, because it is easier and similarily fast and provides a better coding experience then using array indices, e.g. numbers instead of telling names) and it is a bug that should be addressed at the autoit level and probably will be (or already is for future versions, according to the bug tracker)... So unless some specific problem pops up, I would leave it as it is and wait for the fix in the language (which needs to be done anyway). Its not a specific edge case only affecting this UDF.
    1 point
  16. ioa747 THANK YOU SO MUCH! your reply was clear, concise, and it worked immediately. 💯💫 My old "evolving" system is back like new again! "evolving" = dinosaur prototype
    1 point
  17. Sadly you cannot modify the font of a button with NM_CUSTOMDRAW. As per MSDN, you need to inform the parent with CDRF_NEWFONT (This occurs when dwDrawStage equals CDDS_ITEMPREPAINT). To tell that you want an item prepaint, you need to use CDRF_NOTIFYITEMDRAW (This occurs when dwDrawStage equals CDDS_PREPAINT). However the use CDRF_NOTIFYITEMDRAW does not trigger a new drawing stage with a button, as buttons don't have item...
    1 point
  18. Thanks! I'll take that as the official answer back to Grok. I just wanted to make sure it wasn't something I was missing. Grok was really doing a bit of hallucinating telling me he had run the code and it worked. He isn't able to run anything but python in a sandbox. Also tell me it had been used "thousands" of times before. Anyway thanks again for taking the time to answer.
    1 point
  19. MattyD

    Round buttons

    No problems ! You're probably better off with Nine's solution for this one though WM_DRAWITEM doesn't look to trigger when hot-tracking a button. There is a "hover" flag $ODS_HOTLIGHT - but its only useful for menu and listview controls apparently.
    1 point
  20. No. You have to own the GUI. You don't own the hidden window. I guess you're gonna have to go to, as hard as it is, GUICreate() one.
    1 point
  21. Debug-console version of AutoIt3.exe and AutoIt3_x64.exe? I want to test my script (it already passes Au3Check.exe) by running it through CMD, and I want any errors (crashes, syntax errors, array index issues, invalid assignments, etc.) to be printed directly to the console instead of stopping the program and showing an error message box. Those pop-up error dialogs make debugging difficult because I have to switch back to SciTE every time. What I’m asking for is a console-mode debug version of AutoIt3.exe/AutoIt3_x64.exe that, when an error occurs, prints the error to the console and exits immediately with a non-zero exit code. And with compiled scripts too, is it possible to print a message on console instead of showing it?
    1 point
  22. ok, my bad I guess ( because I didn't test with errors as my code is always perfect ) AutoItCui.bat: @Echo OFF :: AutoItCui.bat ; name of the batch file that runs Autoit3cui Autoit3cui /ErrorStdOut /AutoIt3ExecuteScript %* echo rc:%errorlevel% With the above batch file you'd run your script. Say: Opt("SetExitCode",1) Global $a[1] $a[1] = 1 and the output would be: >Autoitcui MyFlaw.au3 "D:\Utilities\AutoIt3\MyFlaw.au3" (3) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $a[1] = 1 ^ ERROR rc:2147479674 were the 2147479674 errorlevel in hex is 0x7FFFF07A. So the code I posted in the beginning is all that is really needed.
    1 point
  23. I have neglected to update the changelog and sources here again. I think that is mostly due to the fact that I just haven't slowed down with it at all yet. I haven't had a moment in between releases and just keep on improving it. So since it was last updated, its gone from 1.5.0 to 2.0.0 with 11 releases in between. If you want to see all of the details, the first post has been updated with all of the changelog details. Or check the Immersive UX repo to see the actual changes with each release if needed. I will try to summarize some of the more significant changes: The engine is multi-process now to benefit performance and especially with precise timing needed Broker process added to manage the various engine processes WCD_IPC UDF by @Nine used to communicate between GUI process and engine process Allows non-elevated GUI to control elevated engine processes Live Wallpaper functionality has been added to the engine (separate engine process, not enabled by default) Live Wallpaper requires <maxversiontested Id="10.0.18362.1"/> added to AutoIt binaries manifest files (see ExternalManifest.au3 below) All Immersive UX GUI colors can be changed in the configuration file GUI now has a beautiful menubar to control most of the options GUI now tracks rule changes to notify user to save (or not) Option to Revert Changes if user does not want to save those changes The entire Immersive UX GUI is completely reactive to the theme used, the desktop wallpaper set and also depending on whether Blur is enabled or one of the Windows 11 materials such as Mica, Mica Alt, Acrylic, etc. Screenshot: ExternalManifest.au3
    1 point
  24. Hi @Trong. The issue is the way AutoIt3.exe does outputs from it's runtime My suggestion is based on this: https://stackoverflow.com/a/54252275 "D:\Downloads\autoit-v3.3.16.1\install\AutoIt3.exe" /ErrorStdOut "D:\Downloads\autoit-v3.3.16.1\install\test.au3" 2>&1|more this was my test script: ConsoleWrite("ConsoleWriteTest"&@crlf) Local $x[1] $x[10] = 9 MsgBox(0, "aya", "yay") and here is the result:
    1 point
  25. I had a similar problem a long time ago. A server application started my script. In rare cases, the script crashed due to faulty data. Trancexx helped me with this code.
    1 point
  26. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icons\au3script_v9.ico #AutoIt3Wrapper_Outfile=Autoit3cui.exe #AutoIt3Wrapper_Outfile_x64=AutoIt3_x64cui.exe #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.1 Author: myName #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here FileChangeDir(@ScriptDir) ; my AutoIt is installed there Opt("TrayAutoPause", 0) ; Script pauses when click on tray icon = OFF/0 Opt("TrayOnEventMode", 0) ; Enable/disable OnEvent functions notifications for the tray = OFF/0 Opt("GUICloseOnESC", 1) ; When ESC is pressed on a GUI the $GUI_EVENT_CLOSE message is sent = ON/1 #pragma compile(Console, True) #pragma compile(AutoItExecuteAllowed, True) ..also used the above and instead of running a script with AutoIt3.exe, I would run it with Autoit3cui.exe If these cui versions are in the same folder as AutoIt3.exe, all will be running just fine.
    1 point
  27. SciTE don't get those popups. They run with "/ErrorStdOut." Then you also have Opt("SetExitCode",1) 1 = Set @exitCode on Fatal error - see Exitcodes. If that is not enough then, let me know. P.S.: I really like the open source code you're integrating. Like really really like it. Thanks for that 💯
    1 point
  28. save your script with UTF-8 encoding Edit: and change _WinWaitActivate("classname=Shell_TrayWnd","") to _WinWaitActivate("[CLASS:Shell_TrayWnd]","")
    1 point
  29. The Open Hardware Monitor is a free open source software that monitors temperature sensors, fan speeds, voltages, load and clock speeds of a computer. I found this has a WMI implementation ( http://openhardwaremonitor.org/documentation/ ) and thought it would be nice to post here. Some code to get started on Hardware ; Generated by AutoIt ScriptOMatic ; Hardware $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $OutputTitle = "" $Output = "" $Output = $Output & '<html><head><title>ScriptOMatic HTML Output</title></head><body> <style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Property </th><th> Value </th></tr>' $OutputTitle &= '<tr bgcolor="yellow"><td>' & "Computer</td><td>&nbsp;" & $strComputer & "</td></tr>" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\OpenHardwareMonitor") $colItems = $objWMIService.ExecQuery("SELECT * FROM Hardware", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then Local $Object_Flag = 0 For $objItem In $colItems $Object_Flag = 1 $Output &= "<tr><td>HardwareType</td><td>&nbsp;" & $objItem.HardwareType & "</td></tr>" & @CRLF $Output &= "<tr><td>Identifier</td><td>&nbsp;" & $objItem.Identifier & "</td></tr>" & @CRLF $Output &= "<tr><td>InstanceId</td><td>&nbsp;" & $objItem.InstanceId & "</td></tr>" & @CRLF $Output &= "<tr><td>Name</td><td>&nbsp;" & $objItem.Name & "</td></tr>" & @CRLF $Output &= "<tr><td>Parent</td><td>&nbsp;" & $objItem.Parent & "</td></tr>" & @CRLF $Output &= "<tr><td>ProcessId</td><td>&nbsp;" & $objItem.ProcessId & "</td></tr>" & @CRLF Next If $Object_Flag = 0 Then Msgbox(1,"WMI Output",$OutputTitle) FileWrite(@TempDir & "\Hardware.HTML", $Output ) Run(@Comspec & " /c start " & @TempDir & "\Hardware.HTML" ) Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Hardware" ) Endif Some code to get started on Sensor ; Generated by AutoIt ScriptOMatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $OutputTitle = "" $Output = "" $Output = $Output & '<html><head><title>ScriptOMatic HTML Output</title></head><body> <style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Property </th><th> Value </th></tr>' $OutputTitle &= '<tr bgcolor="yellow"><td>' & "Computer</td><td>&nbsp;" & $strComputer & "</td></tr>" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\OpenHardwareMonitor") $colItems = $objWMIService.ExecQuery("SELECT * FROM Sensor", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then Local $Object_Flag = 0 For $objItem In $colItems $Object_Flag = 1 $Output &= "<tr><td>Identifier</td><td>&nbsp;" & $objItem.Identifier & "</td></tr>" & @CRLF $Output &= "<tr><td>Index</td><td>&nbsp;" & $objItem.Index & "</td></tr>" & @CRLF $Output &= "<tr><td>InstanceId</td><td>&nbsp;" & $objItem.InstanceId & "</td></tr>" & @CRLF $Output &= "<tr><td>Max</td><td>&nbsp;" & $objItem.Max & "</td></tr>" & @CRLF $Output &= "<tr><td>Min</td><td>&nbsp;" & $objItem.Min & "</td></tr>" & @CRLF $Output &= "<tr><td>Name</td><td>&nbsp;" & $objItem.Name & "</td></tr>" & @CRLF $Output &= "<tr><td>Parent</td><td>&nbsp;" & $objItem.Parent & "</td></tr>" & @CRLF $Output &= "<tr><td>ProcessId</td><td>&nbsp;" & $objItem.ProcessId & "</td></tr>" & @CRLF $Output &= "<tr><td>SensorType</td><td>&nbsp;" & $objItem.SensorType & "</td></tr>" & @CRLF $Output &= "<tr><td>Value</td><td>&nbsp;" & $objItem.Value & "</td></tr>" & @CRLF Next If $Object_Flag = 0 Then Msgbox(1,"WMI Output",$OutputTitle) FileWrite(@TempDir & "\Sensor.HTML", $Output ) Run(@Comspec & " /c start " & @TempDir & "\Sensor.HTML" ) Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Sensor" ) Endif have fun.
    1 point
  30. ioa747

    SciTE_OverlayTab

    SciTE_OverlayTab Highlighting the active & unsaved tab item in SciTE Inspired from 211131-highlighting-the-active-tab-item-in-scite/ (Thanks to BugFix 🏆) While the original was excellent, I found that I needed to change some things. Since I made these adjustments, I decided to share the revised code. ; https://www.autoitscript.com/forum/topic/213330-scite_overlaytab/ ;-------------------------------------------------------------------------------------------------------------------------------- ; Title...........: SciTE_OverlayTab.au3 ; Description.....: Highlighting the active & unsaved tab item in SciTE ; AutoIt Version..: 3.3.18.0 Author: ioa747 Script Version: 0.4 ; Note............: Testet in Windows 11 Pro 24H2 Date:17/11/2025 ; Inspired by.....: https://www.autoitscript.com/forum/topic/211131-highlighting-the-active-tab-item-in-scite ;-------------------------------------------------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GuiTab.au3> #include <Misc.au3> #include <WinAPISysWin.au3> #include <WindowsStylesConstants.au3> Opt('TrayIconHide', 1) _Singleton(@ScriptName) OnAutoItExitRegister(_Exit) ; Colors Const Global Const $g_hActiveColor = 0x0026FF ; 0x0026FF Blue Global Const $g_hUnSavedColor = 0xFF6A00 ; 0xFF6A00 Orange Global Const $g_iOpacity = 40 ; Set Overlay transparency to 40% opacity ; Global Variables Global $g_aOverlayHwnd[0] ; Array to store Hwnd of the overlays. Index in this array corresponds to the SciTE tab index. Global $g_SciTE_Handle = WinGetHandle('[CLASS:SciTEWindow]') If @error Then Exit ;~ While True While WinExists($g_SciTE_Handle) _SciTEState() Sleep(250) WEnd ;~ Sleep(1000) ;~ $g_SciTE_Handle = WinGetHandle('[CLASS:SciTEWindow]') ;~ WEnd ;--------------------------------------------------------------------------------------- Func _Exit() _DestroyAllOverlays() ; Destroy all overlays Exit EndFunc ;==>_Exit ;--------------------------------------------------------------------------------------- Func _SciTEState() ; Retrieve the state of the SciTEWindow. Local $iState = WinGetState($g_SciTE_Handle) Switch $iState Case 15, 47 ; exists+visible+enabled+active +maximized _UpdateTabOverlays() Case Else Sleep(250) EndSwitch EndFunc ;--------------------------------------------------------------------------------------- Func _UpdateTabOverlays() Local $hTab = _GetHwnd_SciTeTabCtrl() Local $iOldCount = UBound($g_aOverlayHwnd) If @error Then ; If the Tab Control is lost, destroy all existing overlays. If $iOldCount > 0 Then _DestroyAllOverlays() Return SetError(1) EndIf Local $iActive = _GUICtrlTab_GetCurFocus($hTab) Local $iCount = _GUICtrlTab_GetItemCount($hTab) If $iCount = 0 Then ; If the Tab Control is found but contains zero tabs, we must clean up any remaining overlays. If $iOldCount > 0 Then _DestroyAllOverlays() Return SetError(2) EndIf ; Array Cleanup and Resize If $iCount < $iOldCount Then ; Tab count decreased: Destroy overlays corresponding to the missing tabs (from iCount up to iOldCount-1) For $i = $iCount To $iOldCount - 1 If IsHWnd($g_aOverlayHwnd[$i]) Then GUIDelete($g_aOverlayHwnd[$i]) Next ReDim $g_aOverlayHwnd[$iCount] ; Resize the array to the new, smaller tab count ElseIf $iCount > $iOldCount Then ReDim $g_aOverlayHwnd[$iCount] ; Tab count increased: Resize the array to accommodate new tabs EndIf ; Update/Create necessary overlays For $i = 0 To $iCount - 1 Local $sItemText = _GUICtrlTab_GetItemText($hTab, $i) Local $tRect = _GUICtrlTab_GetItemRectEx($hTab, $i) Local $iColor = 0 ; 0 means no custom coloring is needed (Saved & Inactive) Local $hOverlay = $g_aOverlayHwnd[$i] ; Get the existing handle If $i = $iActive Then $iColor = $g_hActiveColor ; Active Tab ElseIf StringRight($sItemText, 1) = '*' Then $iColor = $g_hUnSavedColor ; Unsaved Tab EndIf If $iColor <> 0 Then ; Create or Update Overlay $g_aOverlayHwnd[$i] = _CreateOrUpdateOverlay($hTab, $i, $tRect, $iColor, $hOverlay) Else ; Destroy unnecessary overlay (if it's saved and inactive) If IsHWnd($hOverlay) Then GUIDelete($hOverlay) $g_aOverlayHwnd[$i] = 0 ; Reset array element EndIf EndIf Next EndFunc ;==>_UpdateTabOverlays ;--------------------------------------------------------------------------------------- Func _CreateOrUpdateOverlay($hTab, $iIndex, $tRectItem, $iColor, $hExistingOverlay) ; Calculates coordinates and creates/updates the transparent GUI. Local $iLeft = $tRectItem.Left Local $iTop = $tRectItem.Top Local $iWidth = $tRectItem.Right - $tRectItem.Left Local $iHeight = $tRectItem.Bottom - $tRectItem.Top Local $tPoint = DllStructCreate("int X;int Y") DllStructSetData($tPoint, "X", $iLeft) DllStructSetData($tPoint, "Y", $iTop) ; Convert client coordinates (relative to hTab) to screen coordinates _WinAPI_ClientToScreen($hTab, $tPoint) Local $iScrX = $tPoint.X Local $iScrY = $tPoint.Y Local $hOverlay = $hExistingOverlay If Not IsHWnd($hOverlay) Then ; Create the overlay GUI Local $sTitle = 'OverlayTab_' & $iIndex $hOverlay = GUICreate($sTitle, $iWidth, $iHeight, $iScrX, $iScrY, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE, $WS_EX_TRANSPARENT), $hTab) GUISetBkColor($iColor) WinSetTrans($hOverlay, "", $g_iOpacity) ; Set transparency to 40% opacity GUISetState(@SW_SHOWNOACTIVATE, $hOverlay) ; Show without activating Else ; Update existing overlay GUI WinMove($hOverlay, "", $iScrX, $iScrY, $iWidth, $iHeight) ; Move and resize it GUISetBkColor($iColor, $hOverlay) ; Update color EndIf Return $hOverlay EndFunc ;==>_CreateOrUpdateOverlay ;--------------------------------------------------------------------------------------- Func _DestroyAllOverlays() ; Destroys all currently tracked overlay GUIs. For $i = 0 To UBound($g_aOverlayHwnd) - 1 Local $hOverlay = $g_aOverlayHwnd[$i] If IsHWnd($hOverlay) Then GUIDelete($hOverlay) Next ReDim $g_aOverlayHwnd[0] ; Reset the array EndFunc ;==>_DestroyAllOverlays ;--------------------------------------------------------------------------------------- Func _GetHwnd_SciTeTabCtrl() ; Local $hScite = WinGetHandle('[CLASS:SciTEWindow]') ; If @error Then Return SetError(1, 0, Null) Local $aChild, $hWndTab = Null $aChild = _WinAPI_EnumChildWindows($g_SciTE_Handle) If Not @error Then For $i = 1 To $aChild[0][0] If $aChild[$i][1] = "SciTeTabCtrl" Then $hWndTab = $aChild[$i][0] ExitLoop EndIf Next EndIf Return SetError(($hWndTab = Null ? 1 : 0), 0, $hWndTab) EndFunc ;==>_GetHwnd_SciTeTabCtrl ;--------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much
    1 point
  31. Trong

    Delayed MouseClick()

    Because you are working on another software, you are operating that software to receive events that need time to process so you need to rest (although it is not correct, it should be confirmed by checking whether a window or some text appears before performing the action instead of just stopping for a moment)
    1 point
  32. @mr-es335 You are absolutely right in thinking about arrays! Here is the optimal way to combine similar functions: Difference Analysis Between Preset 002 and 003, there are only 2 differences: Preset number (002 vs 003) - appears in the function name and text Y mouse click coordinate in ConfigurePresetXXXAmpSimView(): 544 vs 564 Combination solution: #include <AutoItConstants.au3> Opt("MustDeclareVars", 1) Global $iTimeOut = 100 Global $iX = 885, $iY = 222 ; Configuration for each preset Global $aPresetConfig[4][3] = [ _ ["002", 544], _ ["003", 564], _ ["004", 584], _ ; Example of adding new preset ["005", 604] _ ] ; Run preset 002 CreatePresetScene("002") ; Runpreset 003 CreatePresetScene("003") Func CreatePresetScene($sPresetNum) Local $iYCoord = GetPresetYCoord($sPresetNum) If $iYCoord = -1 Then Return SetError(1, 0, 0) ConfigureAmpSimView($iYCoord) ConfigureFMixerView() UpdateScenesView($sPresetNum, $iX, $iY) UpdateSceneProperties($iX, $iY) EndFunc Func GetPresetYCoord($sPresetNum) For $i = 0 To UBound($aPresetConfig) - 1 If $aPresetConfig[$i][0] = $sPresetNum Then Return $aPresetConfig[$i][1] Next Return -1 EndFunc Func ConfigureAmpSimView($iYCoord) Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 534, $iYCoord, 2, 0) EndFunc Func ConfigureFMixerView() Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 50, 120, 1, 0) EndFunc Func UpdateScenesView($sPresetNum, $iX, $iY) Local $hSAC_SCENES = "[CLASS:SAC_SCENES]" WinActivate($hSAC_SCENES) Send("{End}") Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0) Sleep($iTimeOut) ClipPut("Preset " & $sPresetNum) Send("^v") ; Ctrl+V ngắn gọn hơn Send("{ENTER}") EndFunc Func UpdateSceneProperties($iX, $iY) Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]" Sleep(1500) Send("{ENTER}") EndFunc Advantages Adding new presets is easy: Just add 1 line to $aPresetConfig Compact code: From ~90 lines to ~50 lines Easy to maintain: Fixing logic only needs to be done in 1 place instead of multiple functions If there are more different parameters If the preset has more different coordinates, extend the array: Global $aPresetConfig[][] = [ _ ["002", 544, 50, 120], _ ; [preset, yCoord, xMixer, yMixer] ["003", 564, 50, 120] _ ]
    1 point
  33. Another logic, which could be, is to store the Presets or a grouped job in a Section, from an .ini file, (which is also an array) with the format [Preset 002] ConfigureAmpSimView=534 ConfigureFMixerView= UpdateScenesView=Preset 002|885|222 UpdateSceneProperties=885|222 [Preset 003] ConfigureAmpSimView=564 ConfigureFMixerView= UpdateScenesView=Preset 003|885|222 UpdateSceneProperties=885|222 [Open Amp] ... ... and then instead of calling the CallPresetScene() function, change it to one for all, e.g. CallSection() CallPresetScene($aPresets[0][0], $aPresets[0][1], $aPresets[0][2], $aPresets[0][3]) ; 🔔 Preset 002 ; you could call CallSection("Preset 002")
    1 point
  34. water

    Debug Messages Monitor UDF

    Added this UDF to the wiki
    1 point
  35. This is pure gold! The IsProcessElevated() function is also fantastic. Thank you so much. As you said, it works perfectly on x86 and x64. By the way, related to this, I was able to integrate your WCD_IPC UDF into my engine script which is actually a multi-process engine. Your UDF was the only one light enough and fast enough to do the job. I actually ended up creating a "broker" process for my multi-process engine and that is where I put your IPC server function. And now with the help of your RunLow() function, I can drop the privileges of the GUI and the GUI can still control the elevated "broker" process and therefore also control the various processes. Your willingness to help combined with your abilities to educate others on this forum are absolutely top-notch!
    1 point
  36. Here (tested both x86 and x64) ; From Nine #RequireAdmin #AutoIt3Wrapper_UseX64=y #include <WinAPI.au3> Example() Func Example() Local $iPID = RunLow(@ComSpec, " /k Title Low") ConsoleWrite($iPID & " : " & IsProcessElevated($iPID) & @CRLF) EndFunc ;==>Example Func IsProcessElevated($iPID) Local $aRet, $iError = 0 Local $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, False, $iPID, True) If Not $hProcess Then Return SetError(1, 0, False) Local $hToken = _WinAPI_OpenProcessToken($TOKEN_QUERY, $hProcess) If Not $hToken Then $iError = 2 Else $aRet = DllCall('advapi32.dll', 'bool', 'GetTokenInformation', 'handle', $hToken, 'uint', 20, 'uint*', 0, 'dword', 4, 'dword*', 0) ; TOKEN_ELEVATION If @error Or Not $aRet[0] Then $iError = 3 EndIf _WinAPI_CloseHandle($hToken) _WinAPI_CloseHandle($hProcess) If $iError Then Return SetError($iError, 0, False) Return $aRet[3] = 1 EndFunc ;==>IsProcessElevated Func RunLow($sPath, $sCmd = "") Local $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION, False, ProcessExists("explorer.exe")) Local $hToken = _WinAPI_OpenProcessToken($TOKEN_DUPLICATE, $hProcess) Local $hDupToken = _WinAPI_DuplicateTokenEx($hToken, $TOKEN_ALL_ACCESS, $SECURITYIMPERSONATION) Local $tSTARTUPINFO = DllStructCreate($tagSTARTUPINFO) $tSTARTUPINFO.Size = DllStructGetSize($tSTARTUPINFO) Local $tPROCESS = DllStructCreate($tagPROCESS_INFORMATION) _WinAPI_CreateProcessWithToken($sPath, $sCmd, 0, $tSTARTUPINFO, $tPROCESS, $hDupToken) _WinAPI_CloseHandle($hDupToken) _WinAPI_CloseHandle($hToken) _WinAPI_CloseHandle($hProcess) Return $tPROCESS.ProcessID EndFunc ;==>RunLow
    1 point
  37. I have removed the redundant - or, non-essential lines...which are implemented in "other" scripts...but of which are NOT required here. Thanks for the clarification....
    1 point
  38. It could be something like this. #include <AutoItConstants.au3> Opt("MustDeclareVars", 1) Global $iTimeOut = 100 ; **** Preset Configuration Array **** ; This is a 2D array holding all the data that changes between presets. ; Column 0: Preset Name - e.g. "Preset 002" ; Column 1: AmpSimView MouseClick Y-coordinate - e.g. 544 or 564 ; Column 2: Mouse positioning X-coordinate - e.g. 885 ; Column 3: Mouse positioning Y-coordinate - e.g. 222 Global $aPresets[2][4] = [ _ ["Preset 002", 544, 885, 222], _ ["Preset 003", 564, 885, 222] _ ] CallPresetScene($aPresets[0][0], $aPresets[0][1], $aPresets[0][2], $aPresets[0][3]) ; 🔔 Preset 002 ;~ CallPresetScene($aPresets[1][0], $aPresets[1][1], $aPresets[1][2], $aPresets[1][3]) ; 🔔 Preset 003 ; ... ; ------------------------------------------------------------------------------ Func CallPresetScene($sPresetName, $iAmpSimY, $iMPosX, $iMPosY) ConfigureAmpSimView($sPresetName, $iAmpSimY) ConfigureFMixerView() UpdateScenesView($sPresetName, $iMPosX, $iMPosY) UpdateSceneProperties($iMPosX, $iMPosY) EndFunc ;==>CallPresetScene ; ------------------------------------------------------------------------------ Func ConfigureAmpSimView($sPresetName, $iMPosY) Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 534, $iMPosY, 2, 0) EndFunc ;==>ConfigureAmpSimView ; ------------------------------------------------------------------------------ Func ConfigureFMixerView() Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 50, 120, 1, 0) ; Select: Channel Label [ZMixer] EndFunc ;==>ConfigureFMixerView ; ------------------------------------------------------------------------------ Func UpdateScenesView($sPresetName, $iMPosX, $iMPosY) Local $hSAC_SCENES = "[CLASS:SAC_SCENES]" WinActivate($hSAC_SCENES) Send("{End}") ; Select: [End Of List] Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0) ; Select: [New] Sleep($iTimeOut) ClipPut($sPresetName) ; Copy the variable Preset Name ; Paste text Send("{CTRLDOWN}") Send("v") Send("{CTRLUP}") Send("{ENTER}") ; Select: [Ok] EndFunc ;==>UpdateScenesView ; ------------------------------------------------------------------------------ Func UpdateSceneProperties($iMPosX, $iMPosY) Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]" Sleep(1500) Send("{ENTER}") ; Select: [OK] EndFunc ;==>UpdateSceneProperties ; ------------------------------------------------------------------------------ Edit: It reflects the idea more. Because it has some problems, which stem from your examples. Like Func UpdatePreset002SceneProperties($iX, $iY) Func UpdatePreset003SceneProperties($iX, $iY) there are parameters $iX, $iY, but you don't use them anywhere in the function Func UpdatePreset002ScenesView($iX, $iY) Func UpdatePreset003ScenesView($iX, $iY) there are parameters $iX, $iY, but you don't use them anywhere in the function
    1 point
  39. WinSockUDF - TCP/UDP Networking Library for AutoIt Version: 1.1 | Author: Dao Van Trong - TRONG.PRO | AutoIt: 3.3.14.2+ 📖 Overview WinSockUDF is a powerful, production-ready TCP/UDP networking library for AutoIt that brings enterprise-level networking capabilities to your scripts. Built on top of the Windows Sockets API (Winsock2), it provides asynchronous, event-driven communication with advanced features that go far beyond AutoIt's built-in networking functions. This library is designed for developers who need reliable, high-performance network communication in their AutoIt applications - whether you're building chat systems, file transfer utilities, remote administration tools, or IoT device controllers. ⚡ Key Features Core Networking ✅ Asynchronous Event-Driven Architecture - True non-blocking I/O with elegant callback system ✅ Full Winsock2 API Access - Direct Windows Sockets implementation for maximum performance ✅ TCP Server & Client - Production-ready server with multi-client support ✅ UDP Support - Connectionless datagram communication (SendTo/RecvFrom) ✅ Multiple Simultaneous Connections - Handle hundreds of clients with ease Advanced Features 🔒 Binary Data Transfer - Safe transmission with automatic Base64 encoding/decoding 🎯 Smart Connection Management - Automatic reconnection, timeouts, and error recovery 📡 Broadcasting - Send messages to all connected clients instantly 🔍 Client Management - Track, query, and control individual client connections ⚙️ Flexible Event System - Register custom callbacks for all network events Developer Experience 📚 Comprehensive Error Handling - Detailed @error/@extended codes for debugging 🎨 Clean API Design - Intuitive function names and consistent parameter patterns 📝 Well Documented - Complete function reference with examples 🚀 Production Ready - Battle-tested in real-world applications 📦 Installation Method 1: Quick Start Download WinSockUDF.au3 from this repository Place it in your AutoIt include directory (usually C:\Program Files (x86)\AutoIt3\Include) Include it in your script: #include <WinSockUDF.au3> Method 2: Project-Local Copy WinSockUDF.au3 to your project folder Include with relative path: #include "WinSockUDF.au3" Requirements: AutoIt v3.3.14.2 or higher Windows OS (XP or later) No external dependencies required Quick Start TCP Server Example #include "WinSockUDF.au3" _TCP_Startup() ; Create server on port 8080 $hServer = _TCP_Server_Create(8080) ; Register event callbacks _TCP_Server_OnNewClient($hServer, "OnNewClient") _TCP_Server_OnReceive($hServer, "OnReceive") _TCP_Server_OnDisconnect($hServer, "OnDisconnect") ; Event loop While 1 Sleep(10) WEnd Func OnNewClient($hClient, $iError) ConsoleWrite("New client connected: " & $hClient & @CRLF) _TCP_Send($hClient, "Welcome to server!" & @CRLF) EndFunc Func OnReceive($hClient, $sData, $iError) ConsoleWrite("Received: " & $sData & @CRLF) _TCP_Send($hClient, "Echo: " & $sData) EndFunc Func OnDisconnect($hClient, $iError) ConsoleWrite("Client disconnected: " & $hClient & @CRLF) EndFunc TCP Client Example #include "WinSockUDF.au3" _TCP_Startup() ; Connect to server $hClient = _TCP_Client_Create("127.0.0.1", 8080) ; Register event callbacks _TCP_Client_OnConnect($hClient, "OnConnect") _TCP_Client_OnReceive($hClient, "OnReceive") _TCP_Client_OnDisconnect($hClient, "OnDisconnect") ; Event loop While 1 Sleep(10) WEnd Func OnConnect($hSocket, $iError) If $iError Then ConsoleWrite("Connection failed: " & $iError & @CRLF) Else ConsoleWrite("Connected successfully!" & @CRLF) _TCP_Send($hSocket, "Hello Server!") EndIf EndFunc Func OnReceive($hSocket, $sData, $iError) ConsoleWrite("Received: " & $sData & @CRLF) EndFunc Func OnDisconnect($hSocket, $iError) ConsoleWrite("Disconnected from server" & @CRLF) EndFunc Function Reference Initialization Functions Function Description _TCP_Startup() Initialize Winsock and async system _TCP_Shutdown() Close all connections and free resources TCP Server Functions Function Description _TCP_Server_Create($iPort[, $sIP = "0.0.0.0"[, $iMaxPending = 5]]) Create TCP server _TCP_Server_Stop($hSocket) Stop server and close all clients _TCP_Server_ClientList() Get array of connected clients _TCP_Server_ClientIP($hSocket) Get client IP address _TCP_Server_DisconnectClient($hSocket) Disconnect specific client _TCP_Server_Broadcast($vData) Send data to all clients _TCP_Server_OnNewClient($hServer, $sCallback) Register new client callback _TCP_Server_OnReceive($hServer, $sCallback) Register receive callback _TCP_Server_OnSend($hServer, $sCallback) Register send ready callback _TCP_Server_OnDisconnect($hServer, $sCallback) Register disconnect callback TCP Client Functions Function Description _TCP_Client_Create($sIP, $iPort[, $sSourceIP = ""[, $iSourcePort = 0[, $iTimeout = 0]]]) Create TCP client connection _TCP_Client_Stop($hSocket) Close client connection _TCP_Client_OnConnect($hClient, $sCallback) Register connect callback _TCP_Client_OnReceive($hClient, $sCallback) Register receive callback _TCP_Client_OnSend($hClient, $sCallback) Register send ready callback _TCP_Client_OnDisconnect($hClient, $sCallback) Register disconnect callback Common TCP Functions Function Description _TCP_Send($hSocket, $vData[, $iFlag = 0]) Send data through socket _TCP_Recv($hSocket, $iMaxLen[, $iFlag = 0]) Receive data from socket _TCP_Send_Ex($hSocket, $vData[, $iFlag = 0]) Send with automatic Base64 encoding _TCP_Recv_Ex($hSocket, $iMaxLen[, $iFlag = 0]) Receive with automatic Base64 decoding _TCP_NameToIP($sName) Convert hostname to IP address _TCP_GetIPs([$sServerName = ""]) Get local and public IP addresses UDP Functions Function Description _UDP_Startup() Initialize UDP system _UDP_Shutdown() Shutdown UDP system _UDP_Bind([$sSourceIP = ""[, $iSourcePort = 0]]) Create and bind UDP socket _UDP_SendTo($sIP, $iPort, $vData[, $hSocket = 0]) Send UDP packet _UDP_RecvFrom($hSocket, $iMaxLen[, $iFlag = 0]) Receive UDP packet _UDP_CloseSocket($vSocket) Close UDP socket Base64 Functions Function Description _Base64Encode($bInput[, $bNoCRLF = True]) Encode binary data to Base64 string _Base64Decode($sInput[, $bReturnBinary = False[, $iDecodeType = 1]]) Decode Base64 string _Base64EncodeStr($sInput[, $iEncodeType = 4[, $bNoCRLF = True]]) Encode string to Base64 _Base64DecodeStr($sInput[, $iDecodeType = 4]) Decode Base64 to string Path Utility Functions Function Description _PathWithSlash($sPath) Add trailing backslash to path _PathRemoveTrail($sPath) Remove trailing backslashes from path Constants Data Flags $TCP_DEFAULT_DATA = 0 ; Default string data $TCP_BINARY_DATA = 1 ; Binary data mode $TCP_EOT_DATA = 2 ; End-of-transmission marker Event Types $TCP_EVENT_SEND = 1 ; Send ready event $TCP_EVENT_RECEIVE = 2 ; Data received event $TCP_EVENT_CONNECT = 4 ; Connection established $TCP_EVENT_DISCONNECT = 8 ; Connection closed $TCP_EVENT_NEWCLIENT = 16 ; New client connected (server) Advanced Features Binary File Transfer Use _TCP_Send_Ex() and _TCP_Recv_Ex() for automatic Base64 encoding/decoding of binary data: ; Send binary file Local $bData = FileRead("image.jpg") _TCP_Send_Ex($hSocket, $bData) ; Receive binary file Local $bData = _TCP_Recv_Ex($hSocket, 8192, $TCP_BINARY_DATA) FileWrite("received.jpg", $bData) Multiple Server Support The library supports running multiple servers on different ports simultaneously with independent callback handlers. Connection Timeout Client connections support timeout parameter: ; Wait up to 5 seconds for connection $hClient = _TCP_Client_Create("192.168.1.100", 8080, "", 0, 5000) Error Handling All functions set @error on failure: -1 = General error (check @extended for WSA error code) -2 = Failed to load Winsock DLL -4 = Invalid parameters or socket not found -5 = Connection failed -6 = Timeout Example: $hServer = _TCP_Server_Create(8080) If @error Then ConsoleWrite("Failed to create server. Error: " & @error & ", Extended: " & @extended & @CRLF) Exit EndIf 📚 Example Applications This repository includes three complete, production-ready example applications: TCP Chat System - Full-featured chat room with authentication, private messaging, and user management UDP Chat Application - Lightweight UDP-based chat demonstrating connectionless communication Lab Manager System - Professional client-server remote administration tool with system monitoring Each example includes both client and server implementations with complete source code. 💡 Use Cases 💬 Chat Applications - Real-time messaging systems with multi-user support 📁 File Transfer Tools - Binary file sharing with Base64 encoding 🖥️ Remote Administration - Control and monitor computers over network 🎮 Game Servers - Multiplayer game networking and matchmaking 🌐 IoT Communication - Device-to-device communication and control 🔌 API Servers - Custom protocol implementations and microservices 📊 Data Collection - Sensor data aggregation and monitoring systems 🔔 Notification Systems - Push notification and alert distribution Note: This library uses direct Winsock API calls for advanced networking features. Make sure to call _TCP_Startup() before using any TCP/UDP functions and _TCP_Shutdown() when done. UDF: ; #INDEX# ======================================================================================================================= ; Title .........: WinSockUDF ; AutoIt Version : 3.3.14.2+ ; Language ......: English ; Description ...: Advanced TCP/UDP networking library with async events, error handling, full Winsock2 API support ; Author(s) .....: Dao Van Trong - TRONG.PRO ; Version .......: 1.1 ; =============================================================================================================================== #include-once ; #CONSTANTS# =================================================================================================================== Global Const $TCP_DEFAULT_DATA = 0 Global Const $TCP_BINARY_DATA = 1 Global Const $TCP_EOT_DATA = 2 ; Async Events Global Const $TCP_EVENT_SEND = 1 Global Const $TCP_EVENT_RECEIVE = 2 Global Const $TCP_EVENT_CONNECT = 4 Global Const $TCP_EVENT_DISCONNECT = 8 Global Const $TCP_EVENT_NEWCLIENT = 16 ; Winsock Events (internal) Global Const $FD_READ = 1 Global Const $FD_WRITE = 2 Global Const $FD_OOB = 4 Global Const $FD_ACCEPT = 8 Global Const $FD_CONNECT = 16 Global Const $FD_CLOSE = 32 ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== Global $__TCP_hWs2_32 = -1 Global $__TCP_AsyncWindow = 0 Global $__TCP_Sockets[1][11] ; [socket, msgID, onRecv, onSend, onConnect, onDisconnect, onNewClient, ip, port, isServer, parentServer] Global $__TCP_Initialized = False ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; Initialization ; _TCP_Startup ; _TCP_Shutdown ; ; Server Functions ; _TCP_Server_Create ; _TCP_Server_Stop ; _TCP_Server_ClientList ; _TCP_Server_ClientIP ; _TCP_Server_DisconnectClient ; _TCP_Server_Broadcast ; _TCP_Server_OnNewClient ; _TCP_Server_OnReceive ; _TCP_Server_OnSend ; _TCP_Server_OnDisconnect ; ; Client Functions ; _TCP_Client_Create ; _TCP_Client_Stop ; _TCP_Client_OnConnect ; _TCP_Client_OnReceive ; _TCP_Client_OnSend ; _TCP_Client_OnDisconnect ; ; Common Functions ; _TCP_Send ; _TCP_Recv ; _TCP_Send_Ex ; _TCP_Recv_Ex ; _TCP_RegisterEvent ; _TCP_NameToIP ; _TCP_GetIPs ; _TCP_OnConnect (alias for Client) ; _TCP_OnDisconnect (universal) ; _TCP_OnReceive (universal) ; _TCP_OnSend (universal) ; ; UDP Functions ; _UDP_Startup ; _UDP_Shutdown ; _UDP_Bind ; _UDP_SendTo ; _UDP_RecvFrom ; _UDP_CloseSocket ; ; Base64 Functions ; _Base64Encode ; _Base64Decode ; _Base64EncodeStr ; _Base64DecodeStr ; ; Path Functions ; _PathWithSlash ; _PathRemoveTrail ; ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Startup ; Description ...: Initialize Winsock and async system ; Syntax ........: _TCP_Startup() ; Return values .: Success - 1, Failure - 0 and sets @error ; =============================================================================================================================== Func _TCP_Startup() If $__TCP_Initialized Then Return 1 Local $iResult = TCPStartup() If @error Then Return SetError(@error, 0, 0) $__TCP_hWs2_32 = DllOpen("Ws2_32.dll") If $__TCP_hWs2_32 = -1 Then Return SetError(-2, 0, 0) $__TCP_AsyncWindow = GUICreate("TCP_AsyncWindow_" & Random(1000, 9999, 1)) $__TCP_Initialized = True Return SetError(0, 0, 1) EndFunc ;==>_TCP_Startup ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Shutdown ; Description ...: Close all connections and free resources ; Syntax ........: _TCP_Shutdown() ; Return values .: Success - 1 ; =============================================================================================================================== Func _TCP_Shutdown() If Not $__TCP_Initialized Then Return 1 ; Close all sockets For $i = UBound($__TCP_Sockets) - 1 To 0 Step -1 If $__TCP_Sockets[$i][0] Then ___TCP_CloseSocket($__TCP_Sockets[$i][0]) EndIf Next ReDim $__TCP_Sockets[1][11] If $__TCP_hWs2_32 <> -1 Then DllClose($__TCP_hWs2_32) $__TCP_hWs2_32 = -1 TCPShutdown() $__TCP_Initialized = False Return 1 EndFunc ;==>_TCP_Shutdown ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_Create ; Description ...: Create TCP server with async support ; Syntax ........: _TCP_Server_Create($iPort[, $sIP = "0.0.0.0"[, $iMaxPending = 5]]) ; Parameters ....: $iPort - Port to listen on ; $sIP - [optional] IP address (default = "0.0.0.0" - all interfaces) ; $iMaxPending - [optional] Max pending connections (default = 5) ; Return values .: Success - Socket handle ; Failure - -1 and sets @error ; =============================================================================================================================== Func _TCP_Server_Create($iPort, $sIP = "0.0.0.0", $iMaxPending = 5) If Not $__TCP_Initialized Then If Not _TCP_Startup() Then Return SetError(@error, 0, -1) EndIf Local $hSocket = ___TCP_Socket() If @error Then Return SetError(@error, 0, -1) ; Bind socket Local $tSockAddr = ___TCP_SockAddr($sIP, $iPort) If @error Then ___TCP_CloseSocket($hSocket) Return SetError(@error, 0, -1) EndIf Local $aRet = DllCall($__TCP_hWs2_32, "int", "bind", "uint", $hSocket, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Or $aRet[0] <> 0 Then ___TCP_CloseSocket($hSocket) Return SetError(-1, ___TCP_WSAGetLastError(), -1) EndIf ; Listen $aRet = DllCall($__TCP_hWs2_32, "int", "listen", "uint", $hSocket, "int", $iMaxPending) If @error Or $aRet[0] <> 0 Then ___TCP_CloseSocket($hSocket) Return SetError(-1, ___TCP_WSAGetLastError(), -1) EndIf ; Setup async Local $iMsgID = 0x0400 + UBound($__TCP_Sockets) If Not ___TCP_AsyncSelect($hSocket, $__TCP_AsyncWindow, $iMsgID, $FD_ACCEPT) Then ___TCP_CloseSocket($hSocket) Return SetError(@error, @extended, -1) EndIf GUIRegisterMsg($iMsgID, "___TCP_Server_OnAccept") ; Store socket info ReDim $__TCP_Sockets[UBound($__TCP_Sockets) + 1][11] Local $idx = UBound($__TCP_Sockets) - 1 $__TCP_Sockets[$idx][0] = $hSocket $__TCP_Sockets[$idx][1] = $iMsgID $__TCP_Sockets[$idx][7] = $sIP $__TCP_Sockets[$idx][8] = $iPort $__TCP_Sockets[$idx][9] = True ; isServer $__TCP_Sockets[$idx][10] = 0 ; parentServer Return $hSocket EndFunc ;==>_TCP_Server_Create ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_Stop ; Description ...: Stop server and close all client connections ; Syntax ........: _TCP_Server_Stop($hSocket) ; Parameters ....: $hSocket - Server socket handle ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _TCP_Server_Stop($hSocket) Local $iServerIdx = ___TCP_FindSocket($hSocket) If $iServerIdx < 0 Then Return SetError(-4, 0, 0) ; Close all clients of this server For $i = UBound($__TCP_Sockets) - 1 To 0 Step -1 If $i <> $iServerIdx And $__TCP_Sockets[$i][0] Then If Not $__TCP_Sockets[$i][9] Then ; Not a server ___TCP_CloseSocket($__TCP_Sockets[$i][0]) ___TCP_ArrayDelete($__TCP_Sockets, $i) EndIf EndIf Next ; Close server socket ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $iServerIdx) Return 1 EndFunc ;==>_TCP_Server_Stop ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Client_Create ; Description ...: Create TCP client connection with timeout and async support ; Syntax ........: _TCP_Client_Create($sIP, $iPort[, $sSourceIP = ""[, $iSourcePort = 0[, $iTimeout = 0]]]) ; Parameters ....: $sIP - Server IP address ; $iPort - Server port ; $sSourceIP - [optional] Local IP to bind (default = "") ; $iSourcePort - [optional] Local port to bind (default = 0) ; $iTimeout - [optional] Connection timeout in ms (0 = async without waiting) ; Return values .: Success - Socket handle ; Failure - -1 and sets @error ; =============================================================================================================================== Func _TCP_Client_Create($sIP, $iPort, $sSourceIP = "", $iSourcePort = 0, $iTimeout = 0) If Not $__TCP_Initialized Then If Not _TCP_Startup() Then Return SetError(@error, 0, -1) EndIf ; Validate parameters If Not ($iPort > 0 And $iPort < 65535) Then Return SetError(-4, 0, -1) If Not ($iSourcePort >= 0 And $iSourcePort < 65535) Then Return SetError(-4, 0, -1) Local $hSocket = ___TCP_Socket() If @error Then Return SetError(@error, 0, -1) ; Bind source if specified If $sSourceIP <> "" Or $iSourcePort > 0 Then Local $tSockAddr = ___TCP_SockAddr($sSourceIP <> "" ? $sSourceIP : "0.0.0.0", $iSourcePort) If @error Then ___TCP_CloseSocket($hSocket) Return SetError(@error, 0, -1) EndIf Local $aRet = DllCall($__TCP_hWs2_32, "int", "bind", "uint", $hSocket, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Or $aRet[0] <> 0 Then ___TCP_CloseSocket($hSocket) Return SetError(-1, ___TCP_WSAGetLastError(), -1) EndIf EndIf ; Store socket info BEFORE async setup ReDim $__TCP_Sockets[UBound($__TCP_Sockets) + 1][11] Local $idx = UBound($__TCP_Sockets) - 1 $__TCP_Sockets[$idx][0] = $hSocket $__TCP_Sockets[$idx][7] = $sIP $__TCP_Sockets[$idx][8] = $iPort $__TCP_Sockets[$idx][9] = False ; isClient $__TCP_Sockets[$idx][10] = 0 ; parentServer ; Setup async - IMPORTANT: Do this before connect Local $iMsgID = 0x0400 + $idx $__TCP_Sockets[$idx][1] = $iMsgID If Not ___TCP_AsyncSelect($hSocket, $__TCP_AsyncWindow, $iMsgID, BitOR($FD_READ, $FD_WRITE, $FD_CONNECT, $FD_CLOSE)) Then ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $idx) Return SetError(@error, @extended, -1) EndIf GUIRegisterMsg($iMsgID, "___TCP_Client_OnSocketEvent") ; Connect Local $tSockAddr = ___TCP_SockAddr($sIP, $iPort) If @error Then ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $idx) Return SetError(@error, 0, -1) EndIf Local $aRet = DllCall($__TCP_hWs2_32, "int", "connect", "uint", $hSocket, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) ; For async sockets, connect() returns SOCKET_ERROR with WSAEWOULDBLOCK Local $iError = ___TCP_WSAGetLastError() ; Check if connected immediately (rare for TCP) If Not @error And $aRet[0] = 0 Then ; Connected immediately - call connect callback if set Return $hSocket EndIf ; WSAEWOULDBLOCK (10035) is normal for async connect If $iError <> 10035 And $iError <> 0 Then ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $idx) Return SetError(-1, $iError, -1) EndIf ; Wait for connection if timeout specified If $iTimeout > 0 Then Local $hTimer = TimerInit() Local $bConnected = False While TimerDiff($hTimer) < $iTimeout Sleep(10) ; Check if socket still exists (might have been connected via callback) Local $iCheckIdx = ___TCP_FindSocket($hSocket) If $iCheckIdx >= 0 Then ; Try to check connection status Local $tErr = DllStructCreate("int") Local $aCheck = DllCall($__TCP_hWs2_32, "int", "getsockopt", _ "uint", $hSocket, "int", 0xFFFF, "int", 0x1007, _ "ptr", DllStructGetPtr($tErr), "int*", DllStructGetSize($tErr)) ; SOL_SOCKET, SO_ERROR If Not @error And $aCheck[0] = 0 Then Local $iSockErr = DllStructGetData($tErr, 1) If $iSockErr = 0 Then ; Connected successfully $bConnected = True ExitLoop ElseIf $iSockErr <> 10035 Then ; Not WSAEWOULDBLOCK ; Connection error ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $iCheckIdx) Return SetError(-1, $iSockErr, -1) EndIf EndIf Else ; Socket was removed (probably connected and then disconnected) ExitLoop EndIf WEnd ; Check timeout If Not $bConnected And TimerDiff($hTimer) >= $iTimeout Then Local $iCheckIdx = ___TCP_FindSocket($hSocket) If $iCheckIdx >= 0 Then ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $iCheckIdx) EndIf Return SetError(-6, 0, -1) ; Timeout EndIf EndIf Return $hSocket EndFunc ;==>_TCP_Client_Create ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Client_Stop ; Description ...: Close client connection ; Syntax ........: _TCP_Client_Stop($hSocket) ; Parameters ....: $hSocket - Client socket handle ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _TCP_Client_Stop($hSocket) Local $idx = ___TCP_FindSocket($hSocket) If $idx < 0 Then Return SetError(-4, 0, 0) ___TCP_Shutdown($hSocket) ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $idx) Return 1 EndFunc ;==>_TCP_Client_Stop ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Send ; Description ...: Send data through socket ; Syntax ........: _TCP_Send($hSocket, $vData[, $iFlag = 0]) ; Parameters ....: $hSocket - Socket handle ; $vData - Data to send (string or binary) ; $iFlag - [optional] $TCP_DEFAULT_DATA (0) or $TCP_EOT_DATA (2) ; Return values .: Success - Number of bytes sent ; Failure - -1 and sets @error ; =============================================================================================================================== Func _TCP_Send($hSocket, $vData, $iFlag = 0) If BitAND($iFlag, $TCP_EOT_DATA) Then $vData = String($vData) & Chr(3) Local $iResult = TCPSend($hSocket, $vData) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCP_Send ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Recv ; Description ...: Receive data from socket ; Syntax ........: _TCP_Recv($hSocket, $iMaxLen[, $iFlag = 0]) ; Parameters ....: $hSocket - Socket handle ; $iMaxLen - Max bytes to receive ; $iFlag - [optional] $TCP_DEFAULT_DATA (0), $TCP_BINARY_DATA (1), or $TCP_EOT_DATA (2) ; Return values .: Success - Data received ; Failure - "" and sets @error/@extended ; Remarks .......: @extended = 1 if connection closed, = 2 if EOT reached ; =============================================================================================================================== Func _TCP_Recv($hSocket, $iMaxLen, $iFlag = 0) If Not $__TCP_Initialized Then Return SetError(-1, 0, "") Local $tBuf If BitAND($iFlag, $TCP_BINARY_DATA) Then $tBuf = DllStructCreate("byte[" & $iMaxLen & "]") Else $tBuf = DllStructCreate("char[" & $iMaxLen & "]") EndIf If Not ___TCP_SetNonBlocking($hSocket) Then Return SetError(@error, 0, "") Local $aRet = DllCall($__TCP_hWs2_32, "int", "recv", "uint", $hSocket, "ptr", DllStructGetPtr($tBuf), "int", $iMaxLen, "int", 0) If @error Then Return SetError(-1, 0, "") If $aRet[0] = -1 Or $aRet[0] = 4294967295 Then Local $iError = ___TCP_WSAGetLastError() If $iError = 0 Or $iError = 10035 Then Return SetError(0, 0, "") ; WSAEWOULDBLOCK - no data Return SetError($iError, 0, "") EndIf If $aRet[0] = 0 Then Return SetError(0, 1, "") ; Connection closed Local $sResult = DllStructGetData($tBuf, 1) If BitAND($iFlag, $TCP_EOT_DATA) Then If StringRight($sResult, 1) = Chr(3) Then $sResult = StringTrimRight($sResult, 1) Return SetError(0, 2, $sResult) ; EOT reached EndIf EndIf Return SetError(0, 0, $sResult) EndFunc ;==>_TCP_Recv ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_OnNewClient ; Description ...: Register callback when new client connects ; Syntax ........: _TCP_Server_OnNewClient($hServerSocket, $sFunction) ; Parameters ....: $hServerSocket - Server socket handle ; $sFunction - Callback function name: Func OnNewClient($hClientSocket, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Server_OnNewClient($hServer, "OnNewClient") ; Func OnNewClient($hClient, $iError) ; If $iError Then ConsoleWrite("Accept error: " & $iError & @CRLF) ; Else ConsoleWrite("New client: " & $hClient & @CRLF) ; EndFunc ; =============================================================================================================================== Func _TCP_Server_OnNewClient($hServerSocket, $sFunction) Return _TCP_RegisterEvent($hServerSocket, $TCP_EVENT_NEWCLIENT, $sFunction) EndFunc ;==>_TCP_Server_OnNewClient ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_OnReceive ; Description ...: Register callback when server receives data from client ; Syntax ........: _TCP_Server_OnReceive($hServerSocket, $sFunction) ; Parameters ....: $hServerSocket - Server socket handle ; $sFunction - Callback function name: Func OnReceive($hClientSocket, $sData, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Server_OnReceive($hServer, "OnReceive") ; Func OnReceive($hClient, $sData, $iError) ; If Not $iError Then _TCP_Send($hClient, "Echo: " & $sData) ; EndFunc ; =============================================================================================================================== Func _TCP_Server_OnReceive($hServerSocket, $sFunction) Return _TCP_RegisterEvent($hServerSocket, $TCP_EVENT_RECEIVE, $sFunction) EndFunc ;==>_TCP_Server_OnReceive ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_OnSend ; Description ...: Register callback when server is ready to send data ; Syntax ........: _TCP_Server_OnSend($hServerSocket, $sFunction) ; Parameters ....: $hServerSocket - Server socket handle ; $sFunction - Callback function name: Func OnSend($hClientSocket, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Server_OnSend($hServer, "OnSend") ; Func OnSend($hClient, $iError) ; If Not $iError Then ConsoleWrite("Ready to send on: " & $hClient & @CRLF) ; EndFunc ; =============================================================================================================================== Func _TCP_Server_OnSend($hServerSocket, $sFunction) Return _TCP_RegisterEvent($hServerSocket, $TCP_EVENT_SEND, $sFunction) EndFunc ;==>_TCP_Server_OnSend ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_OnDisconnect ; Description ...: Register callback when client disconnects ; Syntax ........: _TCP_Server_OnDisconnect($hServerSocket, $sFunction) ; Parameters ....: $hServerSocket - Server socket handle ; $sFunction - Callback function name: Func OnDisconnect($hClientSocket, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Server_OnDisconnect($hServer, "OnDisconnect") ; Func OnDisconnect($hClient, $iError) ; ConsoleWrite("Client disconnected: " & $hClient & @CRLF) ; EndFunc ; =============================================================================================================================== Func _TCP_Server_OnDisconnect($hServerSocket, $sFunction) Return _TCP_RegisterEvent($hServerSocket, $TCP_EVENT_DISCONNECT, $sFunction) EndFunc ;==>_TCP_Server_OnDisconnect ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Client_OnConnect ; Description ...: Register callback when client connection succeeds/fails ; Syntax ........: _TCP_Client_OnConnect($hClientSocket, $sFunction) ; Parameters ....: $hClientSocket - Client socket handle ; $sFunction - Callback function name: Func OnConnect($hSocket, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Client_OnConnect($hClient, "OnConnect") ; Func OnConnect($hSocket, $iError) ; If $iError Then ConsoleWrite("Connect failed: " & $iError & @CRLF) ; Else ConsoleWrite("Connected successfully!" & @CRLF) ; EndFunc ; =============================================================================================================================== Func _TCP_Client_OnConnect($hClientSocket, $sFunction) Return _TCP_RegisterEvent($hClientSocket, $TCP_EVENT_CONNECT, $sFunction) EndFunc ;==>_TCP_Client_OnConnect ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Client_OnReceive ; Description ...: Register callback when client receives data from server ; Syntax ........: _TCP_Client_OnReceive($hClientSocket, $sFunction) ; Parameters ....: $hClientSocket - Client socket handle ; $sFunction - Callback function name: Func OnReceive($hSocket, $sData, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Client_OnReceive($hClient, "OnReceive") ; Func OnReceive($hSocket, $sData, $iError) ; If Not $iError Then ConsoleWrite("Received: " & $sData & @CRLF) ; EndFunc ; =============================================================================================================================== Func _TCP_Client_OnReceive($hClientSocket, $sFunction) Return _TCP_RegisterEvent($hClientSocket, $TCP_EVENT_RECEIVE, $sFunction) EndFunc ;==>_TCP_Client_OnReceive ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Client_OnSend ; Description ...: Register callback when client is ready to send data ; Syntax ........: _TCP_Client_OnSend($hClientSocket, $sFunction) ; Parameters ....: $hClientSocket - Client socket handle ; $sFunction - Callback function name: Func OnSend($hSocket, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Client_OnSend($hClient, "OnSend") ; Func OnSend($hSocket, $iError) ; If Not $iError Then ConsoleWrite("Ready to send" & @CRLF) ; EndFunc ; =============================================================================================================================== Func _TCP_Client_OnSend($hClientSocket, $sFunction) Return _TCP_RegisterEvent($hClientSocket, $TCP_EVENT_SEND, $sFunction) EndFunc ;==>_TCP_Client_OnSend ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Client_OnDisconnect ; Description ...: Register callback when client disconnects ; Syntax ........: _TCP_Client_OnDisconnect($hClientSocket, $sFunction) ; Parameters ....: $hClientSocket - Client socket handle ; $sFunction - Callback function name: Func OnDisconnect($hSocket, $iError) ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Example .......: _TCP_Client_OnDisconnect($hClient, "OnDisconnect") ; Func OnDisconnect($hSocket, $iError) ; ConsoleWrite("Disconnected from server" & @CRLF) ; EndFunc ; =============================================================================================================================== Func _TCP_Client_OnDisconnect($hClientSocket, $sFunction) Return _TCP_RegisterEvent($hClientSocket, $TCP_EVENT_DISCONNECT, $sFunction) EndFunc ;==>_TCP_Client_OnDisconnect ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_OnConnect ; Description ...: Alias of _TCP_Client_OnConnect for simpler syntax ; Syntax ........: _TCP_OnConnect($hSocket, $sFunction) ; Parameters ....: $hSocket - Socket handle ; $sFunction - Callback function name ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _TCP_OnConnect($hSocket, $sFunction) Return _TCP_Client_OnConnect($hSocket, $sFunction) EndFunc ;==>_TCP_OnConnect ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_OnReceive ; Description ...: Universal callback for both client and server ; Syntax ........: _TCP_OnReceive($hSocket, $sFunction) ; Parameters ....: $hSocket - Socket handle (client or server) ; $sFunction - Callback function name ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Remarks .......: Can be used for both client and server sockets ; =============================================================================================================================== Func _TCP_OnReceive($hSocket, $sFunction) Return _TCP_RegisterEvent($hSocket, $TCP_EVENT_RECEIVE, $sFunction) EndFunc ;==>_TCP_OnReceive ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_OnSend ; Description ...: Universal callback for both client and server ; Syntax ........: _TCP_OnSend($hSocket, $sFunction) ; Parameters ....: $hSocket - Socket handle (client or server) ; $sFunction - Callback function name ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _TCP_OnSend($hSocket, $sFunction) Return _TCP_RegisterEvent($hSocket, $TCP_EVENT_SEND, $sFunction) EndFunc ;==>_TCP_OnSend ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_OnDisconnect ; Description ...: Universal callback for both client and server ; Syntax ........: _TCP_OnDisconnect($hSocket, $sFunction) ; Parameters ....: $hSocket - Socket handle (client or server) ; $sFunction - Callback function name ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _TCP_OnDisconnect($hSocket, $sFunction) Return _TCP_RegisterEvent($hSocket, $TCP_EVENT_DISCONNECT, $sFunction) EndFunc ;==>_TCP_OnDisconnect ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_RegisterEvent ; Description ...: Internal function to register event callbacks ; Syntax ........: _TCP_RegisterEvent($hSocket, $iEvent, $sFunction) ; Parameters ....: $hSocket - Socket handle ; $iEvent - Event type constant ; $sFunction - Callback function name ; Return values .: Success - 1 ; Failure - 0 and sets @error ; Remarks .......: This is an internal function. Use specific _TCP_*_On* functions instead ; =============================================================================================================================== Func _TCP_RegisterEvent($hSocket, $iEvent, $sFunction) Local $idx = ___TCP_FindSocket($hSocket) If $idx < 0 Then Return SetError(-4, 0, 0) Switch $iEvent Case $TCP_EVENT_SEND $__TCP_Sockets[$idx][3] = $sFunction Case $TCP_EVENT_RECEIVE $__TCP_Sockets[$idx][2] = $sFunction Case $TCP_EVENT_CONNECT $__TCP_Sockets[$idx][4] = $sFunction Case $TCP_EVENT_DISCONNECT $__TCP_Sockets[$idx][5] = $sFunction Case $TCP_EVENT_NEWCLIENT $__TCP_Sockets[$idx][6] = $sFunction Case Else Return SetError(-4, 0, 0) EndSwitch Return 1 EndFunc ;==>_TCP_RegisterEvent ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_ClientList ; Description ...: Get list of client sockets ; Syntax ........: _TCP_Server_ClientList() ; Return values .: Array of client sockets, [0] = count ; =============================================================================================================================== Func _TCP_Server_ClientList() Local $aClients[1] = [0] For $i = 0 To UBound($__TCP_Sockets) - 1 If $__TCP_Sockets[$i][0] And Not $__TCP_Sockets[$i][9] Then ; Not a server socket ReDim $aClients[UBound($aClients) + 1] $aClients[UBound($aClients) - 1] = $__TCP_Sockets[$i][0] $aClients[0] += 1 EndIf Next Return $aClients EndFunc ;==>_TCP_Server_ClientList ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_ClientIP ; Description ...: Get IP address of client ; Syntax ........: _TCP_Server_ClientIP($hSocket) ; Parameters ....: $hSocket - Client socket handle ; Return values .: Success - IP address string ; Failure - "" and sets @error ; =============================================================================================================================== Func _TCP_Server_ClientIP($hSocket) Local $tSockAddr = DllStructCreate("short;ushort;uint;char[8]") Local $aRet = DllCall($__TCP_hWs2_32, "int", "getpeername", "int", $hSocket, "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Or $aRet[0] <> 0 Then Return SetError(-1, 0, "") $aRet = DllCall($__TCP_hWs2_32, "str", "inet_ntoa", "int", DllStructGetData($tSockAddr, 3)) If @error Then Return SetError(-1, 0, "") Return $aRet[0] EndFunc ;==>_TCP_Server_ClientIP ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_Broadcast ; Description ...: Send data to all clients ; Syntax ........: _TCP_Server_Broadcast($vData) ; Parameters ....: $vData - Data to broadcast ; Return values .: Number of clients sent to ; =============================================================================================================================== Func _TCP_Server_Broadcast($vData) Local $iCount = 0 For $i = 0 To UBound($__TCP_Sockets) - 1 If $__TCP_Sockets[$i][0] And Not $__TCP_Sockets[$i][9] Then TCPSend($__TCP_Sockets[$i][0], $vData) $iCount += 1 EndIf Next Return $iCount EndFunc ;==>_TCP_Server_Broadcast ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Server_DisconnectClient ; Description ...: Disconnect a client ; Syntax ........: _TCP_Server_DisconnectClient($hSocket) ; Parameters ....: $hSocket - Client socket handle ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _TCP_Server_DisconnectClient($hSocket) Return _TCP_Client_Stop($hSocket) EndFunc ;==>_TCP_Server_DisconnectClient ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_NameToIP ; Description ...: Convert hostname to IP address ; Syntax ........: _TCP_NameToIP($sName) ; Parameters ....: $sName - Hostname ; Return values .: Success - IP address ; Failure - "" and sets @error ; =============================================================================================================================== Func _TCP_NameToIP($sName) Local $sIP = TCPNameToIP($sName) Return SetError(@error, 0, $sIP) EndFunc ;==>_TCP_NameToIP ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_GetIPs ; Description ...: Get local and public IP addresses ; Syntax ........: _TCP_GetIPs([$sServerName = ""]) ; Parameters ....: $sServerName - [optional] Server to check public IP ; Return values .: Success - Array [localIP, publicIP] ; Failure - -1 and sets @error ; =============================================================================================================================== Func _TCP_GetIPs($sServerName = "") If Not $__TCP_Initialized Then If Not _TCP_Startup() Then Return SetError(@error, 0, -1) EndIf Local $aServers[][2] = [["www.myexternalip.com/raw"], ["checkip.dyndns.org/"], ["bot.whatismyipaddress.com/"]] If $sServerName <> "" Then ReDim $aServers[UBound($aServers) + 1][2] $aServers[UBound($aServers) - 1][0] = $sServerName EndIf Local $sLocalIP = "", $sPublicIP = "" Local $hSocket = ___TCP_Socket() If @error Then Return SetError(@error, 0, -1) For $i = 0 To UBound($aServers) - 1 Local $sHost = StringRegExp($aServers[$i][0], "^([^/]+)", 1) If @error Then ContinueLoop $sHost = $sHost[0] Local $sServerIP = TCPNameToIP($sHost) If $sServerIP = "" Then ContinueLoop ; Connect Local $tSockAddr = ___TCP_SockAddr($sServerIP, 80) If @error Then ContinueLoop ___TCP_SetNonBlocking($hSocket) DllCall($__TCP_hWs2_32, "int", "connect", "uint", $hSocket, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) ; Wait for connection If Not ___TCP_WaitForConnect($hSocket, 2000) Then ___TCP_CloseSocket($hSocket) $hSocket = ___TCP_Socket() ContinueLoop EndIf ; Get local IP If $sLocalIP = "" Then Local $tLocalAddr = DllStructCreate("short;ushort;uint;char[8]") Local $aRet = DllCall($__TCP_hWs2_32, "int", "getsockname", "uint", $hSocket, "ptr", DllStructGetPtr($tLocalAddr), "int*", DllStructGetSize($tLocalAddr)) If Not @error And $aRet[0] = 0 Then $aRet = DllCall($__TCP_hWs2_32, "ptr", "inet_ntoa", "ulong", DllStructGetData($tLocalAddr, 3)) If Not @error And $aRet[0] <> Null Then $sLocalIP = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) EndIf EndIf EndIf ; Get public IP Local $sRequest = "GET /" & StringRegExpReplace($aServers[$i][0], "^[^/]+/?", "") & " HTTP/1.1" & @CRLF & _ "Host: " & $sHost & @CRLF & _ "Connection: close" & @CRLF & @CRLF TCPSend($hSocket, $sRequest) Sleep(500) Local $sRecv = "" Local $hTimer = TimerInit() While TimerDiff($hTimer) < 3000 Local $sChunk = _TCP_Recv($hSocket, 2048) If @extended = 1 Then ExitLoop ; Connection closed $sRecv &= $sChunk If $sChunk = "" Then Sleep(10) WEnd Local $aIP = StringRegExp($sRecv, "((?:\d{1,3}\.){3}\d{1,3})", 3) If Not @error And UBound($aIP) > 0 Then $sPublicIP = $aIP[0] ExitLoop EndIf ___TCP_CloseSocket($hSocket) $hSocket = ___TCP_Socket() Next ___TCP_CloseSocket($hSocket) If $sLocalIP = "" Or $sPublicIP = "" Then Return SetError(-6, 0, -1) Local $aResult[2] = [$sLocalIP, $sPublicIP] Return $aResult EndFunc ;==>_TCP_GetIPs ; #UDP FUNCTIONS# =============================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UDP_Startup ; Description ...: Initialize UDP system ; Syntax ........: _UDP_Startup() ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _UDP_Startup() Local $iResult = UDPStartup() Return SetError(@error, 0, $iResult) EndFunc ;==>_UDP_Startup ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UDP_Shutdown ; Description ...: Shutdown UDP system ; Syntax ........: _UDP_Shutdown() ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _UDP_Shutdown() Local $iResult = UDPShutdown() Return SetError(@error, 0, $iResult) EndFunc ;==>_UDP_Shutdown ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UDP_Bind ; Description ...: Create and bind UDP socket ; Syntax ........: _UDP_Bind([$sSourceIP = ""[, $iSourcePort = 0]]) ; Parameters ....: $sSourceIP - [optional] Local IP to bind (default = "") ; $iSourcePort - [optional] Local port to bind (default = 0) ; Return values .: Success - Socket handle ; Failure - -1 and sets @error ; =============================================================================================================================== Func _UDP_Bind($sSourceIP = "", $iSourcePort = 0) If Not $__TCP_Initialized Then If Not _TCP_Startup() Then Return SetError(@error, 0, -1) EndIf If Not ($iSourcePort >= 0 And $iSourcePort < 65535) Then Return SetError(-4, 0, -1) Local $aRet = DllCall($__TCP_hWs2_32, "uint", "socket", "int", 2, "int", 2, "int", 17) ; AF_INET, SOCK_DGRAM, IPPROTO_UDP If @error Then Return SetError(-1, 0, -1) If $aRet[0] = 4294967295 Or $aRet[0] = -1 Then Return SetError(-1, ___TCP_WSAGetLastError(), -1) Local $hSocket = $aRet[0] ; Bind if IP or port specified If $sSourceIP <> "" Or $iSourcePort > 0 Then Local $tSockAddr = ___TCP_SockAddr($sSourceIP <> "" ? $sSourceIP : "0.0.0.0", $iSourcePort) If @error Then ___TCP_CloseSocket($hSocket) Return SetError(@error, 0, -1) EndIf $aRet = DllCall($__TCP_hWs2_32, "int", "bind", "uint", $hSocket, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Or $aRet[0] <> 0 Then ___TCP_CloseSocket($hSocket) Return SetError(-1, ___TCP_WSAGetLastError(), -1) EndIf EndIf Return $hSocket EndFunc ;==>_UDP_Bind ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UDP_SendTo ; Description ...: Send UDP packet to specified address ; Syntax ........: _UDP_SendTo($sIP, $iPort, $vData[, $hSocket = 0]) ; Parameters ....: $sIP - Destination IP address ; $iPort - Destination port ; $vData - Data to send (string or binary) ; $hSocket - [optional] Socket handle (0 = create temporary socket) ; Return values .: Success - Array [bytes_sent, socket_handle] ; Failure - -1 and sets @error ; =============================================================================================================================== Func _UDP_SendTo($sIP, $iPort, $vData, $hSocket = 0) If Not $__TCP_Initialized Then If Not _TCP_Startup() Then Return SetError(@error, 0, -1) EndIf If Not ($iPort > 0 And $iPort < 65535) Then Return SetError(-4, 0, -1) Local $bCloseAfter = False If $hSocket = 0 Then $hSocket = _UDP_Bind() If @error Then Return SetError(@error, 0, -1) $bCloseAfter = True EndIf Local $tSockAddr = ___TCP_SockAddr($sIP, $iPort) If @error Then If $bCloseAfter Then ___TCP_CloseSocket($hSocket) Return SetError(@error, 0, -1) EndIf Local $tBuf, $iLen If IsBinary($vData) Then $iLen = BinaryLen($vData) $tBuf = DllStructCreate("byte[" & $iLen & "]") DllStructSetData($tBuf, 1, $vData) Else $vData = String($vData) $iLen = StringLen($vData) $tBuf = DllStructCreate("char[" & $iLen & "]") DllStructSetData($tBuf, 1, $vData) EndIf ___TCP_SetNonBlocking($hSocket) Local $aRet = DllCall($__TCP_hWs2_32, "int", "sendto", _ "uint", $hSocket, "ptr", DllStructGetPtr($tBuf), "int", $iLen, "int", 0, _ "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Or $aRet[0] = -1 Or $aRet[0] = 4294967295 Then Local $iError = ___TCP_WSAGetLastError() If $bCloseAfter Then ___TCP_CloseSocket($hSocket) Return SetError($iError, 0, -1) EndIf Local $aResult[2] = [$aRet[0], $hSocket] If $bCloseAfter Then ___TCP_CloseSocket($hSocket) Return $aResult EndFunc ;==>_UDP_SendTo ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UDP_RecvFrom ; Description ...: Receive UDP packet ; Syntax ........: _UDP_RecvFrom($hSocket, $iMaxLen[, $iFlag = 0]) ; Parameters ....: $hSocket - Socket handle ; $iMaxLen - Max bytes to receive ; $iFlag - [optional] 0 = string, 1 = binary ; Return values .: Success - Array [data, source_ip, source_port] ; Failure - -1 and sets @error ; =============================================================================================================================== Func _UDP_RecvFrom($hSocket, $iMaxLen, $iFlag = 0) If Not $__TCP_Initialized Then Return SetError(-1, 0, -1) If $iMaxLen < 1 Then Return SetError(-4, 0, -1) If $iFlag <> 0 And $iFlag <> 1 Then Return SetError(-4, 0, -1) ___TCP_SetNonBlocking($hSocket) Local $tSockAddr = DllStructCreate("short;ushort;uint;char[8]") Local $tBuf If $iFlag = 1 Then $tBuf = DllStructCreate("byte[" & $iMaxLen & "]") Else $tBuf = DllStructCreate("char[" & $iMaxLen & "]") EndIf Local $aRet = DllCall($__TCP_hWs2_32, "int", "recvfrom", _ "uint", $hSocket, "ptr", DllStructGetPtr($tBuf), "int", $iMaxLen, "int", 0, _ "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Then Return SetError(-1, 0, -1) If $aRet[0] = -1 Or $aRet[0] = 4294967295 Then Local $iError = ___TCP_WSAGetLastError() If $iError = 0 Or $iError = 10035 Then Return SetError(0, 0, -1) ; WSAEWOULDBLOCK Return SetError($iError, 0, -1) EndIf Local $aResult[3] $aResult[0] = DllStructGetData($tBuf, 1) $aRet = DllCall($__TCP_hWs2_32, "ptr", "inet_ntoa", "ulong", DllStructGetData($tSockAddr, 3)) If @error Or $aRet[0] = Null Then Return SetError(-1, 0, -1) $aResult[1] = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) $aRet = DllCall($__TCP_hWs2_32, "ushort", "ntohs", "ushort", DllStructGetData($tSockAddr, 2)) If @error Then Return SetError(-1, 0, -1) $aResult[2] = $aRet[0] Return $aResult EndFunc ;==>_UDP_RecvFrom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UDP_CloseSocket ; Description ...: Close UDP socket ; Syntax ........: _UDP_CloseSocket($vSocket) ; Parameters ....: $vSocket - Socket handle or array from _UDP_SendTo ; Return values .: Success - 1 ; Failure - 0 and sets @error ; =============================================================================================================================== Func _UDP_CloseSocket($vSocket) Local $hSocket If IsArray($vSocket) And UBound($vSocket) = 2 Then $hSocket = $vSocket[1] Else $hSocket = $vSocket EndIf If $hSocket < 1 Then Return SetError(-4, 0, 0) Local $aRet = DllCall($__TCP_hWs2_32, "int", "closesocket", "uint", $hSocket) If @error Or $aRet[0] <> 0 Then Return SetError(___TCP_WSAGetLastError(), 0, 0) EndIf Return 1 EndFunc ;==>_UDP_CloseSocket ; #INTERNAL FUNCTIONS# ========================================================================================================== Func ___TCP_Socket() Local $aRet = DllCall($__TCP_hWs2_32, "uint", "socket", "int", 2, "int", 1, "int", 6) ; AF_INET, SOCK_STREAM, IPPROTO_TCP If @error Then Return SetError(-1, 0, -1) If $aRet[0] = 4294967295 Or $aRet[0] = -1 Then Return SetError(-1, ___TCP_WSAGetLastError(), -1) Return $aRet[0] EndFunc ;==>___TCP_Socket Func ___TCP_CloseSocket($hSocket) DllCall($__TCP_hWs2_32, "int", "closesocket", "uint", $hSocket) Return TCPCloseSocket($hSocket) EndFunc ;==>___TCP_CloseSocket Func ___TCP_Shutdown($hSocket) DllCall($__TCP_hWs2_32, "int", "shutdown", "uint", $hSocket, "int", 2) ; SD_BOTH EndFunc ;==>___TCP_Shutdown Func ___TCP_SockAddr($sIP, $iPort) Local $tAddr = DllStructCreate("short sin_family;ushort sin_port;uint S_addr;char sin_zero[8]") If @error Then Return SetError(-1, 0, False) DllStructSetData($tAddr, "sin_family", 2) ; AF_INET Local $aRet = DllCall($__TCP_hWs2_32, "ushort", "htons", "ushort", $iPort) If @error Then Return SetError(-1, 0, False) DllStructSetData($tAddr, "sin_port", $aRet[0]) If $sIP = "" Or $sIP = "0.0.0.0" Then DllStructSetData($tAddr, "S_addr", 0x00000000) Else $aRet = DllCall($__TCP_hWs2_32, "ulong", "inet_addr", "str", $sIP) If @error Or $aRet[0] = -1 Or $aRet[0] = 4294967295 Then Return SetError(-4, 0, False) DllStructSetData($tAddr, "S_addr", $aRet[0]) EndIf Return $tAddr EndFunc ;==>___TCP_SockAddr Func ___TCP_SetNonBlocking($hSocket) Local $aRet = DllCall($__TCP_hWs2_32, "int", "ioctlsocket", "uint", $hSocket, "long", 0x8004667e, "ulong*", 1) ; FIONBIO If @error Or $aRet[0] <> 0 Then Return SetError(-1, ___TCP_WSAGetLastError(), False) Return True EndFunc ;==>___TCP_SetNonBlocking Func ___TCP_AsyncSelect($hSocket, $hWnd, $iMsg, $iEvents) ; WSAAsyncSelect automatically sets socket to non-blocking mode Local $aRet = DllCall($__TCP_hWs2_32, "int", "WSAAsyncSelect", _ "uint", $hSocket, "hwnd", $hWnd, "uint", $iMsg, "int", $iEvents) If @error Or $aRet[0] <> 0 Then Return SetError(-1, ___TCP_WSAGetLastError(), False) Return True EndFunc ;==>___TCP_AsyncSelect Func ___TCP_WaitForConnect($hSocket, $iTimeout) Local $tFdWrite = DllStructCreate("uint fd_count;uint fd_array[64]") Local $tFdExcept = DllStructCreate("uint fd_count;uint fd_array[64]") Local $tTimeval = DllStructCreate("long tv_sec;long tv_usec") DllStructSetData($tFdWrite, "fd_count", 1) DllStructSetData($tFdWrite, "fd_array", $hSocket, 1) DllStructSetData($tFdExcept, "fd_count", 1) DllStructSetData($tFdExcept, "fd_array", $hSocket, 1) DllStructSetData($tTimeval, "tv_sec", Floor($iTimeout / 1000)) DllStructSetData($tTimeval, "tv_usec", Mod($iTimeout, 1000) * 1000) Local $aRet = DllCall($__TCP_hWs2_32, "int", "select", _ "int", 0, "ptr", 0, "ptr", DllStructGetPtr($tFdWrite), _ "ptr", DllStructGetPtr($tFdExcept), "ptr", DllStructGetPtr($tTimeval)) If @error Then Return SetError(-1, 0, False) If $aRet[0] = 0 Then Return SetError(-6, 0, False) ; Timeout If $aRet[0] = -1 Then Return SetError(-1, ___TCP_WSAGetLastError(), False) ; Check if connected or error If DllStructGetData($tFdWrite, "fd_count") = 1 Then Return True If DllStructGetData($tFdExcept, "fd_count") = 1 Then Local $tErr = DllStructCreate("int") $aRet = DllCall($__TCP_hWs2_32, "int", "getsockopt", _ "uint", $hSocket, "int", 0xFFFF, "int", 0x1007, _ "ptr", DllStructGetPtr($tErr), "int*", DllStructGetSize($tErr)) ; SOL_SOCKET, SO_ERROR If Not @error And $aRet[0] = 0 Then Return SetError(DllStructGetData($tErr, 1), 0, False) EndIf EndIf Return SetError(-5, 0, False) ; Not connected EndFunc ;==>___TCP_WaitForConnect Func ___TCP_WSAGetLastError() Local $aRet = DllCall($__TCP_hWs2_32, "int", "WSAGetLastError") If @error Then Return 0 Return $aRet[0] EndFunc ;==>___TCP_WSAGetLastError Func ___TCP_FindSocket($hSocket) For $i = 0 To UBound($__TCP_Sockets) - 1 If $__TCP_Sockets[$i][0] = $hSocket Then Return $i Next Return -1 EndFunc ;==>___TCP_FindSocket Func ___TCP_LoWord($iValue) Return BitAND($iValue, 0xFFFF) EndFunc ;==>___TCP_LoWord Func ___TCP_HiWord($iValue) Return BitShift($iValue, 16) EndFunc ;==>___TCP_HiWord Func ___TCP_ArrayDelete(ByRef $aArray, $iElement) If Not IsArray($aArray) Then Return SetError(1, 0, 0) Local $iUBound = UBound($aArray, 1) - 1 If $iUBound < 0 Then Return 0 If $iElement < 0 Then $iElement = 0 If $iElement > $iUBound Then $iElement = $iUBound Switch UBound($aArray, 0) Case 1 For $i = $iElement To $iUBound - 1 $aArray[$i] = $aArray[$i + 1] Next ReDim $aArray[$iUBound] Case 2 Local $iSubMax = UBound($aArray, 2) - 1 For $i = $iElement To $iUBound - 1 For $j = 0 To $iSubMax $aArray[$i][$j] = $aArray[$i + 1][$j] Next Next ReDim $aArray[$iUBound][$iSubMax + 1] Case Else Return SetError(3, 0, 0) EndSwitch Return $iUBound EndFunc ;==>___TCP_ArrayDelete ; #ASYNC EVENT HANDLERS# ======================================================================================================== Func ___TCP_Server_OnAccept($hWnd, $iMsgID, $wParam, $lParam) Local $hSocket = $wParam Local $iError = ___TCP_HiWord($lParam) Local $iEvent = ___TCP_LoWord($lParam) Abs($hWnd) ; Suppress AU3Check warning ; Find server socket Local $iServerIdx = -1 For $i = 0 To UBound($__TCP_Sockets) - 1 If $__TCP_Sockets[$i][1] = $iMsgID Then $iServerIdx = $i ExitLoop EndIf Next If $iServerIdx < 0 Then Return If $iEvent = $FD_ACCEPT Then If Not $iError Then Local $hClient = TCPAccept($hSocket) If $hClient < 0 Then Return ; Setup client async Local $iClientMsgID = 0x0400 + UBound($__TCP_Sockets) ___TCP_AsyncSelect($hClient, $__TCP_AsyncWindow, $iClientMsgID, BitOR($FD_READ, $FD_WRITE, $FD_CLOSE)) GUIRegisterMsg($iClientMsgID, "___TCP_Server_OnClientEvent") ; Store client ReDim $__TCP_Sockets[UBound($__TCP_Sockets) + 1][11] Local $idx = UBound($__TCP_Sockets) - 1 $__TCP_Sockets[$idx][0] = $hClient $__TCP_Sockets[$idx][1] = $iClientMsgID $__TCP_Sockets[$idx][7] = _TCP_Server_ClientIP($hClient) $__TCP_Sockets[$idx][9] = False ; isClient $__TCP_Sockets[$idx][10] = $hSocket ; parentServer ; Call callback If $__TCP_Sockets[$iServerIdx][6] <> "" Then Call($__TCP_Sockets[$iServerIdx][6], $hClient, $iError) EndIf Else ; Error accepting If $__TCP_Sockets[$iServerIdx][6] <> "" Then Call($__TCP_Sockets[$iServerIdx][6], 0, $iError) EndIf EndIf EndIf EndFunc ;==>___TCP_Server_OnAccept Func ___TCP_Server_OnClientEvent($hWnd, $iMsgID, $wParam, $lParam) Local $hSocket = $wParam Local $iError = ___TCP_HiWord($lParam) Local $iEvent = ___TCP_LoWord($lParam) Abs($hWnd) Local $iClientIdx = -1 For $i = 0 To UBound($__TCP_Sockets) - 1 If $__TCP_Sockets[$i][1] = $iMsgID Then $iClientIdx = $i ; BUG FIX: Don't override the actual socket handle from $wParam ; $hSocket = $__TCP_Sockets[$i][0] ; This was causing socket mismatch! ExitLoop EndIf Next If $iClientIdx < 0 Then Return ; Find parent server for this client - CRITICAL FIX for multi-server support Local $iServerIdx = -1 Local $hParentServer = $__TCP_Sockets[$iClientIdx][10] If $hParentServer > 0 Then ; Find the parent server by socket handle For $i = 0 To UBound($__TCP_Sockets) - 1 If $__TCP_Sockets[$i][0] = $hParentServer And $__TCP_Sockets[$i][9] Then $iServerIdx = $i ExitLoop EndIf Next EndIf If $iServerIdx < 0 Then Return Switch $iEvent Case $FD_READ Local $sData = TCPRecv($hSocket, 4096) If $__TCP_Sockets[$iServerIdx][2] <> "" Then Call($__TCP_Sockets[$iServerIdx][2], $hSocket, $sData, $iError) EndIf Case $FD_WRITE If $__TCP_Sockets[$iServerIdx][3] <> "" Then Call($__TCP_Sockets[$iServerIdx][3], $hSocket, $iError) EndIf Case $FD_CLOSE If $__TCP_Sockets[$iServerIdx][5] <> "" Then Call($__TCP_Sockets[$iServerIdx][5], $hSocket, $iError) EndIf ___TCP_Shutdown($hSocket) ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $iClientIdx) EndSwitch EndFunc ;==>___TCP_Server_OnClientEvent Func ___TCP_Client_OnSocketEvent($hWnd, $iMsgID, $wParam, $lParam) Local $hSocket = $wParam Local $iError = ___TCP_HiWord($lParam) Local $iEvent = ___TCP_LoWord($lParam) Abs($hWnd) Local $iClientIdx = -1 For $i = 0 To UBound($__TCP_Sockets) - 1 If $__TCP_Sockets[$i][1] = $iMsgID Then $iClientIdx = $i ; BUG FIX: Don't override the actual socket handle from $wParam ; $hSocket = $__TCP_Sockets[$i][0] ; This was causing socket mismatch! ExitLoop EndIf Next If $iClientIdx < 0 Then Return Switch $iEvent Case $FD_CONNECT ; Connection completed (success or failure) If $__TCP_Sockets[$iClientIdx][4] <> "" Then Call($__TCP_Sockets[$iClientIdx][4], $hSocket, $iError) EndIf Case $FD_READ Local $sData = TCPRecv($hSocket, 4096) If $__TCP_Sockets[$iClientIdx][2] <> "" Then Call($__TCP_Sockets[$iClientIdx][2], $hSocket, $sData, $iError) EndIf Case $FD_WRITE If $__TCP_Sockets[$iClientIdx][3] <> "" Then Call($__TCP_Sockets[$iClientIdx][3], $hSocket, $iError) EndIf Case $FD_CLOSE If $__TCP_Sockets[$iClientIdx][5] <> "" Then Call($__TCP_Sockets[$iClientIdx][5], $hSocket, $iError) EndIf ___TCP_Shutdown($hSocket) ___TCP_CloseSocket($hSocket) ___TCP_ArrayDelete($__TCP_Sockets, $iClientIdx) EndSwitch EndFunc ;==>___TCP_Client_OnSocketEvent ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Send_Ex ; Description ...: Send data through socket with automatic Base64 encoding ; Syntax ........: _TCP_Send_Ex($hSocket, $vData[, $iFlag = 0]) ; Parameters ....: $hSocket - Socket handle ; $vData - Data to send (string or binary) - auto Base64 encoded ; $iFlag - [optional] $TCP_DEFAULT_DATA (0) or $TCP_EOT_DATA (2) ; Return values .: Success - Number of bytes sent ; Failure - -1 and sets @error ; =============================================================================================================================== Func _TCP_Send_Ex($hSocket, $vData, $iFlag = 0) ; Auto encode to Base64 Local $sEncoded = _Base64Encode($vData) If @error Then Return SetError(@error, 0, -1) If BitAND($iFlag, $TCP_EOT_DATA) Then $sEncoded = $sEncoded & Chr(3) Local $iResult = TCPSend($hSocket, $sEncoded) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCP_Send_Ex ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TCP_Recv_Ex ; Description ...: Receive data from socket with automatic Base64 decoding ; Syntax ........: _TCP_Recv_Ex($hSocket, $iMaxLen[, $iFlag = 0]) ; Parameters ....: $hSocket - Socket handle ; $iMaxLen - Max bytes to receive (after decoding) ; $iFlag - [optional] $TCP_DEFAULT_DATA (0), $TCP_BINARY_DATA (1), or $TCP_EOT_DATA (2) ; Return values .: Success - Data received (decoded from Base64) ; Failure - "" and sets @error/@extended ; Remarks .......: @extended = 1 if connection closed, = 2 if EOT reached ; Data is automatically decoded from Base64 ; =============================================================================================================================== Func _TCP_Recv_Ex($hSocket, $iMaxLen, $iFlag = 0) If Not $__TCP_Initialized Then Return SetError(-1, 0, "") ; Calculate buffer size for Base64 (encoded is ~33% larger) Local $iBase64MaxLen = Int($iMaxLen * 1.35) + 100 Local $tBuf = DllStructCreate("char[" & $iBase64MaxLen & "]") If Not ___TCP_SetNonBlocking($hSocket) Then Return SetError(@error, 0, "") Local $aRet = DllCall($__TCP_hWs2_32, "int", "recv", "uint", $hSocket, "ptr", DllStructGetPtr($tBuf), "int", $iBase64MaxLen, "int", 0) If @error Then Return SetError(-1, 0, "") If $aRet[0] = -1 Or $aRet[0] = 4294967295 Then Local $iError = ___TCP_WSAGetLastError() If $iError = 0 Or $iError = 10035 Then Return SetError(0, 0, "") ; WSAEWOULDBLOCK - no data Return SetError($iError, 0, "") EndIf If $aRet[0] = 0 Then Return SetError(0, 1, "") ; Connection closed Local $sBase64Result = DllStructGetData($tBuf, 1) ; Check for EOT marker Local $bHasEOT = False If BitAND($iFlag, $TCP_EOT_DATA) Then If StringRight($sBase64Result, 1) = Chr(3) Then $sBase64Result = StringTrimRight($sBase64Result, 1) $bHasEOT = True EndIf EndIf ; Auto decode from Base64 Local $sDecoded = _Base64Decode($sBase64Result, True) ; Convert to binary if requested If BitAND($iFlag, $TCP_BINARY_DATA) Then $sDecoded = Binary($sDecoded) EndIf If $bHasEOT Then Return SetError(0, 2, $sDecoded) ; EOT reached EndIf Return SetError(0, 0, $sDecoded) EndFunc ;==>_TCP_Recv_Ex ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Base64Encode ; Description ...: Encode binary data to Base64 string ; Syntax ........: _Base64Encode($bInput[, $bNoCRLF = True]) ; Parameters ....: $bInput - Binary data to encode (can also accept ASCII string directly) ; $bNoCRLF - [optional] True: no line breaks, False: add CRLF every 76 chars (default = True) ; Return values .: Success - Base64 encoded string ; Failure - "" and sets @error ; Remarks .......: For ASCII strings, you can use this function directly. For UTF-8 strings, use _Base64EncodeStr() instead ; Author ........: Dao Van Trong - TRONG.PRO ; =============================================================================================================================== Func _Base64Encode($bInput, $bNoCRLF = True) $bInput = Binary($bInput) Local $iFlags = 1 ; CRYPT_STRING_BASE64 If $bNoCRLF Then $iFlags = 0x40000001 ; CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF Local $tInput = DllStructCreate("byte[" & BinaryLen($bInput) & "]") DllStructSetData($tInput, 1, $bInput) ; Get required buffer size Local $aResult = DllCall("Crypt32.dll", "bool", "CryptBinaryToStringW", _ "struct*", $tInput, _ "dword", DllStructGetSize($tInput), _ "dword", $iFlags, _ "ptr", 0, _ "dword*", 0) If @error Or Not $aResult[0] Then Return SetError(1, 0, "") Local $iSize = $aResult[5] Local $tOutput = DllStructCreate("wchar[" & $iSize & "]") ; Perform encoding $aResult = DllCall("Crypt32.dll", "bool", "CryptBinaryToStringW", _ "struct*", $tInput, _ "dword", DllStructGetSize($tInput), _ "dword", $iFlags, _ "struct*", $tOutput, _ "dword*", $iSize) If @error Or Not $aResult[0] Then Return SetError(2, 0, "") Return DllStructGetData($tOutput, 1) EndFunc ;==>_Base64Encode ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Base64Decode ; Description ...: Decode Base64 string to binary or string ; Syntax ........: _Base64Decode($sInput[, $bReturnBinary = False[, $iDecodeType = 1]]) ; Parameters ....: $sInput - Base64 string to decode ; $bReturnBinary - [optional] False: return string, True: return binary (default = False) ; $iDecodeType - [optional] 1: ASCII, 4: UTF-8 (default = 1, only used when $bReturnBinary = False) ; Return values .: Success - Binary data or string ; Failure - Binary("") and sets @error ; Remarks .......: For ASCII-only data, use default parameters. For UTF-8 data, use $iDecodeType = 4. For binary data, use $bReturnBinary = True ; Author ........: Dao Van Trong - TRONG.PRO ; =============================================================================================================================== Func _Base64Decode($sInput, $bReturnBinary = False, $iDecodeType = 1) If ($iDecodeType > 4) Or ($iDecodeType < 1) Then $iDecodeType = 4 ; Remove all whitespace and CRLF $sInput = StringRegExpReplace($sInput, "\s", "") If ($sInput = "") Then Return SetError(1, 0, ($bReturnBinary ? Binary("") : "")) Local $iFlags = 1 ; CRYPT_STRING_BASE64 ; Get required buffer size Local $aResult = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryW", _ "wstr", $sInput, _ "dword", StringLen($sInput), _ "dword", $iFlags, _ "ptr", 0, _ "dword*", 0, _ "ptr", 0, _ "ptr", 0) If @error Or Not $aResult[0] Then Return SetError(2, 0, ($bReturnBinary ? Binary("") : "")) Local $iSize = $aResult[5] Local $tOutput = DllStructCreate("byte[" & $iSize & "]") ; Perform decoding $aResult = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryW", _ "wstr", $sInput, _ "dword", StringLen($sInput), _ "dword", $iFlags, _ "struct*", $tOutput, _ "dword*", $iSize, _ "ptr", 0, _ "ptr", 0) If @error Or Not $aResult[0] Then Return SetError(3, 0, ($bReturnBinary ? Binary("") : "")) Local $bBinary = DllStructGetData($tOutput, 1) If $bReturnBinary Then Return $bBinary Else ; Convert binary to string with specified encoding Return BinaryToString($bBinary, $iDecodeType) EndIf EndFunc ;==>_Base64Decode ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Base64EncodeStr ; Description ...: Encode string to Base64 ; Syntax ........: _Base64EncodeStr($sInput[, $iEncodeType = 4[, $bNoCRLF = True]]) ; Parameters ....: $sInput - String to encode ; $iEncodeType - [optional] 1: ASCII, 4: UTF-8 (default = 4) ; $bNoCRLF - [optional] True: no line breaks, False: add CRLF (default = True) ; Return values .: Success - Base64 encoded string ; Failure - "" and sets @error ; Author ........: Dao Van Trong - TRONG.PRO ; =============================================================================================================================== Func _Base64EncodeStr($sInput, $iEncodeType = 4, $bNoCRLF = True) If ($iEncodeType > 4) Or ($iEncodeType < 1) Then $iEncodeType = 4 Local $bBinary = StringToBinary($sInput, $iEncodeType) Return _Base64Encode($bBinary, $bNoCRLF) EndFunc ;==>_Base64EncodeStr ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Base64DecodeStr ; Description ...: Decode Base64 string to text string ; Syntax ........: _Base64DecodeStr($sInput[, $iDecodeType = 4]) ; Parameters ....: $sInput - Base64 string to decode ; $iDecodeType - [optional] 1: ASCII, 4: UTF-8 (default = 4) ; Return values .: Success - Text string ; Failure - "" and sets @error ; Author ........: Dao Van Trong - TRONG.PRO ; =============================================================================================================================== Func _Base64DecodeStr($sInput, $iDecodeType = 4) Return _Base64Decode($sInput, False, $iDecodeType) EndFunc ;==>_Base64DecodeStr ; #FUNCTION# ==================================================================================================================== ; Name ..........: _PathWithSlash ; Description ...: Add single backslash to path if not present ; Syntax ........: _PathWithSlash($sPath) ; Parameters ....: $sPath - Path string ; Return values .: Path with trailing backslash ; Author ........: Dao Van Trong - TRONG.PRO ; =============================================================================================================================== Func _PathWithSlash($sPath) Return _PathRemoveTrail($sPath) & '\' EndFunc ;==>_PathWithSlash ; #FUNCTION# ==================================================================================================================== ; Name ..........: _PathRemoveTrail ; Description ...: Remove trailing backslashes from path ; Syntax ........: _PathRemoveTrail($sPath) ; Parameters ....: $sPath - Path string ; Return values .: Path without trailing backslashes ; Author ........: Dao Van Trong - TRONG.PRO ; =============================================================================================================================== Func _PathRemoveTrail($sPath) $sPath = StringStripWS($sPath, 3) While (StringRight($sPath, 1) == '\') $sPath = StringTrimRight($sPath, 1) WEnd Return $sPath EndFunc ;==>_PathRemoveTrail
    1 point
  40. Added this UDF to the Wiki
    1 point
  41. The max. topic name is 64 characters in ntfy. The max. char viewable in the WebUI is about 18 char. That means that you can have a topic that shows the name, and a hidden randomness added to it. And lets say that you'd like to change the unique random part of the topic makes impossible to guess but for you to be able to calculate. Topics like these: Testing_AutoIt_script______NBlR3rhNisx0Wz4NAWkGbgLWwqmiC5Mowncgk Testing_AutoIt_script______mTTKMjxeZoP3f2VtMU8M5x1Zn3y5OdmVmQfJd Testing_AutoIt_script______hGUseiM3rlxFnrhzaFizYj1JjClxBEyAtIi19 Testing_AutoIt_script______C6USjfsYrgOrPQqp7U0DEkgvkiMXDLgSxKRTd Testing_AutoIt_script______fm8GAGVEXcsuIKe2WTzMM922h4GL5CdqyHxkz Testing_AutoIt_script______ZhbeFm92lm7OZdnkH7LsZDkqWYfHit4FH10im that has that random part of it and, can be calculated by you by knowing the variables that creates it
    1 point
  42. I am just supporting the au3stripper questions in this thread. So without looking at the details it is pretty simple to me: Does the original script work?: if Yes: Does au3stripper run cleanly without any warnings? if Yes: The stripped script should work as the original if No: You are responsible and "don't come crying to me" when you override the default to continue with force! 😉
    1 point
  43. Now it is. Thanks. So here is my solution for this script: ;~ https://www.autoitscript.com/forum/topic/154081-avoid-autoit-error-message-box-in-unknown-errors/page/4/#findComment-1547476 #Region - AutoIt3Wrapper directives section ; General section #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Compression=4 ; Au3Check section #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 6 -w 7 ; Au3Stripper section #AutoIt3Wrapper_Run_Au3Stripper=y ;~ #Au3Stripper_Parameters=/SO /PE #Au3Stripper_Parameters=/SO /PE /RM #AutoIt3Wrapper_Au3Stripper_OnError=f ;~ #Au3Stripper_Ignore_Funcs=Intercept_MessageBoxW ;~ #Au3Stripper_Ignore_Funcs=__AddHookApi_DllCallbackRegister_wrapper #EndRegion - AutoIt3Wrapper directives section #include <WinApi.au3> #Region - exmaple ;~ AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint") AddHookApi("user32.dll", "MessageBoxW", FuncName(Intercept_MessageBoxW), "int", "hwnd;wstr;wstr;uint") MsgBox(0, 'Test', 'Some normal MsgBox text') DllStructCreate("byte[123456789097]") ; This is a deliberate action intended to display an error, as this script demonstrates how to change error handling - interact with MsgBox's title and text. #EndRegion - exmaple #Region @trancexx - https://www.autoitscript.com/forum/topic/154081-avoid-autoit-error-message-box-in-unknown-errors/#findComment-1111917 Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType) If $sTitle = 'AutoIt' Then $sTitle = 'TESTING: ' & StringReplace($sTitle, "AutoIt", @ScriptName) Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _ "hwnd", $hWnd, _ "wstr", $sText, _ "wstr", $sTitle, _ "uint", $iType) If @error Or Not $aCall[0] Then Return 0 Return $aCall[0] EndFunc ;==>Intercept_MessageBoxW ; The magic is down below Func AddHookApi($sModuleName, $vFunctionName, $vNewFunction, $sRet = "", $sParams = "") Local Static $pImportDirectory, $hInstance Local Const $IMAGE_DIRECTORY_ENTRY_IMPORT = 1 If Not $pImportDirectory Then $hInstance = _WinAPI_GetModuleHandle(0) $pImportDirectory = ImageDirectoryEntryToData($hInstance, $IMAGE_DIRECTORY_ENTRY_IMPORT) If @error Then Return SetError(1, 0, 0) EndIf Local $iIsInt = IsInt($vFunctionName) Local $iRestore = Not IsString($vNewFunction) Local $tIMAGE_IMPORT_MODULE_DIRECTORY Local $pDirectoryOffset = $pImportDirectory Local $tModuleName Local $iInitialOffset, $iInitialOffset2 Local $iOffset2 Local $tBufferOffset2, $iBufferOffset2 Local $tBuffer, $tFunctionOffset, $pOld, $fMatch, $pModuleName, $pFuncName Local Const $PAGE_READWRITE = 0x04 While 1 $tIMAGE_IMPORT_MODULE_DIRECTORY = DllStructCreate("dword RVAOriginalFirstThunk;" & _ "dword TimeDateStamp;" & _ "dword ForwarderChain;" & _ "dword RVAModuleName;" & _ "dword RVAFirstThunk", _ $pDirectoryOffset) If Not DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") Then ExitLoop $pModuleName = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName") $tModuleName = DllStructCreate("char Name[" & _WinAPI_StringLenA($pModuleName) & "]", $pModuleName) If DllStructGetData($tModuleName, "Name") = $sModuleName Then ; function from this module $iInitialOffset = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") $iInitialOffset2 = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAOriginalFirstThunk") If $iInitialOffset2 = $hInstance Then $iInitialOffset2 = $iInitialOffset $iOffset2 = 0 While 1 $tBufferOffset2 = DllStructCreate("dword_ptr", $iInitialOffset2 + $iOffset2) $iBufferOffset2 = DllStructGetData($tBufferOffset2, 1) If Not $iBufferOffset2 Then ExitLoop If $iIsInt Then If BitAND($iBufferOffset2, 0xFFFFFF) = $vFunctionName Then $fMatch = True ; wanted function Else $pFuncName = $hInstance + $iBufferOffset2 + 2 ; 2 is size od "word", see line below... $tBuffer = DllStructCreate("word Ordinal; char Name[" & _WinAPI_StringLenA($pFuncName) & "]", $hInstance + $iBufferOffset2) If DllStructGetData($tBuffer, "Name") == $vFunctionName Then $fMatch = True ; wanted function EndIf If $fMatch Then $tFunctionOffset = DllStructCreate("ptr", $iInitialOffset + $iOffset2) VirtualProtect(DllStructGetPtr($tFunctionOffset), DllStructGetSize($tFunctionOffset), $PAGE_READWRITE) If @error Then Return SetError(3, 0, 0) $pOld = DllStructGetData($tFunctionOffset, 1) If $iRestore Then DllStructSetData($tFunctionOffset, 1, $vNewFunction) Else #Region ; the #Au3Stripper_Off/#Au3Stripper_On directives, used in this place will lead to errors as /RM is used and all variables was changed in entire script but not within this region ;~ #Au3Stripper_Off ;~ DllStructSetData($tFunctionOffset, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction, $sRet, $sParams))) ;~ #Au3Stripper_On #EndRegion ; the #Au3Stripper_Off/#Au3Stripper_On directives, used in this place will lead to errors as /RM is used and all variables was changed in entire script but not within this region ; for this reason __AddHookApi_DllCallbackRegister_wrapper() was added and enclosed within #Au3Stripper_Off >>> #Au3Stripper_On section __AddHookApi_DllCallbackRegister_wrapper($tFunctionOffset, $vNewFunction, $sRet, $sParams) EndIf Return $pOld EndIf $iOffset2 += DllStructGetSize($tBufferOffset2) WEnd ExitLoop EndIf $pDirectoryOffset += 20 ; size of $tIMAGE_IMPORT_MODULE_DIRECTORY WEnd Return SetError(4, 0, 0) EndFunc ;==>AddHookApi #Au3Stripper_Off Func __AddHookApi_DllCallbackRegister_wrapper($tFunctionOffset__Wrapped, $vNewFunction__Wrapped, $sRet__Wrapped, $sParams__Wrapped) DllStructSetData($tFunctionOffset__Wrapped, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction__Wrapped, $sRet__Wrapped, $sParams__Wrapped))) EndFunc ;==>__AddHookApi_DllCallbackRegister_wrapper #Au3Stripper_On Func VirtualProtect($pAddress, $iSize, $iProtection) Local $aCall = DllCall("kernel32.dll", "bool", "VirtualProtect", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iProtection, "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>VirtualProtect Func ImageDirectoryEntryToData($hInstance, $iDirectoryEntry) ; Get pointer to data Local $pPointer = $hInstance ; Start processing passed binary data. 'Reading' PE format follows. Local $tIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & _ "word BytesOnLastPage;" & _ "word Pages;" & _ "word Relocations;" & _ "word SizeofHeader;" & _ "word MinimumExtra;" & _ "word MaximumExtra;" & _ "word SS;" & _ "word SP;" & _ "word Checksum;" & _ "word IP;" & _ "word CS;" & _ "word Relocation;" & _ "word Overlay;" & _ "char Reserved[8];" & _ "word OEMIdentifier;" & _ "word OEMInformation;" & _ "char Reserved2[20];" & _ "dword AddressOfNewExeHeader", _ $pPointer) Local $sMagic = DllStructGetData($tIMAGE_DOS_HEADER, "Magic") ; Check if it's valid format If Not ($sMagic == "MZ") Then Return SetError(1, 0, 0) ; MS-DOS header missing. Btw 'MZ' are the initials of Mark Zbikowski in case you didn't know. ; Move pointer $pPointer += DllStructGetData($tIMAGE_DOS_HEADER, "AddressOfNewExeHeader") ; move to PE file header ; In place of IMAGE_NT_SIGNATURE structure Local $tIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $pPointer) ; Check signature If DllStructGetData($tIMAGE_NT_SIGNATURE, "Signature") <> 17744 Then ; IMAGE_NT_SIGNATURE Return SetError(2, 0, 0) ; wrong signature. For PE image should be "PE\0\0" or 17744 dword. EndIf ; Move pointer $pPointer += 4 ; size of $tIMAGE_NT_SIGNATURE structure ; In place of IMAGE_FILE_HEADER structure ; Move pointer $pPointer += 20 ; size of $tIMAGE_FILE_HEADER structure ; Determine the type Local $tMagic = DllStructCreate("word Magic;", $pPointer) Local $iMagic = DllStructGetData($tMagic, 1) Local $tIMAGE_OPTIONAL_HEADER If $iMagic = 267 Then ; x86 version ; Move pointer $pPointer += 96 ; size of $tIMAGE_OPTIONAL_HEADER ElseIf $iMagic = 523 Then ; x64 version ; Move pointer $pPointer += 112 ; size of $tIMAGE_OPTIONAL_HEADER Else Return SetError(3, 0, 0) ; unsupported module type EndIf ; Validate input by checking available number of structures that are in the module Local Const $IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16 ; predefined value that PE modules always use (AutoIt certainly) If $iDirectoryEntry > $IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1 Then Return SetError(4, 0, 0) ; invalid input ; Calculate the offset to wanted entry (every entry is 8 bytes) $pPointer += 8 * $iDirectoryEntry ; At place of correst directory entry Local $tIMAGE_DIRECTORY_ENTRY = DllStructCreate("dword VirtualAddress; dword Size", $pPointer) ; Collect data Local $pAddress = DllStructGetData($tIMAGE_DIRECTORY_ENTRY, "VirtualAddress") If $pAddress = 0 Then Return SetError(5, 0, 0) ; invalid input ; $pAddress is RVA, add it to base address Return $hInstance + $pAddress EndFunc ;==>ImageDirectoryEntryToData #EndRegion @trancexx - https://www.autoitscript.com/forum/topic/154081-avoid-autoit-error-message-box-in-unknown-errors/#findComment-1111917 Explanations: Using @trancexx code, in order to use: #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe #AutoIt3Wrapper_Au3Stripper_OnError=f there is also a need to use: #Au3Stripper_Ignore_Funcs=Intercept_MessageBoxW Because in other way: #Au3Stripper_Parameters=/so /pe Will strip down the function as she is not called directly. Only the function name is used but as a string and not directly like a "pointer" To prevent using: #Au3Stripper_Ignore_Funcs=Intercept_MessageBoxW The Intercept_MessageBoxW can be called as a parameter for FuncName(Intercept_MessageBoxW) this way: ;~ AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint") AddHookApi("user32.dll", "MessageBoxW", FuncName(Intercept_MessageBoxW), "int", "hwnd;wstr;wstr;uint") In such case Au3Stripper knows that Intercept_MessageBoxW was used and should not be stripped. REMARK: You can also notice that I used: #Au3Stripper_Parameters=/SO /PE /RM I mean the the most demanding/restrictive option /RM For this reason this following mod was added: ..... #Region ; the #Au3Stripper_Off/#Au3Stripper_On directives, used in this place will lead to errors as /RM is used and all variables was changed in entire script but not within this region ;~ #Au3Stripper_Off ;~ DllStructSetData($tFunctionOffset, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction, $sRet, $sParams))) ;~ #Au3Stripper_On #EndRegion ; the #Au3Stripper_Off/#Au3Stripper_On directives, used in this place will lead to errors as /RM is used and all variables was changed in entire script but not within this region ; for this reason __AddHookApi_DllCallbackRegister_wrapper() was added and enclosed within #Au3Stripper_Off >>> #Au3Stripper_On section __AddHookApi_DllCallbackRegister_wrapper($tFunctionOffset, $vNewFunction, $sRet, $sParams) ..... #Au3Stripper_Off Func __AddHookApi_DllCallbackRegister_wrapper($tFunctionOffset__Wrapped, $vNewFunction__Wrapped, $sRet__Wrapped, $sParams__Wrapped) DllStructSetData($tFunctionOffset__Wrapped, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction__Wrapped, $sRet__Wrapped, $sParams__Wrapped))) EndFunc ;==>__AddHookApi_DllCallbackRegister_wrapper #Au3Stripper_On ..... The reason that I do not must to use: ;~ #Au3Stripper_Ignore_Funcs=__AddHookApi_DllCallbackRegister_wrapper is because __AddHookApi_DllCallbackRegister_wrapper() is used/called before the #Au3Stripper_Off / #Au3Stripper_Off sections occurs so Au3Stripper already dit the /RM action on the function name in entire script but at this moment do not touched $******__Wrapped variables. @Jos Does this example cover the whole topic of using Au3Stripper with this @trancexx script, I mean all releated with the /SO /PE /RM parameters? btw. I wonder whether, for the correctness of "code reading" and protection against possible changes in Au3Stripper, I should still use: #Au3Stripper_Ignore_Funcs=__AddHookApi_DllCallbackRegister_wrapper
    1 point
  44. I fixed this by using the "Compile script to .exe" tool and setting compatibility mode on the generated executable to run as Administrator. Works in Windows 7 and Windows 10.
    1 point
  45. This is my another try on playing XM music in AutoIt. Usually you would need third party dll to play this music. The problem is need for both x86 and x64 dlls for universal application. Deploying these new files has its own downsides. That's why I decided to write my engine for the player. It's written in c++ following available XM documentation, and compiled using free version of Visual Studio. After that binary data is extracted and embedded compressed inside the script. When the script is used the code is decompressed. Download zip file and extract folder inside together with all files (most of them are XM music files of my choice), run Player.au3 and see if it's working for you. XM_Play.zip There are no dlls, external files or anything else of such kind. Available functions are: Load_XM Free_XM Pause_XM Play_XM Vol_XM Player.au3 is just an example. ...Oh, and you can load online XMs directly specifying URL.
    1 point
  46. twitchyliquid64

    Proxy Checker

    Scans a textfile (@ScriptDir & "/proxylist.txt") for addresses and checks to see if the proxy at that address still works. Addresses in this file are placed in the format <ipaddress>:<port> and addresses are separated by lines. Credit to Zatorg - his Asynchronous sockets UDF is used (included) #include <GUIConstantsEx.au3> #include <file.au3> #include <array.au3> #Include <GuiListView.au3> Opt("GUIOnEventMode", 1) global $PROXY_LIST[1][5] TCPStartup() Global $hWs2_32 = -1 ;Create the GUI $win = GUICreate( "Proxy Scanner", 400, 400) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $list = GUICtrlCreateListView( "# | IP | Port | Status", 10, 10, 380, 330) Readin_Proxies() GUISetState() Global Const $__TCP_WINDOW = GUICreate("Async Sockets UDF") ;Set the status of each proxy. For $x = 0 to UBound($PROXY_LIST)-2 step 1 Test_Connection( $x) Sleep(100) Next While 1 Sleep(20) WEnd Func CLOSEClicked() Exit EndFunc Func Readin_Proxies() ProgressOn( "Proxy Scanner", "Loading...Please Wait.", "populating lists...") local $linecount = _FileCountLines( @ScriptDir & "/proxylist.txt") ReDim $PROXY_LIST[$linecount][5] $filehnd = FileOpen( @ScriptDir & "/proxylist.txt") For $x = 0 to $linecount step 1 ProgressSet( ($x/$linecount)*100) $Line = "" While 1 ;Collect the entire line into a variable. $character = FileRead( $filehnd, 1) if @error = -1 then ExitLoop 2 if $character = @CR Then ExitLoop if $character = @LF then ContinueLoop $Line &= $character WEnd $spl = StringSplit( $Line, ":", 1) $PROXY_LIST[$x][0] = $spl[1] if $spl[0] >= 2 Then $PROXY_LIST[$x][1] = $spl[2] Else $PROXY_LIST[$x][1] = 80 EndIf $PROXY_LIST[$x][2] = GUICtrlCreateListViewItem( $x&"|"&$spl[1]&"|"&$PROXY_LIST[$x][1]&"|Unknown", $list) GUICtrlSetBkColor( $PROXY_LIST[$x][2], 0xFFFFAA) Next FileClose( $filehnd) ProgressOff() EndFunc Func Test_Connection( $arrayslot) local $SocketID = ___ASocket() ___ASockSelect( $SocketID, $__TCP_WINDOW, 0x401 + $arrayslot, BitOR( 1, 2, 16, 32)) GUIRegisterMsg( 0x401 + $arrayslot, "Opensocket_data_" ) ___ASockConnect( $SocketID, $PROXY_LIST[$arrayslot][0], $PROXY_LIST[$arrayslot][1]) $PROXY_LIST[$arrayslot][3] = $SocketID EndFunc Func Opensocket_data_( $hWnd, $iMsgID, $WParam, $LParam ) Local $iError = ___HiWord( $LParam ) Local $iEvent = ___LoWord( $LParam ) Abs($hWnd) local $Array_Slot = $iMsgID-0x0401 ;No more loops to slow down message delievery! local $x = $Array_Slot Switch $iEvent Case 16 If $iError Then ;FAILED CONNECTION GUICtrlSetData( $PROXY_LIST[$x][2], $x&"|"&$PROXY_LIST[$x][0]&"|"&$PROXY_LIST[$x][1]&"|OFFLINE") GUICtrlSetBkColor( $PROXY_LIST[$x][2], 0xEEEEAA) Else GUICtrlSetData( $PROXY_LIST[$x][2], $x&"|"&$PROXY_LIST[$x][0]&"|"&$PROXY_LIST[$x][1]&"|ONLINE") GUICtrlSetBkColor( $PROXY_LIST[$x][2], 0x00FF00) EndIf ___ASockShutdown($PROXY_LIST[$x][3]) TCPCloseSocket($PROXY_LIST[$x][2]) EndSwitch EndFunc ;================================================================================================================== ; ; Zatorg's Asynchronous Sockets UDF Starts from here. ; ;================================================================================================================== Func ___ASocket($iAddressFamily = 2, $iType = 1, $iProtocol = 6) If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) Local $hSocket = DllCall($hWs2_32, "uint", "socket", "int", $iAddressFamily, "int", $iType, "int", $iProtocol) If @error Then SetError(1, @error) Return -1 EndIf If $hSocket[ 0 ] = -1 Then SetError(2, ___WSAGetLastError()) Return -1 EndIf Return $hSocket[ 0 ] EndFunc ;==>_ASocket Func ___ASockShutdown($hSocket) If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) Local $iRet = DllCall($hWs2_32, "int", "shutdown", "uint", $hSocket, "int", 2) If @error Then SetError(1, @error) Return False EndIf If $iRet[ 0 ] <> 0 Then SetError(2, ___WSAGetLastError()) Return False EndIf Return True EndFunc ;==>_ASockShutdown Func ___ASockClose($hSocket) If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) Local $iRet = DllCall($hWs2_32, "int", "closesocket", "uint", $hSocket) If @error Then SetError(1, @error) Return False EndIf If $iRet[ 0 ] <> 0 Then SetError(2, ___WSAGetLastError()) Return False EndIf Return True EndFunc ;==>_ASockClose Func ___ASockSelect($hSocket, $hWnd, $uiMsg, $iEvent) If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) Local $iRet = DllCall( _ $hWs2_32, _ "int", "WSAAsyncSelect", _ "uint", $hSocket, _ "hwnd", $hWnd, _ "uint", $uiMsg, _ "int", $iEvent _ ) If @error Then SetError(1, @error) Return False EndIf If $iRet[ 0 ] <> 0 Then SetError(2, ___WSAGetLastError()) Return False EndIf Return True EndFunc ;==>_ASockSelect ; Note: you can see that $iMaxPending is set to 5 by default. ; IT DOES NOT MEAN THAT DEFAULT = 5 PENDING CONNECTIONS ; 5 == SOMAXCONN, so don't worry be happy Func ___ASockListen($hSocket, $sIP, $uiPort, $iMaxPending = 5); 5 == SOMAXCONN => No need to change it. Local $iRet Local $stAddress If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) $stAddress = ___SockAddr($sIP, $uiPort) If @error Then SetError(@error, @extended) Return False EndIf $iRet = DllCall($hWs2_32, "int", "bind", "uint", $hSocket, "ptr", DllStructGetPtr($stAddress), "int", DllStructGetSize($stAddress)) If @error Then SetError(3, @error) Return False EndIf If $iRet[ 0 ] <> 0 Then $stAddress = 0; Deallocate SetError(4, ___WSAGetLastError()) Return False EndIf $iRet = DllCall($hWs2_32, "int", "listen", "uint", $hSocket, "int", $iMaxPending) If @error Then SetError(5, @error) Return False EndIf If $iRet[ 0 ] <> 0 Then $stAddress = 0; Deallocate SetError(6, ___WSAGetLastError()) Return False EndIf Return True EndFunc ;==>_ASockListen Func ___ASockConnect($hSocket, $sIP, $uiPort) Local $iRet Local $stAddress If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) $stAddress = ___SockAddr($sIP, $uiPort) If @error Then SetError(@error, @extended) Return False EndIf $iRet = DllCall($hWs2_32, "int", "connect", "uint", $hSocket, "ptr", DllStructGetPtr($stAddress), "int", DllStructGetSize($stAddress)) If @error Then SetError(3, @error) Return False EndIf $iRet = ___WSAGetLastError() If $iRet = 10035 Then; WSAEWOULDBLOCK Return True; Asynchronous connect attempt has been started. EndIf SetExtended(1); Connected immediately Return True EndFunc ;==>_ASockConnect ; A wrapper function to ease all the pain in creating and filling the sockaddr struct Func ___SockAddr($sIP, $iPort, $iAddressFamily = 2) Local $iRet Local $stAddress If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) $stAddress = DllStructCreate("short; ushort; uint; char[8]") If @error Then SetError(1, @error) Return False EndIf DllStructSetData($stAddress, 1, $iAddressFamily) $iRet = DllCall($hWs2_32, "ushort", "htons", "ushort", $iPort) DllStructSetData($stAddress, 2, $iRet[ 0 ]) $iRet = DllCall($hWs2_32, "uint", "inet_addr", "str", $sIP) If $iRet[ 0 ] = 0xffffffff Then; INADDR_NONE $stAddress = 0; Deallocate SetError(2, ___WSAGetLastError()) Return False EndIf DllStructSetData($stAddress, 3, $iRet[ 0 ]) Return $stAddress EndFunc ;==>__SockAddr Func ___WSAGetLastError() If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" ) Local $iRet = DllCall($hWs2_32, "int", "WSAGetLastError") If @error Then ;if $console_out = True then ConsoleWrite("+> _WSAGetLastError(): WSAGetLastError() failed. Script line number: " & @ScriptLineNumber & @CRLF) SetExtended(1) Return 0 EndIf Return $iRet[ 0 ] EndFunc ;==>_WSAGetLastError ; Got these here: ; http://www.autoitscript.com/forum/index.php?showtopic=5620&hl=MAKELONG Func ___MakeLong($LoWord, $HiWord) Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF)); Thanks Larry EndFunc ;==>_MakeLong Func ___HiWord($Long) Return BitShift($Long, 16); Thanks Valik EndFunc ;==>_HiWord Func ___LoWord($Long) Return BitAND($Long, 0xFFFF); Thanks Valik EndFunc ;==>_LoWord ;----------------------------------OTHER AUTOIT INBUILT FUNCS----## ;=============================================================================== ; ; Function Name: _GetIP() ; Description: Get public IP address of a network/computer. ; Parameter(s): None ; Requirement(s): Internet access. ; Return Value(s): On Success - Returns the public IP Address ; On Failure - -1 and sets @ERROR = 1 ; Author(s): Larry/Ezzetabi & Jarvis Stubblefield ; ;=============================================================================== Func _Get_IP() Local $ip, $t_ip If InetGet("http://checkip.dyndns.org/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp")) FileDelete(@TempDir & "\~ip.tmp") $ip = StringTrimLeft($ip, StringInStr($ip, ":") + 1) $ip = StringTrimRight($ip, StringLen($ip) - StringInStr($ip, "/") + 2) $t_ip = StringSplit($ip, '.') If $t_ip[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) Then Return $ip EndIf EndIf If InetGet("http://www.whatismyip.com/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp")) FileDelete(@TempDir & "\~ip.tmp") $ip = StringTrimLeft($ip, StringInStr($ip, "Your ip is") + 10) $ip = StringLeft($ip, StringInStr($ip, " ") - 1) $ip = StringStripWS($ip, 8) $t_ip = StringSplit($ip, '.') If $t_ip[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) Then Return $ip EndIf EndIf SetError(1) Return -1 EndFunc ;==>_Get_IP Some Proxies to get you started: 118.96.94.36:8080 69.125.128.138:27977 114.129.97.46:8080 124.195.18.119:80 62.75.145.245:9100 98.183.251.11:27977 173.196.50.100:27977 221.12.61.214:8080 222.186.43.82:1080 69.33.181.42:80 114.129.100.35:8080 64.76.188.126:80 114.129.97.101:8080 212.58.10.10:80 77.241.165.114:8080 159.226.234.7:80 114.59.80.243:8080 190.94.1.195:80 118.182.20.242:8080 41.234.207.197:8080 98.155.37.249:47793 79.125.28.242:8080 24.126.55.101:27977 193.188.125.173:80 124.193.109.15:80 109.203.196.121:808 80.239.243.18:80 218.6.13.35:80 69.136.47.4:27977 216.104.161.208:80 24.179.18.15:12378 189.1.162.4:8080 195.97.254.137:80 117.28.232.186:80 41.215.177.206:8080 110.138.211.56:8080 66.193.15.82:80 124.225.57.10:8080 112.169.94.143:8088 70.44.61.7:1233 204.15.147.149:8080 114.129.98.35:8080 76.18.96.186:27977 180.241.98.194:8080 72.13.94.164:80 209.237.236.110:80 41.205.110.85:8080 91.210.104.104:80 121.14.104.244:80 68.199.165.7:3697 122.70.156.157:80 174.129.133.21:8000 114.129.98.236:8080 75.73.231.37:27977 118.137.65.154:8080 200.167.162.203:8080 187.45.232.176:8080 115.69.216.98:80 70.163.50.203:27977 112.95.238.199:808 193.87.7.65:80 95.0.211.186:8080 182.48.43.12:80 114.129.98.108:8080 222.247.48.221:808 182.48.23.77:8090 69.244.133.182:1168 78.93.242.7:80 114.129.97.49:8080 114.129.98.66:8080 67.192.11.165:80 63.130.248.252:80 210.23.76.200:8080 196.202.83.129:8000 65.32.56.224:1083 68.84.169.216:27977 208.110.220.133:8080 198.12.16.170:80 69.124.240.221:37701 85.214.50.156:8118 222.188.10.1:1080 183.62.24.34:808 114.129.100.143:8080 98.183.9.251:1137 218.19.119.99:8080 203.186.62.125:8080 91.200.171.245:8080 202.4.155.234:808 212.33.237.113:80 163.152.133.22:8080 88.85.125.78:8080 64.4.98.119:27977 89.188.141.51:80 212.51.207.126:80 118.174.36.190:8080 200.82.126.87:80 212.85.146.236:80 96.240.2.237:42863 120.136.22.154:8080 111.67.80.116:80 61.4.234.216:8080 66.119.43.37:80 122.227.22.214:63000 114.129.98.231:8080 80.239.242.225:80 82.160.44.55:8080 72.3.245.248:80 222.124.25.74:80 119.235.53.131:80 98.199.27.21:27977 85.254.213.163:80 61.4.219.6:8080 93.189.5.138:8080 195.189.142.69:80 212.209.194.144:80 202.159.8.74:8080 118.97.13.60:8080 88.87.215.114:81 67.84.134.22:27977 114.129.98.37:8080 116.55.19.96:1080 203.142.72.107:80 175.111.89.16:8080 99.248.60.100:1939 63.130.248.251:80 62.129.243.242:8080 200.242.222.139:80 114.129.98.212:8080 193.160.201.95:80 202.212.166.90:8080 189.47.194.196:8080 114.129.99.161:8080 114.129.97.136:8080 59.77.17.24:8080 98.109.59.184:1797 114.129.100.77:8080 114.129.99.254:8080 98.222.69.66:27977 201.75.73.131:8080 24.90.235.196:27977 98.208.56.122:10971 201.234.133.41:1080 46.0.203.7:80 67.184.98.250:27977 92.61.188.141:8080 65.34.150.112:27977 112.216.29.245:80 114.129.98.10:8080 67.249.168.198:8085 188.40.173.106:80 83.170.116.143:80 61.4.219.10:8080 66.65.70.65:1252 159.226.251.180:83 80.239.242.242:80 76.100.17.159:27977 209.62.20.171:80 193.28.52.145:80 203.130.195.193:8080 189.200.240.68:80 68.62.73.13:1733 180.243.86.215:8080 118.96.142.61:80 92.63.52.73:8080 88.250.70.208:80 95.168.181.219:8080 118.97.83.245:8090 75.125.143.84:80 189.17.0.35:8000 178.213.33.129:443 24.234.67.140:27977 209.235.218.83:80 119.40.100.113:8080 114.129.98.142:8080 76.31.62.106:27977 202.77.107.34:80 189.3.160.42:80 114.129.97.42:8080 87.226.106.203:8080 64.34.213.148:80 190.40.28.83:8080 201.67.138.98:80 82.117.192.227:8080 193.252.48.31:8080 92.61.189.129:8080 209.62.20.196:80 118.98.216.27:8080 41.73.2.35:8080 66.92.169.250:80 194.170.16.75:8080 173.212.195.196:1337 58.246.182.60:8088 65.23.156.161:80 134.37.254.27:80 68.111.211.98:27977 77.78.3.83:9090 190.41.192.210:8080 87.250.129.151:80 62.176.18.25:80 174.134.42.74:80 220.227.100.59:8080 217.91.32.16:8080 91.194.246.49:8080 218.242.254.74:1080 200.20.0.246:80 119.235.53.130:80 67.63.92.33:27977 180.246.179.34:8080 110.137.40.102:8080 58.246.200.114:80 68.38.24.73:48397 195.189.142.132:80 69.123.91.137:27977 221.1.96.22:443 71.174.102.72:80 125.162.32.222:80 66.119.43.36:80 68.39.144.196:1385 221.215.106.82:1337 119.15.86.20:8080 68.118.109.226:27977 70.158.130.208:8080 125.40.181.247:8080 114.129.99.111:8080 117.41.228.6:2 210.48.147.36:80 67.53.116.252:80 24.109.239.138:80 114.129.99.72:8080 211.100.4.71:80 218.21.91.214:80 58.241.40.228:1080 200.88.125.4:8008 187.111.11.72:8080 118.122.88.7:8080 187.11.250.175:8080 114.129.99.144:8080 196.23.152.220:80 148.235.153.178:8080 91.194.247.234:8080 165.228.212.223:80 80.82.235.179:80 187.111.223.10:8080 202.181.164.100:80 216.40.33.31:80 195.162.130.20:8080 188.94.228.46:8080 202.147.198.69:80 202.212.166.124:8080 222.35.137.220:80 114.129.98.241:8080 41.73.15.211:8080 114.129.98.175:8080 188.40.173.101:80 98.110.80.191:1734 213.29.63.62:8080 114.129.98.146:8080 114.129.99.125:8080 60.191.232.230:80 115.124.66.30:8080 180.241.106.54:80 202.117.35.249:80 114.129.98.99:8080 190.1.137.130:8080 114.129.100.237:8080 81.217.6.239:80 196.214.141.221:8080 98.255.196.232:1590 68.49.201.216:27977 122.52.117.92:8080 202.143.148.61:80 222.70.137.238:80 222.124.136.103:8080 187.85.160.3:80 189.73.221.49:80 64.120.166.23:1080 114.129.100.55:8080 87.197.42.171:8080 180.246.114.66:8080 119.36.138.131:1080 67.223.227.21:80 221.233.134.87:8080 94.195.11.147:80 71.72.30.250:28052 209.226.31.160:80 74.197.10.24:27977 209.200.46.108:80 8.4.59.117:80 109.74.202.89:80 119.40.100.9:8080 200.63.71.225:8080 110.138.51.76:8080 203.172.167.8:8080 82.177.67.1:8080 77.67.17.17:8080 76.188.219.178:4458 221.229.119.186:80 81.0.235.172:80 216.104.161.120:80 110.138.211.56:80 212.177.17.74:80 186.24.13.125:8080 118.97.129.74:8080 80.239.242.223:80 114.129.99.83:8080 114.129.99.210:8080 202.4.155.234:1080 67.159.52.76:8080 68.192.216.10:1337 219.235.228.182:1080 118.98.215.10:8080 200.81.59.101:80 202.143.149.36:8080 195.49.188.226:80 123.125.156.92:80 92.61.191.17:8080 201.208.100.167:8080 68.169.183.117:27977 112.105.69.163:80 61.4.11.193:8080 122.72.20.218:80 200.148.135.234:8080 203.199.9.4:80 74.114.116.101:80 122.144.1.212:8080 97.65.164.214:8080 200.171.25.203:8000 41.134.81.234:80 119.235.53.130:8080 125.165.125.83:8080 160.79.35.27:80 24.0.213.12:8008 24.0.82.254:58029 91.90.120.40:1080 218.61.196.69:8080 114.129.99.243:8080 114.129.98.131:8080 70.174.29.174:27977 114.129.98.211:8080 202.51.107.34:8080 61.207.158.6:8088 122.248.213.39:80 84.22.27.4:80 110.136.207.37:80 77.66.25.53:80 98.200.72.55:1908 119.110.81.226:8080 85.214.61.55:80 202.44.53.94:80 75.69.78.108:1405 194.187.110.72:80 118.96.94.45:80 200.85.79.22:80 75.64.57.44:57907 203.142.71.149:8080 202.146.129.133:8080 67.165.33.228:27977 202.191.122.239:80 202.99.27.3:8080 61.4.253.175:8080 218.28.233.214:9000 114.129.97.51:8080 114.129.100.252:8080 63.134.178.211:27977 87.119.213.25:80 109.254.88.136:1080 66.235.245.150:80 212.118.224.151:80 80.206.48.100:80 67.182.241.56:27977 24.242.167.123:8080 210.8.224.2:80 114.129.100.86:8080 77.27.27.65:16589 210.94.189.210:8080 195.117.121.2:1080 92.63.96.135:8080 210.31.160.55:9 212.49.64.3:80 98.198.54.147:27977 220.113.15.220:8081 195.89.37.91:80 59.39.67.158:8080 218.92.252.38:8080 122.155.13.18:80 202.103.67.98:80 189.72.173.220:80 24.228.100.186:27977 76.16.165.171:1091 87.120.166.182:88 189.22.150.34:80 174.142.125.161:80 187.4.118.221:80 114.129.98.129:8080 83.36.60.252:80 112.175.251.56:8080 208.45.143.104:80 217.20.163.72:80 61.185.143.178:8080 188.142.49.254:8080 193.179.209.200:80 91.90.122.1:1080 209.62.20.239:80 64.255.180.31:80 67.205.67.45:80 222.124.5.82:8080 80.239.242.112:80 98.200.64.178:1174 75.190.141.203:27977 174.129.195.8:8123 87.106.197.98:443 195.248.250.142:80 114.129.98.73:8080 85.214.152.105:1337 68.52.107.181:27977 74.213.164.188:80 114.129.100.249:8080 200.125.243.122:8080 219.83.100.204:8080 64.211.66.142:80 62.216.165.131:8080 175.41.151.200:80 180.246.116.28:80 221.204.246.161:80 201.75.71.33:8080 24.16.196.237:1907 168.176.5.223:80 61.4.11.19:8080 61.6.245.46:80 98.212.102.97:1628 190.144.55.147:8080 120.136.21.131:80 222.69.91.144:63000 216.6.202.27:80 193.255.195.72:80 213.192.85.98:8080 189.22.105.205:8080 193.190.145.92:80 184.22.251.43:80 204.12.250.147:64616 118.96.78.2:8080 108.36.100.249:14925 119.82.239.62:8080 219.117.212.126:8080 200.206.175.108:8080 79.106.1.83:8080 173.203.102.80:8080 193.255.192.190:80 63.166.247.31:80 187.12.229.178:8080 174.108.120.102:3390 75.126.176.161:80 118.96.78.16:8080 24.215.22.136:3969 72.55.130.45:80 178.165.55.79:8008 114.129.99.131:8080 66.7.124.203:27977 117.102.83.218:80 196.28.237.43:8080 24.230.247.138:29505 202.69.33.143:8080 61.4.251.243:8080 58.20.41.168:1080 111.67.80.84:80 114.113.228.202:1080 180.249.131.31:80 112.95.238.199:1080 218.29.89.203:8080 213.41.80.7:80 200.37.204.93:8080 201.23.107.11:8080 114.129.97.73:8080 80.237.156.177:80 184.22.248.124:8080 190.145.116.22:80 120.29.157.234:8080 118.96.30.11:8080 82.99.211.50:8080 114.129.98.127:8080 72.167.202.24:8000 202.212.165.205:8080 75.102.3.18:80 97.81.175.62:1414 222.237.79.140:80 111.68.100.8:8080 210.48.147.82:80 200.97.9.234:8080 92.61.188.41:8080 75.125.242.146:80 61.191.187.23:8080 24.0.68.158:1355 58.59.31.82:1337 211.239.121.249:43565 186.136.72.41:80 118.96.94.45:8080 200.181.30.37:8080 173.22.82.104:13229 118.98.202.123:8080 85.185.105.26:8080 66.75.93.204:8088 190.147.197.35:8080 70.185.184.141:11331 111.68.28.27:8080 216.104.161.205:80 122.48.31.74:80 114.129.100.126:8080 173.217.173.248:27977 222.124.144.178:80 180.247.218.28:8080 114.129.99.129:8080 114.129.98.159:8080 72.218.74.95:27977 116.90.162.147:80 112.65.216.174:1080 221.2.144.135:1080 118.69.192.62:8088 202.74.65.69:8080 122.48.31.73:80 196.202.41.254:80 202.64.130.236:80 114.129.97.66:8080 210.166.221.61:8080 196.3.182.146:80 202.65.122.226:8080 118.122.88.44:80 58.221.129.158:1337 118.96.136.76:80 61.166.144.29:80 189.31.180.236:80 114.129.100.238:8080 202.43.74.66:8080 117.102.226.142:80 124.225.55.30:8080 115.236.98.109:80 203.251.21.105:80 69.195.207.230:7257 190.77.30.109:8080 115.124.65.94:8080 116.205.127.43:8080 216.249.85.43:27977 118.97.224.2:8080 110.139.180.151:8080 118.97.84.20:80 222.124.218.164:8080 180.244.211.224:8080 66.229.95.87:8085 110.138.207.144:8080 187.4.82.68:8080 115.124.75.36:80 200.63.71.54:8080 98.209.176.218:1565 200.181.109.20:80 115.124.73.166:80 115.124.64.241:8080 202.149.90.234:8080 24.46.89.172:1147 187.4.104.99:8080 125.164.72.200:8080 98.222.112.179:27977 24.3.70.138:27977 180.243.231.55:8080 74.109.211.64:1564 220.237.25.106:1087 8080 78.188.153.229:8080 210.48.147.52:80 208.64.176.157:80 69.125.100.96:27977 58.96.134.22:8000 24.139.43.249:8085 184.72.55.152:443 114.129.100.80:8080 119.109.115.149:8909 67.167.89.121:14073 71.82.96.242:1421 109.87.143.120:9 173.74.178.23:31779 68.144.41.195:17719 71.234.200.202:37373 24.13.125.182:2003 66.27.207.82:27977 72.240.34.23:80 182.48.167.10:8080 EDIT: All the Proxies in this list are legal, public Proxies so dont get any ideas!
    1 point
  47. I had a quick look around and couldn't find this anywhere so I'm posting up some code. This allows you to drag-and-drop the items in the listbox in order to reorder them. A nice UI touch when you want users to have the ability to do this. I'm writing something right now that will use this but thought I'd put this code here in case someone wants to use it. #include <Constants.au3> #include <GUIListBox.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $gnDRAGLISTMSGSTRING = _WinAPI_RegisterWindowMessage("commctrl_DragListMsg") Global $DL_BEGINDRAG = $WM_USER + 133 Global $DL_DRAGGING = $WM_USER + 134 Global $DL_DROPPED = $WM_USER + 135 Global $DL_CANCELDRAG = $WM_USER + 136 Global Enum $DL_STOPCURSOR = 1, $DL_COPYCURSOR, $DL_MOVECURSOR Global $gtDRAGLISTINFO = "long uNotification;long hWnd;long x;long y" Global $gfItemAdded = False Global $hMain = GUICreate("DragList", 200, 400) Global $cListbox = GUICtrlCreateList("", 16, 16, 168, 368, $WS_BORDER + $WS_VSCROLL) GUICtrlSetFont($cListbox, 10, Default, Default, "Tahoma") Global $hListbox = GUICtrlGetHandle($cListbox) GUICtrlSetData($cListbox, "Apples|Oranges|Bananas|Pears|Grapefruits|Limes|Lemons|Strawberries|Plums|Melons|Grapes|") GUISetState() _ComCtl32_MakeDragList($hListbox) Global $wProcNew = DllCallbackRegister("_MyWndProc", "int", "hwnd;int;wparam;lparam") Global $wProcOld = _WinAPI_SetWindowLong($hMain, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) While GUIGetMsg() <> -3 Sleep(10) Wend Exit Func _MyWndProc($hWnd, $nMsg, $wParam, $lParam) Local $aRet, $nOldIndex, $sItemText If $nMsg = $gnDRAGLISTMSGSTRING Then Local $tDRAGLISTINFO = DllStructCreate($gtDRAGLISTINFO, $lParam) Local $uNotification = DllStructGetData($tDRAGLISTINFO, "uNotification") Local $x = DllStructGetData($tDRAGLISTINFO, "x"), $y = DllStructGetData($tDRAGLISTINFO, "y") Local $nItem = _ComCtl32_LBItemFromPt($hListbox, $x, $y) Switch $uNotification Case $DL_BEGINDRAG If $nItem < (_GUICtrlListBox_GetCount($hListbox) - 1) Then _GUICtrlListBox_AddString($hListbox, "") $gfItemAdded = True EndIf Return 1 Case $DL_DRAGGING _ComCtl32_DrawInsert($hMain, $hListbox, $nItem) If $nItem = _GUICtrlListBox_GetCurSel($hListbox) Then Return $DL_STOPCURSOR Return $DL_MOVECURSOR Case $DL_DROPPED If $nItem > -1 Then $nOldIndex = _GUICtrlListBox_GetCurSel($hListbox) If $nItem <> $nOldIndex Then $sItemText = _GUICtrlListBox_GetText($hListbox, $nOldIndex) If $nItem < $nOldIndex Then $nOldIndex += 1 _GUICtrlListBox_InsertString($hListbox, $sItemText, $nItem) _GUICtrlListBox_DeleteString($hListbox, $nOldIndex) If $nItem > $nOldIndex Then $nItem -= 1 _GUICtrlListBox_SetCurSel($hListbox, $nItem) EndIf EndIf If $gfItemAdded Then _GUICtrlListBox_DeleteString($hListbox, _GUICtrlListBox_GetCount($hListbox) - 1) $gfItemAdded = False EndIF _ComCtl32_DrawInsert($hMain, $hListbox, -1) Return 0 Case $DL_CANCELDRAG If $gfItemAdded Then _GUICtrlListBox_DeleteString($hListbox, _GUICtrlListBox_GetCount($hListbox) - 1) $gfItemAdded = False EndIF _ComCtl32_DrawInsert($hMain, $hListbox, -1) Return 0 EndSwitch EndIf Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $nMsg, $wParam, $lParam) EndFunc Func _ComCtl32_MakeDragList($hWnd) Local $aRet = DllCall("comctl32.dll", "int", "MakeDragList", "hwnd", $hWnd) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc Func _ComCtl32_LBItemFromPt($hWnd, $x, $y) Local $aRet = DllCall("comctl32.dll", "long", "LBItemFromPt", "hwnd", $hWnd, "long", $x, "long", $y, "long", 1) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc Func _ComCtl32_DrawInsert($hWndParent, $hWnd, $nItem) DllCall("comctl32.dll", "none", "DrawInsert", "hwnd", $hWndParent, "hwnd", $hWnd, "long", $nItem) If @error Then Return SetError(@error, @extended, 0) Return EndFunc Enjoy. WBD
    1 point
  48. Mt version: Func IsChecked($control) Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED EndFunc
    1 point
×
×
  • Create New...