Page 1 of 1

How to correctly launch and terminate script using ahktextdll?

Posted: 31 Oct 2018, 03:21
by SunAndSuch
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):

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
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?

Re: How to correctly launch and terminate script using ahktextdll?

Posted: 31 Oct 2018, 19:43
by HotKeyIt
There was a bug, download latest release and it should work.

Re: How to correctly launch and terminate script using ahktextdll?

Posted: 01 Nov 2018, 01:49
by SunAndSuch
Downloaded just now, but still the same problem. But I am not sure, if I'm terminating the scripts, run by ahktextdll correctly. Should I use "ExitApp", or just "Exit", or perhaps "ahkTerminate" somehow?

Re: How to correctly launch and terminate script using ahktextdll?

Posted: 01 Nov 2018, 06:19
by HotKeyIt
ExitApp is correct.
I just downloaded too and tested your script and all works fine.
1. Can you try to download and extract to separate folder
2. then create AutoHotkey.ahk in the folder Win32w
3. then run AutoHotkey.exe in the same folder.

Re: How to correctly launch and terminate script using ahktextdll?

Posted: 01 Nov 2018, 07:28
by SunAndSuch
Did as you suggested, got the same error, clicked "Cancel", another error window popped up:
---------------------------
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: 9156
Line: 3
LineFile: ?#?#ohn\Ahk\ScriptLauncher\Ahk_H with spaces\test3\ahkdll-v1-release-master\Win32w\AutoHotkey.exe
---------------------------
Yes No Cancel
---------------------------

Re: How to correctly launch and terminate script using ahktextdll?

Posted: 01 Nov 2018, 09:13
by HotKeyIt
Are you on Win10 64-bit?

Re: How to correctly launch and terminate script using ahktextdll?

Posted: 01 Nov 2018, 10:05
by SunAndSuch
Nope. Windows 7, 64-bit.

Re: How to correctly launch and terminate script using ahktextdll?

Posted: 01 Nov 2018, 12:13
by HotKeyIt
That should be fixed now ;)