Click here to Skip to main content
15,896,453 members
Articles / Programming Languages / C++

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

Rate me:
Please Sign up or sign in to vote.
4.72/5 (20 votes)
20 Dec 200313 min read 63.9K   1.1K   39  
Create a fully integrated document window inside the Visual Studio IDE.
#include "StdAfx.h"
#include "classfactory.h"
#include "VsPackage.h"

START_IMPL_SPY(IClassFactory,5)


STDMETHODIMP CF_QueryInterface( void* pThat, REFIID refiid, LPVOID* ppv )
{
	HRESULT hr;

	CDbg::Trace( " IClassFactory::QueryInterface(%p, refiid=", pThat );
	CDbg::TraceGuid( refiid );
	CDbg::TraceC( "[out]ppv )\n" );

	CALL_METHOD3(0,pThat,refiid,ppv)
	GET_RET_VAL(hr)
	
	CDbg::Trace( " IClassFactory::QueryInterface(,,[out](?)ppv=0x%p ) = %X", *ppv, hr );
	CDbg::TraceGuid( refiid );

	if ( refiid == IID_IVsPackage )
	{
		CDbg::Trace( "###ClassFactory.cpp - NOT PRINTED\n\n" );
	}
	return hr;
}


STDMETHODIMP_(ULONG) CF_AddRef(void* pThat)
{
	ULONG uRC;
	CALL_METHOD1(1,pThat);//AddRef();
	GET_RET_VAL(uRC);
	//CDbg::Trace( " IClassFactory::AddRef returned %u\n", uRC );
	return uRC;
}

STDMETHODIMP_(ULONG) CF_Release(void* pThat)
{
	ULONG uRC;
	CALL_METHOD1(2,pThat)//Release();
	GET_RET_VAL(uRC);
	//CDbg::Trace( " IClassFactory::Release returned %u\n", uRC );
	return uRC;
}

STDMETHODIMP CF_CreateInstance( void* pThat, IUnknown * pUnkOuter, REFIID riid, void ** ppvObject )
{
	HRESULT hr;
	
	CDbg::Trace( " IClassFactory::CreateInstance(0x%p, pUnkOuter, 0x%p, riid=", pThat, pUnkOuter );
	CDbg::TraceGuid( riid );
	CDbg::TraceC( ",[out]ppvObject)\n" );

	CALL_METHOD4(3,pThat,pUnkOuter,riid,ppvObject)//CreateInstance( pUnkOuter, riid, ppvObject );
	GET_RET_VAL(hr)

	if ( riid == IID_IVsPackage )
	{
		SET_SPY(IVsPackage,*ppvObject);
		CDbg::Trace( "<--------------->IVsPackage subclassed: obj=0x%p\n", *ppvObject );
	}

	CDbg::Trace( " IClassFactory::CreateInstance( , , , ppvObject=0x%p )= %X\n", *ppvObject, hr );
	return hr;
}

STDMETHODIMP CF_LockServer( void* pThat, BOOL fLock )
{
	HRESULT hr;
	CALL_METHOD2(4,pThat,fLock)//LockServer( fLock );
	GET_RET_VAL(hr);
	//CDbg::Trace( " ClsF::LockServer returned %X\n", hr );
	return hr;
}

SPY_START_VTBL(5)
	SPY_ENTRY_(CF_QueryInterface,0)
	SPY_ENTRY_(CF_AddRef,1)
	SPY_ENTRY_(CF_Release,2)
	SPY_ENTRY_(CF_CreateInstance,3)
	SPY_ENTRY_(CF_LockServer,4)
SPY_END_VTBL()

END_IMPL_SPY()

//D-
/*
CClassFactory::CClassFactory(void)
{
	m_pCF = NULL;
}

CClassFactory::~CClassFactory(void)
{
}

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

// IUnknown
STDMETHODIMP CClassFactory::QueryInterface( REFIID refiid, LPVOID* ppv )
{
	if ( m_pCF )
	{
		HRESULT hr = m_pCF->QueryInterface( refiid, ppv );
		CDbg::Trace( " ClsF::QueryInterface returned %X, ptr=%p, REFIID=", hr, *ppv );
		CDbg::TraceGuid( refiid );
		if ( refiid == IID_IVsPackage )
		{
			if ( m_VP.Attach( (IVsPackage*)*ppv ) )
			{
				*ppv = &m_VP; // sic
			}
		}
		return hr;
	}
	return E_INVALIDARG;
}

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

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

// IClassFactory
STDMETHODIMP CClassFactory::CreateInstance( IUnknown * pUnkOuter, REFIID riid, void ** ppvObject )
{
	if ( m_pCF )
	{
		HRESULT hr = m_pCF->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_VP.Attach( (IVsPackage*)*ppvObject ) )
			{
				*ppvObject = &m_VP; // sic
			}
		}
		return hr;
	}
	return E_INVALIDARG;
}

STDMETHODIMP CClassFactory::LockServer( BOOL fLock )
{
	if ( m_pCF )
	{
		HRESULT hr = m_pCF->LockServer( fLock );
		CDbg::Trace( " ClsF::LockServer returned %X\n", hr );
		return hr;
	}
	return E_INVALIDARG;
}
*/

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


Written By
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.

Comments and Discussions