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: ServiceProvider.cpp
- Date: 12/7/2003 6:22:52 PM
- Author: Michael Sheinin
- Description : 
	Implementation of CServiceProvider class.
- Notes: 
	original package queries for IVsRegisterEditors interface in QueryService
	method. The request intercepted, V-Studio supplied object wrapped, and
	passed back to original "bined.dll" package..
**********************************************************************/
#include "StdAfx.h"
#include "serviceprovider.h"
#include "VsRegisterEditors.h"


CServiceProvider::CServiceProvider(void)
{
	m_pSP = NULL;
	m_pRE = NULL;
}

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

BOOL CServiceProvider::Attach( IServiceProvider* pSP )
{
	if ( m_pSP == NULL )
	{
		m_pSP = pSP;
		return TRUE;
	}
	return FALSE;
}

// IUnknown
STDMETHODIMP CServiceProvider::QueryInterface( REFIID refiid, LPVOID* ppv )
{
	if ( m_pSP )
	{
		CDbg::Trace( "   IServiceProvider::QueryInterface( REFIID=" );
		CDbg::TraceGuid( refiid );
		CDbg::TraceC( ", [out] ppv=0x%p )\n", ppv );
		
		HRESULT hr = m_pSP->QueryInterface( refiid, ppv );
		CDbg::Trace( "   IServiceProvider::QueryInterface( ,[out] *ppv=0x%p ) = %X\n", *ppv, hr );
		return hr;
	}
	return E_INVALIDARG;
}

STDMETHODIMP_(ULONG) CServiceProvider::AddRef(void)
{
	if ( m_pSP )
	{
		ULONG uRC = m_pSP->AddRef();
		return uRC;
	}
	return 0;
}

STDMETHODIMP_(ULONG) CServiceProvider::Release(void)
{
	if ( m_pSP )
	{
		ULONG uRC = m_pSP->Release();
		if ( 0 == uRC )
		{
			m_pSP = NULL;
		}
		return uRC;
	}
	return 0;
}

STDMETHODIMP CServiceProvider::QueryService( REFGUID guidService, REFIID riid, void** ppv)
{
	if ( m_pSP )
	{
		CDbg::Trace( "   IServiceProvider::QueryService( guidSvc=" );
		CDbg::TraceGuid( guidService );
		CDbg::TraceC( ", riid=" );
		CDbg::TraceGuid( riid );
		CDbg::TraceC( ", [out]ppv=0x%p )\n", ppv );

		HRESULT hr = m_pSP->QueryService( guidService, riid, ppv );
		
		if ( riid == IID_IVsRegisterEditors )
		{
			if ( (m_pRE != NULL) && (m_pRE->m_pRealObject == *ppv) )
			{
				*ppv = m_pRE;
			}
			else
			{
				m_pRE = new CVsRegisterEditors;
				if ( m_pRE )
				{
					if ( m_pRE->Attach( (IVsRegisterEditors*)(*ppv) ) )
					{
						*ppv = (void*)m_pRE;
					}
				}
				CDbg::Trace( "<------------->IVsRegisterEditors wrapped: orig=0x%p, new=0x%p\n", m_pRE->m_pRealObject, m_pRE );
			}
		}
		CDbg::Trace( "   IServiceProvider::QueryService(,,[out]*ppv=0x%p ) = %X\n", *ppv, 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

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