Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/12/2023 in all areas

  1. Danp2

    DllCall to GetFileSize

    @taylansanWhat's your obsession with using DLLCall? Also, how to do you that FileGetSize isn't calling the same API behind the scenes? Example 3 isn't valid because you can't use a file handle with FileGetSize Examples 4 & 5 will work if adjust as follows -- ;Example 4 $hFile = _WinAPI_CreateFile(@AutoItExe, 2, 2, 2) ;### Debug CONSOLE ↓↓↓ ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hFile = ' & $hFile & @CRLF & '>Error code: ' & @error & @CRLF) $iFileSize = 0 $iFileSize = _WinAPI_GetFileSizeEx($hFile) ConsoleWrite("Example 4: " & $iFileSize & @CRLF) ;Example 5 $iFileSize = 0 Local $aCall = DllCall("kernel32.dll", "bool", "GetFileSizeEx", "handle", $hFile, "int64*", 0) ConsoleWrite("Example 5: " & $aCall[2] & @CRLF) _WinAPI_CloseHandle($hFile)
    2 points
  2. Yes, for now I am happy 😁
    1 point
  3. Well... the directive's name is a sort of give-away: #AutoIt3Wrapper_ Which mean AutoIt3Wrapper.au3 is required to be used as the shell around Run/Compile! ... and Autoit3Wrapper come with the Full SciTE4AutoIt3 installer. That is why this isn;t mentioned in the AutoIt3 helpfile where #Pragma is.
    1 point
  4. Have a look at _GUICtrlRichEdit_InsertText and the example.
    1 point
  5. Jos

    Get HTML Page

    @All ... It was correct what @SOLVE-SMARTstated, but I have removed the links and am waiting for the OP to reply. Jos
    1 point
  6. Danp2

    Get HTML Page

    Hi @SOLVE-SMARTI suspect that "website.com" isn't the real URL. I imagine he has simply used that to avoid disclosing the actual site for privacy. FWIW, I get a HTTP 403 page when I try that link. @major4579Have you tried using InetGet()?
    1 point
  7. Trong

    DllCall to GetFileSize

    Might be superfluous, but I can add a WINAPI function that checks the size with a single Function: Global $iFileSize, $iFilePath = @AutoItExe ; "C:\Program Files (x86)\AutoIt3\autoit3.exe" ConsoleWrite(">File to Check: " & $iFilePath & " | FileExists=" & FileExists($iFilePath) & " " & @CRLF) ;Example 1 = Built-in functions $iFileSize = FileGetSize($iFilePath) ConsoleWrite("+ FileSize: " & $iFileSize & @CRLF) ;Example 2 = WinAPI DllCall $iFileSize = _WinAPI_GetFileSize($iFilePath) ConsoleWrite("- FileSize: " & $iFileSize & @CRLF) Func _WinAPI_GetFileSize($sFileNameOrHandle) Local $hFile = 0, $aCall = 0 If VarGetType($sFileNameOrHandle) = 'Ptr' And (Not FileExists($sFileNameOrHandle)) Then $hFile = $sFileNameOrHandle Else Local Const $iOpenExist = 3, $iShareRead = 0x00000001, $iAccessRead = 0x80000000, $iAttributes = 0, $tSecurity = 0 $aCall = DllCall("kernel32.dll", "handle", "CreateFileW", "wstr", $sFileNameOrHandle, "dword", $iAccessRead, "dword", $iShareRead, "struct*", $tSecurity, "dword", $iOpenExist, "dword", $iAttributes, "ptr", 0) If @error Or ($aCall[0] = Ptr(-1)) Then Return SetError(1, @extended, 0) $hFile = $aCall[0] EndIf $aCall = DllCall("kernel32.dll", "bool", "GetFileSizeEx", "handle", $hFile, "int64*", 0) If @error Or Not $aCall[0] Then Return SetError(2, @extended, 0) Return $aCall[2] EndFunc ;==>_WinAPI_GetFileSize
    1 point
  8. @taylansan If you read carefully @Danp2 last script, then you should have the answers to your 3 questions. By using the _WinAPI_CreateFile function that returns the correct handle. If you look carefully, I also created a new file only in Script 1, but not in script 2, where I wrote just before the script : 2nd script, with an already existing file on disk (your case) By the way, it's not because the function is called _WinAPI_CreateFile that it always creates a new file. I know it sounds strange but this function works also with existing files stored on disk. Maybe Microsoft could have given a better name to the function, avoiding the word "Create" in it. Look at the explanations found on msdn : CreateFile function : Creates OR opens a file or I/O device [...] Danp2 answered to that concerning your example 3, in his own words : "you can't use a file handle with FileGetSize" . Always look carefully at the help file to make sure when you need a file string name, or a file handle Yes you do need to open it but don't be scared of this, because _WinAPI_CreateFile opens it immediately, even if it's several GB. Danp2 answered to that, in his own words : "Also, how do you know that FileGetSize isn't calling the same API behind the scenes?" (e.g. CreateFile) Now let's go back to my last post (the "Edit post") where I asked at the end : I just did interesting tests concerning the _WinAPI_GetFileSize (using my Script #2 found in a post above) and the results are crystal clear. First the resulting pic : As you can see, the assumption was correct : $aRet[2] must be checked in case the file size is >= 4GB If you don't check it, then you'll have correct results for a file whose size is < 4GB - 2 bytes, but as soon as a file size is >= 4GB, then $aRet[2] is required to retrieve the high-order Dword (remember it was scripted dword* with a star, e.g. to retrieve in the resulting array a value returned by the system. Without the star it won't have retrieved anything and $aRet[2] would have been = 0 in all pics !) In 3 out of 4 pics, $aRet[2] = 1 means that 4GB need to be added to $aRet[0] . If $aRet[2] was equal to 2, then 8GB would have needed to be added to $aRet[0] (which contains bytes), so the calculation of an accurate result isn't that hard to do. I won't do it here and keep the precedent script #2 "as-is" because of all explanations that followed the post, also because noone should use this non AutoIt _WinAPI_GetFileSize function when there are better, easier and safer ways to retrieve a file size. But it was interesting to dig in it and understand better how the function works. Thanks to you for creating the thread ! For the record, to create all these big files in a snap, I typed fsutil at the command prompt... but that's another story
    1 point
  9. @Danp2 Yeah, FileGetSize will get the file size. But I want to use DllCall to get the size. So, maybe we can try _WinAPI_GetFileSizeEx @pixelsearch In the help documentation, you are creating a new file to be used in _WinAPI_GetFileSizeEx. Let's say, I want to get the size of "autoit3.exe" which is around 900kb. This is stored (in my computer) in "C:\Program Files (x86)\AutoIt3\autoit3.exe" and we have a shortcut to reach this easily: @AutoItExe So, I tried this: 1 + 2 is working as expected because they are using FileGetSize. But I wanted to make it work for 3 + 4 + 5. So, I tried several random options: #include <WinAPIFiles.au3> ;Example 1 = OK Local $iFileSize = FileGetSize(@AutoItExe) ConsoleWrite("Example 1: " & $iFileSize & @CRLF) ;Example 2 = OK $iFileSize = 0 $iFileSize = FileGetSize("C:\Program Files (x86)\AutoIt3\autoit3.exe") ConsoleWrite("Example 2: " & $iFileSize & @CRLF) ;Example 3 = NOT OK Local $hFile = FileOpen(@AutoItExe) ;OR Local $hFile = FileOpen("C:\Program Files (x86)\AutoIt3\autoit3.exe") $iFileSize = 0 $iFileSize = FileGetSize($hFile) ConsoleWrite("Example 3: " & $iFileSize & @CRLF) ;Example 4 = NOT OK $iFileSize = 0 $iFileSize = _WinAPI_GetFileSizeEx($hFile) ConsoleWrite("Example 4: " & $iFileSize & @CRLF) ;Example 5 = NOT OK $iFileSize = 0 Local $aCall = DllCall("kernel32.dll", "bool", "GetFileSizeEx", "handle", $hFile, "int64*", 0) ConsoleWrite("Example 5: " & $aCall[2] & @CRLF) FileClose($hFile) My output is as the following: Example 1: 946776 Example 2: 946776 Example 3: 0 Example 4: -1 Example 5: 0 So, I think I couldn't send handle $hFile correctly. So: How can I send "C:\Program Files (x86)\AutoIt3\autoit3.exe" or @AutoItExe as the correct handle? I used FileOpen() to get the handle, is this the place where I did wrong? Should I use a different function to open and get the file? Which one is it? What if the file I'm looking for is a big file, like few GB? Do I still need to open them to assign as a handle? Because FileGetSize() doesn't use a handle. Please note the same as before; the goal for me is to use the DllCall function, not to get the file size by using FileGetSize().
    1 point
  10. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _vf_ArrayToSqlStatement ; Description ...: ; Syntax ........: _vf_ArrayToSqlStatement($array, $tablename) ; Parameters ....: $array - an 2d array with header in first row to make insert command ; $tablename - Table Name of Already Created Table(Insert into <$tablename>) ; Return values .: A String Containing insert Command(Insert into ) ; Author ........: Vinit ; Modified ......: 01/01/2023 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _vf_ArrayToSqlStatement($array, $tablename) $statement = "INSERT INTO `" & $tablename & "` "&@CRLF&"(" $header = _ArrayExtract($array, 0, 0) _ArrayTranspose($header) $headercount = UBound($header) - 1 For $i = 0 To $headercount If $i <> 0 Then $statement &= ', ' EndIf $statement &= "`" & ($header[$i][0]) & "`" Next $statement &= ") values " & @CRLF _ArrayDelete($array, 0) $rows = UBound($array) - 1 $cols = UBound($array, 2) - 1 $cols1 = $cols + 1 For $r = 0 To $rows For $c = 0 To $cols If $c = UBound($array, 2) Then $statement &= '' ElseIf $c <> 0 Then $statement &= ', ' Else $statement &= '(' EndIf If $array[$r][$c] = Null Then $statement &= "'" & "'" Else If IsBool($array[$r][$c]) Then ;~ MsgBox(0, 0, 0) If $array[$r][$c] = True Then $array[$r][$c] = 'True' Else $array[$r][$c] = 'False' EndIf EndIf If IsBinary($array[$r][$c]) Then $array[$r][$c] = _SQLite_FastEncode($array[$r][$c]) EndIf $statement &= "" & _SQLite_FastEscape($array[$r][$c]) & "" EndIf Next If $r <> $rows Then $statement &= '),' Else $statement &= ');' EndIf $statement &= @CRLF Next Return $statement EndFunc ;==>_vf_ArrayToSqlStatement Updated Code @jchd Please Check once Also I Couldn't Figure out What to do with default Variable as Attached also will update with column names as default thing in next update
    1 point
  11. bdr529

    PDF or PDF/A file? - (Moved)

    #include <String.au3> msgbox("","",check_pdfa("AutoIt_Featured_640x480.pdf")) func check_pdfa($file_init_pdf) dim $fileopen=fileopen($file_init_pdf,16) dim $fileread=BinaryToString(FileRead ($fileopen)) fileclose($fileopen) dim $versione_pdf=stringmid($fileread,2,7) dim $_StringBetween_part=_StringBetween($fileread,"pdfaid:part='","'") dim $_StringBetween_conformance=_StringBetween($fileread,"pdfaid:conformance='","'") if not isarray($_StringBetween_part) or not isarray($_StringBetween_conformance) then $_StringBetween_part=_StringBetween($fileread,'pdfaid:part="','"') $_StringBetween_conformance=_StringBetween($fileread,'pdfaid:conformance="','"') endif if not isarray($_StringBetween_part) or not isarray($_StringBetween_conformance) then $_StringBetween_part=_StringBetween($fileread,"pdfaid:part>","<") $_StringBetween_conformance=_StringBetween($fileread,"pdfaid:conformance>","<") endif if isarray($_StringBetween_part) and isarray($_StringBetween_conformance) and ($_StringBetween_part[0]="1" or $_StringBetween_part[0]="2" or $_StringBetween_part[0]="3") and _ ($_StringBetween_conformance[0]="a" or $_StringBetween_conformance[0]="b" or $_StringBetween_conformance[0]="u") Then if $_StringBetween_part[0]&$_StringBetween_conformance[0]<>"1u" then return seterror(0,0,$versione_pdf&" PDF/A-"&$_StringBetween_part[0]&$_StringBetween_conformance[0]) Else return seterror(2,0,$versione_pdf) endif Else return seterror(1,0,$versione_pdf) endif EndFunc AutoIt_Featured_640x480.pdf
    1 point
  12. qwert, change this part in BinaryCall If $HasMemoryDll Then Local $Module = Execute('__MemoryModule_ModuleRecord("get", Null, $DllName)') If $Module Then Local $MemoryGetProcAddress = Execute('__MemoryModule_RuntimeLoader("MemoryGetProcAddress")') If $MemoryGetProcAddress Then $Proc = DllCallAddress("ptr:cdecl", $MemoryGetProcAddress, "ptr", $Module, "str", $ProcName)[0] If Not $Proc Then Return SetError(2, _BinaryCall_LastError("MemoryGetProcAddress failed on " & $ProcName), False) EndIf EndIf
    1 point
×
×
  • Create New...