[AHK_H v2] problem with Single/Multi Thread Apartment? Topic is solved

Ask for help, how to use AHK_H, etc.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

[AHK_H v2] problem with Single/Multi Thread Apartment?

13 Apr 2019, 08:57

hi, i have this script which opens internet explorer in a thread. i want to have the thread's OnExit routine auto-close the internet explorer, but that isnt working:

Code: Select all

T := AhkThread("
(
	#Persistent
	#NoTrayIcon

	IE := ComObjCreate("InternetExplorer.Application")
	IE.Visible := true
	IE.Navigate("www.google.com")

	OnExit(() => IE.Quit())
)")

Esc::
	T.AhkTerminate()
	ExitApp()
Return
the error
this guy says u can only postmessage to it, which does work, but requires gymnastics:

Code: Select all

T := AhkThread("
(
	#Persistent
	#NoTrayIcon

	IE := ComObjCreate("InternetExplorer.Application")
	IE.Visible := true
	IE.Navigate("www.google.com")

	terminate() {
		global IE
		IE.Quit()
		ExitApp
	}
)")

Esc::
	terminate(T)
	ExitApp()
Return

terminate(ByRef T) {
	T.AhkPostFunction("terminate")
	T := ""
}
is there a way to get the onexit thing to work too?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [AHK_H v2] problem with Single/Multi Thread Apartment?  Topic is solved

13 Apr 2019, 17:53

Seems to work fine with ExeThread, Com/SendMessage does not work with dll: (

Code: Select all

T := ExeThread("
(
	#Persistent
	#NoTrayIcon

	IE := ComObjCreate("InternetExplorer.Application")
	IE.Visible := true
	IE.Navigate("www.google.com")

	OnExit(() => IE.Quit())
)")

Esc::
	ExitApp()
Return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [AHK_H v2] problem with Single/Multi Thread Apartment?

13 Apr 2019, 18:18

yes ExeThread works, as does ThreadObj. ill use that

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 4 guests