i
i
i
i
i
i
i
i
12.4. The Component Object Model 297
• Interface. A pointer by which to access all the methods and properties
of a COM object.
• Method. The functions of a COM object’s interface that do all the work
of the COM object.
Earlier in this chapter, we hinted at the problems of versioning in DLLs.
There are other problems, too, such as calling external functions from within
a DLL, say, one written in C++, from BASIC language subroutines. COM
seeks to overcome this by never upgrading any object or interface. If the
authors of a COM library want to provide extra functionality, they must
define a new interface but they must not remove the original one, either.
This is one reason why one has interfaces such as ICaptureGraphBuilder and
ICaptureG raphBuilder2. COM components can still be packaged in a DLL
or as an executable. They can be located in different places or indeed moved
if necessary. Application programs know where they are by looking in the
Windows registry for their class identifier (CLSID) which has the form of
a globally unique identifier (a GUID). Before COM objects can be used,
therefore, they have to be installed into Windows. This effectively means
writing the GUID into the registry and mapping their location on disk. In a
typical Windows registry, there may be may hundreds of these COM classes.
For example, the video codec Xvid (discussed in Section 5.5.2)
can be used by any video player programs installed on the same
computer because it is implemented as a COM component. On
a typical system, the binary code for the codec is stored in the
file C:windowssystem32xvid.ax, but the key to making Xvid
available is its registration through its GUID entry in the CLSID
section of the registry (see Figure 12.1).
One of the biggest headaches for novice COM programmers looking for
example code that they can reuse is the fact that there are often many ways to
do exactly the same thing. If you read a book on COM and then turn to an
example from the Direct3D SDK, it is likely that even getting hold of the first
interface will break the rules so carefully explained by the COM purist in her
book on COM. Sadly, that is one of the things those of us who only want to
do 3D or video programming will just have to accept as the price to be paid
for not having to write every line of an MPEG-4 DVD decoder ourselves.
To try to find a path through the COM maze, all our example programs that
need to use COM will stick to one or two standard ways to get the programs
up and running.