IPO's now available on the new E*Trade (R).  Click Here.

PC Magazine

  PC Tech

COM Objects in Delphi, Part 1

Introduction

COM object essentials

Satellites and Containers

Satellite objects

Container objects

The Class Factory

GUIDs, CLSIDs, and IIDs

Figure 1

 
  Categories:
Programming
COM Objects in Delphi, Part 1
Container objects

Continued from Satellite objects

The IContainerUnknown object type is another direct descendant of IUnknown. It maintains its own reference count as a protected data field named FRefCount; the AddRef function increments FRefCount and the Release function decrements it. Both AddRef and Release return the new reference count; in addition, if the count has reached 0, the Release function frees the object.

The DelphCOM unit also defines a global reference count for the entire DLL that contains descendants of the generic COM objects. The constructor and destructor of the container object increment and decrement, respectively, the global reference count. Every DLL that contains COM objects is required to supply two specific functions, DLLCanUnloadNow and DLLGetClassObject. DLLCanUnloadNow, implemented in the DelphCOM unit, returns False unless the global DLL reference count is 0. DLLGetClassObject will be specific to each DLL that relies on DelphCOM and can't be written until the COM objects (descendants of ISatelliteUnknown and IContainerUnknown) have been defined.

The IContainerUnknown object responds to a QueryInterface request for the IUnknown interface by returning a pointer to itself. If any other interface is requested, it returns the error code E_NOINTERFACE. In a descendant of IContainerUnknown, the QueryInterface function will first call this inherited function. If the inherited method returns E_NOINTERFACE, the descendant will check the requested interface ID against the additional interfaces it supports, and return the satellite object that matches the request.

Continues...

Published as Power Programming in the 01/07/97 issue of PC Magazine.


 SPONSORED LINKS
Finance   Save now, save later - 9.99% Visa card - NOT an intro rate.
Shopping   Buy a 56K modem for $19.95 after rebate from NetMarket!
Software   X10.com -- The SuperSite for Home Automation
 ZDNET FEATURED LINKS
Freeware   It's a software free for all - 100 FREE downloads!
Contests   Enter to win a FREE multimedia PC from ZDNet!
 MAGAZINE OFFERS
Free Trial   Try the next issue of Computer Gaming World FREE!

TOP
Copyright (c) 1997 Ziff-Davis Inc.