/*
*********************************************************************
*
*	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
*
**********************************************************************
*/

// safecntrl.cpp : Implementation of CSafecntrlApp and DLL registration.

#include "stdafx.h"
#include "safecntrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CSafecntrlApp NEAR theApp;

const GUID CDECL BASED_CODE _tlid =
		{ 0x4b3c0650, 0xbd2, 0x11d0, { 0x8b, 0xfd, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3 } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;


////////////////////////////////////////////////////////////////////////////
// CSafecntrlApp::InitInstance - DLL initialization

BOOL CSafecntrlApp::InitInstance()
{
	BOOL bInit = COleControlModule::InitInstance();

	if (bInit)
	{
		// TODO: Add your own module initialization code here.
	}

	return bInit;
}


////////////////////////////////////////////////////////////////////////////
// CSafecntrlApp::ExitInstance - DLL termination

int CSafecntrlApp::ExitInstance()
{
	// TODO: Add your own module termination code here.

	return COleControlModule::ExitInstance();
}


/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

#include <objsafe.h>
#include <comcat.h>

STDAPI DllRegisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
		return ResultFromScode(SELFREG_E_CLASS);

/*
Register control component categories.
*/
    ICatRegister* pcr = NULL ;

    HRESULT hr = CoCreateInstance(
		CLSID_StdComponentCategoriesMgr, 
		NULL, CLSCTX_INPROC_SERVER, 
		IID_ICatRegister, (void**)&pcr);
    
	if (SUCCEEDED(hr))
    {
		static const GUID guid = {	0x4b3c0653, 0xbd2, 0x11d0, {0x8b, 0xfd, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3}} ;
		CATID catid[2] ;
		catid[0] = CATID_SafeForScripting ;
		catid[1] = CATID_SafeForInitializing ;

		hr = pcr->RegisterClassImplCategories(guid, 2, catid);
    }

    if (pcr != NULL)
	{
        pcr->Release();
	}
  



	return NOERROR;
}


/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}
