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

// CtrlHolder.cpp : implementation file
//

#include "stdafx.h"
#include "script.h"
#include "CtrlHolder.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCtrlHolder

CCtrlHolder::CCtrlHolder(CString ClsidString)
{
	USES_CONVERSION

	m_ClsidString = ClsidString ;
	CLSIDFromString (A2W((LPCTSTR) ClsidString), &m_Clsid) ;
}

CCtrlHolder::~CCtrlHolder()
{
}


BEGIN_MESSAGE_MAP(CCtrlHolder, CWnd)
	//{{AFX_MSG_MAP(CCtrlHolder)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CCtrlHolder message handlers


/*
My own stuff added for acess to private members
*/

#include <occimpl.h>

HRESULT	CCtrlHolder::GetDispatch (LPDISPATCH * ppOut) 
{
	*ppOut = m_pCtrlSite->m_dispDriver.m_lpDispatch ;
	m_pCtrlSite->m_dispDriver.m_lpDispatch->AddRef( ) ;
	return S_OK ;
}

HRESULT CCtrlHolder::GetTypeInfo (LPTYPEINFO * ppOut)
{
	HKEY hKey, hSubKey ;
	char TypeLibString [256] ;
	long length = sizeof (TypeLibString) ;
	CLSID TypeLibClsid ;
	USES_CONVERSION

	RegOpenKey (HKEY_CLASSES_ROOT, "Clsid", &hKey) ;
	RegOpenKey (hKey, (LPCTSTR) m_ClsidString, &hSubKey) ;
	RegQueryValue (hSubKey, "TypeLib", TypeLibString, &length) ;

	CLSIDFromString (A2W(TypeLibString), &TypeLibClsid) ;
	ITypeLib *pTypeLib;
	LoadRegTypeLib (TypeLibClsid, 1, 0, LOCALE_SYSTEM_DEFAULT, &pTypeLib) ;
	HRESULT hr = pTypeLib->GetTypeInfoOfGuid (m_Clsid, ppOut) ;
	
	return hr ;
}

