4.3.1 OLESERVERVTBL

The following table summarizes the set of callback functions needed to perform fundamental server tasks such as opening files, creating objects, and terminating after an editing session. The pointers to these callbacks must be defined in an OLESERVERVTBL structure, and the functions must be exported in your application's module definition file (.DEF).

Server Callback Description

Create Makes a new object that will be embedded by the client application.
CreateFromTemplate Creates a new document that is initialized with the data in a specified file.
Edit Creates a document to be edited (data is sent from the client application).
Execute Specifies DDE execute strings in support of the StdExecute protocol (optional use for an OLE server).
Exit Instructs the server application to terminate if no documents are registered.
Open Opens an existing file and prepares to edit the contents.
Release Notifies a server application that all connections to it have closed and that it is safe to terminate.

For more information about the OLESERVERVTBL structure and its associated callback functions, see Chapter 7, "Callback Functions and Data Structures."

The following code example defines the OLESERVER Create callback, as used in the sample SRVRDEMO.EXE program:

/* SrvrCreate SERVER "Create" METHOD

*

* Create a document, allocate and initialize the

* OLESERVERDOC structure, and associate the library's

* handle with it. In this demo server, we also create an

* object for the user to edit.

*

* LPOLESERVER lpolesrvr - The server structure

* registered by the application

* LHSERVERDOC lhdoc - The library's handle

* LPSTR lpszClassName - The class of document to

* create

* LPSTR lpszDoc - The name of the document

* LPOLESERVERDOC FAR *lplpoledoc - Indicates the server doc

* structure to be created

*

* RETURNS: OLE_OK if the named document was created.

* OLE_ERROR_NEW if the document could not

* be created.

*/

OLESTATUS FAR PASCAL SrvrCreate

(LPOLESERVER lpolesrvr, LHSERVERDOC lhdoc,

LPSTR lpszClassName, LPSTR lpszDoc,

LPOLESERVERDOC FAR *lplpoledoc)

{

if (!CreateNewDoc (lhdoc, lpszDoc, doctypeEmbedded))

return OLE_ERROR_NEW;

// Although the document has not actually been changed,

// the client has not received any data from the server

// yet, so the client will need to be updated.

// Therefore, CreateNewObj sets fDocChanged to TRUE.

CreateNewObj (TRUE);

*lplpoledoc = (LPOLESERVERDOC) &docMain;

EmbeddingModeOn();

return OLE_OK;

}