Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URLDownloadToVar(URL)
- {
- Result := ""
- hModule := DllCall("LoadLibrary", "Str", "wininet.dll")
- AccessType := Proxy != "" ? 3 : 1
- io := DllCall("wininet\InternetOpenA"
- , "Str", UserAgent
- , "UInt", AccessType
- , "Str", Proxy
- , "Str", ProxyBypass
- , "UInt", 0)
- iou := DllCall("wininet\InternetOpenUrlA"
- , "UInt", io
- , "Str", url
- , "Str", ""
- , "UInt", 0
- , "UInt", 0x80000000
- , "UInt", 0)
- If (ErrorLevel != 0 or iou = 0) {
- DllCall("FreeLibrary", "UInt", hModule)
- return "ERROR_CONNECTION"
- }
- VarSetCapacity(buffer, 10240, 0)
- VarSetCapacity(BytesRead, 4, 0)
- Loop
- {
- irf := DllCall("wininet\InternetReadFile", "UInt", iou, "UInt", &buffer, "UInt", 10240, "UInt", &BytesRead)
- VarSetCapacity(buffer, -1)
- BytesRead_ = 0
- Loop, 4
- BytesRead_ += *(&BytesRead + A_Index-1) << 8*(A_Index-1)
- If (irf = 1 and BytesRead_ = 0)
- break
- Else
- Result .= SubStr(buffer, 1, BytesRead_)
- }
- DllCall("wininet\InternetCloseHandle", "UInt", iou)
- DllCall("wininet\InternetCloseHandle", "UInt", io)
- DllCall("FreeLibrary", "UInt", hModule)
- return Result
- }
Add Comment
Please, Sign In to add comment