delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


Registering an ActiveX for its class (CLSID)Component available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 6.x (or higher)
Category:
Win API
Skill Level:
Scoring:
Last Update:
02/01/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet RegisterActiveObject CoLockObjectExternal RevokeActiveObject CoDisconnectObject GetActiveOleObject GetActiveObject
Times Scored:
3
Visits:
2566
Uploader: Bertrand Goetzmann
Company:
Reference: http://www.object-everywhere.com
Component Download: http://perso.worldonline.fr/objecteverywhere/ActiveObject.zip
 
Question/Problem/Abstract:
How getting the IUnknown reference on a specific COM object's instance created by an application ?
Answer:



The RegisterActiveObject function -from the Win32 API- can register an object by passing its IUnknown reference and its CLSID to make it the active object for its CLSID.
Registration causes the object to be listed in OLE's running object table, a globally accessible lookup table that keeps track of the objects that are currently running on your computer.
An application can then create an OLE automation object for example, register it as the active object at startup.
Other application can have access to this particular instance by getting a IDispatch reference with the Delphi's GetActiveOleObject using its progID.

I've placed the registration mecanism in the TActiveObject class showed
bellow and you can download the demo applications.


unit ActiveObject;

// Written by Bertrand Goetzmann (http://www.object-everywhere.com)
// Keywords : RegisterActiveObject, CoLockObjectExternal, RevokeActiveObject, CoDisconnectObject, GetActiveOleObject, GetActiveObject

interface

type
  TActiveObject = class
  private
    FUnk: IInterface;
    FRegister: Integer;
  public
    constructor Create(Unk: IInterface; const clsid: TGUID); overload;
    constructor Create(Unk: IInterface; const ProgId: string); overload;
    destructor Destroy; override;
  end;

implementation

uses ActiveX, ComObj;

{ TActiveObject }

constructor TActiveObject.Create(Unk: IInterface; const clsid: TGUID);
begin
  inherited Create;
  FUnk := Unk;
  OleCheck(RegisterActiveObject(FUnk, clsid, ACTIVEOBJECT_WEAK, FRegister));
  OleCheck(CoLockObjectExternal(FUnk, True, True));
end;

constructor TActiveObject.Create(Unk: IInterface; const ProgId: string);
begin
  Create(Unk, ProgIDToClassID(ProgId));
end;

destructor TActiveObject.Destroy;
begin
  OleCheck(CoLockObjectExternal(FUnk, False, True));
  OleCheck(RevokeActiveObject(FRegister, nil));
  OleCheck(CoDisconnectObject(FUnk, 0));
  inherited;
end;

end.


In the demo applications, OleObject.dll is the implementation of the OLE automation object with "OleObject.Test" as progId and supporting the ITest interface. This interface has a single property named Message : you can read or write a simple string of characters.
The AppTest.exe creates an instance of this OLE automation object and register it with an instance of TActiveObject. When the applicatino shut down, the registration of the active objet is revoked.
Start several instances of ClientTest. ClientTest gets the IDispatch reference, via a Variant variable, on the active object by using a call of GetActiveOleObject('OleObject.Test'), to set or get the Message property value.

I think it is a powerful way to make applications more collaborative.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Can't download the zip
    ginsonic (Jan 29 2002 8:53PM)

Forbidden
You don't have permission to access the requested URL on this server.
Respond

RE: Can't download the zip
Bertrand Goetzmann (Jan 30 2002 10:00AM)

The URL is valid, but I don't know why the web server can return with this error message. If you try again, you can download the zip file.
Else, send me a e-mail, I'll send you ActiveObject.zip.
Respond

RE: RE: Can't download the zip
Stefan Walther (Jan 30 2002 3:30PM)

Dear Bertrand,

could you please send the Component to delphi3000@bluestep.com and we'll attach it to the article ...

Thanks

Greetings
Stefan WALTHER
delphi3000.com
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
S. Kucherov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)