/*
*********************************************************************
*
*	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 OLE Automation server app HELLO32.EXE
*
*********************************************************************
*/

#include <windows.h>
#include "resource.h"
#include "iclassf.h"

extern long CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

 
TCHAR *AppName = TEXT("Hello");	// Name of the application.
HWND hMainWnd ;

// {6CED2900-A1DD-11cf-8A33-00AA00A58097}
static const GUID CLSID_CHello = { 0x6ced2900, 0xa1dd, 0x11cf, 
	{ 0x8a, 0x33, 0x0, 0xaa, 0x0, 0xa5, 0x80, 0x97 } };


int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;      
    DWORD dwCHelloCF = 0;
    class CHelloCF *pCF ;   

/*
Initialize the OLE libraries
*/

 	OleInitialize(NULL) ;
 	
 	    
/*
Register window class
*/
	
   	WNDCLASS  wc;

   	wc.style		= CS_HREDRAW | CS_VREDRAW;
   	wc.lpfnWndProc	= WndProc;
   	wc.cbClsExtra	= 0;
   	wc.cbWndExtra	= DLGWINDOWEXTRA;
  	wc.hInstance	= hInst;
	wc.hIcon		= LoadIcon(hInst, AppName);	// Loads hello.ico
   	wc.hCursor		= LoadCursor(NULL, IDC_ARROW);	// Normal arrow pointer
   	wc.hbrBackground    = (HBRUSH) (COLOR_APPWORKSPACE+1);
   	wc.lpszMenuName	= NULL;				// No menus.
    wc.lpszClassName= AppName;

   	if(!RegisterClass(&wc))
   	{
   		return FALSE;
   	}

		


/*
Register class factory.  
*/

	pCF = new CHelloCF ( ) ;
	
	CoRegisterClassObject(
		CLSID_CHello,
    	pCF,
	   	CLSCTX_LOCAL_SERVER,
		REGCLS_SINGLEUSE,
		&dwCHelloCF);

	
/*
Create the main window and show it.
*/
	      
    hMainWnd = CreateDialog(hInst, AppName, 0, NULL);
    ShowWindow(hMainWnd, nCmdShow);

    
/*
Standard message loop
*/
 	while(GetMessage(&msg, NULL, NULL, NULL)) 
    {
    	TranslateMessage(&msg);
    	DispatchMessage(&msg);
    }
       
/*
Revoke the class factory if we have one
*/
       
 	if(dwCHelloCF != 0)
  	{
      CoRevokeClassObject(dwCHelloCF);
      pCF->Release( ) ;
 	}


/*
Close down OLE libraries
*/

    OleUninitialize();

    return msg.wParam;
}





