Page 1 of 1

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

Posted: 13 Apr 2019, 08:57
by swagfag
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?

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

Posted: 13 Apr 2019, 17:53
by HotKeyIt
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

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

Posted: 13 Apr 2019, 18:18
by swagfag
yes ExeThread works, as does ThreadObj. ill use that