www.pudn.com > TVToolbar_demo > ClsFact.cpp
/////////////////////////////////////////////////////////////////////////////
// ClsFact.cpp - CClassFactory Implementation
//
/////////////////////////////////////////////////////////////////////////////
//
/**************************************************************
** __ __
** __/_/__________________________________________\_\__
** __|_ |__
** (___O) William SerGio & Co., Inc. (O___)
**(_____O) www.codearchive.com/~sergio (O_____)
**(_____O) Author: Bill SerGio (O_____)
** (__O) (O__)
** |___________________________________________________|
****************************************************************/
/*
* (C) Copyright 1997-1999 by William SerGio, All Rights Reserved Worldwide.
* 20547 Old Cutler Road, PMB #222, Miami, FL 33189
* www.codearchive.com/~sergio sergio@codearchive.com (305)233-7654
* NO PART of this code may be used for any comercial purposes whatsoever.
* Patents Pending regarding design and user interface concepts embodied herein.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted under this non-exclusive license for NON-COMMERCIAL USE ONLY
* provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Licensee does not utilize the software in a manner which is disparaging
* to the Author and/or any products or companies of the Author.
* 4. This code/software may NOT be used for any commercial purpose whatsoever
* or by any government, federal agency, or, any employee or agent of any
* government or federal agency. This software is not designed or intended for
* use in on-line control of aircraft, air traffic, aircraft navigation or
* aircraft communications; or in design, construction, operation or maintenance
* of any nuclear facility. Licensee represents and warrants that it will not use
* or redistribute the Software for such purposes.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR FOR EDUCATIONAL PURPOSES ONLY,
* 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS,
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION),
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* NOTICE:
* Contact author regarding commercial licensing of this code.
* The marks: TV Toolbar(tm), TVToolbar(tm), 3D TV Toolbar(tm), 3D TVToolbar(tm),
* SlickSkins(tm), VideoSkins(tm), LiquidVideo(tm), Email Anywhere(tm), SpeedE(tm),
* Windows SuperCharger(tm), Internet SuperCharger(tm), 1st Place(tm), SpeedD(tm),
* Speed Demon(tm), LiquidDesktop(tm), VideoAnywhere(tm) are copyrights and trademarks
* of William SerGio & Co., Inc. and may NOT be used in any way whatsoever.
*
*/
#include "stdafx.h"
#include "resource.h"
#include "ClsFact.h"
#include "Guid.h"
///////////////////////////////////////////////////////////////////////////
// IClassFactory Methods
//
CClassFactory::CClassFactory(CLSID clsid)
: m_cRef(1),
m_clsidObject(clsid)
{
InterlockedIncrement(&g_cDllRefCount);
}
CClassFactory::~CClassFactory()
{
InterlockedDecrement(&g_cDllRefCount);
}
STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, LPVOID* ppvObject)
{
*ppvObject = NULL;
if (IsEqualIID(riid, IID_IUnknown))
*ppvObject = this;
else if(IsEqualIID(riid, IID_IClassFactory))
*ppvObject = static_cast(this);
if (*ppvObject)
{
static_cast(*ppvObject)->AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) CClassFactory::AddRef()
{
return InterlockedIncrement(&m_cRef);
}
STDMETHODIMP_(ULONG) CClassFactory::Release()
{
if (0 == InterlockedDecrement(&m_cRef))
{
delete this;
return 0;
}
return m_cRef;
}
STDMETHODIMP CClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppvObject)
{
HRESULT hr = E_FAIL;
LPVOID pTemp = NULL;
*ppvObject = NULL;
if (pUnkOuter != NULL)
return CLASS_E_NOAGGREGATION;
// Create proper object, it feels so good!
//
if (IsEqualCLSID(m_clsidObject, CLSID_WBToolBar))
{
CWBToolBar* pWBToolBar = new CWBToolBar();
if (NULL == pWBToolBar)
return E_OUTOFMEMORY;
pTemp = pWBToolBar;
}
if (pTemp)
{
// Become a queer, and QI for requested interface
//
hr = (static_cast(pTemp))->QueryInterface(riid, ppvObject);
// Call release to go down on the wet ref count
//
(static_cast(pTemp))->Release();
}
return hr;
}
STDMETHODIMP CClassFactory::LockServer(BOOL)
{
return E_NOTIMPL;
}