/*
**************************************************************************

	Copyright (C) 1995

	Rolling Thunder Computing, Inc.
	25 Heartbreak Rd
	Ipswich MA 01938

	E-Mail: 73540.3430@compuserve.com

*****************************************************************************
*/


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

#include	<windows.h>
#include 	<initguid.h>

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


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


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


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


HINSTANCE hInst;
HWND  hMainWnd ;

UINT cfTimeData, cfTimeTest ;


// {3943B650-E0F3-11d0-9135-00608C86B89C}
static const GUID GUID_TimeData = 
{ 0x3943b650, 0xe0f3, 0x11d0, { 0x91, 0x35, 0x0, 0x60, 0x8c, 0x86, 0xb8, 0x9c } };

/*
*****************************************************************************
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 ;
	char *Class = "Ole 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 = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  NULL;    
    wc.lpszClassName = Class;

	if (RegisterClass(&wc) == FALSE)
	{
		MessageBox (NULL, "FATAL ERROR\nCould not register Main window class", "ERROR", MB_ICONSTOP) ;
		return FALSE ;
	}



/*
Create a main window for this application instance.
Position and size it as it was the last time it was shut down with SAVE
CHANGES checked
If window could not be created, return "failure"
*/



    hMainWnd = CreateWindow (Class,                    
        "Essence of COM Data4 DCOM Local Server",     
        WS_OVERLAPPEDWINDOW | WS_VISIBLE ,         
	 	CW_USEDEFAULT,  CW_USEDEFAULT,   
	 	400, 200,
	 	NULL, NULL, hInst, NULL);


    if (!hMainWnd)
	{
		MessageBox (NULL, "FATAL ERROR\nCould not create Main window", ERROR, MB_ICONSTOP) ;
        return (FALSE);
	}

/*
Register private clipboard formats
*/

	cfTimeData = RegisterClipboardFormat ("TimeDataObject") ;
	cfTimeTest = RegisterClipboardFormat ("TimeTestDataObject") ;

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

	DWORD dwRegister ;

	if (strstr (lpCmdLine, "-Embedding"))
	{
		LPCLASSFACTORY pCF = new CClassFactory ( ) ;

		CoRegisterClassObject(
			GUID_TimeData, 
			pCF, 
			CLSCTX_LOCAL_SERVER,
			REGCLS_MULTIPLEUSE,
			&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
*/

	CoRevokeClassObject (dwRegister) ;


/*
Shut down OLE libraries
*/

	OleUninitialize ( ) ;


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


	 return (msg.wParam);

}

