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 / chap24 / polyline / iextconn.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  4KB  |  143 lines

  1. /*
  2.  * IEXTCONN.CPP
  3.  * Polyline Component Chapter 23
  4.  *
  5.  * Implementation of IExternalConnection as required for an
  6.  * in-process object that supports linking to embedding.
  7.  * Specifically, this will call IOleObject::Close when there
  8.  * are no more strong locks on the object.
  9.  *
  10.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  11.  *
  12.  * Kraig Brockschmidt, Microsoft
  13.  * Internet  :  kraigb@microsoft.com
  14.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  15.  */
  16.  
  17.  
  18. #include "polyline.h"
  19.  
  20.  
  21. /*
  22.  * CImpIExternalConnection::CImpIExternalConnection
  23.  * CImpIExternalConnection::~CImpIExternalConnection
  24.  *
  25.  * Parameters (Constructor):
  26.  *  pObj            PCPolyline of the object we're in.
  27.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  28.  */
  29.  
  30. CImpIExternalConnection::CImpIExternalConnection(PCPolyline pObj
  31.     , LPUNKNOWN pUnkOuter)
  32.     {
  33.     m_cRef=0;
  34.     m_pObj=pObj;
  35.     m_pUnkOuter=pUnkOuter;
  36.     m_cLockStrong=0L;
  37.     return;
  38.     }
  39.  
  40. CImpIExternalConnection::~CImpIExternalConnection(void)
  41.     {
  42.     return;
  43.     }
  44.  
  45.  
  46.  
  47. /*
  48.  * CImpIExternalConnection::QueryInterface
  49.  * CImpIExternalConnection::AddRef
  50.  * CImpIExternalConnection::Release
  51.  *
  52.  * Purpose:
  53.  *  Delegating IUnknown members for CImpIExternalConnection.
  54.  */
  55.  
  56. STDMETHODIMP CImpIExternalConnection::QueryInterface(REFIID riid
  57.     , LPVOID *ppv)
  58.     {
  59.     return m_pUnkOuter->QueryInterface(riid, ppv);
  60.     }
  61.  
  62.  
  63. STDMETHODIMP_(ULONG) CImpIExternalConnection::AddRef(void)
  64.     {
  65.     ++m_cRef;
  66.     return m_pUnkOuter->AddRef();
  67.     }
  68.  
  69. STDMETHODIMP_(ULONG) CImpIExternalConnection::Release(void)
  70.     {
  71.     --m_cRef;
  72.     return m_pUnkOuter->Release();
  73.     }
  74.  
  75.  
  76.  
  77.  
  78. /*
  79.  * CImpIExternalConnection::AddConnection
  80.  *
  81.  * Purpose:
  82.  *  Informs the object that a strong connection has been made to it.
  83.  *
  84.  * Parameters:
  85.  *  dwConn          DWORD identifying the type of connection, taken
  86.  *                  from the EXTCONN enumeration.
  87.  *  dwReserved      DWORD reserved.  This is used inside OLE and
  88.  *                  should not be validated.
  89.  *
  90.  * Return Value:
  91.  *  DWORD           The number of connection counts on the
  92.  *                  object, used for debugging purposes only.
  93.  */
  94.  
  95. STDMETHODIMP_(DWORD) CImpIExternalConnection::AddConnection
  96.     (DWORD dwConn, DWORD dwReserved)
  97.     {
  98.     if (EXTCONN_STRONG & dwConn)
  99.         return ++m_cLockStrong;
  100.  
  101.     return 0;
  102.     }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. /*
  110.  * CImpIExternalConnection::ReleaseConnection
  111.  *
  112.  * Purpose:
  113.  *  Informs an object that a connection has been taken away from
  114.  *  it in which case the object may need to shut down.
  115.  *
  116.  * Parameters:
  117.  *  dwConn              DWORD identifying the type of connection,
  118.  *                      taken from the EXTCONN enumeration.
  119.  *  dwReserved          DWORD reserved.  This is used inside OLE and
  120.  *                      should not be validated.
  121.  *  dwRerved            DWORD reserved
  122.  *  fLastReleaseCloses  BOOL indicating if the last call to this
  123.  *                      function should close the object.
  124.  *
  125.  * Return Value:
  126.  *  DWORD           The number of remaining connection counts on
  127.  *                  the object, used for debugging purposes only.
  128.  */
  129.  
  130. STDMETHODIMP_(DWORD) CImpIExternalConnection::ReleaseConnection
  131.     (DWORD dwConn, DWORD dwReserved, BOOL fLastReleaseCloses)
  132.     {
  133.     if (EXTCONN_STRONG==dwConn)
  134.         {
  135.         if (0==--m_cLockStrong && fLastReleaseCloses)
  136.             m_pObj->m_pImpIOleObject->Close(OLECLOSE_SAVEIFDIRTY);
  137.  
  138.         return m_cLockStrong;
  139.         }
  140.  
  141.     return 0L;
  142.     }
  143.