[AHK_L v1] working with an included autohotkey.dll Topic is solved

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

[AHK_L v1] working with an included autohotkey.dll

26 Dec 2018, 08:38

i want to pass a mathematical expression to a new thread, have it evaluate it, then retrieve the result in my main script. however, i want to do this in a ahk_l v1 script by including ahk.dll and using its exported functions. is this possible? also how do u manage threads started this way(start, pause, stop, kill etc)?

Code: Select all

hModule := DllCall("LoadLibrary", "Str", "AutoHotkey.dll")

DllCall("AutoHotkey.dll\ahktextdll", "Str", "", "Str", "")

math := "5 + 5"
DllCall("AutoHotkey.dll\ahkExec", "Str", "MsgBox `% result := " math) ; this shows '10' from ahkExec as expected

result := DllCall("AutoHotkey\ahkgetvar", "Str", "result", "UInt", 0)
MsgBox % result ; returns an address, presumably
MsgBox % *result ; returns 49 (???)

DllCall("FreeLibrary", "Ptr", hModule)
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [AHK_L v1] working with an included autohotkey.dll

26 Dec 2018, 09:08

See available exported functions here: http://hotkeyit.github.io/v2/docs/AutoHotkeyDll.htm
It must be a string: result := DllCall("AutoHotkey\ahkgetvar", "Str", "result", "UInt", 0, "CDecl Str")
Also if you want to start a thread that waits for action you need #Persistent: DllCall("AutoHotkey.dll\ahktextdll", "Str", "#Persistent", "Str", "", "Str", "")
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [AHK_L v1] working with an included autohotkey.dll

26 Dec 2018, 09:22

ah i see i was missing the return type in the dllcall. cool it works now:

Code: Select all

hModule := DllCall("LoadLibrary", "Str", "AutoHotkey.dll")

hThread := DllCall("AutoHotkey.dll\ahktextdll")

math := "5 + 5"
DllCall("AutoHotkey.dll\ahkExec", "Str", "MsgBox `% ""from thread: "" result := " math) ; this shows '10' from ahkExec as expected

result := DllCall("AutoHotkey\ahkgetvar", "Str", "result", "UInt", 0, "CDecl Str")
MsgBox % "from main: " result ; returns correctly now, as str

DllCall("FreeLibrary", "Ptr", hModule)
ahktextdll should be creating a script with #Persistent by default, if it wasnt supplied any parameters

next question: now that ahkgetvar is done executing, what happens with this second script thread that was started. i want to terminate it and keep working with my main script. how?
ahktextdll returns a ptr to the created thread, but what do i do with it?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [AHK_L v1] working with an included autohotkey.dll

26 Dec 2018, 11:32

You are right, forgot already about #Persistent ;)
Script keeps working, you can add new script or run a function, label, hotkey or ahkTerminate it.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [AHK_L v1] working with an included autohotkey.dll

26 Dec 2018, 12:31

i couldnt get it to work:

Code: Select all

hModule := DllCall("LoadLibrary", "Str", "AutoHotkey.dll")

hTickCount := DllCall("AutoHotkey.dll\ahktextdll") ; start new thread that will display A_TickCount updates
DllCall("AutoHotkey.dll\ahkExec", "Str", "
(LTrim %
	Loop
	{
		ToolTip % A_TickCount
		Sleep 100
	}
)")

hNow := DllCall("AutoHotkey.dll\ahktextdll") ; start a second new thread that will display A_Now updates
DllCall("AutoHotkey.dll\ahkExec", "Str", "
(LTrim %
	Loop
	{
		ToolTip % A_Now
		Sleep 100
	}
)")

 ; what is this supposed to do anyways
; 'function that exits script currently executed by AutoHotkey module.'
; kill whichever thread is currently running?
; what if i have multiple? do i have to call terminate in a loop until theyre all gone?
; what if i want to just kill a specific thread?
q::DllCall("AutoHotkey\ahkTerminate", "Int", 500)

w::
	DllCall("FreeLibrary", "Ptr", hModule)
	ExitApp
Return
so, thread 1 starts, the Loop begins updating A_TickCount and stays stuck that way. i was expecting 2 tooltips to show up. the 2nd thread is never even reached(?). furthermore, i dont think the hotkeys in the main script do anything at all either. its like the script gets stuck in the first loop, all single-threaded-like. whats going on?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [AHK_L v1] working with an included autohotkey.dll  Topic is solved

26 Dec 2018, 12:49

For each thread you will need another AutoHotkey.dll, simply copy+rename it to AutoHotkey2.dll or similar.
In AutoHotkey_H using AhkThread you would not have to do that or even need an AutoHotkey.dll because it is included.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [AHK_L v1] working with an included autohotkey.dll

26 Dec 2018, 13:00

ahh yes i see how that would make sense.
yeah, ure right about ahk_h, but this was an exercise in using the .dll in v1 _l scripts.
all is cleared up, thanks

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 15 guests