Solved

Automation Object Connection

Posted on 2001-07-17
6
181 Views
Last Modified: 2012-05-04
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
Comment
Question by:WoodyJ007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Expert Comment

by:sdm395
ID: 6288888
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
 

Author Comment

by:WoodyJ007
ID: 6288969
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
 
LVL 1

Accepted Solution

by:
sdm395 earned 50 total points
ID: 6288978
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6288984
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
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6288988
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
 

Author Comment

by:WoodyJ007
ID: 6289008
Ah!! I see.  I Didn't know you could just not pass anything in.

Thanks
Woody.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question