Before calling any function in the server DLL, the server application must initialize the function callback tables with the MakeProcInstance call, giving each VTBL field an instance thunk. Every field in the OLESERVERVTBL, OLESERVERDOCVTBL, and OLEOBJECTVTBL structures must be initialized.
The server application creates the callback function pointers in these structures by using the MakeProcInstance function. The callback functions must also be listed in the EXPORTS section of your application's module-definition file (.DEF) in order for the server DLL to call them.
Note If MakeProcInstance call for any VTBL fails, then the initialization fails and the application terminates; an OLE server cannot execute properly without the ability for the OLE libraries to call these callback functions.
In the following code example, the InitVTbls function creates procedure instances for all of the OLE callback functions:
OLESERVERVTBL srvvtbl;
OLESERVERDOCVTBL docvtbl;
OLEOBJECTVTBL objvtbl;
.
.
.
void InitVTbls (void)
{
typedef LPVOID (FAR PASCAL *LPVOIDPROC) (LPOLEOBJECT,LPSTR);
// Server method table
srvrvtbl.Create = MakeProcInstance(SrvrCreate,hInst);
srvrvtbl.CreateFromTemplate = MakeProcInstance
(SrvrCreateFromTemplate,hInst);
srvrvtbl.Edit = MakeProcInstance (SrvrEdit,hInst);
srvrvtbl.Execute = MakeProcInstance(SrvrExecute,hInst);
srvrvtbl.Exit = MakeProcInstance (SrvrExit,hInst);
srvrvtbl.Open = MakeProcInstance (SrvrOpen,hInst);
srvrvtbl.Release = MakeProcInstance(SrvrRelease,hInst);
// Document method table
docvtbl.Close = MakeProcInstance (DocClose,hInst);
docvtbl.GetObject = MakeProcInstance (DocGetObject,hInst);
docvtbl.Execute = MakeProcInstance (DocExecute,hInst);
docvtbl.Release = MakeProcInstance (DocRelease,hInst);
docvtbl.Save = MakeProcInstance (DocSave,hInst);
docvtbl.SetColorScheme = MakeProcInstance
(DocSetColorScheme,hInst);
docvtbl.SetDocDimensions = MakeProcInstance
(DocSetDocDimensions, hInst);
docvtbl.SetHostNames = MakeProcInstance
(DocSetHostNames,hInst);
// Object method table
..objvtbl.DoVerb = MakeProcInstance (ObjDoVerb,hInst);
objvtbl.EnumFormats = MakeProcInstance
(ObjEnumFormats, hInst);
objvtbl.GetData = MakeProcInstance (ObjGetData,hInst);
objvtbl.QueryProtocol = (LPVOIDPROC) MakeProcInstance
((FARPROC)ObjQueryProtocol, hInst);
objvtbl.Release = MakeProcInstance (ObjRelease,hInst);
objvtbl.SetBounds = MakeProcInstance (ObjSetBounds,hInst);
objvtbl.SetColorScheme = MakeProcInstance
(ObjSetColorScheme, hInst);
objvtbl.SetData = MakeProcInstance (ObjSetData,hInst);
objvtbl.SetTargetDevice = MakeProcInstance
(ObjSetTargetDevice,hInst);
objvtbl.Show = MakeProcInstance (ObjShow,hInst);
}