James_Chans

URLDownloadToVar

May 21st, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. URLDownloadToVar(URL)
  2. {
  3.     Result := ""
  4.     hModule := DllCall("LoadLibrary", "Str", "wininet.dll")
  5.     AccessType := Proxy != "" ? 3 : 1
  6.     io := DllCall("wininet\InternetOpenA"
  7.     , "Str", UserAgent
  8.     , "UInt", AccessType
  9.     , "Str", Proxy
  10.     , "Str", ProxyBypass
  11.     , "UInt", 0)
  12.     iou := DllCall("wininet\InternetOpenUrlA"
  13.     , "UInt", io
  14.     , "Str", url
  15.     , "Str", ""
  16.     , "UInt", 0
  17.     , "UInt", 0x80000000
  18.     , "UInt", 0)
  19.     If (ErrorLevel != 0 or iou = 0) {
  20.         DllCall("FreeLibrary", "UInt", hModule)
  21.         return "ERROR_CONNECTION"
  22.     }
  23.    
  24.     VarSetCapacity(buffer, 10240, 0)
  25.     VarSetCapacity(BytesRead, 4, 0)
  26.     Loop
  27.     {
  28.         irf := DllCall("wininet\InternetReadFile", "UInt", iou, "UInt", &buffer, "UInt", 10240, "UInt", &BytesRead)
  29.         VarSetCapacity(buffer, -1)
  30.         BytesRead_ = 0
  31.         Loop, 4
  32.         BytesRead_ += *(&BytesRead + A_Index-1) << 8*(A_Index-1)
  33.         If (irf = 1 and BytesRead_ = 0)
  34.         break
  35.         Else
  36.         Result .= SubStr(buffer, 1, BytesRead_)
  37.     }
  38.     DllCall("wininet\InternetCloseHandle", "UInt", iou)
  39.     DllCall("wininet\InternetCloseHandle", "UInt", io)
  40.     DllCall("FreeLibrary", "UInt", hModule)
  41.     return Result
  42. }
Add Comment
Please, Sign In to add comment