Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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.
#include "StdAfx.h"
#include "vspackage.h"
#include "ServiceProvider.h"
#include "Dbg.h"

START_IMPL_SPY(IVsPackage,10)

//IUnknown=======================
STDMETHODIMP VP_QueryInterface( void* pThat, REFIID refiid, LPVOID* ppv )
{
	HRESULT hr;
	
	CDbg::Trace( "  IVsPackage::QueryInterface(0x%p, refiid=", pThat );
	CDbg::TraceGuid( refiid );
	CDbg::TraceC( ", [out](?)ppv )\n" );

	CALL_METHOD3(0,pThat,refiid,ppv)
	GET_RET_VAL(hr)
	
	CDbg::Trace( "  IVsPackage::QueryInterface( , , [out] ppv=0x%p ) = 0x%p\n", *ppv, hr );

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

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

STDMETHODIMP_(ULONG) VP_Release(void* pThat)
{
	ULONG uRC;
	CALL_METHOD1(2,pThat)//Release();
	GET_RET_VAL(uRC);
	//CDbg::Trace( "  IVsPackage::Release returned %u\n", uRC );
	return uRC;
}
//IVsPackage=======================
STDMETHODIMP VP_SetSite( void* pThat, IServiceProvider* pSP )
{
	HRESULT hr;

	CDbg::Trace( "  IVsPackage::SetSite(0x%p, (IServiceProvider)pSp=0x%p )\n", pThat, pSP );

	//SET_SPY(IServiceProvider,pSP) cannot spy - not ours object
	CServiceProvider* pMySP = new CServiceProvider;

	if ( pMySP->Attach( pSP ) )
	{
		CDbg::Trace("<--------------->IServiceProvider wrapped: orig=0x%p, new=0x%p\n", pSP, pMySP );
		pSP = pMySP;
	}

	CALL_METHOD2(3,pThat,pSP)//SetSite( (IServiceProvider*)&m_SP );
	GET_RET_VAL(hr)

	CDbg::Trace( "  IVsPackage::SetSite( , ) = %X\n", hr );
	return hr;
}

STDMETHODIMP VP_QueryClose(void* pThat, long* pfCanClose)
{
	HRESULT hr;
	CDbg::Trace( "  IVsPackage::QueryClose(0x%p, *CanClose=%d (0x%p) )\n", pThat, (pfCanClose? *pfCanClose : -100), pfCanClose );
	
	CALL_METHOD2(4,pThat,pfCanClose)//QueryClose( pfCanClose );
	GET_RET_VAL(hr)
	
	CDbg::Trace( "  IVsPackage::QueryClose( , *CanClose=%d) = %X\n", *pfCanClose, hr );
	return hr;
}

STDMETHODIMP VP_Close(void* pThat)
{
	CDbg::Trace( "  IVsPackage::Close( 0x%p )\n", pThat );
	HRESULT hr;

	CALL_METHOD1(5,pThat)//Close( );
	GET_RET_VAL(hr)
	
	CDbg::Trace( "  IVsPackage::Close( ) = %X\n", hr );
	return hr;
}

STDMETHODIMP VP_GetAutomationObject(void* pThat, LPWSTR pszPropName, IDispatch** ppDisp)
{
	HRESULT hr;
	CDbg::Trace( "  IVsPackage::GetAutomationObject(0x%p, propName=%S(0x%p), [out]pp )\n", pThat, pszPropName, pszPropName );

	CALL_METHOD3(6,pThat,pszPropName,ppDisp)//GetAutomationObject( pszPropName, ppDisp );
	GET_RET_VAL(hr)
	
	CDbg::Trace( "  IVsPackage::GetAutomationObject( , ,[out](IDispatch)ppDisp=0x%p ) = %X\n", *ppDisp, hr );
	return hr;
}

STDMETHODIMP VP_CreateTool(void* pThat, GUID* rguidPersistenceSlot)
{
	HRESULT hr;
	CDbg::Trace( "##IVsPackage::CreateTool(0x%p,.. )\n", pThat );

	CALL_METHOD2(7,pThat,rguidPersistenceSlot)//CreateTool( rguidPersistenceSlot );
	GET_RET_VAL(hr)

	CDbg::Trace( "##IVsPackage::CreateTool returned %X, rguid=\n", hr );
	if ( rguidPersistenceSlot )
	{
		CDbg::TraceGuid( *rguidPersistenceSlot );
	}
	return hr;
}

STDMETHODIMP VP_ResetDefaults(void* pThat, unsigned long grfFlags)
{
	HRESULT hr;

	CDbg::Trace( "  IVsPackage::ResetDefaults( 0x%p, flags=0x%X )\n", pThat, grfFlags );

	CALL_METHOD2(8,pThat,grfFlags)//ResetDefaults( grfFlags );
	GET_RET_VAL(hr);
	
	CDbg::Trace( "  IVsPackage::ResetDefaults(, ) = %X\n", hr, grfFlags );
	return hr;
}

STDMETHODIMP VP_GetPropertyPage(void *pThat, GUID* rguidPage, _VSPROPSHEETPAGE* ppage)
{
	HRESULT hr;

	CDbg::Trace( "##IVsPackage::GetPropertyPage(0x%p,..)\n", pThat );
	CALL_METHOD3(9,pThat,rguidPage,ppage)
	GET_RET_VAL(hr);
	CDbg::Trace( "##IVsPackage::GetPropertyPage( ) = %X\n", hr );
	if ( rguidPage )
	{
		CDbg::TraceGuid( *rguidPage );
	}
	return hr;
}

SPY_START_VTBL(10)
	SPY_ENTRY_(VP_QueryInterface,0)
	SPY_ENTRY_(VP_AddRef,1)
	SPY_ENTRY_(VP_Release,2)
	SPY_ENTRY_(VP_SetSite,3)
	SPY_ENTRY_(VP_QueryClose,4)
	SPY_ENTRY_(VP_Close,5)
	SPY_ENTRY_(VP_GetAutomationObject,6)
	SPY_ENTRY_(VP_CreateTool,7)
	SPY_ENTRY_(VP_ResetDefaults,8)
	SPY_ENTRY_(VP_GetPropertyPage,9)
SPY_END_VTBL()

END_IMPL_SPY()

/*D-
CVsPackage::CVsPackage(void)
{
	m_pVP = NULL;
}

CVsPackage::~CVsPackage(void)
{
}

BOOL CVsPackage::Attach( IVsPackage* pVP )
{
	if ( m_pVP == NULL )
	{
		m_pVP = pVP;
		CDbg::Trace( " VsPackage attached (pVP=%p)\n", m_pVP );
		return TRUE;
	}
	return FALSE;
}

// IUnknown
STDMETHODIMP CVsPackage::QueryInterface( REFIID refiid, LPVOID* ppv)
{
	if ( m_pVP )
	{
		HRESULT hr = m_pVP->QueryInterface( refiid, ppv );
		CDbg::Trace( " CVsPackage::QueryInterface returned %X, ptr=%p, REFIID=", hr, *ppv );
		CDbg::TraceGuid( refiid );
		return hr;
	}
	return E_INVALIDARG;
}

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

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

// IVsPackage
STDMETHODIMP CVsPackage::SetSite( IServiceProvider* pSP )
{
	if ( m_pVP )
	{
		if ( pSP ) // pSP supplied by framework(IDE)
		{
			m_SP.Attach( pSP );
			// supply (our) proxy interface for bined:
			HRESULT hr = m_pVP->SetSite( (IServiceProvider*)&m_SP );
			CDbg::Trace( " CVsPackage::SetSite returned %X, pSP=%p\n", hr, pSP );
			return hr;
		}
	}
	return E_INVALIDARG;
}

STDMETHODIMP CVsPackage::QueryClose(long* pfCanClose)
{
	if ( m_pVP )
	{
		if ( pfCanClose )
		{
			CDbg::Trace( " CVsPackage::QueryClose is passed %d\n", *pfCanClose );
		}
		HRESULT hr = m_pVP->QueryClose( pfCanClose );
		CDbg::Trace( " CVsPackage::QueryClose returned %X, CanClose=%d\n", hr,
			(pfCanClose? *pfCanClose : -100) );
		return hr;
	}
	return E_INVALIDARG;
}

STDMETHODIMP CVsPackage::Close()
{
	if ( m_pVP )
	{
		HRESULT hr = m_pVP->Close( );
		CDbg::Trace( " CVsPackage::Close returned %X\n", hr );
		return hr;
	}
	return E_INVALIDARG;
}

STDMETHODIMP CVsPackage::GetAutomationObject(LPWSTR pszPropName, IDispatch** ppDisp)
{
	if ( m_pVP )
	{
		HRESULT hr = m_pVP->GetAutomationObject( pszPropName, ppDisp );
		CDbg::Trace( " CVsPackage::GetAutomationObject returned %X, name=%S\n", hr, pszPropName );
		return hr;
	}
	return E_INVALIDARG;
}

STDMETHODIMP CVsPackage::CreateTool(GUID* rguidPersistenceSlot)
{
	if ( m_pVP )
	{
		HRESULT hr = m_pVP->CreateTool( rguidPersistenceSlot );
		CDbg::Trace( " CVsPackage::CreateTool returned %X, rguid=\n", hr );
		if ( rguidPersistenceSlot )
		{
			CDbg::TraceGuid( *rguidPersistenceSlot );
		}
		return hr;
	}
	return E_INVALIDARG;
}

STDMETHODIMP CVsPackage::ResetDefaults(unsigned long grfFlags)
{
	if ( m_pVP )
	{
		HRESULT hr = m_pVP->ResetDefaults( grfFlags );
		CDbg::Trace( " CVsPackage::ResetDefaults returned %X, flags=%X\n", hr, grfFlags );
		return hr;
	}
	return E_INVALIDARG;
}

STDMETHODIMP CVsPackage::GetPropertyPage(GUID* rguidPage, _VSPROPSHEETPAGE* ppage)
{
	if ( m_pVP )
	{
		HRESULT hr = m_pVP->GetPropertyPage( rguidPage, ppage );
		CDbg::Trace( " CVsPackage::GetPropertyPage returned %X, guid=\n", hr );
		if ( rguidPage )
		{
			CDbg::TraceGuid( *rguidPage );
		}
		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

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.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 21 Dec 2003
Article Copyright 2003 by Michael Sheinin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid