Board index » delphi » OLE & OLE Running Table

OLE & OLE Running Table

Hello all -

I am attempting to access a function out of another running application.  I
started out using the CreateOLEObject function, but realized that was
creating another instance of the server.  I've figured out that I need to
use the GetActiveOLEObject function to access it without having a second
instance.  However, when I use the GetActiveOLEObject function, I get the
error 'Operation Unavailable'.  What I've found from the web is that I need
to use the RegisterActiveObject API call to register the OLE component with
the Running OLE Table.  How do I use that call?  I have found examples of
usage, but I'm not sure what the parameters stand for.  Anyone out there
willing to give a guy a hand?  -=)

Thanks,

-Aaron

 

Re:OLE & OLE Running Table


Hi Aaron,

here's a short example of ROT (Running Object Table) usage... you can read
further about it in the Delphi Help...

First, you'll need to register the object in the ROT... in this example it
is the server that registers itself into the ROT (ie. the first time it
get's created).

var
  FRotCookie : integer;
...
  // Register the object in the ROT
  RegisterActiveObject(Self, Class_BSMsgSvr, ACTIVEOBJECT_WEAK, FROTCookie);

the call use a reference to the object (Self), the Class ID of the CoClass
GUID, a registration type constant, and a cookie. You'll need to change the
Class ID for your own class, and perhaps the registration type depending on
your needs... the registration type can be either the one in the example, or
ACTIVEOBJECT_STRONG... a weak registration basically means that the ROT
doesn't AddRef the object when it is registered, and a strong registration
that it does. The weak registration will mean that the registered object
will be destroyed when the last client drops it's reference(s) to the
object.

To unregister the object, you'll only need the cookie (FROTCookie from the
example above).

  // Revoke (unregister) object from ROT
  RevokeActiveObject(FROTCookie, nil);

the second parameter is reserved... just pass 'nil'.

For a user (or client) to retrieve the object from the ROT, you'll use
GetActiveObject along with the Class ID of the object you desire... in the
example above, the Class ID was Class_BSMsgSvr so that's what we'll have to
use.

var
    Unk : IUnknown;
begin
    GetActiveObject(Class_BSMsgSvr, nil, Unk);

The second parameter is (again) reservered... the last parameter, Unk, is a
pointer to the object. All you need to do from here is a Unk.QueryInterface
for the interface you need.

And don't forget to check the HResult of the calls, or perform a OleCheck on
the call ;-)

Cheers,
Thomas

Quote
"A G" <aa...@ugomedia.com> wrote in message news:3b8e6f54_2@dnews...
> Hello all -

> I am attempting to access a function out of another running application.
I
> started out using the CreateOLEObject function, but realized that was
> creating another instance of the server.  I've figured out that I need to
> use the GetActiveOLEObject function to access it without having a second
> instance.  However, when I use the GetActiveOLEObject function, I get the
> error 'Operation Unavailable'.  What I've found from the web is that I
need
> to use the RegisterActiveObject API call to register the OLE component
with
> the Running OLE Table.  How do I use that call?  I have found examples of
> usage, but I'm not sure what the parameters stand for.  Anyone out there
> willing to give a guy a hand?  -=)

> Thanks,

> -Aaron

Re:OLE & OLE Running Table


Tom (and anyone else paying attention),

I tried what you said, and I still recieve the 'Operation Unavailable'
error.  Here's the scoop...

I have a Service Application with an Automation Object attached to it.  The
Automation Object has a class CoUMIEIS with an application name of umieiss
(making the ProgID umieiss.CoUMIEIS).  The service's OnStart event registers
the object with the ROT (based on the code you gave me).  The OnStop event
Revokes it.

I have a client application that I am trying to run on the same machine.
When I try to do a GetActiveOLEObject, I recieve the 'Operation Unavailable'
error.  So, I tried what you said and used an OLECheck(GetActiveObject...),
and recieved the same error.  I am using ProgIDToClassID('umieiss.CoUMIEIS')
to get the class ID.  Any ideas why I would still be recieving the error?

Thank you very much for your help and time,

-Aaron

Quote
"Thomas Rose" <tr...@intellix.com> wrote in message news:3b8e9c0c_2@dnews...
> Hi Aaron,

> here's a short example of ROT (Running Object Table) usage... you can read
> further about it in the Delphi Help...

> First, you'll need to register the object in the ROT... in this example it
> is the server that registers itself into the ROT (ie. the first time it
> get's created).

> var
>   FRotCookie : integer;
> ...
>   // Register the object in the ROT
>   RegisterActiveObject(Self, Class_BSMsgSvr, ACTIVEOBJECT_WEAK,
FROTCookie);

> the call use a reference to the object (Self), the Class ID of the CoClass
> GUID, a registration type constant, and a cookie. You'll need to change
the
> Class ID for your own class, and perhaps the registration type depending
on
> your needs... the registration type can be either the one in the example,
or
> ACTIVEOBJECT_STRONG... a weak registration basically means that the ROT
> doesn't AddRef the object when it is registered, and a strong registration
> that it does. The weak registration will mean that the registered object
> will be destroyed when the last client drops it's reference(s) to the
> object.

> To unregister the object, you'll only need the cookie (FROTCookie from the
> example above).

>   // Revoke (unregister) object from ROT
>   RevokeActiveObject(FROTCookie, nil);

> the second parameter is reserved... just pass 'nil'.

> For a user (or client) to retrieve the object from the ROT, you'll use
> GetActiveObject along with the Class ID of the object you desire... in the
> example above, the Class ID was Class_BSMsgSvr so that's what we'll have
to
> use.

> var
>     Unk : IUnknown;
> begin
>     GetActiveObject(Class_BSMsgSvr, nil, Unk);

> The second parameter is (again) reservered... the last parameter, Unk, is
a
> pointer to the object. All you need to do from here is a
Unk.QueryInterface
> for the interface you need.

> And don't forget to check the HResult of the calls, or perform a OleCheck
on
> the call ;-)

> Cheers,
> Thomas

> "A G" <aa...@ugomedia.com> wrote in message news:3b8e6f54_2@dnews...
> > Hello all -

> > I am attempting to access a function out of another running application.
> I
> > started out using the CreateOLEObject function, but realized that was
> > creating another instance of the server.  I've figured out that I need
to
> > use the GetActiveOLEObject function to access it without having a second
> > instance.  However, when I use the GetActiveOLEObject function, I get
the
> > error 'Operation Unavailable'.  What I've found from the web is that I
> need
> > to use the RegisterActiveObject API call to register the OLE component
> with
> > the Running OLE Table.  How do I use that call?  I have found examples
of
> > usage, but I'm not sure what the parameters stand for.  Anyone out there
> > willing to give a guy a hand?  -=)

> > Thanks,

> > -Aaron

Re:OLE & OLE Running Table


An NT service usually runs under a different account/window station separate
from your interative user. The ROT does not work across window stations. If
you convert your server to a regular EXE server, the problem should be
fixed.

Otherwise tip #19 on my site might help.

--
have fun
Binh Ly
http://www.techvanguards.com

Quote
"A G" <aa...@ugomedia.com> wrote in message news:3b8ece02$1_1@dnews...
> Tom (and anyone else paying attention),

> I tried what you said, and I still recieve the 'Operation Unavailable'
> error.  Here's the scoop...

> I have a Service Application with an Automation Object attached to it.
The
> Automation Object has a class CoUMIEIS with an application name of umieiss
> (making the ProgID umieiss.CoUMIEIS).  The service's OnStart event
registers
> the object with the ROT (based on the code you gave me).  The OnStop event
> Revokes it.

> I have a client application that I am trying to run on the same machine.
> When I try to do a GetActiveOLEObject, I recieve the 'Operation
Unavailable'
> error.  So, I tried what you said and used an

OLECheck(GetActiveObject...),
Quote
> and recieved the same error.  I am using

ProgIDToClassID('umieiss.CoUMIEIS')

- Show quoted text -

Quote
> to get the class ID.  Any ideas why I would still be recieving the error?

> Thank you very much for your help and time,

Re:OLE & OLE Running Table


Thanks for the reply, Binh,

I just tried the exact same code as an application instead of a service, and
now I recieve a new error: "Interface Not Supported.".  Great...another
issue I have to track down.  COM/OLE seem like a great thing...I'm starting
to think otherwise -=)

Thanks,

-Aaron

Quote
"Binh Ly" <b...@castle.net> wrote in message news:3b8ed5ae_1@dnews...
> An NT service usually runs under a different account/window station
separate
> from your interative user. The ROT does not work across window stations.
If
> you convert your server to a regular EXE server, the problem should be
> fixed.

> Otherwise tip #19 on my site might help.

> --
> have fun
> Binh Ly
> http://www.techvanguards.com

> "A G" <aa...@ugomedia.com> wrote in message news:3b8ece02$1_1@dnews...
> > Tom (and anyone else paying attention),

> > I tried what you said, and I still recieve the 'Operation Unavailable'
> > error.  Here's the scoop...

> > I have a Service Application with an Automation Object attached to it.
> The
> > Automation Object has a class CoUMIEIS with an application name of
umieiss
> > (making the ProgID umieiss.CoUMIEIS).  The service's OnStart event
> registers
> > the object with the ROT (based on the code you gave me).  The OnStop
event
> > Revokes it.

> > I have a client application that I am trying to run on the same machine.
> > When I try to do a GetActiveOLEObject, I recieve the 'Operation
> Unavailable'
> > error.  So, I tried what you said and used an
> OLECheck(GetActiveObject...),
> > and recieved the same error.  I am using
> ProgIDToClassID('umieiss.CoUMIEIS')
> > to get the class ID.  Any ideas why I would still be recieving the
error?

> > Thank you very much for your help and time,

Other Threads