/*
*********************************************************************
*
*	The Essence of OLE
*
*	Source code sample
*
*	Copyright (c) 1996, Rolling Thunder Computing, Ipswich MA
*
*	e-mail: essence@rollthunder.com
*	CompuServe: 73540,3430
*	Web: http://www.rollthunder.com
*
*	File Name: WINMAIN.CPP
*
*	Purpose: Entry point for moniker server example
*
*********************************************************************
*/

/*
*****************************************************************************
System header files
*****************************************************************************
*/

#include	<windows.h>

/*
*****************************************************************************
Application header files
*****************************************************************************
*/


#include "main.h"
#include "cclassf.h"


/*
*****************************************************************************
Function prototype files
*****************************************************************************
*/


/*
*****************************************************************************
Global Variables defined here
*****************************************************************************
*/


HINSTANCE hInst;
HWND  hMainWnd ;

// {2154EAD0-502D-11cf-89F3-00AA00A58097}

GUID CLSID_MonikerSv = { 0x2154ead0, 0x502d, 0x11cf, {0x89, 0xf3, 0x0, 0xaa, 0x0, 0xa5, 0x80, 0x97 }};


/*
*****************************************************************************
EXTERNS of global variables defined in other files
*****************************************************************************
*/


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
	LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    WNDCLASS  wc;
 	
	hInst = hInstance ;
	LPTSTR Class = TEXT("Ole Moniker Demo");

/*
Initialize OLE Libraries
*/

	HRESULT hr = OleInitialize (NULL) ;

/*
Initialize window classes, exits if it can't
First for the main window
*/

	wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; 		
    wc.lpfnWndProc = MainWndProc;       
    wc.cbClsExtra = 0;                 
    wc.cbWndExtra = 0;                 
    wc.hInstance = hInst;         
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  TEXT("MainMenu");  
    wc.lpszClassName = Class; 

	RegisterClass (&wc) ;



/*
Create a main window for this application instance.
*/



    hMainWnd = CreateWindow(
        Class,                    
        TEXT("Essence of OLE  Monikersv.exe"),     
        WS_OVERLAPPEDWINDOW | WS_VISIBLE ,          
	 	CW_USEDEFAULT,  
	 	CW_USEDEFAULT,   
	 	400,   
	 	200,
	 	NULL,                          
        NULL,                          
        hInst,	                   
        NULL                          
    );




/*
Check command line to see if launched as an OLE server.  If so, register
the class factory for this app.
*/

	DWORD dwRegister ;
	BOOL bEmbedding = FALSE ;

	if (strstr (lpCmdLine, "-Embedding"))
	{
		bEmbedding = TRUE ;

		LPCLASSFACTORY pCF = new CClassFactory ( ) ;

		CoRegisterClassObject(
			CLSID_MonikerSv, 
			pCF, 
			CLSCTX_LOCAL_SERVER,
			REGCLS_SINGLEUSE,
			&dwRegister) ;

	}

/*
Acquire and dispatch messages until a WM_QUIT message is received.
*/

	 while (GetMessage(&msg,	  
	    NULL,							   
	    NULL,		   				
	    NULL))		   				
	{
	 	TranslateMessage(&msg);	  
		DispatchMessage(&msg);	   
	}


/*
App going down, shut down class factory
*/

	if (bEmbedding)
	{
		CoRevokeClassObject (dwRegister) ;
	}


/*
Shut down OLE libraries
*/

	OleUninitialize ( ) ;


/*
Finished with WinSv application.  Return value from PostQuitMessage
*/                                  


	return (msg.wParam);

}

