7.1.3 Multiple Instances of Objects

Since a server or client application may need to deal with more than one object simultaneously, they need more than one instance of the wrapper data structure—one instance of the wrapper data structure for each object. When an OLE DLL makes a callback function call, it passes a pointer to the callback function that references the wrapper corresponding to the object.

While it makes sense to have unique instances of the wrappers for each object, document, server, client, and stream, it is not necessary to have multiple instances of the VTBL structure. All instances of a given type of wrapper can refer to the same VTBL structure. For example, all server applications must provide the OLEOBJECTVTBL, similar to that shown in Figure 36. Most server applications will need multiple instances of the wrapper structures, such as the OBJ structure shown wrapping the OLEOBJECT structure.

Figure 36. Unique object wrappers and a shared object VTBL

Each OBJ wrapper can contain the same OLEOBJECT structure, which points to one OLEOBJECTVTBL structure. The server application can have multiple wrapper instances that share the same VTBL structure.

Note Client and server applications are responsible for providing memory for the data structures associated with the VTBLs. VTBLs may be kept in the application's data segment, either as global variables or as dynamically allocated blocks on the global heap.