-
Notifications
You must be signed in to change notification settings - Fork 72
/
AhkDllThread (2).ahk
145 lines (142 loc) · 4.87 KB
/
AhkDllThread (2).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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
AhkDllThread(dll="AutoHotkey.dll",obj=0){
static
local v,v1,v2
static init, DynaCall:="DynaCall", MemoryLoadLibrary:="MemoryLoadLibrary",MemoryFreeLibrary:="MemoryFreeLibrary"
,ResourceLoadLibrary:="ResourceLoadLibrary", MemoryGetProcAddress:="MemoryGetProcAddress"
static functions ="
(Join
ahkKey:s|ahkFunction:s=sssssssssss|ahkPostFunction:i=sssssssssss|
ahkdll:ui=sss|ahktextdll:ui=sss|ahkReady:|ahkReload:ui=|
ahkTerminate:i|addFile:ui=sucuc|addScript:ui=si|ahkExec:ui=s|
ahkassign:ui=ss|ahkExecuteLine:ui=uiuiui|ahkFindFunc:ui=s|
ahkFindLabel:ui=s|ahkgetvar:s=sui|ahkLabel:ui=sui|ahkPause:s
)"
static AhkDllThreadfunc ="
(Join`r`n
#Persistent
#NoTrayIcon
Return
AhkDllThread(dll=""AutoHotkey.dll"",obj=0,map=""""){
static
local v,v1,v2
static functions = ""ahkKey:s|ahkFunction:s=sssssssssss|ahkPostFunction:i=sssssssssss|""
. ""ahkdll:ui=sss|ahktextdll:ui=sss|ahkReady:|ahkReload:ui=|""
. ""ahkTerminate:i|addFile:ui=sucuc|addScript:ui=si|ahkExec:ui=s|""
. ""ahkassign:ui=ss|ahkExecuteLine:ui=uiuiui|ahkFindFunc:ui=s|""
. ""ahkFindLabel:ui=s|ahkgetvar:s=sui|ahkLabel:ui=sui|ahkPause:s""
If !dll {
Loop `% i
{
idx:=A_Index
`%MemoryFreeLibrary`%(dllmodule`%A_Index`%)
obj`%A_Index`%:="""",dll`%A_Index`%:="""",dllmodule`%A_Index`%:=""""
}
i=0
return
} else if (!FileExist(dll)){
MsgBox File: `%dll`% does not exist`, provide correct path for AutoHotkey.dll
ExitApp
}
i++
dllmodule`%i`%:= MemoryLoadLibrary(dll)
if IsObject(obj)
object:=obj
else
object := Object()
object[""""]:=dllmodule`%i`%
Loop,Parse,functions,|
{
StringSplit,v,A_LoopField,:
object[map="""" ? v1 : !InStr(map,v1) ? v1 : SubStr(map,InStr(map,v1)+StrLen(v1)+1,InStr(map,A_Space,0,InStr(map,v1)))]:=DynaCall(MemoryGetProcAddress(dllmodule`%i`%,v1),v2)
}
obj`%i`%:=object
dll`%i`%:=dll
return &obj`%i`%
}
)"
If !(dll){
If !AHK_H{
return DllCall(dll "\ahkFunction","Str","AhkDllThread","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str")
}
Loop % i
{
idx:=A_Index
%MemoryFreeLibrary%(dllmodule%A_Index%)
obj%A_Index%:="",dll%A_Index%:="",dllmodule%A_Index%:=""
}
i=0
return
} else if (!FileExist(dll) && !A_IsCompiled){
MsgBox File: %dll%`ndoes not exist`, provide correct path for AutoHotkey.dll
ExitApp
}
If !AHK_H{
If (init || init:=DllCall("LoadLibrary","Str",dll)){
If DllCall(dll "\ahktextdll","Str",AhkDllThreadfunc,"Str","","Str","","Cdecl UInt")
Return Object(0+DllCall(dll "\ahkFunction","Str","AhkDllThread","Str",dll,"Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str"))
else
Return 0,ErrorLevel:="Could not load AutoHotkey.dll"
} else {
MsgBox Could not load %dll%
Return 0
}
}
i++
dllmodule%i%:=A_IsCompiled ? %ResourceLoadLibrary%(dll) : %MemoryLoadLibrary%(dll)
if IsObject(obj)
object:=obj
else
object := Object()
object[""]:=dllmodule%i%
Loop,Parse,functions,|
{
StringSplit,v,A_LoopField,:
object[map="" ? v1 : !InStr(map,v1) ? v1 : SubStr(map,InStr(map,v1)+StrLen(v1)+1,InStr(map,A_Space,0,InStr(map,v1)))]:=%DynaCall%(%MemoryGetProcAddress%(dllmodule%i%,v1),v2)
}
obj%i%:=object
dll%i%:=dll
return obj%i%
}
/*
AhkDllThread(dll=""){
static
static ResourceLoadLibrary:="ResourceLoadLibrary"
static functions:="ahkdll|ahktextdll|ahkReady|ahkReload|ahkTerminate|addFile|addScript|assign|ahkExecuteLine|ahkFindFunc|ahkFindLabel|ahkgetvar|ahkLabel|ahkPause"
If !(dll){
Loop % i
{
idx:=A_Index
Loop,Parse,functions,|
DynaCall(dll%idx% . "\" . A_LoopField)
MemoryFreeLibrary(dllmodule%A_Index%)
obj%A_Index%=
dll%A_Index%=
dllmodule%A_Index%=
}
i=0
return
}
i++
dllmodule%i%:=A_IsCompiled ? %ResourceLoadLibrary%(dll) : MemoryLoadLibrary(dll)
object := Object()
Loop,Parse,functions,|
object[A_LoopField]:=MemoryGetProcAddress(dllmodule%i%,A_LoopField)
DynaCall(object.ahkdll,"Str","","Str","","Str","","CDecl UInt")
DynaCall(object.ahktextdll,"Str","","Str","","Str","","CDecl UInt")
DynaCall(object.ahkReady,"Cdecl Int")
DynaCall(object.ahkReload,"Cdecl Int")
DynaCall(object.ahkTerminate,"Int",0,"Cdecl Int")
DynaCall(object.addFile,"Str","","uchar",0,"uchar",0,"CDecl UInt")
DynaCall(object.addScript,"Str","","Int",0,"Int",0,"CDecl UInt")
DynaCall(object.ahkassign,"Str","","Str","")
DynaCall(object.ahkExecuteLine,"UInt",0,"UInt",0,"UInt",0,"CDecl UInt")
DynaCall(object.ahkFindFunc,"Str","","CDecl UInt")
DynaCall(object.ahkFunction,"Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str")
DynaCall(object.ahkPostFunction,"Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str")
DynaCall(object.ahkgetvar,"Str","","UInt",0,"CDecl Str")
DynaCall(object.ahkLabel,"Str","","CDecl UInt")
DynaCall(object.ahkPause,"Str","")
obj%i%:=object
dll%i%:=dll
return obj%i%
}