Connecting multiple objects to a single COM object using ComObjConnect()

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tester
Posts: 84
Joined: 10 Jun 2021, 23:03

Connecting multiple objects to a single COM object using ComObjConnect()

Post by tester » 02 Oct 2022, 09:31

Hello,

Is it somehow possible to connect multiple AutoHotkey objects to a single COM object? When I try the below code, only the method of the second connected object is called. Besides, the message box is shown twice per event which I think is not normal.

Code: Select all

#NoEnv
#SingleInstance, Force
SendMode, Input
SetWorkingDir, %A_ScriptDir%

Gui, Add, ActiveX, w1280 h720 vWB, Shell.Explorer
Gui, Show
ComObjConnect( WB, new WB_Events1() )
ComObjConnect( WB, new WB_Events2() )
sURL := "http://www.google.com"
WB.Silent := True
WB.Navigate( sURL )
Return

class WB_Events1 {
    TitleChange(title) {
        msgbox % "first: " A_ThisFunc
    }
}
class WB_Events2 {
    TitleChange(title) {
        msgbox % "second: " A_ThisFunc
    }
}

GuiClose:
ExitApp
This is an experiment on whether it is feasible to call separate functions at the same time. My goal is to simulate multithreading among different processes using a COM object that supports events.

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Connecting multiple objects to a single COM object using ComObjConnect()

Post by safetycar » 04 Oct 2022, 12:41

Doesn't seem to be thought with that use in mind.
Possible idea for alternative:

Code: Select all

#NoEnv
#SingleInstance, Force
SendMode, Input
SetWorkingDir, %A_ScriptDir%

Gui, Add, ActiveX, w1280 h720 vWB, Shell.Explorer
Gui, Show

WB_Multiplier := new WB_Multiplier ; Using instantiation because of __call
ComObjConnect(WB, WB_Multiplier)
sURL := "http://www.autohotkey.com"
WB.Silent := True
WB.Navigate( sURL )
Return

class WB_Multiplier {
    __call(name, params*) {
        WB_Events1[name](params*)
        WB_Events2[name](params*)
    }
}
class WB_Events1 {
    TitleChange(title) {
        msgbox % "first: " A_ThisFunc
    }
}
class WB_Events2 {
    TitleChange(title) {
        msgbox % "second: " A_ThisFunc
    }
}

GuiClose:
ExitApp

tester
Posts: 84
Joined: 10 Jun 2021, 23:03

Re: Connecting multiple objects to a single COM object using ComObjConnect()

Post by tester » 05 Oct 2022, 03:18

@safetycar That's not something I'm looking for. Thanks anyway.

When replacing the msgbox lines with

Code: Select all

loop {
    ToolTip, % A_TickCount " " A_ThisFunc " " title
}
the execution flow is trapped there and the second call isn't triggered.

Although the example doesn't use child processes to simplify the code, it is assumed that each connected object (new WB_Events1() and new WB_Events2() in the example) is of a child process.

I'm wondering if it is somehow possible to call simultaneous function calls through COM that supports events.

If this is possible, we can control child processes through COM events. It appears not possible unfortunately. I'm leaning towards using window events instead.

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Connecting multiple objects to a single COM object using ComObjConnect()

Post by safetycar » 05 Oct 2022, 08:48

It's true that the way your original code duplicated calls on the same event is strange. Maybe it's a good reason to open a bug report and ask for more details about it.
I was thinking that it was simply not supported to call a sink twice, but I haven't read in the docs anything in favor or against it.

tester
Posts: 84
Joined: 10 Jun 2021, 23:03

Re: Connecting multiple objects to a single COM object using ComObjConnect()

Post by tester » 06 Oct 2022, 01:31

safetycar wrote:
05 Oct 2022, 08:48
It's true that the way your original code duplicated calls on the same event is strange.
Actually, I was careless to say that "the message box is shown twice per event" which seems incorrect. If I change the msgbox lines with msgbox % A_ThisFunc " " title, the first and second message boxes show different titles indicating they are separate events of TitleChange. With the posted example code, the total of 4 message boxes appear and the first and second appear at once and the third and fourth appear at once. The second to fourth message boxes show the same title "Google" which is confusing because it is not changed but maybe something internal like an attribute has changed.

This occurs even if calling ComObjConnect() only once so the multiple calls of ComObjConnect() has nothing to do with this behavior.

Just, double message boxes appearing at once is a bit unusual.

Post Reply

Return to “Ask for Help (v1)”