![]() |
![]() ![]() |
|
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. Published as Power Programming in the 01/07/97 issue of PC Magazine. |
|
TOP | ![]() Copyright (c) 1997 Ziff-Davis Inc. |