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 / iunknown.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  2KB  |  122 lines

  1. /*
  2.  * IUNKNOWN.CPP
  3.  *
  4.  * Template implementation of a delegating IUnknown.
  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 "iunknown.h"
  15.  
  16.  
  17. /*
  18.  * CImpIUnknown::CImpIUnknown
  19.  * CImpIUnknown::~CImpIUnknown
  20.  *
  21.  * Constructor Parameters:
  22.  *  pObj            LPVOID of the object containing us.
  23.  *  pUnkOuter       LPUNKNOWN to which we blindly delegate
  24.  *                  all IUnknown calls.
  25.  */
  26.  
  27. CImpIUnknown::CImpIUnknown(LPVOID pObj, LPUNKNOWN pUnkOuter)
  28.     {
  29.     m_cRef=0;
  30.     m_pObj=pObj;
  31.  
  32.     /*
  33.      * We don't need to AddRef pUnkOuter since it defines
  34.      * our lifetime.
  35.      */
  36.     m_pUnkOuter=pUnkOuter;
  37.     return;
  38.     }
  39.  
  40.  
  41. CImpIUnknown::~CImpIUnknown(void)
  42.     {
  43.     return;
  44.     }
  45.  
  46.  
  47.  
  48.  
  49. /*
  50.  * CImpIUnknown::QueryInterface
  51.  *
  52.  * Purpose:
  53.  *  Delegate to whoever is providing IUnknown implementations
  54.  *  for this interface.  May be our containing object, may be
  55.  *  a controlling unknown.  We don't care.
  56.  *
  57.  * Parameters:
  58.  *  riid            REFIID being asked for.
  59.  *  ppv             LPVOID * in which to return the interface.
  60.  *
  61.  * Return Value:
  62.  *  HRESULT         NOERROR if successful, otherwise contains
  63.  *                  E_NOINTERFACE.
  64.  */
  65.  
  66. STDMETHODIMP CImpIUnknown::QueryInterface(REFIID riid
  67.     , LPVOID *ppv)
  68.     {
  69.     return m_pUnkOuter->QueryInterface(riid, ppv);
  70.     }
  71.  
  72.  
  73.  
  74.  
  75.  
  76. /*
  77.  * CImpIUnknown::AddRef
  78.  *
  79.  * Purpose:
  80.  *  Increments the interface reference count (for debugging) and
  81.  *  delegates to whoever is controlling this interface.
  82.  *
  83.  * Parameters:
  84.  *  None
  85.  *
  86.  * Return Value:
  87.  *  ULONG           New reference count of the object.
  88.  */
  89.  
  90. STDMETHODIMP_(ULONG) CImpIUnknown::AddRef(void)
  91.     {
  92.     ++m_cRef;
  93.     return m_pUnkOuter->AddRef();
  94.     }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*
  102.  * CImpIUnknown::Release
  103.  *
  104.  * Purpose:
  105.  *  Decrements the interface reference count (for debugging) and
  106.  *  delegates to whoever is controlling this interface.
  107.  *
  108.  * Parameters:
  109.  *  None
  110.  *
  111.  * Return Value:
  112.  *  ULONG           Current reference count after decrement.  If
  113.  *                  this returns zero then the interface is no
  114.  *                  longer valid because the object is dead.
  115.  */
  116.  
  117. STDMETHODIMP_(ULONG) CImpIUnknown::Release(void)
  118.     {
  119.     --m_cRef;
  120.     return m_pUnkOuter->Release();
  121.     }
  122.