home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / interfac / iclassf.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  143 lines

  1. /*
  2.  * ICLASSF.CPP
  3.  *
  4.  * Template implementation of a Class Factory object.
  5.  *
  6.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Microsoft
  9.  * Internet  :  kraigb@microsoft.com
  10.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  11.  */
  12.  
  13.  
  14. #include "iclassf.h"
  15.  
  16.  
  17. /*
  18.  * CClassFactory::CClassFactory
  19.  * CClassFactory::~CClassFactory
  20.  *
  21.  * Constructor Parameters:
  22.  *  None
  23.  */
  24.  
  25. CClassFactory::CClassFactory(void)
  26.     {
  27.     m_cRef=0L;
  28.     return;
  29.     }
  30.  
  31.  
  32. CClassFactory::~CClassFactory(void)
  33.     {
  34.     return;
  35.     }
  36.  
  37.  
  38.  
  39.  
  40.  
  41. /*
  42.  * CClassFactory::QueryInterface
  43.  * CClassFactory::AddRef
  44.  * CClassFactory::Release
  45.  *
  46.  * Purpose:
  47.  *  Non-delegating IUnknown members for CClassFactory.
  48.  */
  49.  
  50. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid
  51.     , LPVOID *ppv)
  52.     {
  53.     *ppv=NULL;
  54.  
  55.     if (IID_IUnknown==riid || IID_IClassFactory==riid)
  56.         *ppv=(LPVOID)this;
  57.  
  58.     if (NULL!=*ppv)
  59.         {
  60.         ((LPUNKNOWN)*ppv)->AddRef();
  61.         return NOERROR;
  62.         }
  63.  
  64.     return ResultFromScode(E_NOINTERFACE);
  65.     }
  66.  
  67.  
  68. STDMETHODIMP_(ULONG) CClassFactory::AddRef(void)
  69.     {
  70.     return ++m_cRef;
  71.     }
  72.  
  73.  
  74. STDMETHODIMP_(ULONG) CClassFactory::Release(void)
  75.     {
  76.     if (0L!=--m_cRef)
  77.         return m_cRef;
  78.  
  79.     //Free the object if the reference and lock counts are zero.
  80.     delete this;
  81.     return 0;
  82.     }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. /*
  91.  * CClassFactory::CreateInstance
  92.  *
  93.  * Purpose:
  94.  *  Instantiates an object supported by this class factory.  That
  95.  *  object must at least support IUnknown.
  96.  *
  97.  *  Derived classes should override this function.
  98.  *
  99.  * Parameters:
  100.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  101.  *                  being used in an aggregation.
  102.  *  riid            REFIID identifying the interface the caller
  103.  *                  desires to have for the new object.
  104.  *  ppvObj          LPVOID * in which to store the desired
  105.  *                  interface pointer for the new object.
  106.  *
  107.  * Return Value:
  108.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  109.  *                  if we cannot support the requested interface.
  110.  */
  111.  
  112. STDMETHODIMP CClassFactory::CreateInstance(LPUNKNOWN pUnkOuter
  113.     , REFIID riid, LPVOID *ppvObj)
  114.     {
  115.     *ppvObj=NULL;
  116.     return ResultFromScode(E_OUTOFMEMORY);
  117.     }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. /*
  125.  * CClassFactory::LockServer
  126.  *
  127.  * Purpose:
  128.  *  Increments or decrements the lock count of the serving
  129.  *  IClassFactory object.  When the lock count is zero and the
  130.  *  reference count is zero we get rid of this object.
  131.  *
  132.  *  DLL objects should override this to affect their DLL ref count.
  133.  *
  134.  * Parameters:
  135.  *  fLock           BOOL specifying whether to increment or
  136.  *                  decrement the lock count.
  137.  */
  138.  
  139. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  140.     {
  141.     return NOERROR;
  142.     }
  143.