How to correctly launch and terminate script using ahktextdll?

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
SunAndSuch
Posts: 46
Joined: 05 Oct 2015, 12:11

How to correctly launch and terminate script using ahktextdll?

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):

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?
Windows 10, Ahk v1 x64-bit.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

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

31 Oct 2018, 19:43

There was a bug, download latest release and it should work.
SunAndSuch
Posts: 46
Joined: 05 Oct 2015, 12:11

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

01 Nov 2018, 01:49

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?
Windows 10, Ahk v1 x64-bit.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

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

01 Nov 2018, 06:19

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.
SunAndSuch
Posts: 46
Joined: 05 Oct 2015, 12:11

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

01 Nov 2018, 07:28

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
---------------------------
Windows 10, Ahk v1 x64-bit.
SunAndSuch
Posts: 46
Joined: 05 Oct 2015, 12:11

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

01 Nov 2018, 10:05

Nope. Windows 7, 64-bit.
Windows 10, Ahk v1 x64-bit.

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 20 guests