ComObjConnect - Example

Share your ideas as to how the documentation can be improved.
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

ComObjConnect - Example

10 Jun 2022, 03:08

https://lexikos.github.io/v2/docs/commands/ComObjConnect.htm#Examples

crashes with:

Code: Select all

---------------------------
ComObjConnect - Example.ahk
---------------------------
Error:  Expected a String but got a VarRef.

	Line#
	011: s := ""
	012: If (ie != ieEventParam)
	013: s .= "First parameter is a new wrapper object."
	014: If (ie == ieFinalParam)
	015: s .= "Final parameter is the original wrapper object."
	016: If (ComObjValue(ieEventParam) == ComObjValue(ieFinalParam))
	017: s .= "Both wrapper objects refer to the same IDispatch instance."
--->	018: MsgBox(s . "Finished loading " ie.Document.title " @ " url)
	019: ie.Quit()
	020: ExitApp()
	021: }
	022: Exit

The current thread will exit.
---------------------------
OK   
---------------------------
AutoHotkey_2.0-beta.4 x64
Windows 11 21H2 (Build 22000.675)




OT:
If I run this example as nested function, the PrefixEventName functions will not be called (without any hint). Is this desired?
Spoiler
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
lexikos
Posts: 9665
Joined: 30 Sep 2013, 04:07
Contact:

Re: ComObjConnect - Example

10 Jun 2022, 03:45

The so-called "crash" is because the parameter is passed as VT_BYREF, which translates to VarRef. The MS documentation just says it is "A pointer to a Variant structure of type String".

A minimal fix would be to declare the parameter as &url.

OT:
Suppose that you were to implement something similar. How would you create a function that can take a prefix, and call any arbitrary nested function of some other function that called you? It's not possible. Nested functions are local. They are not accessible to other functions.

However, built-in functions don't follow the rules. ComObjConnect naively searches for a function with default variable lookup rules, equivalent to a double-deref. COM events do not launch new threads, therefore it will look up a variable in whatever function happens to be running when the event is raised. It would work if you waited for the event to be raised before returning. (This will probably only apply to v2.0-beta.4 and earlier.)

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 6 guests