Solved

Automation Object Connection

Posted on 2001-07-17
6
177 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now