Solved

Automation Object Connection

Posted on 2001-07-17
6
175 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now