• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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;
0
WoodyJ007
Asked:
WoodyJ007
  • 2
  • 2
  • 2
1 Solution
 
sdm395Commented:
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.
0
 
WoodyJ007Author Commented:
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.
0
 
sdm395Commented:
That is because you are passing a blank string instead of omitting the first parameters....try
Dim mydebug as DebuggerPro

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

If there is not an instance running, this will return an error.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
WolfgangKoenigCommented:
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
0
 
WolfgangKoenigCommented:
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
0
 
WoodyJ007Author Commented:
Ah!! I see.  I Didn't know you could just not pass anything in.

Thanks
Woody.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now