Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get object of an already running instance

Status
Not open for further replies.

rdgerken

Technical User
Jul 8, 2002
108
Can anyone elaborate on how to access the object model of an already running instance of an application? I found this old archived thread, but I need some more information to make this happen. thread222-946494

Basically I have a non-microsoft program that supports VBA. Normally, you start the application from a VB application and you have access to all of it's properties and methods and what not. What I'm trying to do is get access to all those properties and methods by hooking into an already running instance of the aforementioned application. It seems to be fairly easy to do with products like Excel and Word, using the GetObject method - but that just returns a "method not supported" error or something when I try to substitute in that code.

Thanks in advance!
 
Here's a little more info...

When I run this code that I found on MSDN:

Code:
Dim oTmpObject As TellerAPP.Application

Sub Command1_Click()
      Dim fResult As Integer
      fResult = SmartGetObject("TellerAPP.Application")
End Sub
                        
Function SmartGetObject(sClass As String) As Integer
    ' If Server running, oTmpObject refers to that instance.
    ' If Server not running Error 429 is generated.
    On Error Resume Next
    Set oTmpObject = GetObject(, sClass)
    ' oTmpObject is reference to new object.
    If Err = 429 Then
       ' Server not running, so create a new instance:
       Set oTmpObject = GetObject("", sClass)
       ' NOTE: for Excel, you can add the next line to view the object
        oTmpObject.Visible = True
    ElseIf Err > 0 Then
       MsgBox Error$
       SmartGetObject = False
       Exit Function
    End If
    SmartGetObject = True
End Function
Private Sub Form_Unload(Cancel As Integer)
    Set oTmpObject = Nothing
End Sub

It comes back with error 429, which means that it thinks its not running, and it DOES actually launch a new instance of the application. The question is, why does GetObject return 429 when there is an instance running?
 
OK, more info... I've found a ROT (running object table) viewer, and it seems that my application that I'm trying to hook into is not registering itself in the ROT. From my understanding, if the application doesn't register itself in the ROT, the GetObject won't be able to find it.

If this is true, then this may be my problem. Does anyone know if I can somehow register it in the ROT? or am I out of luck on this one?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top