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

	Filename: DLLMAIN.C


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

  e-mail 73540.3430@compuserve.com
*****************************************************************************
*/


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

#include	<windows.h>

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


#include "cclassf.h"
#include "ctimedta.h"


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


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

UINT cfTimeData ;
CClassFactory cf ;


static const GUID GUID_TimeData = 
{ 0xe7767a70, 0xa409, 0x11ce, { 0xad, 0xf, 0x0, 0x60, 0x8c, 0x86, 0xb8, 0x9c } };

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


int ObjectCount = 0, LockCount = 0 ;
SYSTEMTIME lt ;
CTimeData *lpFirstObj = NULL ;

void CALLBACK TimerProc (HWND hWnd, UINT umsg, UINT id, DWORD time)
{
	GetLocalTime (&lt) ;

	if (lpFirstObj)
	{
		lpFirstObj->SendDataChangeToClient( )  ;
	}

}


__declspec (dllexport) BOOL WINAPI DllMain (HINSTANCE hInst, DWORD why, LPVOID reserved)
{
	static UINT TimerID ;

	MessageBeep (0) ;

	if (why == DLL_PROCESS_ATTACH)
	{				
/*
Set timer for regular notifications
*/
		TimerID = SetTimer (NULL, 0, 1000, (TIMERPROC) TimerProc) ;


/*
Register private clipboard format
*/

		cfTimeData = RegisterClipboardFormat ("TimeDataObject") ;
	}
	else if (why == DLL_PROCESS_DETACH)
	{
		KillTimer (NULL, TimerID) ;
	}


	return TRUE ;
}



STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID FAR* ppv)
{

/*
Check to make sure that COM is asking for the CLSID that we support.
Maybe someone got the registry entry wrong.
*/

	if (rclsid !=  GUID_TimeData)
	{
		return E_FAIL ;
	}

/*
Take our hard-wired class factory and call QueryInterface on it, on
behalf of the COM that called this function.
*/

	return cf.QueryInterface (riid, ppv) ;

}					 

STDAPI DllCanUnloadNow(void)
{
	if (ObjectCount == 0 && LockCount == 0) 
	{
		return S_OK ;
	}
	else
	{
		return S_FALSE ;
	}

	return 0 ;
}
