Chapter 18 OLE Documents and Local Embedding Servers

C O O - K I E S!

Cookie Monster

In Chapter 17, I compared embedded objects and a batch of cookies in a cookie jar and described how, figuratively, to create the cookie jar. That leaves us with the question of how to bake cookies. At least some of us, I'm sure, have at one time or another gotten out all the ingredients—flour, sugar, eggs, butter, shortening, baking soda, salt, and vanilla (maybe also an obscene number of chocolate chips)—to mix up and bake a batch of cookies. (OK, I'll admit that once or twice I didn't bother to bake them.) Later we remove them from the oven, let them cool, and put them in the cookie jar.

Baking cookies is a good analogy for what's involved in creating a server for embedded compound document content objects. As bakers, we first create the cookies by mixing the dough, and then we manage the cookies by baking, cooling, and storing them. As bakers, we are cookie servers. In the case of embedded objects, a server must create objects and then manage those objects. Object creation, as we saw in Chapter 5, is the responsibility of a class factory. Object management is the responsibility of all the object's interfaces, including IOleObject, IDataObject, and IPersistStorage.

This chapter deals exclusively with local servers that provide embedded content objects. Those objects need to implement only the three interfaces mentioned above. As an example, we'll follow a step-by-step approach for adding OLE Documents support to the Cosmo application. We'll turn its internal Polyline object into a shareable content object that can be embedded while still keeping that object inside the executable itself. In Chapter 19, we'll cover additional issues surrounding in-process servers and object handlers, which are a bit more complicated than a local server. Even then, Cosmo and the samples in Chapter 19 will not explore every facet of OLE Documents. There are so many recipes for objects that we'd go crazy trying to look at them all at once. We need to start with the OLE equivalent of your basic chocolate chip cookie. That will be enough to satisfy a container as well as a furry, blue, ball-eyed maniac from Sesame Street.