home *** CD-ROM | disk | FTP | other *** search
- /*
- * IUnknown.cpp
- * $Header: /bcsample/IFACEDLL/IUNKNOWN.CPP 1 5/28/96 1:12p Dave $
- *
- * Description:
- * The implementation of the CIUnknown interface base class.
- *
- * Notes:
- * <implementation notes go here>
- *
- ***********************************************************************
- *
- * NuMega Technologies, Inc.
- * P.O. Box 7780
- * Nashua, NH 03060
- *
- * (c) Copyright 1994, 1995, 1996 NuMega Technologies, Inc.
- * ALL RIGHTS RESERVED.
- *
- ***********************************************************************
- *
- **********************************************************************/
- #include "IFT_OLE.h"
- #include "IUnknown.h"
- // For each class that is an interface, include it here.
- // IOleWindow
- #include "OleWnd.h"
- // IOleControl
- #include "OleCntrl.h"
- // IDataObject
- #include "DataObj.h"
- // IViewObject
- #include "VwObj.h"
-
- /*----------------------------------------------------------------------
- FUNCTION : CIUnknown :: CIUnknown
- DISCUSSION :
- Constructor for the main IUnknown interface.
- PARAMETERS :
- pUnkOuter - LPUKNOWN of controlling unknown.
- RETURN :
- None.
- ----------------------------------------------------------------------*/
- CIUnknown :: CIUnknown ( LPUNKNOWN pUnkOuter ,
- PFNDESTROYED pfnDestroy )
-
- {
- m_cRef = 0 ;
- m_pUnkOuter = pUnkOuter ;
- m_pfnDestroy = pfnDestroy ;
- for ( int i = 0 ; i < 100 ; i++ )
- {
- m_pInterfaceTable[ i ] = NULL ;
- }
- }
-
- /*----------------------------------------------------------------------
- FUNCTION : CIUnknown :: ~CIUnknown
- DISCUSSION :
- Destructor for the main IUnknown interface.
- PARAMETERS :
- None.
- RETURN :
- None.
- ----------------------------------------------------------------------*/
- CIUnknown :: ~CIUnknown ( void )
- {
- delete m_pInterfaceTable[0] ;
- delete m_pInterfaceTable[1] ;
- delete m_pInterfaceTable[2] ;
- delete m_pInterfaceTable[3] ;
- }
-
- /*----------------------------------------------------------------------
- FUNCTION : CIUnknown :: Init
- DISCUSSION :
- The initialization function for the class. This is where we need to
- do work that could fail. This is called by the class factory when the
- class is created.
- PARAMETERS :
- None.
- RETURN :
- TRUE - The initialization was completed.
- FALSE - There was a problem.
- ----------------------------------------------------------------------*/
- BOOL CIUnknown :: Init ( void )
- {
- // Here is where we allocate all the interfaces that we know about.
- // IOleWindow
- m_pInterfaceTable[ 0 ] =
- (PCInternalQuery)new CIOleWindow ( m_pUnkOuter ,
- this );
- // IOleControl
- m_pInterfaceTable[ 1 ] =
- (PCInternalQuery)new CIOleControl ( m_pUnkOuter ,
- this );
- // IDataObject
- m_pInterfaceTable[ 2 ] =
- (PCInternalQuery)new CIDataObject ( m_pUnkOuter ,
- this );
- // IViewObject
- m_pInterfaceTable[ 3 ] =
- (PCInternalQuery)new CIViewObject ( m_pUnkOuter ,
- this );
-
- return ( TRUE ) ;
- }
-
- /*----------------------------------------------------------------------
- FUNCTION : CIUnknown :: QueryInterface
- DISCUSSION :
- The implementation of the IUnknown::QueryInterface function.
- PARAMETERS :
- riid - The IID of the interface requested.
- ppv - Receives the returned interface.
- RETURN :
- NOERROR - The requested interface is in ppv.
- E_NOINTERFACE - The requested interface is not implemented.
- ----------------------------------------------------------------------*/
- STDMETHODIMP CIUnknown :: QueryInterface ( REFIID riid , PPVOID ppv )
- {
- if ( NULL == ppv )
- {
- return ( E_INVALIDARG ) ;
- }
- // Always set the interface memory location to NULL.
- *ppv = NULL ;
-
- // If it is just the IUnknown, return ourselves.
- if ( IID_IUnknown == riid )
- {
- *ppv = (IUnknown*)this ;
- }
- else
- {
- // For any other interface, pound through the table of other
- // interfaces.
- int i = 0 ;
- do
- {
- PCInternalQuery pClass =
- (PCInternalQuery)m_pInterfaceTable[ i ] ;
- if ( NOERROR == pClass->InternalQueryInterface ( riid ,
- ppv ) )
- {
- break ;
- }
- i++ ;
- } while ( NULL != m_pInterfaceTable[ i ] ) ;
- }
-
- if ( NULL != *ppv )
- {
- ((LPUNKNOWN)*ppv)->AddRef ( ) ;
- return ( NOERROR ) ;
- }
-
- return ( E_NOINTERFACE ) ;
- }
-
- /*----------------------------------------------------------------------
- FUNCTION : CIUnknown :: AddRef
- DISCUSSION :
- The implementation of the IUnknown::AddRef function.
- PARAMETERS :
- None.
- RETURN :
- The new reference count for diagnostic purposes only.
- ----------------------------------------------------------------------*/
- STDMETHODIMP_( ULONG ) CIUnknown :: AddRef ( void )
- {
- m_cRef++ ;
- return ( m_cRef ) ;
- }
-
-
- /*----------------------------------------------------------------------
- FUNCTION : CIUnknown :: Release
- DISCUSSION :
- The implementation of the IUnknown::Release function.
- PARAMETERS :
- None.
- RETURN :
- The new reference count for diagnostic purposes only.
- ----------------------------------------------------------------------*/
- STDMETHODIMP_( ULONG ) CIUnknown :: Release ( void )
- {
- m_cRef-- ;
- if ( 0L != m_cRef )
- {
- return ( m_cRef ) ;
- }
-
- // If we have a notification function to call, do so now.
- if ( NULL != m_pfnDestroy )
- {
- (*m_pfnDestroy ) ( ) ;
- }
-
- delete this ;
- return ( 0 ) ;
- }
-