-
Notifications
You must be signed in to change notification settings - Fork 71
/
FileCreate.ahk
22 lines (21 loc) · 957 Bytes
/
FileCreate.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
; by Drugwash 2011-2015
; AHK screws up certain bytes when saving a variable to file
; this is a replacement for AHK's built-in function FileAppend
; var is a variable (buffer) name or a buffer's address
FileCreate(name, ByRef var="", off="0", sz="")
{
Global Ptr, PtrP
;hFile := DllCall("CreateFile", "Str", name, "UInt", 0x40000000, "UInt", 0, "UInt", 0, "UInt", 2, "UInt", 0, "UInt", 0)
hFile := DllCall("CreateFile", "Str", name, "UInt", 0x40000000, "UInt", 1, "UInt", 0, "UInt", 4, "UInt", 0, "UInt", 0)
if var is integer
{
if i := DllCall("lstrlenA", Ptr, var) != j := DllCall("lstrlenW", Ptr, var)
i := j*2
DllCall("WriteFile", Ptr, hFile, Ptr, var, "UInt", (sz ? sz : i), PtrP, realLen, "UInt", 0)
}
else if (VarSetCapacity(var) <> "")
DllCall("WriteFile", Ptr, hFile, Ptr, &var+off, "UInt", (sz ? sz : VarSetCapacity(var)), PtrP, realLen, "UInt", 0)
else msgbox, blank variable!
DllCall("CloseHandle", Ptr, hFile)
return (sz==realLen)
}