[v2] ComObjConnect not working

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
xroot
Posts: 6
Joined: 21 Jun 2019, 08:45

[v2] ComObjConnect not working

23 Jun 2019, 08:26

ComObjConnect not closing AHKV2 when clicking system close button X.
Escape key works fine.
It works in V1, and help docs for ComObjConnect in v1,v2 are pretty much the same.
Anyone know whats up with v2?
Thanks for any help.

Code: Select all

IE_OnQuit(){
    ExitApp
}

ie := ComObjCreate("InternetExplorer.Application")
ComObjConnect(ie,"IE_")
ie.Navigate("about:blank")
ie.Visible := true

Esc::
    ie.Quit
    ExitApp

swagfag
Posts: 2930
Joined: 11 Jan 2017, 17:59

Re: [v2] ComObjConnect not working

23 Jun 2019, 09:21

it has to do with https://www.autohotkey.com/boards/viewtopic.php?f=37&t=2120&start=40#p276644
OnQuit doesnt have any parameters, Params in

Code: Select all

PrefixEventName([Params..., ComObject])
{
    ... event-handling code ...
    return ReturnValue
}
is empty, but ahk additionally passes to the event handler ComObject, the object used in ComObjConnect(in this case ie), so when u close the iexplore, an event is fired and ahk goes looking for a function IE_OnExit which accepts 1 parameter. since no such function has been defined in ur script, nothing happens.

change it to IE_OnExit(*) if u dont care about the additional parameters

i think u should have gotten an exception though
User avatar
kczx3
Posts: 908
Joined: 06 Oct 2015, 21:39

Re: [v2] ComObjConnect not working

26 Jun 2019, 14:17

What about with a101? I have some code that is only working on v1 but not on v2-a101.

Code: Select all

#Persistent

OnExit("beforeExit")

oxl := ComObjCreate("Excel.Application")
ComObjConnect(oxl, "oXL_")
oWorkbook := oxl.Workbooks.Add()

oxl.Visible := True
oxl.WindowState := xlMaximized := -4137
return

oXL_WorkbookNewSheet(args*) {
    msgbox("new workbook")
}

beforeExit() {
    Global
    
    oxl := ""
}

; uncomment for v1
; msgbox(text) {
    ; msgbox, % text
; }
swagfag
Posts: 2930
Joined: 11 Jan 2017, 17:59

Re: [v2] ComObjConnect not working

26 Jun 2019, 14:37

idk about a101. what if u specified the arguments explicitly, no varargs?
User avatar
kczx3
Posts: 908
Joined: 06 Oct 2015, 21:39

Re: [v2] ComObjConnect not working

26 Jun 2019, 14:55

I tried this but still didn't work

Code: Select all

#Persistent

OnExit("beforeExit")

oxl := ComObjCreate("Excel.Application")
ComObjConnect(oxl, "oXL_")
oWorkbook := oxl.Workbooks.Add()

oxl.Visible := True
oxl.WindowState := xlMaximized := -4137
return

oXL_NewWorkbook(wb) {
    ; msgbox(Type(wb))
    msgbox("new workbook")
}

beforeExit() {
    Global
    
    oxl := ""
}

; uncomment for v1
; msgbox(text) {
    ; msgbox, % text
; }
User avatar
kczx3
Posts: 908
Joined: 06 Oct 2015, 21:39

Re: [v2] ComObjConnect not working

26 Jun 2019, 15:08

It also does not work on a103 even if I use the asterisk to discard surplus params.
swagfag
Posts: 2930
Joined: 11 Jan 2017, 17:59

Re: [v2] ComObjConnect not working

27 Jun 2019, 03:54

the event accepts 3 parameters: the workbook, the new sheet and the ComObjConnected comobject(in this case oxl)
i tested on a101 and a103 the signature oXL_NewWorkbook(wb, sh, comobj) but it didnt trigger.
i also tried all kinds of other combinations: 0,1,2,3,4,5 params; only varargs; varargs with some params; star; star with some params.. but none of them worked on v2
i think this is a bug, however, unrelated to star's implementation
User avatar
kczx3
Posts: 908
Joined: 06 Oct 2015, 21:39

Re: [v2] ComObjConnect not working

27 Jun 2019, 07:15

swagfag wrote:
27 Jun 2019, 03:54
i think this is a bug, however, unrelated to star's implementation
Agreed. Thanks for helping to test!
User avatar
kczx3
Posts: 908
Joined: 06 Oct 2015, 21:39

Re: [v2] ComObjConnect not working

28 Jun 2019, 10:25

Should I post a separate thread for my issue in the Bugs forum or the v2 development forum?
swagfag
Posts: 2930
Joined: 11 Jan 2017, 17:59

Re: [v2] ComObjConnect not working

28 Jun 2019, 10:32

I think it'll get more traction in bugs

Return to “AutoHotkey v2 Help”

Who is online

Users browsing this forum: Flipeador and 1 guest