Platinum Visa - Click here to apply

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
The Class Factory

Continued from Container objects

COM objects can be created on command from the system or a program. The actual creation is handled by a COM object type called a class factory, another direct descendant of IUnknown. The IMyClassFactory object in the DelphCOM unit implements AddRef and Release, just as the IContainerUnknown object did. It responds to QueryInterface requests for IUnknown or IClassFactory by returning a pointer to itself. Besides those three functions, the IClassFactory interface adds two new ones, CreateInstance and LockServer. Since LockServer is not generally required, IMyClassFactory returns the special value E_NOTIMPL, indicating the function is not implemented.

The most essential function of a class factory, the one that makes it a factory, is CreateInstance. The calling program uses CreateInstance to produce an instance of the desired object. The DelphCOM unit, however, doesn't contain any "finished" objects; it holds only the generic satellite and container objects. When we define a COM object descendant of IContainerUnknown, we also need to define an IMyClassFactory descendant whose CreateInstance function returns an instance of that COM object.

With the introduction of IMyClassFactory, the set of generic COM objects for Delphi is complete. The system of container and satellite objects can be used in any object-oriented language, and, in fact, COM objects designed under MFC use a similar system. Part 2 of this article will move from theory to practice. It will extend the generic objects defined in Part 1 to create examples of five Windows 95 shell extension types: a context-menu handler, a property-sheet handler, a right-drag handler, an icon handler, and a copy-hook handler.

Once you use and understand the examples, you'll be completely prepared to build your own practical extensions to the Windows 95 shell.

Neil J. Rubenking is the contributing technical editor ofPC Magazine.

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.