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.
/**********************************************************************
- File Name: VsPackage.cpp
- Date: 12/7/2003 6:17:57 PM
- Author: Michael Sheinin
- Description : 
	Implementation of the CVsPackage class.	
- Notes: 

**********************************************************************/
#include "StdAfx.h"
#include "vspackage.h"
#include "ServiceProvider.h"
#include "Dbg.h"


CVsPackage::CVsPackage(void)
{
	m_pRealObject = NULL;
	m_pServiceProvider = NULL;
}

CVsPackage::~CVsPackage(void)
{
	if ( m_pServiceProvider )
	{
		delete m_pServiceProvider; // the object allocated in SetSite()
		m_pServiceProvider = NULL;
	}
	m_pRealObject = NULL;
	CDbg::Trace( "====> CVsPackage Destructor\n" );
}

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

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

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

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

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

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

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

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

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

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

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

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