How to correctly launch and terminate script using ahktextdll?
Posted: 31 Oct 2018, 03:21
Hi
I am trying to use autohotkey.dll from AutoHotkey_H v1. I store the following script in an *.ahk file and run it (using the installed Autohotkey_L):It shows the tray icon with the corresponding menu items. When I click for example 'Launch Script1', it launches the code from variable vtxtScript (with the corresponding icon and menu items). Also the label 'msg' works and displays the expected message. When I click 'Exit launcher' menu item it exits (I guess, since the tray icon disappears). But when I try to launch either 'Script1', or 'Script2' afterwards, it fails, displaying this message:
---------------------------
AutoHotkey
---------------------------
Error: CONTINUABLE EXCEPTION_ACCESS_VIOLATION
Mouse and Keyboard hooks have been disabled.
- Press yes to exit thread and continue execution.
- Press no to continue thread (debug).
- Press cancel to exit application.
Exception was caused in thread id: 10176
Line: 2
LineFile: #Persistent
Menu,Tray,Icon,% StrReplace(A_Args[1],"""") "\Icons\GplusOrange.ico"
Menu,tray,add,Show some message scr1,msg
Menu,tray,add,Exit Script1,ExitScript
return
msg:
MsgBox,% "Some message scr1`nA_Args[1]=launcherDir: " A_Args[1] "`nA_Args[2]=hModule: "
---------------------------
Yes No Cancel
---------------------------
What am I doing wrong?
I am trying to use autohotkey.dll from AutoHotkey_H v1. I store the following script in an *.ahk file and run it (using the installed Autohotkey_L):
Code: Select all
;---------------- Launcher for Script1 and Script2 ----------------
#SingleInstance,Ignore
#Persistent
Menu,tray,add,Launch Script1,txtScript1
Menu,tray,add,Launch Script2,txtScript2
Menu,tray,add,Exit launcher,Exitlauncher
hModule:=DllCall("LoadLibrary","Str",AhkDllPath:=(launcherDir:=A_ScriptDir) "\dll\AutoHotkey.dll")
return
Exitlauncher:
ExitApp
;--------------- Script1 ----------------
txtScript1:
vtxtScript=
(% `
#Persistent
Menu,Tray,Icon,% StrReplace(A_Args[1],"""") "\Icons\GplusOrange.ico"
Menu,tray,add,Show some message scr1,msg
Menu,tray,add,Exit Script1,ExitScript
return
msg:
MsgBox,% "Some message scr1`nA_Args[1]=launcherDir: " A_Args[1] "`nA_Args[2]=hModule: " A_Args[2]
return
ExitScript:
MsgBox, % "Exiting Script1"
ExitApp
)
hThread1:=DllCall(AhkDllPath "\ahktextdll","Str",vtxtScript,"Str","Title Script1","Str","""" launcherDir """ " hModule,"Cdecl UPTR")
return
;--------------- Script2 ----------------
txtScript2:
vtxtScript=
(% `
#Persistent
Menu,Tray,Icon,% StrReplace(A_Args[1],"""") "\Icons\GplusOrange.ico"
Menu,tray,add,Show some message scr2,msg
Menu,tray,add,Exit Script2,ExitScript
return
msg:
MsgBox,% "Some message scr2`nA_Args[1]=launcherDir: " A_Args[1] "`nA_Args[2]=hModule: " A_Args[2]
return
ExitScript:
MsgBox, % "Exiting Script2"
ExitApp
)
hThread2:=DllCall(AhkDllPath "\ahktextdll","Str",vtxtScript,"Str","Title Script2","Str","""" launcherDir """ " hModule,"Cdecl UPTR")
return
---------------------------
AutoHotkey
---------------------------
Error: CONTINUABLE EXCEPTION_ACCESS_VIOLATION
Mouse and Keyboard hooks have been disabled.
- Press yes to exit thread and continue execution.
- Press no to continue thread (debug).
- Press cancel to exit application.
Exception was caused in thread id: 10176
Line: 2
LineFile: #Persistent
Menu,Tray,Icon,% StrReplace(A_Args[1],"""") "\Icons\GplusOrange.ico"
Menu,tray,add,Show some message scr1,msg
Menu,tray,add,Exit Script1,ExitScript
return
msg:
MsgBox,% "Some message scr1`nA_Args[1]=launcherDir: " A_Args[1] "`nA_Args[2]=hModule: "
---------------------------
Yes No Cancel
---------------------------
What am I doing wrong?