7.1.2 Object Data Structures

As shown in Figure 35, an object consists of the following three distinct data structures:

An OLEOBJECTVTBL structure that contains only pointers to the object callback functions.

An OLEOBJECT structure, which contains only a pointer to OLEOBJECTVTBL.

A wrapper structure that you define (OBJ) to contain the OLEOBJECT structure, and other members to hold any application-specific data you want associated with the object.

Figure 35. An OLEOBJECTVTBL, OLEOBJECT structure, and wrapper structure (OBJ)

The following code example, taken from the OLE.H header file, shows the definition of the OLEOBJECTVTBL structure for a single function (GetData).

typedef struct _OLEOBJECTVTBL

{

OLESTATUS (CALLBACK *GetData) (LPOLEOBJECT, OLECLIPFORMAT,

HANDLE FAR*);

} OLEOBJECTVTBL;

In OLEOBJECTVTBL, GetData is a callback function that OLESVR.DLL will call when the server application needs to retrieve data from an object.

The following code example, also shown for illustration and included in the header file OLE.H, defines the OLEOBJECT data structure that points to OLEOBJECTVTBL:

typedef OLEOBJECTVTBL FAR *LPOLEOBJECTVTBL;

typedef struct _OLEOBJECT

{

LPOLEOBJECTVTBL lpvtbl;

} OLEOBJECT;

You can define the wrapper structure for the OLEOBJECTVTBL as follows:

typedef struct _OBJ

{

OLEOBJECT oleobject;// OLE's part must come first!

//

// Your member functions go here.

//

} OBJ;

The data structures and VTBLs shown in the preceding code examples correspond to an object created by the server application. Additional VTBLs required to be setup by server and client applications include:

Server VTBLs Purpose

OLESERVERVTBL Contains.pointers to the callback functions used to start and control server applications.
OLESERVERDOCVTBL Contains pointers to the callback functions used to manipulate objects.
Client VTBLs Purpose

OLECLIENTVTBL Contains a pointer to the client application's CallBack function.
OLESTREAMVTBL Contains pointers to the storage and retrieval callback functions.

These data structures are described later in this chapter under their respective headings.

Note Each VTBL has a corresponding structure that points to it—for example, the OLESERVERVTBL structure has an OLESERVER structure that consists of a single, far pointer, LPOLESERVERVTBL.