Click here to Skip to main content
12,300,021 members (48,955 online)
Click here to Skip to main content

Stats

52.7K views
1K downloads
38 bookmarked
Posted

Customized Visual Studio .NET package: your fully integrated document window inside the IDE

, 20 Dec 2003
Create a fully integrated document window inside the Visual Studio IDE.
/**********************************************************************
- File Name: ClassFactory.cpp
- Date: 12/5/2003 1:23:36 PM
- Author: Michael Sheinin
- Description : 
	Implements IClassFactory wrapper.
- Notes: 
	The object life-time: from a first file load to the end of Visual studio
	session.
**********************************************************************/

#include "StdAfx.h"
#include "classfactory.h"
#include "VsPackage.h"

CClassFactory::CClassFactory(void)
{
	m_pRealObject = NULL;
	m_pPackage = NULL;
}

CClassFactory::~CClassFactory(void)
{
	CDbg::Trace( "====> ClassFactory Destructor\n" );
}

void CClassFactory::Attach( IClassFactory* pCF )
{
	if ( m_pRealObject == NULL )
	{
		m_pRealObject = pCF;
		CDbg::Trace( " Class Factory attached (pCF=%p)\n", m_pRealObject );
	}
}

// IUnknown
STDMETHODIMP CClassFactory::QueryInterface( REFIID refiid, LPVOID* ppv )
{
	HRESULT hr = E_INVALIDARG;

	if ( m_pRealObject )
	{
		hr = m_pRealObject->QueryInterface( refiid, ppv );
		CDbg::Trace( " ClsF::QueryInterface returned %X, ptr=%p, REFIID=", hr, *ppv );
		CDbg::TraceGuid( refiid );
	}
	return hr;
}

STDMETHODIMP_(ULONG) CClassFactory::AddRef(void)
{
	ULONG uRC = 0;
	
	if ( m_pRealObject )
	{
		uRC = m_pRealObject->AddRef();
		CDbg::Trace( " ClsF::AddRef returned %u\n", uRC );
	}
	return uRC;
}

STDMETHODIMP_(ULONG) CClassFactory::Release(void)
{
	ULONG uRC = 0;
	
	if ( m_pRealObject )
	{
		uRC = m_pRealObject->Release();
		CDbg::Trace( " ClsF::Release returned %u\n", uRC );
		if ( 0 == uRC )
		{
			delete this;
		}
	}
	return uRC;
}

// IClassFactory
STDMETHODIMP CClassFactory::CreateInstance( IUnknown * pUnkOuter, REFIID riid, void ** ppvObject )
{
	HRESULT hr = E_INVALIDARG;

	if ( m_pRealObject )
	{
		hr = m_pRealObject->CreateInstance( pUnkOuter, riid, ppvObject );
		CDbg::Trace( " ClsF::CreateInstance returned %X, pUnkOuter=%p, ppv=%p, REFIID=", hr, pUnkOuter, *ppvObject );
		CDbg::TraceGuid( riid );
		if ( riid == IID_IVsPackage )
		{
			if ( m_pPackage == NULL )
			{
				m_pPackage = new CVsPackage();
				m_pPackage->Attach( (IVsPackage*)*ppvObject );
			}
			*ppvObject = m_pPackage;
		}
	}
	return hr;
}

STDMETHODIMP CClassFactory::LockServer( BOOL fLock )
{
	HRESULT hr = E_INVALIDARG;

	if ( m_pRealObject )
	{
		hr = m_pRealObject->LockServer( fLock );
		CDbg::Trace( " ClsF::LockServer returned %X\n", hr );
	}
	return hr;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Michael Sheinin
Web Developer
United States United States
For the last 7 years I have developed software in real-time/embedded and MS-Windows environments for military and civil markets. I hold B.Sc. degree in computer engineering. Living in Ontario, Canada, I like hiking and traveling in general. Currently, I'm looking for employment opportunity inside the GTA.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 21 Dec 2003
Article Copyright 2003 by Michael Sheinin
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid