Leaderboard
Popular Content
Showing content with the highest reputation on 05/04/2018 in all areas
-
New MVPs
FrancescoDiMuro and 3 others reacted to Melba23 for a topic
Hi, Some good news today: Danp2, RTFC and junkew have accepted the invitation to become MVPs. I am sure you will all join me in congratulating them on their new status. M234 points -
Introduction Since the introduction of ObjCreateInterface, AutoIt is able to create native, real objects. However, this is quite difficult for non-experienced users. This UDF here enables a "classic" syntax for declaring classes and instantiating objects from them. Before you ask: No, it is not just another preprocessor that's "faking" OOP syntax - this is the real deal. While it assists users with a more familiar syntax, objects are created at runtime. Care has been put into this UDF and it is in the authors interest to fix all bugs remaining and implement features as long as the result works in the Stable release of AutoIt. Features Define an unlimited number of classes.Create unlimited instances of objects.Create arrays of objects.Mix and match different data types in arrays (one or more elements can be objects).Define custom constructors and destructors.Pass an unlimited number of arguments to the constructor (even to all objects in one array at the same time).Automatic garbage collection.Compatible with Object-enabled AutoIt keywords (With etc.), optional parentheses on parameterless functions.Fully AU3Check enabled.IntelliSense catches class-names for auto-completion.Automatically generates a compilable version of the script.Non-instantated classes get optimzed away.Create C-style macros.Download Read the Tutorials - Download - Download (forum mirror) Please use the github issue tracker to report bugs or request features. Please read the tutorial before asking a question. Thanks!1 point
-
Test-00.au3 If you have used ArrayDisplay regularly, you know that it's possible to show more arrays at once in this way (click "Run User Func" button): #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <ArrayDisplay142-1.au3> ShowArray0( 0, 0 ) Func ShowArray0( $p1, $p2 ) Local $aArray0 = [ 00, 01, 02, 03, 04, 05, 06, 07, 08, 09 ] _ArrayDisplay142( $aArray0, "$aArray0", "", 0, Default, Default, Default, Default, ShowArray1 ) #forceref $p1, $p2 EndFunc Func ShowArray1( $p1, $p2 ) Local $aArray1 = [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14 ] _ArrayDisplay142( $aArray1, "$aArray1", "", 0, Default, Default, Default, Default, ShowArray2 ) #forceref $p1, $p2 EndFunc Func ShowArray2( $p1, $p2 ) Local $aArray2 = [ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ] _ArrayDisplay142( $aArray2, "$aArray2", "", 0, Default, Default, Default, Default, ShowArray0 ) #forceref $p1, $p2 EndFunc How does this work? The ArrayDisplay GUI is running in MessageLoop mode. Will the message loop in a later created GUI not block the message loop in a previously created GUI? Yes, it will. But it's important to know exactly what is blocked and what is not blocked. This is the message loop in a slightly modified version of ArrayDisplay from AutoIt 3.3.14.2: While 1 $iMsg = GUIGetMsg() ; Variable needed to check which "Copy" button was pressed Switch $iMsg Case $idCopy_ID, $idCopy_Data ; Count selected rows Local $iSel_Count = GUICtrlSendMsg($idListView, $LVM_GETSELECTEDCOUNT, 0, 0) ; Display splash dialog if required If $iVerbose And (Not $iSel_Count) And ($iItem_End - $iItem_Start) * ($iSubItem_End - $iSubItem_Start) > 10000 Then SplashTextOn("ArrayDisplay", "Copying data" & @CRLF & @CRLF & "Please be patient", 300, 100) EndIf ; Generate clipboard text Local $sClip = "", $sItem, $aSplit ; Add items For $i = 0 To $iItem_End - $iItem_Start ; Skip if copying selected rows and item not selected If $iSel_Count And Not (GUICtrlSendMsg($idListView, $LVM_GETITEMSTATE, $i, $LVIS_SELECTED)) Then ContinueLoop EndIf $sItem = $avArrayText[$i] If $iMsg = $idCopy_Data Then ; Remove row ID if required $sItem = StringRegExpReplace($sItem, "^\[\d+\].(.*)$", "$1") EndIf If $iCW_ColWidth Then ; Expand columns $aSplit = StringSplit($sItem, $sAD_Separator) $sItem = "" For $j = 1 To $aSplit[0] $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth)) Next Else ; Use defined separator $sItem = StringReplace($sItem, $sAD_Separator, $vUser_Separator) EndIf $sClip &= $sItem & @CRLF Next ; Add header line if required If $iMsg = $idCopy_ID Then If $iCW_ColWidth Then $aSplit = StringSplit($sHeader, $sAD_Separator) $sItem = "" For $j = 1 To $aSplit[0] $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth)) Next Else $sItem = StringReplace($sHeader, $sAD_Separator, $vUser_Separator) EndIf $sClip = $sItem & @CRLF & $sClip EndIf ;Send to clipboard ClipPut($sClip) ; Remove splash if used SplashOff() ; Refocus ListView GUICtrlSetState($idListView, $GUI_FOCUS) Case $idUser_Func ; Get selected indices Local $aiSelItems[$iRowLimit] = [0] If GUICtrlSendMsg($idListView, $LVM_GETSELECTEDCOUNT, 0, 0) Then For $i = 0 To GUICtrlSendMsg($idListView, $LVM_GETITEMCOUNT, 0, 0) If GUICtrlSendMsg($idListView, $LVM_GETITEMSTATE, $i, $LVIS_SELECTED) Then $aiSelItems[0] += 1 $aiSelItems[$aiSelItems[0]] = $i + $iItem_Start EndIf Next EndIf ReDim $aiSelItems[$aiSelItems[0] + 1] ; Pass array and selection to user function Opt("GUIDataSeparatorChar", $sCurr_Separator) $hUser_Function($aArray, $aiSelItems) Opt("GUIDataSeparatorChar", $sAD_Separator) GUICtrlSetState($idListView, $GUI_FOCUS) Case $idExit_Script ; Clear up GUIDelete($hGUI) Exit Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd And this is the part of the message loop that handles "Run User Func" button clicks: Case $idUser_Func ; Get selected indices Local $aiSelItems[$iRowLimit] = [0] If GUICtrlSendMsg($idListView, $LVM_GETSELECTEDCOUNT, 0, 0) Then For $i = 0 To GUICtrlSendMsg($idListView, $LVM_GETITEMCOUNT, 0, 0) If GUICtrlSendMsg($idListView, $LVM_GETITEMSTATE, $i, $LVIS_SELECTED) Then $aiSelItems[0] += 1 $aiSelItems[$aiSelItems[0]] = $i + $iItem_Start EndIf Next EndIf ReDim $aiSelItems[$aiSelItems[0] + 1] ; Pass array and selection to user function Opt("GUIDataSeparatorChar", $sCurr_Separator) $hUser_Function($aArray, $aiSelItems) ; <<<<<<<< ; The message loop is blocked Opt("GUIDataSeparatorChar", $sAD_Separator) ; until the function returns. GUICtrlSetState($idListView, $GUI_FOCUS) It's the message loop that's blocked. It's blocked by a function that's still running. And which events does this loop handle? It handles button click events and $GUI_EVENT_CLOSE event. So button clicks and $GUI_EVENT_CLOSE does not work. But are there any listview events in the loop? No there are not. Since there are no AutoIt events to handle the listview, the listview is handled entirely through Windows events. And of course Windows events are not blocked. This means that the listview is fully functional. Note that the message loop isn't blocked in the last created GUI. Button clicks and $GUI_EVENT_CLOSE does work in the last created GUI. Is it possible to unblock the blocked message handlers in the ArrayDisplay GUIs that were created before the last GUI? Before we look at ArrayDisplay let's look at some more simple examples. Test-01.au3 Test-01.au3 is similar to Test-00.au3. Only the last created GUI is responsive. The message loop in the other GUIs is blocked. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> Opt( "MustDeclareVars", 1 ) Global $aGuiInfo[6+1][2] ; 6 rows for GUIs + 1 row for general info $aGuiInfo[0][0] = 0 ; Current number of GUIs $aGuiInfo[0][1] = 6 ; Max number of GUIs Example() Func Example() ; Max number of GUIs is $aGuiInfo[0][1] If $aGuiInfo[0][0] = $aGuiInfo[0][1] Then Return ; Increase number of GUIs $aGuiInfo[0][0] += 1 ; Find first available index For $iIdx = 1 To $aGuiInfo[0][1] If Not $aGuiInfo[$iIdx][0] Then ExitLoop Next ; Create GUI Local $hGui = GUICreate( "GUI " & $iIdx, 300, 200, 100 + 350 * Mod($iIdx-1,Int($aGuiInfo[0][1]/2)), 100 + 270 * Int(($iIdx-1)/Int($aGuiInfo[0][1]/2)) ) Local $idNew = GUICtrlCreateButton( "Create new GUI", 20, 45, 260, 30 ) Local $idExit = GUICtrlCreateButton( "Exit script", 20, 120, 260, 30 ) ; Store GUI info $aGuiInfo[$iIdx][0] = $iIdx ; Show GUI GUISetState() ; Main loop While 1 Switch GUIGetMsg() Case $idNew Example() Case $idExit Exit Case $GUI_EVENT_CLOSE $aGuiInfo[$iIdx][0] = 0 ; $iIdx $aGuiInfo[0][0] -= 1 ; Decrease number of GUIs ExitLoop EndSwitch WEnd GUIDelete( $hGui ) EndFunc Test-02.au3 Test-02.au3 is a non-blocked version of Test-01.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <MenuConstants.au3> Opt( "MustDeclareVars", 1 ) Global $aGuiInfo[6+1][5] ; 6 rows for GUIs + 1 row for general info $aGuiInfo[0][0] = 0 ; Current number of GUIs $aGuiInfo[0][1] = 6 ; Max number of GUIs ; $aGuiInfo[0][2] = $iIdx, $idNew click event ; $aGuiInfo[0][3] = $iIdx, $idExit click event ; $aGuiInfo[0][4] = $iIdx, $GUI_EVENT_CLOSE, GUI close event ; $aGuiInfo[$iIdx][0] = $iIdx, $iIdx > 0 ; $aGuiInfo[$iIdx][1] = $hGui ; $aGuiInfo[$iIdx][2] = $idNew ; $aGuiInfo[$iIdx][3] = $idExit ; $aGuiInfo[$iIdx][4] = $pMsgHandler Example() Func Example() ; Max number of GUIs is $aGuiInfo[0][1] If $aGuiInfo[0][0] = $aGuiInfo[0][1] Then Return ; Increase number of GUIs $aGuiInfo[0][0] += 1 ; Find first available index For $iIdx = 1 To $aGuiInfo[0][1] If Not $aGuiInfo[$iIdx][0] Then ExitLoop Next ; Create GUI Local $hGui = GUICreate( "GUI " & $iIdx, 300, 200, 100 + 350 * Mod($iIdx-1,Int($aGuiInfo[0][1]/2)), 100 + 270 * Int(($iIdx-1)/Int($aGuiInfo[0][1]/2)) ) Local $idNew = GUICtrlCreateButton( "Create new GUI", 20, 45, 260, 30 ) Local $idExit = GUICtrlCreateButton( "Exit script", 20, 120, 260, 30 ) ; Register non-blocked message handler Local $pMsgHandler = DllCallbackGetPtr( DllCallbackRegister( "MsgHandler", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) DllCall( "comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hGui, "ptr", $pMsgHandler, "uint_ptr", $iIdx, "dword_ptr", 0 ) ; $iSubclassId = $iIdx, $pData = 0 ; Store GUI info $aGuiInfo[$iIdx][0] = $iIdx $aGuiInfo[$iIdx][1] = $hGui $aGuiInfo[$iIdx][2] = $idNew $aGuiInfo[$iIdx][3] = $idExit $aGuiInfo[$iIdx][4] = $pMsgHandler ; Show GUI GUISetState() ; Main loop While Sleep(10) If $aGuiInfo[0][0] = 0 Then ExitLoop For $iMsg = 2 To 4 If $aGuiInfo[0][$iMsg] Then ExitLoop Next If $iMsg = 5 Then ContinueLoop $iIdx = $aGuiInfo[0][$iMsg] $aGuiInfo[0][$iMsg] = 0 Switch $iMsg ; $idNew click event Case 2 Example() ; $idExit click event Case 3 For $iIdx = 1 To $aGuiInfo[0][1] If Not $aGuiInfo[$iIdx][0] Then ContinueLoop DllCall( "comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $aGuiInfo[$iIdx][1], "ptr", $aGuiInfo[$iIdx][4], "uint_ptr", $iIdx ) GUIDelete( $aGuiInfo[$iIdx][1] ) ; GUIDelete( $hGui ) Next Exit ; GUI close event Case 4 DllCall( "comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $aGuiInfo[$iIdx][1], "ptr", $aGuiInfo[$iIdx][4], "uint_ptr", $iIdx ) GUIDelete( $aGuiInfo[$iIdx][1] ) ; GUIDelete( $hGui ) $aGuiInfo[$iIdx][0] = 0 ; $iIdx $aGuiInfo[0][0] -= 1 ; Decrease number of GUIs If $aGuiInfo[0][0] = 0 Then ExitLoop EndSwitch WEnd EndFunc Func MsgHandler( $hWnd, $iMsg, $wParam, $lParam, $iIdx, $pData ) ; $iSubclassId = $iIdx If $iMsg <> $WM_COMMAND And $iMsg <> $WM_SYSCOMMAND Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] Switch $iMsg Case $WM_COMMAND Switch BitAND( $wParam, 0xFFFF ) ; LoWord Case $aGuiInfo[$iIdx][2] ; $idNew Switch BitShift( $wParam, 16 ) ; HiWord Case $BN_CLICKED $aGuiInfo[0][2] = $iIdx ; $idNew click event EndSwitch Case $aGuiInfo[$iIdx][3] ; $idExit Switch BitShift( $wParam, 16 ) ; HiWord Case $BN_CLICKED $aGuiInfo[0][3] = $iIdx ; $idExit click event EndSwitch EndSwitch Case $WM_SYSCOMMAND Switch $hWnd Case $aGuiInfo[$iIdx][1] ; $hGui Switch $wParam Case $SC_CLOSE $aGuiInfo[0][4] = $iIdx ; GUI close event EndSwitch EndSwitch EndSwitch Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $pData EndFunc ; $aGuiInfo[0][2] = $iIdx, $idNew click event ; $aGuiInfo[0][3] = $iIdx, $idExit click event ; $aGuiInfo[0][4] = $iIdx, $GUI_EVENT_CLOSE, GUI close event ; $aGuiInfo[$iIdx][0] = $iIdx, $iIdx > 0 ; $aGuiInfo[$iIdx][1] = $hGui ; $aGuiInfo[$iIdx][2] = $idNew ; $aGuiInfo[$iIdx][3] = $idExit ; $aGuiInfo[$iIdx][4] = $pMsgHandler Note that Test-02.au3 is neither running in MessageLoop Mode (GUIGetMsg isn't called) nor in OnEvent Mode (Opt("GUIOnEventMode", 1) isn't set). Instead, messages are handled through subclassing. And of course, the main loop is still blocked in all GUIs except in the last created GUI. But the chain of GUIs and subclasses means that a message is propagated from one GUI to the next. When the message reaches the last created GUI, where the main loop isn't blocked, the message is handled. The information in the global $aGuiInfo array makes it possible to execute the corresponding code against the proper (active) GUI. Test-03.au3 Test-03.au3 is a non-blocked version of Test-00.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <ArrayDisplay142-2.au3> ShowArray0( 0, 0 ) Func ShowArray0( $p1, $p2 ) Local $aArray0 = [ 00, 01, 02, 03, 04, 05, 06, 07, 08, 09 ] _ArrayDisplay142( $aArray0, "$aArray0", "", 0, Default, Default, Default, Default, ShowArray1 ) #forceref $p1, $p2 EndFunc Func ShowArray1( $p1, $p2 ) Local $aArray1 = [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14 ] _ArrayDisplay142( $aArray1, "$aArray1", "", 0, Default, Default, Default, Default, ShowArray2 ) #forceref $p1, $p2 EndFunc Func ShowArray2( $p1, $p2 ) Local $aArray2 = [ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ] _ArrayDisplay142( $aArray2, "$aArray2", "", 0, Default, Default, Default, Default, ShowArray0 ) #forceref $p1, $p2 EndFunc ArrayDisplay142-2.au3 is included instead of ArrayDisplay142-1.au3. After the GUI is created in ArrayDisplay142-2.au3, it's subclassed and information is stored in $aGuiInfo array: ; Register concurrent GUIs ; Increase number of GUIs $aGuiInfo[0][0] += 1 ; Find first available index For $iIdx = 1 To $aGuiInfo[0][1] If Not $aGuiInfo[$iIdx][0] Then ExitLoop Next ; Register non-blocked message handler Local $pMsgHandler = DllCallbackGetPtr( DllCallbackRegister( "MsgHandler", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) DllCall( "comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hGUI, "ptr", $pMsgHandler, "uint_ptr", $iIdx, "dword_ptr", 0 ) ; $iSubclassId = $iIdx, $pData = 0 ; Store GUI info $aGuiInfo[$iIdx][0] = $iIdx $aGuiInfo[$iIdx][1] = $hGUI $aGuiInfo[$iIdx][2] = $idListView $aGuiInfo[$iIdx][3] = $idCopy_ID $aGuiInfo[$iIdx][4] = $idCopy_Data $aGuiInfo[$iIdx][5] = $idUser_Func $aGuiInfo[$iIdx][6] = $idExit_Script $aGuiInfo[$iIdx][7] = $pMsgHandler $aGuiInfo[$iIdx][8] = $avArrayText $aGuiInfo[$iIdx][9] = $aArray $aGuiInfo[$iIdx][10] = $iItem_Start $aGuiInfo[$iIdx][11] = $iItem_End $aGuiInfo[$iIdx][12] = $iSubItem_Start $aGuiInfo[$iIdx][13] = $iSubItem_End $aGuiInfo[$iIdx][14] = $iVerbose $aGuiInfo[$iIdx][15] = $iCW_ColWidth $aGuiInfo[$iIdx][16] = $sHeader $aGuiInfo[$iIdx][17] = $vUser_Separator $aGuiInfo[$iIdx][18] = $hUser_Function This is the new main loop: While Sleep(10) If $aGuiInfo[0][0] = 0 Then ExitLoop ;$iMsg = GUIGetMsg() ; Variable needed to check which "Copy" button was pressed For $iMsg = 3 To 7 If $aGuiInfo[0][$iMsg] Then ExitLoop Next If $iMsg = 8 Then ContinueLoop $iIdx = $aGuiInfo[0][$iMsg] $aGuiInfo[0][$iMsg] = 0 Switch $iMsg ;Case $idCopy_ID, $idCopy_Data Case 3, 4 $idListView = $aGuiInfo[$iIdx][2] $avArrayText = $aGuiInfo[$iIdx][8] $iItem_Start = $aGuiInfo[$iIdx][10] $iItem_End = $aGuiInfo[$iIdx][11] $iSubItem_Start = $aGuiInfo[$iIdx][12] $iSubItem_End = $aGuiInfo[$iIdx][13] $iVerbose = $aGuiInfo[$iIdx][14] $iCW_ColWidth = $aGuiInfo[$iIdx][15] $sHeader = $aGuiInfo[$iIdx][16] $vUser_Separator = $aGuiInfo[$iIdx][17] ; Count selected rows Local $iSel_Count = GUICtrlSendMsg($idListView, $LVM_GETSELECTEDCOUNT, 0, 0) ; Display splash dialog if required If $iVerbose And (Not $iSel_Count) And ($iItem_End - $iItem_Start) * ($iSubItem_End - $iSubItem_Start) > 10000 Then SplashTextOn("ArrayDisplay", "Copying data" & @CRLF & @CRLF & "Please be patient", 300, 100) EndIf ; Generate clipboard text Local $sClip = "", $sItem, $aSplit ; Add items For $i = 0 To $iItem_End - $iItem_Start ; Skip if copying selected rows and item not selected If $iSel_Count And Not (GUICtrlSendMsg($idListView, $LVM_GETITEMSTATE, $i, $LVIS_SELECTED)) Then ContinueLoop EndIf $sItem = $avArrayText[$i] ;If $iMsg = $idCopy_Data Then If $iMsg = 4 Then ; Remove row ID if required $sItem = StringRegExpReplace($sItem, "^\[\d+\].(.*)$", "$1") EndIf If $iCW_ColWidth Then ; Expand columns $aSplit = StringSplit($sItem, $sAD_Separator) $sItem = "" For $j = 1 To $aSplit[0] $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth)) Next Else ; Use defined separator $sItem = StringReplace($sItem, $sAD_Separator, $vUser_Separator) EndIf $sClip &= $sItem & @CRLF Next ; Add header line if required ;If $iMsg = $idCopy_ID Then If $iMsg = 3 Then If $iCW_ColWidth Then $aSplit = StringSplit($sHeader, $sAD_Separator) $sItem = "" For $j = 1 To $aSplit[0] $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth)) Next Else $sItem = StringReplace($sHeader, $sAD_Separator, $vUser_Separator) EndIf $sClip = $sItem & @CRLF & $sClip EndIf ;Send to clipboard ClipPut($sClip) ; Remove splash if used SplashOff() ; Refocus ListView GUICtrlSetState($idListView, $GUI_FOCUS) ;Case $idUser_Func Case 5 ; Get selected indices $idListView = $aGuiInfo[$iIdx][2] $iItem_Start = $aGuiInfo[$iIdx][10] Local $aiSelItems[$iRowLimit] = [0] If GUICtrlSendMsg($idListView, $LVM_GETSELECTEDCOUNT, 0, 0) Then For $i = 0 To GUICtrlSendMsg($idListView, $LVM_GETITEMCOUNT, 0, 0) If GUICtrlSendMsg($idListView, $LVM_GETITEMSTATE, $i, $LVIS_SELECTED) Then $aiSelItems[0] += 1 $aiSelItems[$aiSelItems[0]] = $i + $iItem_Start EndIf Next EndIf ReDim $aiSelItems[$aiSelItems[0] + 1] ; Pass array and selection to user function Opt("GUIDataSeparatorChar", $sCurr_Separator) ;$hUser_Function($aArray, $aiSelItems) $aGuiInfo[$iIdx][18]($aGuiInfo[$iIdx][9], $aiSelItems) Opt("GUIDataSeparatorChar", $sAD_Separator) GUICtrlSetState($idListView, $GUI_FOCUS) ;Case $idExit_Script Case 6 ; Clear up For $iIdx = 1 To $aGuiInfo[0][1] If Not $aGuiInfo[$iIdx][0] Then ContinueLoop DllCall( "comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $aGuiInfo[$iIdx][1], "ptr", $aGuiInfo[$iIdx][7], "uint_ptr", $iIdx ) GUIDelete( $aGuiInfo[$iIdx][1] ) ; GUIDelete( $hGui ) $aGuiInfo[$iIdx][8] = 0 ; $avArrayText $aGuiInfo[$iIdx][9] = 0 ; $aArray Next Exit ;Case $GUI_EVENT_CLOSE Case 7 DllCall( "comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $aGuiInfo[$iIdx][1], "ptr", $aGuiInfo[$iIdx][7], "uint_ptr", $iIdx ) GUIDelete( $aGuiInfo[$iIdx][1] ) ; GUIDelete( $hGui ) $aGuiInfo[$iIdx][8] = 0 ; $avArrayText $aGuiInfo[$iIdx][9] = 0 ; $aArray $aGuiInfo[$iIdx][0] = 0 ; $iIdx $aGuiInfo[0][0] -= 1 ; Decrease number of GUIs If $aGuiInfo[0][0] = 0 Then ExitLoop EndSwitch WEnd And the subclass function: Func MsgHandler( $hWnd, $iMsg, $wParam, $lParam, $iIdx, $pData ) ; $iSubclassId = $iIdx If $iMsg <> $WM_COMMAND And $iMsg <> $WM_SYSCOMMAND Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] Switch $iMsg Case $WM_COMMAND Switch BitAND( $wParam, 0xFFFF ) ; LoWord Case $aGuiInfo[$iIdx][3] ; $idCopy_ID Switch BitShift( $wParam, 16 ) ; HiWord Case $BN_CLICKED $aGuiInfo[0][3] = $iIdx ; $idCopy_ID click event EndSwitch Case $aGuiInfo[$iIdx][4] ; $idCopy_Data Switch BitShift( $wParam, 16 ) ; HiWord Case $BN_CLICKED $aGuiInfo[0][4] = $iIdx ; $idCopy_Data click event EndSwitch Case $aGuiInfo[$iIdx][5] ; $idUser_Func Switch BitShift( $wParam, 16 ) ; HiWord Case $BN_CLICKED $aGuiInfo[0][5] = $iIdx ; $idUser_Func click event EndSwitch Case $aGuiInfo[$iIdx][6] ; $idExit_Script Switch BitShift( $wParam, 16 ) ; HiWord Case $BN_CLICKED $aGuiInfo[0][6] = $iIdx ; $idExit_Script click event EndSwitch EndSwitch Case $WM_SYSCOMMAND Switch $hWnd Case $aGuiInfo[$iIdx][1] ; $hGUI Switch $wParam Case $SC_CLOSE $aGuiInfo[0][7] = $iIdx ; GUI close event EndSwitch EndSwitch EndSwitch Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $pData EndFunc1 point
-
AutoIt ConsoleWrite (using "builtin" Autoit Hidden window)
bowain reacted to boomingranny for a topic
Use this UDF to add a console gui to your script (with log file): It uses the Hidden Autoit window (that you probably didn't even know existed) Closing Console window will terminate script. example of console: #include-once #include <GuiEdit.au3> EnableConsoleGui("example.log") ;example: ;------------------------ ConsoleWrite ("Hello World") For $i = 1 To 10 ConsoleWrite (".") Sleep(200) Next ConsoleWrite ("done") ConsoleWrite(@CRLF) ConsoleWrite ("close me to exit"&@CRLF) While 1 Sleep(1000) WEnd ;------------------------ ;end of example code Func EnableConsoleGui($Logfile="") ;EnableConsoleGUI ;by Daniel Barnes 20/04/2018 ;Uses AutoIt's Hidden window as a console (output only) Global $pidChild ;if we don't have a parent (as the parent window would have our script name) If Not WinExists(StringTrimRight(@ScriptName,4)) Then Opt("TrayIconHide",1) ;get Autoit's hidden window handle local $hWnd = WinGetHandle(AutoItWinGetTitle()) ;move the autoit hidden window to the middle of the screen WinMove($hWnd, "", (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ;get the Handle of the edit box in Autoit's hidden window $hEditBox = ControlGetHandle($hWnd,"","[CLASS:Edit; INSTANCE:1]") ;show it WinSetState($hWnd, "", @SW_SHOW) ;set its title = our script name WinSetTitle($hWnd,"",StringTrimRight(@ScriptName,4)) ;Spawn a child "copy" of the script, enabling reading of its console... If @Compiled Then ;2 = $STDOUT_CHILD. This avoids requiring the AutoItConstants.au3 in this sample code $pidChild= Run( FileGetShortName(@ScriptFullPath),@ScriptDir,"",2) Else ;2 = $STDOUT_CHILD. This avoids requiring the AutoItConstants.au3 in this sample code $pidChild= Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath),@ScriptDir,"",2) EndIf OnAutoItExitRegister("EnableConsoleGui_CloseChildPID") ;read the console, while the child window exists (and the console window is visible) While ProcessExists($pidChild) $ConsoleRead = StdoutRead($pidChild) If $ConsoleRead then $text = StringLeft(ControlGetText($hWnd,"",$hEditBox),65535) If $Logfile Then FileWrite($Logfile,$ConsoleRead) $text &= $ConsoleRead ControlSetText($hWnd,"",$hEditBox,$text) ConsoleWrite($ConsoleRead) ;scroll to bottom of console edit window _GUICtrlEdit_SetSel($hEditBox, 65535, 65535) endif Sleep(250) WEnd exit endif EndFunc Func EnableConsoleGui_CloseChildPID() ;if this func isn't used ;when you close the console gui ;the child "clone" of your script will keep running ProcessClose($pidChild) EndFunc1 point -
The code I wrote did support it. I don't know if something was changed afterwards. However, I did leave small bug with initialization and intention to fix it during beta testing. Something that never happened. The bug was such that randomly execution would fail. But random isn't always.1 point
-
Graphic Effectus - Rotate Text
argumentum reacted to junkew for a topic
Works like a charm with a small fix. (sorry for bubbling up this post but these GDI examples are still very nice) #include <StructureConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <GuiConstantsEx.au3> #Include <Misc.au3> Global Const $iOpacity = 200 ;~ Global Const $ULW_ALPHA = 2 Global Const $nPI = 3.1415926535897932384626433832795 ;~ Global Const $WM_LBUTTONDOWN = 0x0201 ; Drag Window 1 of 3 addin Global $hGui, $hGraphic Global $dll = DllOpen ("user32.dll") Global $GuiSize = 580, $w2 = 144, $h2 = 20 Global $randcol,$fCol,$fontSize = 12,$fRot = -144,$w = 100,$h = 20,$nAngle = 0, $flg = 1 Opt("MustDeclareVars", 1) Opt ("GUIOnEventMode", 1) TextRotate() Func TextRotate() Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hGui = GUICreate("Rotate Text", $GuiSize, $GuiSize, -1,-1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove") ; Drag Window 2 of 3 addin GUISetState() Do _GDIPlus_Startup() $hWnd = _WinAPI_GetDC(0) $hDC = _WinAPI_CreateCompatibleDC ($hWnd) $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd,$GuiSize,$GuiSize) ; $iWidth, $iHeight) _WinAPI_SelectObject ($hDC, $hBitmap) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) If _IsPressed("11") Then $flg += 1 ; CTRL key If $flg = 1 Then RotateText2 () If $flg = 2 Then RotateText () If $flg >= 3 Then $flg = 1 $tSize = DllStructCreate ($tagSIZE) $pSize = DllStructGetPtr ($tSize ) DllStructSetData ($tSize, "X", $GuiSize) ;$iWidth ) DllStructSetData ( $tSize, "Y", $GuiSize) ;$iHeight) $tSource = DllStructCreate ($tagPOINT) $pSource = DllStructGetPtr ($tSource) $tBlend = DllStructCreate ($tagBLENDFUNCTION) $pBlend = DllStructGetPtr ($tBlend ) DllStructSetData ($tBlend, "Alpha" , $iOpacity ) DllStructSetData ($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow($hGUI, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) Sleep(200) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_ReleaseDC (0, $hWnd) _WinAPI_DeleteObject ($hBitmap) _WinAPI_DeleteDC ($hDC ) _GDIPlus_Shutdown () Until _IsPressed("1B") ; ESC key DllClose($dll) EndFunc Func RotateText() Local $txt,$txtlen,$fontSize = 12 $txt = "Autoit Sang" ; Type text to be displayed here - text box display autosizing below $txtlen = StringLen($txt) $fRot = $fRot + 1 if $fRot = 144 Then $fRot = -144 ; 72*5deg=360deg - 2/360's before zero & 2/360's after zero if $fRot < 0 Then $nAngle = mod($nAngle -5, 360) ; 5deg increments (minus anticlockwise) Else $nAngle = mod($nAngle +5, 360) ; 5deg increments (plus clockwise) EndIf ;Text box display autosizing. $w - Width of text rectangle; $h - Heigth of text rectangle $w = int($fontSize*$txtlen*3/4 ) $h = int( ($fontSize*4/3)*(1280/1024)) if $fCol = 0 Then ;Randomize ARGB color $randcol = "0xff" & Hex(Random(0,255,1),2) & Hex(Random(0,255,1),2) & Hex(Random(0,255,1),2) EndIf $fCol = mod($fCol + 1,18) ; Changes color every 18 * 5deg = 90Deg ;DrawText( $nX, $nY, $nAngle, $iWidth, $iHeight, $txt, $iARGB , $fontSize ) DrawText($GuiSize/4, $GuiSize/4, $nAngle, $w, $h, $txt, $randcol ) return 1 EndFunc Func RotateText2() Local $txt2,$txtlen2,$winpos $txt2 = "Autoit Sang" ; Type text to be displayed here - text box display autosizing below $txtlen2 = StringLen($txt2) $fRot = $fRot + 1 if $fRot = 144 Then $fRot = -144 ; 72*5deg=360deg - 2/360's before zero & 2/360's after zero if $fRot < 0 Then $nAngle = mod($nAngle -5, 360) ; 5deg increments (minus anticlockwise) $fontSize = 12 + int(($fRot+144)*20/144 ); increase fontsize 12 to size 32 over 144 increments Else $nAngle = mod($nAngle +5, 360) ; 5deg increments (plus clockwise) $fontSize = 32 - int(($fRot)*20/144 ); decrease fontsize 32 to size 12 over 144 increments EndIf ;$w2 - Width of text rectangle; $h2 - Heigth of text rectangle $w2 = int($fontSize*$txtlen2*3/4 ) $h2 = int( ($fontSize*4/3)*(1280/1024)) $winpos = WinGetPos($hGui) WinMove ( "Rotate Text", "", mod($winpos[0]+1,@DesktopWidth/2) ,$winpos[1] ) if $fCol = 0 Then ;Randomize ARGB color $randcol = "0xff" & Hex(Random(0,255,1),2) & Hex(Random(0,255,1),2) & Hex(Random(0,255,1),2) EndIf $fCol = mod($fCol + 1,18) ; Changes color 18 * 5deg = 90Deg ;DrawText( $nX, $nY, $nAngle, $iWidth, $iHeight, $txt, $iARGB , $fontSize ) DrawText($GuiSize/2, $GuiSize/2, $nAngle, $w2, $h2, $txt2, $randcol, $fontSize ) sleep(40) return 1 EndFunc Func DrawText( $nX, $nY, $nAngle, $nWidth, $nHeight, $txt, $iARGB = 0xFF000000, $fontSize = 12) Local $hMatrix, $nXt, $nYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout,$x,$y ; $nXt - The X coordinate of the upper left corner of the Graphics object before rotation ; $nYt - The Y coordinate of the upper left corner of the Graphics object before rotation ;Rotation Matrix $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, $nAngle, 1) _GDIPlus_GraphicsSetTransform($hGraphic , $hMatrix) ;x, y display coordinates of center of height of the rectanglular text box ($height/2). ;x, y increment in a circular path with radius (width of text box)/2. $x = ($nWidth/2)*cos($nAngle*$nPI/180) - ($nHeight/2)*sin($nAngle*$nPI/180);Parametric equations for a circle $y = ($nWidth/2)*sin($nAngle*$nPI/180) + ($nHeight/2)*cos($nAngle*$nPI/180); and adjusts for center of text box ;Rotation of Coordinate Axes formulae ;Use $nXt, $nYt in _GDIPlus_RectFCreate. These x, y values is the handle of the rectangular text box point ; before rotation (translation of the matrix) $nXt = ($nX-$x)*cos($nAngle*$nPI/180) + ($nY-$y)*sin($nAngle*$nPI/180) ; $nXt - X coordinate before translation $nYt = -($nX-$x)*sin($nAngle*$nPI/180) + ($nY-$y)*cos($nAngle*$nPI/180) ; $nYt - Y coordinate before translation ; Parameters for lus_GraphicsDrawStringEx() $hBrush = _GDIPlus_BrushCreateSolid ($iARGB) $hFormat = _GDIPlus_StringFormatCreate () $hFamily = _GDIPlus_FontFamilyCreate ("Arial") ;$hFont = _GDIPlus_FontCreate ($hFamily, 32, 1) $hFont = _GDIPlus_FontCreate ($hFamily, $fontSize, 1) $tLayout = _GDIPlus_RectFCreate ( $nXt, $nYt, $nWidth, $nHeight ) _GDIPlus_GraphicsDrawStringEx ($hGraphic, $txt, $hFont, $tLayout, $hFormat, $hBrush) sleep(20) ; Clean up resources _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_FontDispose ($hFont) _GDIPlus_FontFamilyDispose ($hFamily) _GDIPlus_StringFormatDispose ($hFormat) _GDIPlus_BrushDispose ($hBrush) Return 1 EndFunc ; ================================================================= ; Drag Window 3 of 3 addin ; ================================================================= Func _WinMove($HWnd, $Command, $wParam, $lParam) If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0) dllcall("user32.dll","int","SendMessage","hWnd", $HWnd, "int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0) EndFunc1 point -
Take a look to this script: #include <File.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> $sTempPath = @ScriptDir & "\temp" $sStackedImagePath = @ScriptDir & "\StackedBitmaps.png" $iScreenShotNumber = 8 ;Set the screenshots number If Not FileExists($sTempPath) Then DirCreate($sTempPath) Else DirRemove($sTempPath, 1) DirCreate($sTempPath) EndIf If FileExists($sStackedImagePath) Then FileDelete($sStackedImagePath) EndIf For $i = 0 To $iScreenShotNumber - 1 _ScreenCapture_Capture($sTempPath & "\" & $i & ".jpg") If @error Then MsgBox(16, "Error", "Unable to take screenshot") Exit EndIf Next Global $aFilter = _FileListToArrayRec($sTempPath, "*.jpg;*.png;*.bmp", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) If @error Then MsgBox($MB_ICONERROR, "Error", "No images were found in selected folder!", 10) Exit EndIf _GDIPlus_Startup() Global $hBitmap_Stacked = _GDIPlus_BitmapCreateStackedBitmaps($aFilter, $iScreenShotNumber) _GDIPlus_ImageSaveToFile($hBitmap_Stacked, $sStackedImagePath) _GDIPlus_ImageDispose($hBitmap_Stacked) _GDIPlus_Shutdown() DirRemove($sTempPath, 1) ShellExecute($sStackedImagePath) MsgBox($MB_ICONINFORMATION, "Done!", "All done!") Func _GDIPlus_BitmapCreateStackedBitmaps($aFiles, $iLimit = 5) If $aFiles[0] = 1 Then Return SetError(1, 0, 0) ;only one image $iLimit = $iLimit > $aFiles[0] ? $aFiles[0] : $iLimit Local $i, $aDim, $iW_max = 0, $iH_max = 0, $aImages[$iLimit + 1], $iY = 0 $aImages[0] = $iLimit For $i = 1 To $iLimit $aImages[$i] = _GDIPlus_ImageLoadFromFile($aFiles[$i]) $aDim = _GDIPlus_ImageGetDimension($aImages[$i]) $iW_max = $aDim[0] > $iW_max ? $aDim[0] : $iW_max $iH_max += $aDim[1] Next Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW_max, $iH_max), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) For $i = 1 To $iLimit $aDim = _GDIPlus_ImageGetDimension($aImages[$i]) _GDIPlus_GraphicsDrawImageRect($hGfx, $aImages[$i], 0, $iY, $aDim[0], $aDim[1]) _GDIPlus_ImageDispose($aImages[$i]) $iY += $aDim[1] Next _GDIPlus_GraphicsDispose($hGfx) Return $hBitmap EndFunc ;==>_GDIPlus_BitmapCreateStackedBitmaps Hi!1 point
-
Try this: Local $aTestStr = [ _ "My Word", _ ; --> My Word (nothing change) "My Word,", _ ; --> My Word (remove last comma if not followed by a word) "My Word, ", _ ; --> My Word (remove last comma and every space after the comma if are not followed by a word) "My Word,AB", _ ; --> My Word,AB (allowed only if 2-letter char follow the comma, nothing change) "My Word, AB", _ ; --> My Word,AB (allowed since 2-letter char follow the comma but remove the space) "My Word, ABC", _ ; --> My Word "My Word,ABC" _ ; --> My Word ] For $s In $aTestStr $s = StringRegExpReplace($s, "(, *$|(?<=,) (?=[A-Z]{2}$)|, *[A-Z]{3,}$)", "") ConsoleWrite($s & @CRLF) Next1 point
-
Try this. Local $sTestStr = _ "My Word" & @CRLF & _ ; --> My Word (nothing change) "My Word," & @CRLF & _ ; --> My Word (remove last comma if not followed by a word) "My Word, " & @CRLF & _ ; --> My Word (remove last comma and every space after the comma if are not followed by a word) "My Word,AB" & @CRLF & _ ; --> My Word,AB (allowed only if 2-letter char follow the comma, nothing change) "My Word, AB" & @CRLF & _ ; --> My Word,AB (allowed since 2-letter char follow the comma but remove the space) "My Word, ABC" & @CRLF & _ ; --> My Word "My Word,ABC" ; --> My Word Local $s = StringRegExpReplace($sTestStr, "(?!,)\h+", "") ; Remove spaces following a coma, $s = StringRegExpReplace($s, "(?im),([a-z]|.{3,})?$", "") ; Remove the coma and the following one letter, or, three or more characters to end of line. ConsoleWrite($s & @CRLF)1 point
-
1 point
-
This should be "will turn any none numeric zero value into false", but yes, that is what happens when you change it to boolean. Jos1 point
-
Be careful because this will turn anything to false - for example if var is number 5 or text "abc". In C there is a Boolean variable type, here it is a little bit different.1 point
-
Just trying out the latest version of AutoIt and thinking more functional #include <Array.au3> ; Example ; An example of filtering, mapping and reducing arrays, using a function reference. ; This is similiar to how it would be done in the likes of JavaScript ; i.e. more functional (declarative) than procedural (imperative) ; Filter example Local $aiFilteredBefore[] = [1, 2, 3, 50, 30, 40, 20, 30] Local $aiFilteredAfter = _ArrayFilter($aiFilteredBefore, GtrThan30) _ArrayDisplay($aiFilteredAfter, '_ArrayFilter::') ; Map example Local $aiMappedBefore[] = [1, 2, 3, 4, 5, 6, 7, 8, 9] Local $aiMappedAfter = _ArrayMap($aiMappedBefore, MultiplyByTwo) _ArrayDisplay($aiMappedAfter, '_ArrayMap::') ; Reduce example ; Sum all values in the array Local $aiReducedBefore[] = [1, 2, 3, 50, 30, 40, 20, 30] ConsoleWrite('_ArrayReduce:: ' & _ArrayReduce($aiReducedBefore, SumValues) & @CRLF) ; Passing an empty array, will return the initial value; otherwise, sets @error to 4 ; if no initial value is defined Local $aEmpty[] = [] ConsoleWrite('_ArrayReduce:: ' & _ArrayReduce($aEmpty, SumValues, 0) & @CRLF) ; Array callback functions (for the examples only) Func GtrThan30($iValue) Return $iValue > 30 EndFunc ;==>GtrThan30 Func MultiplyByTwo($iValue, $iIndex, $aiArray) ; Notice how the function is called with the optional arguments "index" and "original array" ConsoleWrite('Index:: ' & $iIndex & ', Array:: ' & _ArrayToString($aiArray) & @CRLF) Return $iValue * 2 EndFunc ;==>MultiplyByTwo Func SumValues($a, $b) Return $a + $b EndFunc ;==>SumValues ; Functions ; The callback function is invoked with fn(value, [index, [array]]) Func _ArrayFilter($avArray, $hFunc) If Not IsArray($avArray) Then ; Null is more appropriate than returning the likes of -1 or an empty array Return SetError(1, 0, Null) EndIf If Not IsFunc($hFunc) Then Return SetError(2, 0, Null) EndIf Local Const $iLength = UBound($avArray) Local $avFiltered[$iLength] If $iLength = 0 Then Return $avFiltered EndIf Local $iIndex = 0 For $i = 0 To $iLength - 1 Local $bIsFiltered = __ArrayCall($hFunc, 3, $avArray[$i], $i, $avArray) If @error Then Return SetError(@error, @extended, Null) ElseIf $bIsFiltered Then $avFiltered[$iIndex] = $avArray[$i] $iIndex += 1 EndIf Next ReDim $avFiltered[$iIndex] Return $avFiltered EndFunc ;==>_ArrayFilter ; The callback function is invoked with fn(value, [index, [array]]) Func _ArrayMap($avArray, $hFunc) If Not IsArray($avArray) Then ; Null is more appropriate than returning the likes of -1 or an empty array Return SetError(1, 0, Null) EndIf If Not IsFunc($hFunc) Then Return SetError(2, 0, Null) EndIf Local Const $iLength = UBound($avArray) Local $avMapped[$iLength] If $iLength = 0 Then Return $avMapped EndIf For $i = 0 To $iLength - 1 $avMapped[$i] = __ArrayCall($hFunc, 3, $avArray[$i], $i, $avArray) If @error Then Return SetError(@error, @extended, Null) EndIf Next Return $avMapped EndFunc ;==>_ArrayMap ; The callback function is invoked with fn(current, value, [index, [array]]) Func _ArrayReduce($avArray, $hFunc, $vInitial = Default) If Not IsArray($avArray) Then ; Null is more appropriate than returning the likes of -1 or an empty array Return SetError(1, 0, Null) EndIf If Not IsFunc($hFunc) Then Return SetError(2, 0, Null) EndIf Local $bHasInitial = @NumParams >= 3 Local $iLength = UBound($avArray) If $iLength = 0 Then If Not $bHasInitial Then Return SetError(4, 0, Null) EndIf Return $vInitial EndIf For $i = 0 To $iLength - 1 If $bHasInitial Then $vInitial = __ArrayCall($hFunc, 3, $vInitial, $avArray[$i], $i, $avArray) If @error Then Return SetError(@error, @extended, Null) EndIf Else $bHasInitial = True $vInitial = $avArray[$i] EndIf Next Return $vInitial EndFunc ;==>_ArrayReduce Func __ArrayCall($hFunc, $iError, $vArg1 = Default, $vArg2 = Default, $vArg3 = Default, $vArg4 = Default) Local Const $CALL_ERROR = 0xDEAD Local Const $CALL_EXTENDED = 0xBEEF Local $vRet = Call($hFunc, $vArg1) If @error = $CALL_ERROR And @extended = $CALL_EXTENDED Then $vRet = Call($hFunc, $vArg1, $vArg2) If @error = $CALL_ERROR And @extended = $CALL_EXTENDED Then $vRet = Call($hFunc, $vArg1, $vArg2, $vArg3) If @error = $CALL_ERROR And @extended = $CALL_EXTENDED Then $vRet = Call($hFunc, $vArg1, $vArg2, $vArg3, $vArg4) If @error = $CALL_ERROR And @extended = $CALL_EXTENDED Then ; The function exists, but there is no appropriate function signature Return SetError($iError, 0, Null) EndIf EndIf EndIf EndIf Return SetError(@error, @extended, $vRet) EndFunc ;==>__ArrayCall1 point
-
The OP wants a script that continues after ANY key is pressed. Here my solution. ; Wait for key ; #include <WinAPI.au3> Beep(500, 300) _Wait_for_Key() Beep(800, 300) Func _Wait_for_Key() Global $_Wait_for_Key = 1 Local $hProc = DllCallbackRegister("_Wait_for_Key_Proc", "long", "int;wparam;lparam") Local $hGM = _WinAPI_GetModuleHandle(0) Local $handleK = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hProc), $hGM) While $_Wait_for_Key Sleep(100) WEnd _WinAPI_UnhookWindowsHookEx($handleK) DllCallbackFree($hProc) Return EndFunc ;==>_Wait_for_Key Func _Wait_for_Key_Proc($nCode, $wParam, $lParam) $_Wait_for_Key = 0 Return EndFunc ;==>_Wait_for_Key_Proc After the first beep, the script pauses until ANY key is pressed and then beeps again and exits. BTW: You can extend the script to honor also mouse moves.1 point
-
CString.au3 http://www.2shared.com/file/VwaryO_f/cstring.html This header file defines several functions to manipulate C strings and arrays. http://www.cplusplus.com/reference/clibrary/cstring/ #Include <Memory.au3> Global $CSTRING_UNICODE = True , $NULL_PTR = Ptr(0) ;CStrings.au3 ;This header file defines several functions to manipulate C strings and arrays. ;http://www.cplusplus.com/reference/clibrary/cstring/ Func memchr($MemStrVar,$Char,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memchr/ ;http://msdn.microsoft.com/en-us/library/aa246466%28VS.60%29.aspx ;Locate character in block of memory ;Searches within the first num bytes of the block of memory pointed by ptr for the first ;occurrence of value (interpreted as an unsigned char), and returns a pointer to it. Local $MemPtr , $WNum = 1 , $RtStr = "" , $StrTest = False Switch $CSTRING_UNICODE Case True if IsString($Char) Then $Char = AscW($Char) $WNum = 2 $Num *= 2 Case Else if IsString($Char) Then $Char = Asc($Char) EndSwitch Select Case IsString($MemStrVar) $MemPtr = GetStrBuffer($MemStrVar) $StrTest = True Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect if ($Num = 0) Then $Num = (strlen($MemPtr) * $WNum) $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memchr","ptr",$MemPtr,"int",$Char,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTest) Then MemPtrFree($MemPtr) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($MemRt[0] And $StrTest) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemPtr,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func memcmp($MemStrVar1,$MemStrVar2,$Num = 0) ;http://www.cplusplus.com/reference/clibrary/cstring/memcmp/ ;http://msdn.microsoft.com/en-us/library/aa246467%28VS.60%29.aspx ;Compare two blocks of memory ;Compares the first num bytes of the block of memory pointed by ptr1 to the ;first num bytes pointed by ptr2, returning zero if they all match or a value ;different from zero representing which is greater if they do not. Local $CharTypeA = "" , $CharTypeB = "" , $WNum = 1 Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $WNum = 2 $Num *= 2 Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect EndSwitch if ($Num = 0) Then $Num = (strlen($MemStrVar2) * $WNum) $RtError = DllCall("msvcrt.dll","int:cdecl","memcmp", _ $CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2,"int",$Num) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func memcpy($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memcpy/ ;http://msdn.microsoft.com/en-us/library/aa246468%28VS.60%29.aspx ;Copy block of memory ;Copies the values of num bytes from the location pointed by source directly ;to the memory block pointed by destination. Local $CharTypeA = "" , $Wsize = 1 Local $StrTestA = False , $StrTestB = False , $RtStr Switch $CSTRING_UNICODE Case True $Wsize = 2 $Num *= 2 Case Else EndSwitch if ($Num = 0) Then $Num = (strlen($Source) * $Wsize) Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestA = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestB = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memcpy","ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Destination) if ($StrTestB) Then MemPtrFree($Source) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestB) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestA) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func memmove($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memmove/ ;http://msdn.microsoft.com/en-us/library/aa246469%28v=VS.60%29.aspx ;Move block of memory ;Copies the values of num bytes from the location pointed by source to the ;memory block pointed by destination. Copying takes place as if an intermediate ;buffer were used, allowing the destination and source to overlap. Local $CharTypeA = "" , $Wsize = 1 Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $Wsize = 2 $Num *= 2 Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect EndSwitch if ($Num = 0) Then $Num = (strlen($Source) * $Wsize) $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memmove","ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func memset($MemPtr,$Char = 0,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memset/ ;http://msdn.microsoft.com/en-us/library/aa246471%28v=VS.60%29.aspx ;Fill block of memory ;Sets the first num bytes of the block of memory pointed by ptr to the ;specified value (interpreted as an unsigned char). if Not IsPtr($MemPtr) Then Return SetError(1,0,0) if IsString($Char) Then $Char = Asc($Char) if ($Num = 0) Then $Num = strlen($MemPtr) $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memset","ptr",$MemPtr,"int",$Char,"int",$Num) if @error Then Return SetError(2,0,0) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndFunc Func strcat($Destination,$Source,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strcat/ ;http://msdn.microsoft.com/en-us/library/aa272954%28VS.60%29.aspx ;Concatenate strings ;Appends a copy of the source string to the destination string. The terminating ;null character in destination is overwritten by the first character of source, and ;a new null-character is appended at the end of the new string formed by the ;concatenation of both in destination. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscat" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcat" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strchr($MemStrVar,$Char,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strchr/ ;http://msdn.microsoft.com/en-us/library/aa272957%28VS.60%29.aspx ;Locate first occurrence of character in string ;Returns a pointer to the first occurrence of character in the C string str. ;The terminating null-character is considered part of the C string. ;Therefore, it can also be located to retrieve a pointer to the end of a string. Local $MemPtr , $FuncA = "" , $StrTestA = False , $RtStr = "" Switch $CSTRING_UNICODE Case True if IsString($Char) Then $Char = AscW($Char) $FuncA = "wcschr" Case Else if IsString($Char) Then $Char = Asc($Char) $FuncA = "strchr" EndSwitch Select Case IsString($MemStrVar) $MemPtr = GetStrBuffer($MemStrVar) $StrTestA = True Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemPtr,"int",$Char) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($MemPtr) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($MemRt[0] And $StrTestA) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemPtr,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strcmp($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strcmp/ ;http://msdn.microsoft.com/en-us/library/aa272960%28VS.60%29.aspx ;Compare two strings ;Compares the C string str1 to the C string str2. ;This function starts comparing the first character of each string. ;If they are equal to each other, it continues with the following ;pairs until the characters differ or until a terminating null-character ;is reached. Local $FuncA = "" , $CharTypeA = "" , $CharTypeB = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscmp" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcmp" EndSwitch $RtError = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func strcoll($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strcoll/ ;http://msdn.microsoft.com/en-us/library/aa272961%28VS.60%29.aspx ;Compare two strings using locale ;Compares the C string str1 to the C string str2, both interpreted ;appropiately according to the LC_COLLATE category of the current locale. ;This function starts comparing the first character of each string. If they ;are equal to each other continues with the following pair until the characters ;differ or until a null-character signaling the end of a string is reached. Local $FuncA = "" , $CharTypeA = "" , $CharTypeB = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscoll" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcoll" EndSwitch $RtError = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func strcpy($Destination,$Source,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strcpy/ ;http://msdn.microsoft.com/en-us/library/aa272966%28VS.60%29.aspx ;Copy string ;Copies the C string pointed by source into the array pointed by destination, ;including the terminating null character. ;To avoid overflows, the size of the array pointed by destination shall be ;long enough to contain the same C string as source (including the terminating ;null character), and should not overlap in memory with source. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscpy" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcpy" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strcspn($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strcspn/ ;http://msdn.microsoft.com/en-us/library/aa272969%28VS.60%29.aspx ;Get span until character in string ;Scans str1 for the first occurrence of any of the characters that are ;part of str2, returning the number of characters of str1 read before ;this first occurrence. ;The search includes the terminating null-characters, so the function will ;return the length of str1 if none of the characters of str2 are found in str1. Local $FuncA = "" , $CharTypeA = "" , $CharTypeB = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscspn" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcspn" EndSwitch $RtPosition = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtPosition[0]) EndFunc Func strncat($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strncat/ ;http://msdn.microsoft.com/en-us/library/aa272986 ;Append characters from string ;Appends the first num characters of source to destination, plus a terminating ;null-character. If the length of the C string in source is less than num, only ;the content up to the terminating null-character is copied. Local $CharTypeA = "" , $FuncA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsncat" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strncat" EndSwitch if ($Num = 0) Then $Num = (strlen($Source)) $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strncmp($MemStrVar1,$MemStrVar2,$Num = 0) ;http://www.cplusplus.com/reference/clibrary/cstring/strncmp/ ;http://msdn.microsoft.com/en-us/library/aa272987%28VS.60%29.aspx ;Compare characters of two strings ;Compares up to num characters of the C string str1 to those of the C string str2. ;This function starts comparing the first character of each string. If they are equal ;to each other, it continues with the following pairs until the characters differ, ;until a terminating null-character is reached, or until num characters match in both ;strings, whichever happens first. Local $CharTypeA = "" , $CharTypeB = "" , $FuncA = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsncmp" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strncmp" EndSwitch if ($Num = 0) Then $Num = (strlen($MemStrVar2)) $RtError = DllCall("msvcrt.dll","int:cdecl",$FuncA, _ $CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2,"int",$Num) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func strncpy($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strncpy/ ;http://msdn.microsoft.com/en-us/library/aa272990%28VS.60%29.aspx ;Copy characters from string ;Copies the first num characters of source to destination. If the end of the source C ;string (which is signaled by a null-character) is found before num characters have ;been copied, destination is padded with zeros until a total of num characters have ;been written to it. ;No null-character is implicitly appended to the end of destination, so destination ;will only be null-terminated if the length of the C string in source is less than num. Local $CharTypeA = "" , $FuncA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsncpy" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source,strlen($Source)) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strncpy" EndSwitch if ($Num = 0) Then $Num = strlen($Source) $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strpbrk($Destination,$Source,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strpbrk/ ;http://msdn.microsoft.com/en-us/library/aa272993%28VS.60%29.aspx ;Locate character in string ;Returns a pointer to the first occurrence in str1 of any of the characters ;that are part of str2, or a null pointer if there are no matches. ;The search does not include the terminating null-characters. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcspbrk" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strpbrk" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strrchr($MemStrVar,$Char,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strrchr/ ;http://msdn.microsoft.com/en-us/library/aa272996%28VS.60%29.aspx ;Locate last occurrence of character in string ;Returns a pointer to the last occurrence of character in the C string str. ;The terminating null-character is considered part of the C string. Therefore, ;it can also be located to retrieve a pointer to the end of a string. Local $MemPtr , $WNum = 1 , $RtStr = "" Local $FuncA = "" , $StrTest = False Switch $CSTRING_UNICODE Case True if IsString($Char) Then $Char = AscW($Char) $FuncA = "wcsrchr" Case Else if IsString($Char) Then $Char = Asc($Char) $FuncA = "strrchr" EndSwitch Select Case IsString($MemStrVar) $MemPtr = GetStrBuffer($MemStrVar) $StrTest = True Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemPtr,"int",$Char) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTest) Then MemPtrFree($MemRt[0]) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($MemRt[0] And $StrTest) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemPtr,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strspn($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strspn/ ;http://msdn.microsoft.com/en-us/library/aa273001%28VS.60%29.aspx ;Get span of character set in string ;Returns the length of the initial portion of str1 which consists only of ;characters that are part of str2. Local $CharTypeA = "" , $CharTypeB = "" , $FuncA = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsspn" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strspn" EndSwitch $RtLength = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtLength[0]) EndFunc Func strstr($MemStrVar1,$MemStrVar2,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strstr/ ;http://msdn.microsoft.com/en-us/library/aa273008%28VS.60%29.aspx ;Locate substring ;Returns a pointer to the first occurrence of str2 in str1, or a null ;pointer if str2 is not part of str1. ;The matching process does not include the terminating null-characters. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsstr" Case Else Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strstr" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemStrVar1,"ptr",$MemStrVar2) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($StrTestB) Then MemPtrFree($MemStrVar1) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemStrVar1,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strtok($MemStrVar1,$MemStrVar2,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strtok/ ;http://msdn.microsoft.com/en-us/library/aa273013%28VS.60%29.aspx ;Split string into tokens ;A sequence of calls to this function split str into tokens, which are ;sequences of contiguous characters separated by any of the characters ;that are part of delimiters. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcstok" Case Else Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strtok" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemStrVar1,"ptr",$MemStrVar2) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($StrTestB) Then MemPtrFree($MemStrVar1) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemStrVar1,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strxfrm($Destination,$Source,$Num = 0) ;http://www.cplusplus.com/reference/clibrary/cstring/strxfrm/ ;http://msdn.microsoft.com/en-us/library/aa273019 ;Transform string using locale ;Transforms the C string pointed by source according to the current locale ;and copies the first num characters of the transformed string to destination, ;returning its length. ;Alternativelly, the function can be used to only retrieve the length, by ;specifying a null pointer for destination and zero for num. Local $CharTypeA = "" , $FuncA = "" Local $StrTestA = False , $StrTestB = False Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsxfrm" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source,strlen($Source)) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strxfrm" EndSwitch $MemRt = DllCall("msvcrt.dll","int:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndFunc Func puts($MemStrVar) Local $CharTypeA = "" , $FuncA = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar) $CharTypeA = "wstr" Case IsPtr($MemStrVar) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "_putws" Case Else Select Case IsString($MemStrVar) $CharTypeA = "str" Case IsPtr($MemStrVar) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "puts" EndSwitch $EOF = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar) if @error Then Return SetError(2,0,0) Sleep(100) Return SetError(Not $EOF[0],0,$EOF[0]) EndFunc Func printf($Format,$Type1 = "",$Param1 = "",$Type2 = "",$Param2 = "",$Type3 = "",$Param3 = "", _ $Type4 = "",$Param4 = "",$Type5 = "",$Param5 = "",$Type6 = "",$Param6 = "",$Type7 = "", _ $Param7 = "" ,$Type8 = "",$Param8 = "",$Type9 = "",$Param9 = "",$Type10 = "",$Param10 = "") Local $Sring = 'DllCall("msvcrt.dll","int:cdecl","printf","str",Eval("Format")' , $Type = "" For $i = 1 To 10 $Type = Eval("Type" & $i) if $Type == "" Then ExitLoop $Sring &= ',Eval("Type' & $i & '"),Eval("Param' & $i & '")' Next $Sring &= ")" $RT = Execute($Sring) if @error Then Return SetError(2,0,0) Sleep(100) Return SetError($RT[0] < 0,0,$RT[0]) EndFunc Func GetStrBuffer($CString,$MemSize = 0) Local $MemPtr = 0, $FuncA = "", $CharTypeA = "" , $Wsize = 1 if Not IsString($CString) Then Return SetError(3,0,0) Switch $CSTRING_UNICODE Case True $CharTypeA = "wstr" $FuncA = "wcsncpy" $Wsize = 2 Case Else $CharTypeA = "str" $FuncA = "strncpy" EndSwitch if ($MemSize = 0) Then $MemSize = strlen($CString) $hMemory = _MemGlobalAlloc (($MemSize * $Wsize) + $Wsize,$GHND) $MemPtr = _MemGlobalLock ($hMemory) $MemPtrRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemPtr,$CharTypeA,$CString,"int",$MemSize) if @error Then Return SetError(2,0,0) Return SetError(Not $MemPtrRt[0],0,$MemPtrRt[0]) EndFunc Func GetBufferStr($MemStrVar,$MemSize = 0) Local $MemPtr = 0, $FuncA = "", $CharTypeA = "" , $DMemPtr Switch $CSTRING_UNICODE Case True $CharTypeA = "wstr:cdecl" $FuncA = "wcsncpy" Case Else $CharTypeA = "str:cdecl" $FuncA = "strncpy" EndSwitch Select Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect if ($MemSize = 0) Then $MemSize = strlen($MemPtr) $DMemPtr = GetStrBuffer("",$MemSize) $StrRt = DllCall("msvcrt.dll",$CharTypeA,$FuncA,"ptr",$DMemPtr,"ptr",$MemPtr,"int",$MemSize) if @error Then Return SetError(2,0,0) MemPtrFree($DMemPtr) Return SetError(Not $StrRt[0],0,$StrRt[0]) EndFunc Func MemPtrFree($MemPtr) Local $iMemPtr = 0 , $FreeRt = 1 $iMemPtr = Eval(String("#@cstringLib" & $MemPtr)) if Not (@error) Then Assign(String("#@cstringLib" & $MemPtr),"", 2) if ($iMemPtr) Then $MemPtr = $iMemPtr $hMemory = DllCall("Kernel32.dll","HANDLE","GlobalHandle","ptr",$MemPtr) if @error Then Return SetError(2,0,False) if ($hMemory[0]) Then $FreeRt = _MemGlobalFree($hMemory[0]) Return SetError($FreeRt <> 0,0,$FreeRt = 0) EndFunc Func strlen($MemStrVar) Local $CString = "" , $FuncA = "" , $FuncB = "" , $CharTypeA = "" Switch $CSTRING_UNICODE Case True $CharTypeA = "wstr" $FuncA = "wcslen" $FuncB = "wcscpy" Case Else $CharTypeA = "str" $FuncA = "strlen" $FuncB = "strcpy" EndSwitch Select Case IsString($MemStrVar) $CString = $MemStrVar Case IsPtr($MemStrVar) $CString = DllCall("msvcrt.dll",$CharTypeA & ":cdecl",$FuncB,$CharTypeA,"","ptr",$MemStrVar) if @error Then Return SetError(3,0,0) $CString = $CString[0] Case Else Return SetError(1,0,0) EndSelect $LenRt = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$CString) if @error Then Return SetError(2,0,0) Return SetError(0,0,$LenRt[0]) EndFunc Examples memchr cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str = "Example string" $pch = memchr($str,'p',strlen($str)) if ($pch) Then printf (@CRLF & "'p' found at position %d" & @CR,"int",strlen($str) - strlen($pch) + 1) printf ("GetBufferStr($pch) ==> %s" & @CRLF,"str",GetBufferStr($pch)) Else printf ("'p' not found" & @CRLF) EndIf MemPtrFree($pch) $CSTRING_UNICODE = False $str = "Example string" $pch = memchr($str,'p',strlen($str)) if ($pch) Then printf (@CRLF & "'p' found at position %d" & @CR,"int",strlen($str) - strlen($pch) + 1) printf ("GetBufferStr($pch) ==> %s" & @CRLF,"str",GetBufferStr($pch)) Else printf ("'p' not found" & @CRLF) EndIf MemPtrFree($pch) memcmp cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = False $Str1 = "Sentence1" $Str2 = "Sentence1" $N = memcmp($Str1,$Str2) if ($N > 0) Then printf ("'%s' is greater than '%s'." & @CRLF ,"str",$Str1,"str",$Str2) ElseIf ($N < 0) Then printf ("'%s' is less than '%s'." & @CRLF,"str",$Str1,"str",$Str2) Else printf ("'%s' is the same as '%s'." & @CRLF,"str",$Str1,"str",$Str2) EndIf $CSTRING_UNICODE = True $Str1 = "Sentence2" $Str2 = "Sentence3" $Struct1 = DllStructCreate("wchar[" & strlen($Str1) + 2 & "]") DllStructSetData($Struct1,1,$Str1) $Ptr1 = DllStructGetPtr($Struct1) $Struct2 = DllStructCreate("wchar[" & strlen($Str2) + 2 & "]") DllStructSetData($Struct2,1,$Str2) $Ptr2 = DllStructGetPtr($Struct2) $N = memcmp($Ptr1,$Ptr2) if ($N > 0) Then printf ("'%s' is greater than '%s'." & @CRLF ,"str",$Str1,"str",$Str2) ElseIf ($N < 0) Then printf ("'%s' is less than '%s'." & @CRLF,"str",$Str1,"str",$Str2) Else printf ("'%s' is the same as '%s'." & @CRLF,"str",$Str1,"str",$Str2) EndIf $CSTRING_UNICODE = False $Str1 = "Sentence3" $Str2 = "Sentence2" $Struct1 = DllStructCreate("char[" & strlen($Str1) + 1 & "]") $Ptr1 = DllStructGetPtr($Struct1) memcpy($Ptr1,$Str1) $N = memcmp($Ptr1,$Str2) if ($N > 0) Then printf ("'%s' is greater than '%s'." & @CRLF ,"str",$Str1,"str",$Str2) ElseIf ($N < 0) Then printf ("'%s' is less than '%s'." & @CRLF,"str",$Str1,"str",$Str2) Else printf ("'%s' is the same as '%s'." & @CRLF,"str",$Str1,"str",$Str2) EndIf memcpy cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("wchar[40]") $str3 = DllStructGetPtr($Struct3) memcpy($str2,$str1,strlen($str1)+1) memcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3)) MemPtrFree($str2) $CSTRING_UNICODE = False $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("char[40]") $str3 = DllStructGetPtr($Struct3) memcpy($str2,$str1,strlen($str1)+1) memcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3)) MemPtrFree($str2) memmove cplusplus microsoft #Include <cstring.au3> Dim $SizeOfChar = 1 , $SizeOfWchar = 2 $CSTRING_UNICODE = True $str = memcpy("","memmove can be very useful......") memmove($str+(20 * $SizeOfWchar),$str+(15 * $SizeOfWchar),11); printf(@CRLF) puts($str) printf(@CRLF) MemPtrFree($str) $CSTRING_UNICODE = False $str = memcpy("","memmove can be very useful......") memmove($str+(20 * $SizeOfChar),$str+(15 * $SizeOfChar),11); printf(@CRLF) puts($str) printf(@CRLF) MemPtrFree($str) memset cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = False ; Only $istr = "almost every programmer should know memset!" $iStruct = DllStructCreate("char[43]") $iPtr = DllStructGetPtr($iStruct) memcpy($iPtr,$istr) memset($iPtr,'-',6) printf(@CRLF) puts($iPtr) printf(@CRLF) strcat cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $Struct = DllStructCreate("wchar[80]") $iStr = DllStructGetPtr($Struct) memcpy($iStr,"these ") strcat($iStr,"strings ") strcat($iStr,"are ") strcat($iStr,"concatenated.") printf(@CR) puts($iStr) printf(@CR) $CSTRING_UNICODE = False $iStr = GetStrBuffer("",80) memcpy($iStr,"these ") strcat($iStr,"strings ") strcat($iStr,"are ") strcat($iStr,"concatenated.") puts($iStr) printf(@CR) MemPtrFree($iStr) strchr cplusplus microsoft #Include <cstring.au3> Local $SizeOfChar = 1 , $SizeOfWchar = 2 $CSTRING_UNICODE = True $str = "This is a sample string"; printf ('Looking for the "s" character in \"%s\"...' & @CR,"str",$str); $pch = strchr($str,'s'); Dim $Tempch = $pch while ($pch <> 0) printf ("found at %d" & @CR,"int",strlen($str) - strlen($pch) + 1); $pch=strchr($pch+($SizeOfWchar),'s'); WEnd printf(@CRLF) MemPtrFree($Tempch) $CSTRING_UNICODE = False $str = "This is a sample string"; printf ('Looking for the "s" character in \"%s\"...' & @CR,"str",$str); $pch = strchr($str,'s'); Dim $Tempch = $pch while ($pch <> 0) printf ("found at %d" & @CR,"int",strlen($str) - strlen($pch) + 1); $pch=strchr($pch+($SizeOfChar),'s'); WEnd MemPtrFree($Tempch) strcmp cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcmp($szKey,$szInput) = 0) puts("Correct answer!" & @CR); $CSTRING_UNICODE = False Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcmp($szKey,$szInput) = 0) puts("Correct answer!" & @CR); strcoll cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcoll($szKey,$szInput) = 0) puts("Correct answer!" & @CR); $CSTRING_UNICODE = False Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcoll($szKey,$szInput) = 0) puts("Correct answer!" & @CR); strcpy cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("wchar[40]") $str3 = DllStructGetPtr($Struct3) strcpy($str2,$str1,strlen($str1)+1) strcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3)) $CSTRING_UNICODE = False $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("char[40]") $str3 = DllStructGetPtr($Struct3) strcpy($str2,$str1,strlen($str1)+1) strcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3))strcspn cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str = "fcba73" $keys = "1234567890" Dim $i $i = strcspn($str,$keys) printf(@CR) printf ("The first number in str is at position %d.","int",$i+1) printf(@CRLF) $CSTRING_UNICODE = False $str = "fcba73" $keys = "1234567890" Dim $i $i = strcspn($str,$keys) printf(@CR) printf ("The first number in str is at position %d.","int",$i+1) printf(@CRLF) strncat cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str1 = GetStrBuffer("",20) $Struct2 = DllStructCreate("wchar[20]") $str2 = DllStructGetPtr($Struct2) strcpy ($str1,"To be ") strcpy ($str2,"or not to be") strncat ($str1,$str2,6) printf(@CR) puts ($str1) printf(@CRLF) MemPtrFree($str1) $CSTRING_UNICODE = False $str1 = GetStrBuffer("",20) $Struct2 = DllStructCreate("char[20]") $str2 = DllStructGetPtr($Struct2) strcpy ($str1,"To be ") strcpy ($str2,"or not to be") strncat ($str1,$str2,6) printf(@CR) puts ($str1) printf(@CRLF) MemPtrFree($str1) strcpy cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $Struct = DllStructCreate("wchar[5];wchar[5];wchar[5]") strcpy(DllStructGetPtr($Struct,1),"R2D2") strcpy(DllStructGetPtr($Struct,2),"C3PO") strcpy(DllStructGetPtr($Struct,3),"R2A6") puts ("Looking for R2 astromech droids...") For $n = 1 To 3 if (strncmp(DllStructGetPtr($Struct,$n),"R2xx",2) == 0) Then printf ("found %s" & @CR ,"str",GetBufferStr(DllStructGetPtr($Struct,$n))) EndIf Next $CSTRING_UNICODE = False $Struct = DllStructCreate("char[5];char[5];char[5]") strcpy(DllStructGetPtr($Struct,1),"R2D2") strcpy(DllStructGetPtr($Struct,2),"C3PO") strcpy(DllStructGetPtr($Struct,3),"R2A6") puts ("Looking for R2 astromech droids...") For $n = 1 To 3 if (strncmp(DllStructGetPtr($Struct,$n),"R2xx",2) == 0) Then printf ("found %s" & @CR ,"str",GetBufferStr(DllStructGetPtr($Struct,$n))) EndIf Next strncpy cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $Struct2 = DllStructCreate("wchar[6]") $str2 = DllStructGetPtr($Struct2) strncpy($str2,"To be or not to be",5) puts($str2) $CSTRING_UNICODE = False $Struct2 = DllStructCreate("char[6]") $str2 = DllStructGetPtr($Struct2) strncpy($str2,"To be or not to be",5) puts($str2) strpbrk cplusplus microsoft #Include <cstring.au3> Dim $SizeOfWchar = 2 , $SizeOfChar = 1 $CSTRING_UNICODE = True $str = GetStrBuffer("This is a sample string") $key = GetStrBuffer("aeiou") printf("Vowels in '%s': ","str","This is a sample string"); $pch = strpbrk($str,$key) while ($pch <> 0) printf("%s " ,"str",GetBufferStr($pch,1)) $pch = strpbrk($pch + (1 * $SizeOfWchar),$key) WEnd printf(@CR) MemPtrFree($str) MemPtrFree($key) $CSTRING_UNICODE = False $str = GetStrBuffer("This is a sample string") $key = GetStrBuffer("aeiou") printf("Vowels in '%s': ","str","This is a sample string"); $pch = strpbrk($str,$key) while ($pch <> 0) printf("%s " ,"str",GetBufferStr($pch,1)) $pch = strpbrk($pch + (1 * $SizeOfChar),$key) WEnd printf(@CR) MemPtrFree($str) MemPtrFree($key) strrchr cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str = "This is a sample string" $pch=strrchr($str,'s') printf ("Last occurence of 's' found at %d " & @CRLF,"int",strlen($str) - strlen($pch) + 1) MemPtrFree($pch) $CSTRING_UNICODE = False $str = "This is a sample string" $pch=strrchr($str,'s') printf ("Last occurence of 's' found at %d " & @CRLF,"int",strlen($str) - strlen($pch) + 1) MemPtrFree($pch) strspn cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True Dim $i $strtext = "129th" $cset = "1234567890" $i = strspn($strtext,$cset) printf (@CR & "The length of initial number is %d." & @CRLF,"int",$i) $CSTRING_UNICODE = False Dim $i $strtext = "129th" $cset = "1234567890" $i = strspn($strtext,$cset) printf ("The length of initial number is %d." & @CR,"int",$i) strstr cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str = GetStrBuffer("This is a simple string") $pch = strstr($str,"simple") strncpy ($pch,"sample",6) puts ($str) MemPtrFree($str) $CSTRING_UNICODE = False $str = GetStrBuffer("This is a simple string") $pch = strstr($str,"simple") strncpy ($pch,"sample",6) puts ($str) MemPtrFree($str) strtok cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $str = GetStrBuffer("- This, a sample string.") printf ("Splitting string '%s' into tokens:" & @CR ,"str",GetBufferStr($str)); $pch = strtok($str," ,.-") while ($pch <> 0) printf ("%s" & @CR,"str",GetBufferStr($pch)) $pch = strtok($NULL_PTR, " ,.-"); WEnd MemPtrFree($str) $CSTRING_UNICODE = False $str = GetStrBuffer("- This, a sample string.") printf ("Splitting string '%s' into tokens:" & @CR ,"str",GetBufferStr($str)); $pch = strtok($str," ,.-") while ($pch <> 0) printf ("%s" & @CR,"str",GetBufferStr($pch)) $pch = strtok($NULL_PTR, " ,.-"); WEnd MemPtrFree($str) strxfrm cplusplus microsoft #Include <cstring.au3> $CSTRING_UNICODE = True $String = "sample string" $length = strxfrm($NULL_PTR,$String, 0 ) printf (@CR & "the length Of $String is %d" & @CRLF,"int",$length) $CSTRING_UNICODE = False $String = "sample string" $length = strxfrm($NULL_PTR,$String, 0 ) printf (@CR & "the length Of $String is %d" & @CRLF,"int",$length)1 point