ObjRegisterActive

Post your working scripts, libraries and tools
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ObjRegisterActive

27 Oct 2017, 20:22

Your object would need to implement the IConnectionPointContainer and IConnectionPoint interfaces. In order to do that, you would need to construct the object yourself, including an IUnknown interface implementation which can be queried for those interfaces. You could not simply pass an AutoHotkey object to the client.
User avatar
nnnik
Posts: 4480
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: ObjRegisterActive

27 Jan 2018, 18:06

It seems I never said anything.
I'm very greatful to you for this function. It has been used in several projects of mine and really makes coding more powerful.
Recommends AHK Studio
A_User
Posts: 36
Joined: 21 Aug 2017, 01:15

Re: ObjRegisterActive

27 Mar 2018, 14:33

(Sorry for the previous post which I deleted as it had no useful information)

It seems the code below causes memory leaks. I'm guessing ObjRegisterActive() or ComObjActive() is something to do with it.

Main.ahk

Code: Select all

#SingleInstance, Force

loop {
    testMemoryLeak()
}
Return

~Esc::ExitApp

testMemoryLeak() {
    
    _sGUID         := CreateGUID()
    _o := new TestObjRegisterActive
    ObjRegisterActive( _o, _sGUID )

    _sPath         := A_ScriptDir "\Remote.ahk"
    Run, "%A_AhkPath%" "%_sPath%" %_sGUID%,, UseErrorLevel, _iPID    
    
    ; Wait for the remote script to be activated
    while ! _o.oRemote {
        sleep 10
    }
    
    ; ( doing something in an actual script )
    
    ; Done with the remote script
    _o.oRemote.exit()
    
    ObjRegisterActive( _o, "" )
    return _iPID
    
}

class TestObjRegisterActive {
    
    oRemote := ""
    
    __New() {
        this.TickCount := A_TickCount
    }
    
    activate( sRemoteGUID ) {    
        this.oRemote := ComObjActive( sRemoteGUID )
        tooltip % "(From Main) Actiavted: " sRemoteGUID
    }
        
}
Remote.ahk

Code: Select all

#Persistent 
#SingleInstance, Off

_sMainGUID       := %0% ; script argument

_oMain           := ComObjActive( _sMainGUID )

_oRemote         := new Remote
_sRemoteGUID     := CreateGUID()
ObjRegisterActive( _oRemote, _sRemoteGUID )

_oMain.activate( _sRemoteGUID )

ObjRegisterActive( _oRemote, "" )

tooltip % "From Remote: " _oMain.TickCount

Return
~Esc::ExitApp

class Remote {
    
    exit() {
        _func := ObjBindMethod( this, "_exitApp" )
        SetTimer, % _func, -1
    }
        _exitApp() {
            ExitApp
        }
    
}
Tested with: AutoHotkey v1.1.28.00, Windows 7 64bit
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Re: ObjRegisterActive

28 Mar 2018, 03:52

lexicos wrote:
min wrote:Does using ObjRegisterActive mean that now we can write AHK apps which can be controlled by COM by other programs written in other languages?
Yes. It's easy to do from VBScript. However, it seems GetObject() requires a ProgID rather than a CLSID, so you need to register it in the registry.

Code: Select all

' First set HKCR\testy\CLSID (default value) to the GUID
set x = GetObject(,"testy")
x.Message("Hello, world!")

Apparrently according to this site:

http://web.archive.org/web/200210011332 ... /index.asp

You can also use:

Code: Select all

Set o = GetObject(, "clsid:5c172d3c-c8bf-47b0-80a4-a455420a6911")
A full example can be found here

Code: Select all

Sub CreateGorillaAndEatBanana()
  Dim gc as IApeClass
  Dim ape as IApe
  Dim sz as String
  sz = "clsid:571F1680-CC83-11d0-8C48-0080C73925BA:"
' get the class object for gorillas
  Set gc = GetObject(sz)
' ask gorilla class object to create a new gorilla
  Set ape = gc.CreateApe()
' ask gorilla to eat a banana
  ape.EatBanana
End Sub
I've had no luck with either using CLSID or PROGID sadly (in vba), I just receive "Runtime error 429 - ActiveX component can't create object", which seems a bit odd, but perhaps it's due to IT policy or something **shrug**
User avatar
hasantr
Posts: 748
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: ObjRegisterActive

11 Nov 2020, 13:14

If the object does not respond, the crash screen of windows appears. But instead of that screen, can I request the called script file to close automatically? I don't want to see the windows crash message because with my main script I can see that the object is still not healthy and restart it.

I'm talking about this kind of crash.
Image

My goal is to create an isolated process against crashes. Even if there is a crash, the user can continue the process from where it left off without realizing it. The main script will create the object again.

I managed to solve it in a different way.
Last edited by hasantr on 29 Nov 2020, 19:23, edited 1 time in total.
User avatar
hasantr
Posts: 748
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: ObjRegisterActive

29 Nov 2020, 19:22

I wonder if anyone knows how to use it with Python? Or is it already impossible?
KiddoV
Posts: 9
Joined: 11 May 2020, 20:29

Re: ObjRegisterActive

14 Jan 2021, 08:18

Very nice function, but it doesn't work with Class_SQlite object and Neutron object with NeutronObj.wnd.function() even though, they are all ahk object. Any idea why?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: CyberKlabauter, garry, nichatr, Perlence, Steuerfachwissen and 21 guests