home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
msysjour
/
vol07
/
03
/
ole2
/
initsvr.c
Wrap
Text File
|
1992-05-01
|
4KB
|
132 lines
/* From WinMain: */
:
:
if (!InitInstance(hInstance, fFirstInstance))
return FALSE;
if (!InitServer (hwndMain, hInstance))
return FALSE;
:
:
/* InitInstance
* ------------
*
* Do any per-instance initialization.
*
* HANDLE hInstance
*
* RETURNS: TRUE if successful
* FALSE otherwise.
*
* CUSTOMIZATION: Re-implement
*
*/
static BOOL InitInstance (HANDLE hInstance, BOOL fFirstInstance)
{
:
:
// Initialize the method tables.
InitVTbls ();
:
:
// Register clipboard formats.
cfObjectLink= RegisterClipboardFormat ("ObjectLink");
cfOwnerLink = RegisterClipboardFormat ("OwnerLink");
cfNative = RegisterClipboardFormat ("Native");
:
:
return TRUE;
}
/* InitVTbls
* ---------
*
* Create procedure instances for all the OLE methods.
*
*
* CUSTOMIZATION: Your application might not use global variables for srvrvtbl,
* docvtbl, and 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);
}
/* InitServer
* ----------
*
* Initialize the server by allocating memory for it, and calling
* the OleRegisterServer method. Requires that the server method table
* has been properly initialized.
*
* HWND hwnd - Handle to the main window
* LPSTR lpszLine - The Windows command line
*
* RETURNS: TRUE if the memory could be allocated, and the server
* was properly registered.
* FALSE otherwise
*
* CUSTOMIZATION: Your application might not use a global variable
* for srvrMain.
*
*/
BOOL InitServer (HWND hwnd, HANDLE hInst)
{
srvrMain.olesrvr.lpvtbl = &srvrvtbl;
if (OLE_OK != OleRegisterServer
(szClassName, (LPOLESERVER) &srvrMain, &srvrMain.lhsrvr, hInst,
OLE_SERVER_MULTI))
return FALSE;
else
return TRUE;
}