COM Call Fails with Member Not Found

1

I have an application (for which I don't have control of the source), and it exposes a COM interface that works fine from VBA, for example:

Sub test()
    Set myApp = CreateObject("MyApp.Application")
    val1 = myApp.SubPart.Size
    MsgBox CStr(val1)
    myApp.SubPart.IncreaseSize
End Sub

This works perfectly. When I do the equivalent in AutoHotkey-L:

myApp := ComObjCreate("V6.Application")
val1 := myApp.SubPart.Size
MsgBox %val1%
myApp.SubPart.IncreaseSize

The message box fires, and gives me the correct value. The last line halts with an error:

0x80020003 - Member not found

Specifically: IncreaseSize

What can I do to get this to function the same in AHK?

com
autohotkey
asked on Stack Overflow May 16, 2013 by Geoff • edited Jun 20, 2020 by Community

1 Answer

1

For anyone else stuck with this, I solved it by first changing to use the 32-bit ANSI AutoHotkey executable. For me, this is at:

C:\Program Files\AutoHotkey\AutoHotkeyA32.exe

I then changed any COM method calls to be embedded into a ScriptControl call:

myApp := ComObjCreate("MyApp.Application")
val1 := myApp.SubPart.Size
MsgBox %val1%
SC := ComObjCreate("ScriptControl")
SC.Language := "VBScript"
SC.Timeout := -1 
code = 
(
    Set MyApp = CreateObject("MyApp.Application")
    MyApp.SubPart.IncreaseSize
)
sc.ExecuteStatement(code)

Of course, the Size read could be moved into the VB code block too.

answered on Stack Overflow May 16, 2013 by Geoff • edited Jun 6, 2013 by Geoff

User contributions licensed under CC BY-SA 3.0