-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathDownloadBin.ahk
34 lines (30 loc) · 1.17 KB
/
DownloadBin.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
; Link: https://www.autohotkey.com/boards/viewtopic.php?t=44115
; Author:
; Date:
; for: AHK_L
/*
*/
; DOWNLOAD BIN DATA TO A VARIABLE
DownloadBin(url, byref buf){
static a := "AutoHotkey/" A_AhkVersion
if (!DllCall("LoadLibrary", "str", "wininet") || !(h := DllCall("wininet\InternetOpen", "str", a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr")))
return 0
c := s := 0
if (f := DllCall("wininet\InternetOpenUrl", "ptr", h, "str", url, "ptr", 0, "uint", 0, "uint", 0x80003000, "ptr", 0, "ptr"))
{
while (DllCall("wininet\InternetQueryDataAvailable", "ptr", f, "uint*", s, "uint", 0, "ptr", 0) && s > 0)
{
VarSetCapacity(b, c + s, 0)
if (c > 0)
DllCall("RtlMoveMemory", "ptr", &b, "ptr", &buf, "ptr", c)
DllCall("wininet\InternetReadFile", "ptr", f, "ptr", &b + c, "uint", s, "uint*", r)
c += r
VarSetCapacity(buf, c, 0)
if (c > 0)
DllCall("RtlMoveMemory", "ptr", &buf, "ptr", &b, "ptr", c)
}
DllCall("wininet\InternetCloseHandle", "ptr", f)
}
DllCall("wininet\InternetCloseHandle", "ptr", h)
return c
}