Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/01/2016 in all areas

  1. Choose your wording with care. A global function should seldom need to be redeclared. What you are doing here is reassigning new data to an already existing global variable. Declaring a global variable inside a function is a superfluous action.
    2 points
  2. Thanks to Joachim Bauch's tutorial about Loading a DLL from memory. Here comes the easiest way to run the codes written in other language. All you need to do are make a DLL, convert it to HEX format, and embed into your script. For now, only stdcall is supported (up to four parameters) (There is no limit now, see update note). BTW, this script is only tested on Windows XP SP3. If you can run it in other systems, please let me know, thanks. Demo how to use: (this 3k md5.dll is written by myself and anyone is welcome to use it. But the machine code version of MD5 should be better choice in AutoIt) ; ------------------------------------------------------------- ; ; Step 1: Try to use the DLLs in the normal method (by DllCall) ; ; ------------------------------------------------------------- $String = "The quick brown fox jumps over the lazy dog" $Digest = DllStructCreate("byte[16]") DllCall("md5.dll", "str", "md5", "str", $String, "uint", StringLen($String), "ptr", DllStructGetPtr($Digest)) $Hash = DllStructGetData($Digest, 1) $Digest = 0 MsgBox(0, 'MD5 Hash', $Hash) ; ---------------------------------------------------------------------------- ; ; Step 2: Use MemoryDllGen.au3 to convert the DLL to script form and paste it. ; ; ---------------------------------------------------------------------------- Dim $DllBinary = ''; this line is too long to omit, check the attachment ; -------------------------------------------------------------------------------- ; ; Step 3: Replace DllCall to MemoryDllCall, and use $DllBinary instead of dll name ; ; -------------------------------------------------------------------------------- #Include "MemoryDll.au3" MemoryDllInit() $String = "The quick brown fox jumps over the lazy dog" $Digest = DllStructCreate("byte[16]") MemoryDllCall($DllBinary, "str", "md5", "str", $String, "uint", StringLen($String), "ptr", DllStructGetPtr($Digest)) $Hash = DllStructGetData($Digest, 1) $Digest = 0 MsgBox(0, 'MD5 Hash', $Hash) MemoryDllExit() ; ------------------------------------------------------------------------- ; ; Step 4: Finally, you have the functions in Pure AutoIt Scirpt. Have fun ! ; ; -------------------------------------------------------------------------MemoryDll.zip (4.67K) Number of downloads: 253 08/08/03 Update Note: Rearrange the return array of MemoryDllCall, now it's return should just like DllCall.Add support to accept more than four parameters, but in this case, some return value will be destoryed.Add a little Tutorial.MemoryDll.zip (9.17K) Number of downloads: 251 08/08/18 Update Note: I finally found a perfect trick to call a function in memory. So this UDF now supports DLL functions in both stdcall and cdecl mode with any number of parameters. In theory, DllCall now can be fully replaced by MemoryDllCall.There is a new func called MemoryFuncCall in this version. It is a new way to call a memory address. Compared to CallWindowProc (old method), MemoryFuncCall is flexible (supports cdecl, etc. ), but a bit slower.There are also two new utility scripts in attachment. AESFile uses the dll downloaded from http://adeil.com. It encrypt/decrypt files by a key of 32, 48 or 64 bytes long. SHA2 is written by Brian Gladman and compiled to DLL by me. It generates SHA2 hash of 224, 256, 384, or 512 bits long. Thanks to -Ultima- and ProgAndy's suggestion.MemoryDll.zip (50.27K) Number of downloads: 441 08/12/06 Update Note: Improves compatibility. Now MemoryDllCall should work better under Vista.Example of AESFile and SHA512 are removed. Please see my other post about AES and Hashes.MemoryDll.zip (8.95K) Number of downloads: 1118 2010/10/18 Update Note: Avoiding DEP issue.Improves compatibility. Now BASS.DLL is supported.MemoryDll.zip 2011/04/03 Update Note: Rewritten all code in AutoIt. Now both x86 and x64 DLL are supported.MemoryDllInit(), MemoryDllExit(), and old examples are removed.Add new example, MemoryDll version of SQLite.au3.Ps. I think old version are still good or even better when only used under x86 mode.But this version support x64 and has better compatibility I guess.MemoryDll.zip 2015/01/08 Update Note: Update the machine code version. Both x86 and x64 DLL are supported.TLS callback are supported.Remove all MemoryFuncXXX() related functions. Use build-in DllCallAddress instead.Add MemoryDllLoadString(), MemoryDllLoadResource() Add _WinAPI_MemoryFindResource(), _WinAPI_MemoryFindResourceEx(), _WinAPI_MemorySizeOfResource(), _WinAPI_MemoryLoadResource(), _WinAPI_MemoryLoadString(), _WinAPI_MemoryLoadStringEx()Using BinaryCall.au3 to loading the machine code.MemoryDll.zip 2015/01/23 Update Node: Add ability to load a DLL that needs other DLLs. For example: libcurl.dll needs libeay32.dll and ssleay32.dll for https support. Now you can load all of them by MemoryDll UDF. Before this version, only libcurl.dll can loaded by MemoryDll, other files must store on the disk.Add ability to call functions by ordinal value.Add MemoryDllRun(). It run a EXE file from memory. Relocation table in EXE file is required. Most PE rebuilding tools remove the section to reduce the file size.Add a script to demonstrate all the new features.This version of MemoryDll can works together with BinaryCall UDF. Binary machine code can call functions in DLL loaded by MemoryDll. MemoryDll.zip
    1 point
  3. error471, Just for info, so does my code - as I knew that is what you wanted! M23
    1 point
  4. Melba23

    Bug in FileOpen()? - Not!

    mikkokh, If @error is 0 then the read was successful - end of story. I believe you get the -1 @error comes if you opened the file in binary and then asked for a certain number of bytes to be read - if this was not achievable because AutoIt hit an EOF marker (usually 0x00) before that value you get the error. M23
    1 point
  5. j0kky, And there I was expending little grey cells: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <WinAPI.au3> Local $left = 100, $top = 100 $hGui = GUICreate("", 400, 200, $left, $top) GUICtrlCreateLabel("RED LABEL", 9, 9, 302, 102) GUICtrlSetBkColor(-1, $COLOR_RED) $cInput = GUICtrlCreateInput("WHITE INPUT", 10, 10, 300, 100) GUISetState() $aPos = ControlGetPos($hGUI, "", $cInput) _WinAPI_SetWindowPos(GUICtrlGetHandle($cInput), $HWND_TOP, $aPos[0], $aPos[1], $aPos[2], $aPos[3], $SWP_SHOWWINDOW) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd But I would suggest disabling is easier! M23
    1 point
  6. koenp, If you give your _ArrayDisplay dialog a suitably unique title then you can easily close it programmatically: #include <MsgBoxConstants.au3> #include <Array.au3> $sTitle = "Unique Title" Global $aArray[][] = [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]] ; Run a function every 5 secs AdlibRegister("_Close_Array_Dialog", 5000) ; Open the dialog _ArrayDisplay($aArray, $sTitle, Default, 8) MsgBox($MB_SYSTEMMODAL, "Hi", "The array dialog has closed", 2) Func _Close_Array_Dialog() ; Cancel future calls AdlibUnRegister("_Close_Array_Dialog") ; Close the dialog WinClose($sTitle) EndFunc M23
    1 point
  7. koenp, No tabs, so what I posted above works nicely on the real files: #include <Array.au3> #include <File.au3> #include <StringConstants.au3> $aList = _FileListToArray(@ScriptDir, "pat_layout*.txt", 1) For $i = 1 To $aList[0] $sRet = _ParseFile($aList[$i]) ConsoleWrite($sRet & @CRLF) Next Func _ParseFile($sFile) ; Read file into an array Local $aLines _FileReadToArray($sFile, $aLines) ; Find "Method" line $iStart = _ArraySearch($aLines, "Method", 0, 0, 0, 1) + 1 ; Find "NON-STANDARD" line $iEnd = _ArraySearch($aLines, "NON-STANDARD", 0, 0, 0, 1) - 1 ; Construct return $sExtract = "" For $i = $iStart To $iEnd ; Replace spaces in line with "|" $sLine = StringRegExpReplace($aLines[$i], "\s+", "|") ; Count instances StringReplace($sLine, "|", "") ; Valid line if at least 3 If @extended > 2 Then $aSplit = StringSplit($sLine, "|") ; See which form line takes and contruct accordingly If $aSplit[6] = "-" Then $sExtract &= $aSplit[2] & ";" & $aSplit[3] & ";" & $aSplit[4] & ";" & $aSplit[5] & "-" & $aSplit[7] & ";;;" & $aSplit[$aSplit[0]] & @CRLF Else $sExtract &= $aSplit[2] & ";;;" & $aSplit[3] & "-" & $aSplit[5] & ";Below Assay Range;;" & $aSplit[$aSplit[0]] & @CRLF EndIf EndIf Next Return $sExtract EndFunc ;==>_ParseFile Results: RF;431;IU/mL;0.0-15.0;;;13049MA IGG3;0.389;g/L;0.11-0.85;;;12292MA IGG4;;;0.03-2.01;Below Assay Range;;12324MA IGG2;;;1.69-7.86;Below Assay Range;;12310MA IGG4;0.009;g/L;0.03-2.01;;;12324MA IGG2;0.368;g/L;1.69-7.86;;;12310MA M23
    1 point
  8. I highly suspect a tab delimitation in this txt file. In this case it would obviously make brain-storming less painful Could you post the real file ? Edit Without more infos, and empirically assuming that *4 or more spaces* will work as delimiter, here are my 2 cents [btw Melba, your code skips the "diluted" ] #include <Array.au3> #include <StringConstants.au3> #include <File.au3> $sText = "CHU LIEGE SART TILMAN - LIEGE" & @CRLF & _ "Name: ABC CDE Patient ID: 20120831" & @CRLF & _ "Sample ID: 200604003705 Sample Type:Serum Dilution Factor: 1" & @CRLF & _ "Priority: Routine Rack Position: QK000137-6 Completed On: 2013-06-05 15:35:54" & @CRLF & _ "Operator: C135669REGI Instrument ID: DV330681 Aliquot Creation Time: 2013-06-05 14:40:37" & @CRLF & _ "Comment:" & @CRLF & _ " Method Result Units RefRange Flag Comment Reagent" & @CRLF & _ " IGG3 0.389 g/L 0.11 - 0.85 12292MA" & @CRLF & _ " Random 0.03 - 2.01 Below Assay Range 12324MA" & @CRLF & _ " IGG2 1.69 - 7.86 Below Assay Range 12310MA" & @CRLF & _ " ABC4 0.009 random 0.03 - 2.01 Diluted 12324MA" & @CRLF & _ " Below Reference" & @CRLF & _ " Range" & @CRLF & _ " IGG2 0.368 g/L 1.69 - 7.86 Diluted 12310MA" & @CRLF & _ " Below Reference" & @CRLF & _ " Range" & @CRLF & _ "NON-STANDARD CONFIGURATION Printed 2013-06-05 15:35:57" ; $sText = FileRead ... etc $sText = StringRegExpReplace($sText, '(?s).*Reagent\s*(.*?)NON-STANDARD.*', "$1") ;Msgbox(0,"", $sText) $res = StringRegExp($sText, '(?m)^(?!\s+Below|\s+Range)\s*(\N+)\R?', 3) ;_ArrayDisplay($res) For $i = 0 to UBound($res)-1 $tmp = StringRegExp($res[$i], '\s*(.*?\S)(?=\s{4,}|$)', 3) ;_ArrayDisplay($tmp) If $tmp[2] = "Below Assay Range" Then $res[$i] = $tmp[0] & ";;;" & $tmp[1] & ";Below Assay Range;;" & $tmp[3] ElseIf $tmp[4] = "Diluted" Then $res[$i] = $tmp[0] & ";" & $tmp[1] & ";" & $tmp[2] & ";" & $tmp[3] & ";;Diluted;" & $tmp[5] Else $res[$i] = $tmp[0] & ";" & $tmp[1] & ";" & $tmp[2] & ";" & $tmp[3] & ";;;" & $tmp[4] EndIf Next FileDelete("output.txt") _FileWriteFromArray("output.txt", $res) ; verification Sleep(100) Local $aOutput _FileReadToArray("output.txt", $aOutput, 0, ";") _ArrayDisplay($aOutput)
    1 point
  9. water

    OutlookEX UDF

    Glad to be of service BTW: If you like what you get, you could press the "Like this" button to let me know
    1 point
  10. Th only thing not mentioned in the previous topics is the final sorting #Include <Array.au3> Local $txt = "3" &@crlf& "1" &@crlf& "2" &@crlf& "3 " &@crlf& "4" &@crlf& "41" &@crlf& "42" &@crlf& "3" &@crlf& "5" &@crlf& "6" &@crlf& "42" ;Local $txt = FileRead("1.txt") & @crlf & FileRead("2.txt") & @crlf & FileRead("3.txt") Local $uniq = StringRegExp($txt, "(?s)\b(\d+)\b(?!.*\b\1\b)", 3) ; sorting numeric Local $temp, $loop = 1 While $loop $loop = 0 For $i = 1 To UBound($uniq) - 1 If Number($uniq[$i]) < Number($uniq[$i-1]) Then ; sort ascending $temp = $uniq[$i] $uniq[$i] = $uniq[$i-1] $uniq[$i-1] = $temp $loop = 1 EndIf Next WEnd _ArrayDisplay($uniq) Msgbox(0,"", _ArrayToString($uniq, ", ") )
    1 point
  11. Bowmore

    [Solved] Memory Leak

    Hi ahha This is the line in your __scrolltext() function that is using all your memory. GUICtrlSetData($hEdit, $text,1) It's appending to the existing contents of the control each time it is executed. If you change it to this your memory problems will disappear. GUICtrlSetData($hEdit, $text)
    1 point
  12. Here is an alternative method not using arrays. ; Create "Fruita.csv" file If FileExists("Fruita.csv") Then FileDelete("Fruita.csv") Local $sOut For $i = 1 To 5000 $sOut &= 'Food,Fruit,' & (Random(0, 1, 1) ? 'Apple' : 'Orange') & ',$' &$i & '.00' & @CRLF Next FileWrite("Fruita.csv", $sOut) ; Create "Fruit_Orange.csv" file If FileExists("Fruit_Orange.csv") Then FileDelete("Fruit_Orange.csv") $st = TimerInit() Local $sFruitFile = FileRead("Fruita.csv") FileWrite("Fruit_Orange.csv", StringRegExpReplace($sFruitFile, "(.*Apple.*\R*)", "")) ConsoleWrite('"Fruit_Orange.csv" generated in ' & Round(TimerDiff($st) / 1000, 3) & ' secs :- ' & @LF & FileRead("Fruit_Orange.csv") & @LF) ; Create "Fruit_Apple.csv" file If FileExists("Fruit_Apple.csv") Then FileDelete("Fruit_Apple.csv") $st2 = TimerInit() FileWrite("Fruit_Apple.csv", StringRegExpReplace($sFruitFile, "(.*Orange.*\R*)", "")) ConsoleWrite("--------------" & @LF) ConsoleWrite('"Fruit_Apple.csv" generated in ' & Round(TimerDiff($st2) / 1000, 3) & ' secs :- ' & @LF & FileRead("Fruit_Apple.csv") & @LF) ; Cleanup files FileDelete("Fruita.csv") FileDelete("Fruit_Orange.csv") FileDelete("Fruit_Apple.csv") The above script deletes the fruit not wanted in the new file. i.e. If Oranges are needed, then Apples are deleted. Whereas, the following script keeps the fruit that is wanted in the new file. i.e. If Oranges are needed, then "not-Oranges" are deleted. ; https://www.autoitscript.com/forum/topic/180240-delete-row-from-array-where-a-column-matches-a-value/?do=findComment&comment=1293819 ; Create "Fruita.csv" file If FileExists("Fruita.csv") Then FileDelete("Fruita.csv") Local $sOut For $i = 1 To 6000 $sOut &= 'Food,Fruit,' & (Random(0, 2, 1) ? (Random(0, 1, 1) ? 'Apple' : "Pear") : 'Orange') & ',$' &$i & '.00' & @CRLF Next FileWrite("Fruita.csv", $sOut) ; Create "Fruit_Orange.csv" file If FileExists("Fruit_Orange.csv") Then FileDelete("Fruit_Orange.csv") $st = TimerInit() Local $sFruitFile = FileRead("Fruita.csv") ;FileWrite("Fruit_Orange.csv", StringRegExpReplace($sFruitFile, "(.*Apple.*\R*)", "")) FileWrite("Fruit_Orange.csv", StringRegExpReplace($sFruitFile, "Food,Fruit,(?!Orange).*\R?", "")) ConsoleWrite('"Fruit_Orange.csv" generated in ' & Round(TimerDiff($st) / 1000, 3) & ' secs :- ' & @LF & FileRead("Fruit_Orange.csv") & @LF) ; Create "Fruit_Apple.csv" file If FileExists("Fruit_ApplePear.csv") Then FileDelete("Fruit_ApplePear.csv") $st2 = TimerInit() ;FileWrite("Fruit_Apple.csv", StringRegExpReplace($sFruitFile, "(.*Orange.*\R*)", "")) FileWrite("Fruit_ApplePear.csv", StringRegExpReplace($sFruitFile, "Food,Fruit,(?!Apple|Pear).*\R?", "")) ConsoleWrite("--------------" & @LF) ConsoleWrite('"Fruit_Apple.csv" generated in ' & Round(TimerDiff($st2) / 1000, 3) & ' secs :- ' & @LF & FileRead("Fruit_ApplePear.csv") & @LF) ; Cleanup files FileDelete("Fruita.csv") FileDelete("Fruit_Orange.csv") FileDelete("Fruit_ApplePear.csv")
    1 point
  13. Thank's Mat; that's what I wanted. I did search forums (with built-in and Google) for _WinApi_CreateFile("con" but didn't find any direct results) Do you have a link to Valik's example (I like to keep track of authors and seeds of origin where possible). Also, slight mod of your function to make it "all-in-one", kinda like InputBox(): ;credits to Valik & Mat #AutoIt3Wrapper_Change2CUI=y #include <WinAPI.au3> $sResponse = _ConsoleInput("Please input some text: ") ConsoleWrite("You Entered: " & $sResponse & @CRLF) Func _ConsoleInput($sPrompt) If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled ConsoleWrite($sPrompt) Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = "" Local $hFile = _WinAPI_CreateFile("CON", 2, 2) While 1 _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead) If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1) WEnd _WinAPI_CloseHandle($hFile) Return $sRet EndFunc
    1 point
×
×
  • Create New...