Link to home
Start Free TrialLog in
Avatar of WoodyJ007
WoodyJ007

asked on

Automation Object Connection

Hi Guys,

Can VB connect to a running instance of an automation object registered with RegisterActiveObject.

Here is some delphi code that I wrote that does what I want.  I need to convert this to VB but most of the calls are not supported.  I know about GetObject but that creates an instance instead of connects to a running one.

Many Thanks
Woody.


Delphi Code
-----------
 
GetActiveObject(Class_DebuggerPro, Nil, AttachDebuggerProUnknown);

If Assigned(AttachDebuggerProUnknown) Then
Begin
   AttachDebuggerProUnknown.QueryInterface(IDebuggerPro, AttachDebuggerPro);
   If Assigned(AttachDebuggerPro) Then
   Begin
            AttachDebuggerPro.DoSomeMethod;
   End;
End;
Avatar of sdm395
sdm395

You can use GetObject to connect to a currently running instance, just omit the first parameter....

Here's a bit from MSDN

If pathname is a zero-length string (""), GetObject returns a new object instance of the specified type. If the pathname argument is omitted, GetObject returns a currently active object of the specified type. If no object of the specified type exists, an error occurs.
Avatar of WoodyJ007

ASKER

I've tried that before.  Calling that function creates a new instance if one is not running.


Dim mydebug As DebuggerPro    

Set mydebug = GetObject("", "DebuggerX.DebuggerPro")


I need to connect to an running instance.  If one is not running then do nothing.

Cheers
Woody.
ASKER CERTIFIED SOLUTION
Avatar of sdm395
sdm395

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, how sdm295 means you can use the GetObject function to
receive a running automation instance:
There are to possibilities:

1) Late binding:
Dim MyObject As Object
Set MyObject = GetObject([pathname] [, class])

Where:
pathname Optional; String. Full path and name of the file containing the object to retrieve. If pathname is omitted, class is required.
class Optional; String. Class of the object.

The class argument uses the syntax appname.objectype and has these parts:
appname Required; String. Name of the application providing the object.
objectype Required; String. Type or class of object to create.

In your case perhaps:
GetObject("","DebuggerPro.AttachDebuggerPro")

2) Early binding:
Therefore you must link the your OLE Automation class in
your VB project at the menu item "Project/References ..."
That links the type lib of your Automation server to VB.
And now you find you Class appears after you typed:
"Dim MyObject As"
Now you can write something like this:
Dim MyObject As DebuggerPro.AttachDebuggerPro
Set MyObject = New DebuggerPro.AttachDebuggerPro
or
Set MyObject = GetObject("","DebuggerPro.AttachDebuggerPro")


Hope this helps
WoK
Yes, how sdm295 means you can use the GetObject function to
receive a running automation instance:
There are to possibilities:

1) Late binding:
Dim MyObject As Object
Set MyObject = GetObject([pathname] [, class])

Where:
pathname Optional; String. Full path and name of the file containing the object to retrieve. If pathname is omitted, class is required.
class Optional; String. Class of the object.

The class argument uses the syntax appname.objectype and has these parts:
appname Required; String. Name of the application providing the object.
objectype Required; String. Type or class of object to create.

In your case perhaps:
GetObject("","DebuggerPro.AttachDebuggerPro")

2) Early binding:
Therefore you must link the your OLE Automation class in
your VB project at the menu item "Project/References ..."
That links the type lib of your Automation server to VB.
And now you find you Class appears after you typed:
"Dim MyObject As"
Now you can write something like this:
Dim MyObject As DebuggerPro.AttachDebuggerPro
Set MyObject = New DebuggerPro.AttachDebuggerPro
or
Set MyObject = GetObject("","DebuggerPro.AttachDebuggerPro")


Hope this helps
WoK
Ah!! I see.  I Didn't know you could just not pass anything in.

Thanks
Woody.