Leaderboard
Popular Content
Showing content with the highest reputation on 12/31/2024 in all areas
-
WinActiveBorder()
Danyfirex and one other reacted to argumentum for a topic
2 points -
Problems when returning DllStructGetPtr from function
emcodem and one other reacted to pixelsearch for a topic
Hello, Instead of creating the Global variable $out in the main body of the script and passing 2 parameters to MakeWstrPtr() , why not simply return the structure variable name when the function ends, something like this : Global $g_tStruct = WstrPtr("test") For $i = 5 To 1 Step -1 CallEcho() Next Func WstrPtr($str) Local $tStruct = DllStructCreate("wchar [" & StringLen($str) + 1 & "]") ; +1 for null terminator DllStructSetData($tStruct, 1, $str) Return $tStruct EndFunc Func CallEcho() Local Static $pStruct = DllStructGetPtr($g_tStruct) DllCall($hDll, "WSTR", "Echo", "ptr", $pStruct) EndFunc Concerning the pointer, juste use a Static variable inside CallEcho() so its value won't be destroyed when the function ends. I tested the memory content and it was ok (e.g. "t e s t" was constantly there, during the 5 calls to CallEcho)2 points -
RustDesk UDF
SOLVE-SMART reacted to BinaryBrother for a topic
Here it is. ; #CURRENT# ===================================================================================================================== ; _RustDesk_Config ; _RustDesk_DebugEnable ; _RustDesk_Deploy ; _RustDesk_GenerateRandomPassword ; _RustDesk_GetID ; _RustDesk_GetLatestVersion ; _RustDesk_GetLocalVersion ; _TustDesk_isInstalled ; _RustDesk_SetPassword ; _RustDesk_Start ; =============================================================================================================================== Update: 1/10/25 - Added _RustDesk_Config() for those who need to configure a custom relay. Update: 1/23/25 - Overhauled some portions of the code with redundancy and timers. Update: 1/26/25 - Inched closer to UDF-Spec and added Constants. Update: 1/27/25 - Finished UDF-Spec Update: 2/4/2025 - Disregard nightly builds for the download. Current.zip1 point -
WinActiveBorder()
argumentum reacted to Nine for a topic
Instead of drawing the 4 sides individually, you could use this function : Func Rect($hWnd, $iX, $iY, $iWidth, $iHeight, $iSize = 4) Local $hMain = _WinAPI_CreateRectRgn($iX, $iY, $iX + $iWidth, $iY + $iHeight) Local $hMask = _WinAPI_CreateRectRgn($iX + $iSize, $iY + $iSize, $iX + $iWidth - $iSize, $iY + $iHeight - $iSize) _WinAPI_CombineRgn($hMain, $hMain, $hMask, $RGN_DIFF) _WinAPI_DeleteObject($hMask) _WinAPI_SetWindowRgn($hWnd, $hMain) EndFunc ;==>Rect1 point -
Need help removing multiple nodes in XML
WildByDesign reacted to Nine for a topic
Glad I could help.1 point -
Problems when returning DllStructGetPtr from function
pixelsearch reacted to emcodem for a topic
Thank you for your time and Brains. The problem was that i was just poking around but not really understand what exactly is going on even if you told me already that i need to return the struct. I don't want to use statics and globals because this will be used in a UDF that allows to access the exportet methods from my C dll. This whole Echo code was just created to explain and debug this very issue. From this perspective it might be good to just dump the idea of the MakeWstrPtr funciton completely and write out the for DllStructCreate,SetData and GetPtr everywhere. This would make the final code very ugly to read, there would be hundred lines like this, it would be hard to track the variables for me. $struct = DllStructCreate("wchar [" & StringLen($s_str) + 1 & "]") ; +1 for null terminator DllStructSetData($struct, 1, $s_str) But i think i understand now every Aspect of this and i may go with the following solution: Func __MakeWstrPtr($s_str, ByRef $struct) $struct = DllStructCreate("wchar [" & StringLen($s_str) + 1 & "]") ; +1 for null terminator DllStructSetData($struct, 1, $s_str) return DllStructGetPtr($struct) EndFunc Func CallEcho($sToEcho) Local $struct_1 Local $_ptr1 = __MakeWstrPtr($sToEcho,$struct_1) DllCall($hdll, "WSTR", "Echo", "ptr", $_ptr1) ;the C side prints You wrote: to scite console EndFunc We still need 2 Lines for using MakeWstrPtr function where i would prefer one line but i think at least this way we will end up with much better readable code. This way all the releases of structs and ptrs is done when CallEcho returns which is highly desired. If i understood correctly, to avoid the Byref Struct parameter, we could potentially return an Array holding struct and ptr but performance is a big concern so we want to avoid spending time on allocating arrays or similar just to make the code more readable. The final result using above solution can look like: Func UpdateOne($ptr_mongocollection, $search, $update, $options) ;~https://www.mongodb.com/docs/manual/reference/method/db.collection.updateOne/ ;~commonly used options: {"upsert":true} ;~returns json str like { "modifiedCount" : 1, "matchedCount" : 1, "upsertedCount" : 0 } Local $_s1,$_s2,$_s3; Local $_searchptr = __MakeWstrPtr($search,$_s1) Local $_updateptr = __MakeWstrPtr($update,$_s2) Local $_optptr = __MakeWstrPtr($options,$_s3) Local $a_result = DllCall($hdll, "WSTR", "UpdateOne", "ptr",$ptr_mongocollection, "ptr", $_searchptr, "ptr", $_updateptr, "ptr", $_optptr); ConsoleWrite("UpdateOne: " & $a_result[0] & " Error: " & _WinAPI_GetLastError() & @CRLF) return $a_result[0] EndFunc1 point -
Need help removing multiple nodes in XML
WildByDesign reacted to Nine for a topic
#include <Constants.au3> Global $oComError = ObjEvent('AutoIt.Error', ErrorHandler) Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.async = False $oXML.load("Event.xml") If $oXML.parseError.errorCode Then Exit MsgBox($MB_SYSTEMMODAL, "You have an error", $oXML.parseError.reason) Local $oNodes = $oXML.SelectNodes("//ComplexData") $oNodes.removeAll() $oNodes = $oXML.SelectNodes("//Event") For $oNode In $oNodes $oData = $oNode.selectSingleNode("EventData") If Not IsObj($oData) Then $oXML.documentElement.removeChild($oNode) EndIf Next $oXML.save("Event New.xml") Func ErrorHandler($oError) EndFunc I will let you do the <ProcessingErrorData> part.1 point -
Problems when returning DllStructGetPtr from function
Musashi reacted to pixelsearch for a topic
I think the memory content used by a structure (created inside a function with DllStructCreate) is released when the function ends (except if you Return the structure variable name to the calling function) That's why Func WstrPtr() returns a correct string (see "t e s t" in the pic below) But after you return from Func WstrPtr() and call Func CallEcho() then the memory content at the same location has changed (see pic below where we don't read "t e s t" anymore at the same memory location) I just found an old discussion about this, between 3 MVP's (PaulIA, Valik, Zedna) in a topic named... DllStructCreate and Scope Correction : 2 MVP's (PaulIA, Zedna) and a developer (Valik)1 point -
Need help removing multiple nodes in XML
WildByDesign reacted to jchd for a topic
FYI, a pedestrian way using regex is also pretty fast: Local $s = FileRead("events.xml") Local $t = StringRegExpReplace($s, "(?is)(\s*<ComplexData .*?</ComplexData>)", "") ConsoleWrite($t & @LF)1 point -
Here is a commented version that will hopefully help you further : #include <Color.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <Array.au3> HotKeySet("{Escape}", "_Exit") ; Shift-Alt-E to Exit the script Global $g_hRichEdit , $g_aRichEditFields[0][3], $g_sSearchPattern, $g_iIndex = 1, $g_bMatchesFound = False ; Description : ; 1. $g_hRichEdit : the text(string) you want to analyze, using a regular expression. ; 2. $g_sSearchPattern : the regular expression to match (pattern). ; 3. $g_aRichEditFields[0][3] : ; a two dimensional "one-based"-array, which means that the data starts in Row 1. ; Row 0 [0][0] contains the number of 'data-rows' ; Row 1, Element 1 (Index 0) ==> [1][0] = Match 1 ; Row 1, Element 2 (Index 1) ==> [1][1] = Startposition in text ; Row 1, Element 3 (Index 2) ==> [1][2] = Endposition in text ; Row 2 ... ; The function _GenerateRichEditFields() populates this array with data. ; 4. $g_iIndex : global helper index for accessing the desired row. ; 5. $g_bMatchesFound : False, if no matches were found, otherwise True. $g_sSearchPattern = "\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d|\d\d\d\d[-.\s]\d\d\d[-.\s]\d\d\d" ; Un numéro de tél FR (A revoir) Example() Func Example() Local $hGui, $idBtnNext, $iStep = 0 $hGui = GUICreate(StringTrimRight(@ScriptName, StringLen(".exe")), 420, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create( $hGui, 'Bonjour mon numéro de téléphone est le 06.12.34.56.78 06.12.34.56.78 ou 07.12.34.56.78 08.12.34.56.78 06.12.34.56.78 09.12.34.56.78', _ 10, 10, 400, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30) GUISetState(@SW_SHOW) If _GenerateRichEditFields() Then $g_bMatchesFound = True While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes GUIDelete() Exit Case $idBtnNext If $g_bMatchesFound Then ; Variation 1 : ; ------------- ; The matches will be colored STEP by STEP if the Next button is pushed. ;If $g_iIndex <= $g_aRichEditFields[0][0] Then ; _GUICtrlRichEdit_SetSel($g_hRichEdit, $g_aRichEditFields[$g_iIndex][1] , $g_aRichEditFields[$g_iIndex][2]) ; _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red ; _GUICtrlRichEdit_Deselect($g_hRichEdit) ; $g_iIndex += 1 ;Else ; $g_iIndex = 1 ;EndIf ; Variation 2 : ; ------------- ; ALL matches will be colored if the Next button is pushed. While $g_iIndex <= $g_aRichEditFields[0][0] _GUICtrlRichEdit_SetSel($g_hRichEdit, $g_aRichEditFields[$g_iIndex][1] , $g_aRichEditFields[$g_iIndex][2]) _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red _GUICtrlRichEdit_Deselect($g_hRichEdit) $g_iIndex += 1 WEnd $g_iIndex = 1 EndIf EndSwitch WEnd EndFunc ;==>Example Func _GenerateRichEditFields() Local $aMatches, $iStringStart, $iStringEnd, $iOffset = 1 ; Check if the search pattern ($g_sSearchPattern) was found. Matches are stored in an array. ; If there are no matches, the function will be exited with the return value 0. $aMatches = StringRegExp(_GUICtrlRichEdit_GetText($g_hRichEdit), $g_sSearchPattern , 3) If @error Then Return 0 ; Redimension of the array $g_aRichEditFields (the size is now known) ReDim $g_aRichEditFields[UBound($aMatches) + 1][3] $g_aRichEditFields[0][0] = UBound($aMatches) ; To find multiple (identical) matches, the starting position (offset) within StringInStr ; is increased. Parts of the already searched string are thereby skipped. For $i = 0 To UBound($aMatches) - 1 $iStringStart = StringInStr( _GUICtrlRichEdit_GetText($g_hRichEdit), $aMatches[$i], 0 , 1, $iOffset) - 1 $iStringEnd = $iStringStart + StringLen($aMatches[$i]) $iOffset = $iStringEnd $g_aRichEditFields[$i+1][0] = $aMatches[$i] $g_aRichEditFields[$i+1][1] = $iStringStart $g_aRichEditFields[$i+1][2] = $iStringEnd Next Return 1 EndFunc ;==>_GenerateRichEditFields Func _Exit() Exit EndFunc ;==>_Exit If you have further questions, you are welcome to write me a PM, as already mentioned .1 point
-
I have found a solution. I will describe the relevant parts of the project -- for the benefit of others I use Pegasus Mail and back up the settings and data daily: just the files that have changed, i.e. have the archive bit set. Pegasus organizes saved emails into what it calls "folders" (but which are actually files). The "folders' are organized into a tree structure. Very occasionally a Pegasus "folder" disappears, and when it does, it needs to be retrieved from back ups. But to retrieve a "folder" one needs to know its filename, and the name of the file is FOL followed by seemingly random hex-looking digits. Pegasus maintains a file, hierarch.pm. It is in CSV format and contains the tree structure including the name of the "folder" and the filename. It is, of course, flat, My project is to show hierarch.pm in a treeview so the user can select a "folder" and have the script tell him the name of the corresponding file. So the treeview needs a string to be associated with each "folder" item. To do this, I avoided using GuiTreeviewCreateItem() so I, not calling this native AutoIt funcion, get to store the file name in the $iParam parameter of the treeview struct. So I created the treeview by calling _GuiCtrlTreeview_Add() and _GuiCtrlTreeview_AddChild(). I thought of calling _GuiCtrlTreeview_SetItemParam() to store the file name with each treeview item. But $iParam cannot be used directly to store a string. In Structureconstants.au3, $iParam is a 4-byte integer. In 32-bit AutoIt, a pointer is also 4 bytes. I decided to try storing a pointer to a string there. To allocate memory and get a pointer back, I call _WinAPI_CreateString(). To get the string back, I call PointerToStringW(): Func _PointerToStringW($ptr) Return DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW($ptr) & "]", $ptr), 1) EndFunc To store the string with the treeview item, I coded; $pStr = _WinAPI_CreateString(StringInStr($a20[$i][$kFull],':FOL') ? $a20[$i][$kFull] : '') _GUICtrlTreeView_SetItemParam($g_hTV,$hItem,$pStr) To retrieve a string I coded: Local $ptr = _GUICtrlTreeView_GetItemParam($g_hTV,$hItem) Local $s = _PointerToStringW($ptr) . . . Func _PointerToStringW($ptr) Return DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW($ptr) & "]", $ptr), 1) EndFunc I also keep track of these pointers in an array, and when the script is ending I free the memory: OnAutoItExitRegister('FreePointersToParamStrings') Func FreePointersToParamStrings() For $i = 0 To $g_iqPointers _WinAPI_FreeMemory($g_pointers[$i]) Next EndFunc This works in x86 AutoIt. It may not work in AutoIt x64.1 point