How to share variables between main threads and others ?

Ask for help, how to use AHK_H, etc.
LOVE HOTKEY
Posts: 2
Joined: 31 Dec 2023, 04:17

How to share variables between main threads and others ?

01 Jan 2024, 06:27

I am using thqby/AutoHotkey_H v2.1-alpha.8. I try to use dllcall funtion,but seems to not right.

Code: Select all

test1 := "test1"

newScripts :="
(
{
a::b
test2 := "test2"
}
)"

newT := NewThread(newScripts)

dllpath:=A_AhkDir "\AutoHotkey64.dll"

MsgBox DllCall(dllpath "\ahkGetVar","Str",test2,"Uint",newT)
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
image.png
image.png (145.12 KiB) Viewed 2065 times
image.png
image.png (35 KiB) Viewed 2065 times
LOVE HOTKEY
Posts: 2
Joined: 31 Dec 2023, 04:17

Re: How to share variables between main threads and others ?

01 Jan 2024, 12:03

@thqbyThank you so much!

But i still not figure out how to make them communicate correctly.

I found out if add this line "MsgBox Worker(A_MainThreadID)['myvar']", Msgbox dont work anymore.

Code: Select all

myvar := 50

Script := "
(
	Persistent(true)
	MsgBox Worker(A_MainThreadID)['myvar']
	var := 1000
)"

t := Worker(Script)

MsgBox t["var"]

Alias(var := 0, ahkGetVar('var', 1, t.ThreadID))
MsgBox(var)

Could you please show me an example about how to make variables can write a read between Main and other Threads very frequently?



[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: How to share variables between main threads and others ?

01 Jan 2024, 12:44

@LOVE HOTKEY — Please use [code][/code] tags when posting code on the forum. Thank you.
User avatar
thqby
Posts: 408
Joined: 16 Apr 2021, 11:18
Contact:

Re: How to share variables between main threads and others ?

15 Jan 2024, 06:52

MsgBox Worker(A_MainThreadID)['myvar'] interrupted script execution, and var has not been assigned.

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 101 guests