home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / numega / sc501.exe / data1.cab / Examples / EX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  2.1 KB  |  87 lines

  1. /*----------------------------------------------------------------------
  2. Using this file to build other OLE interfaces.....
  3. 0.  Follow the directions in EX.H first.
  4. 1.  Replace the include file "EX.H" with the name of the proper include
  5.     file.
  6. 2.  Place the interface functions at the end of the file.
  7. 3.  Update IUnknown.cpp to include your new class.
  8. 4.  Add your new file to the BuildMak file, rebuild and compile.
  9. ----------------------------------------------------------------------*/
  10.  
  11. #include "Ole2Inc.h"
  12. // Replace this include with yours.
  13. #include "Ex.h"
  14.  
  15. CI* :: CI* ( LPUNKNOWN  pUnkOuter , PCIUnknown pMainIUnk )
  16. {
  17.     m_cRef = 0 ;
  18.     m_pUnkOuter = pUnkOuter ;
  19.     m_pBaseUnk = pMainIUnk ;
  20. }
  21.  
  22. CI* :: ~CI* ( void )
  23. {
  24. }
  25.  
  26. BOOL CI* :: Init ( void )
  27. {
  28.     return ( TRUE ) ;
  29. }
  30.  
  31. STDMETHODIMP_( ULONG ) CI* :: AddRef ( void )
  32. {
  33.     m_cRef++ ;
  34.     return ( m_cRef ) ;
  35. }
  36.  
  37. STDMETHODIMP_( ULONG ) CI* :: Release ( void )
  38. {
  39.     m_cRef-- ;
  40.     if ( 0L != m_cRef )
  41.     {
  42.         return ( m_cRef ) ;
  43.     }
  44.  
  45.     delete this ;
  46.     return ( 0 ) ;
  47. }
  48.  
  49. STDMETHODIMP CI* :: QueryInterface ( REFIID riid ,
  50.                                                     PPVOID ppv   )
  51. {
  52.     *ppv = NULL ;
  53.  
  54.     // Replace IID_I* with the proper IID.
  55.     if ( IID_I* == riid )
  56.     {
  57.         *ppv = (I**)this ;
  58.         ((LPUNKNOWN)*ppv)->AddRef ( ) ;
  59.         return ( NOERROR ) ;
  60.     }
  61.     else
  62.     {
  63.         // We just defer any other calls to the base IUnknown.
  64.         return ( m_pBaseUnk->QueryInterface ( riid , ppv ) ) ;
  65.     }
  66. }
  67.  
  68. STDMETHODIMP CI* :: InternalQueryInterface ( REFIID riid ,
  69.                                                         PPVOID ppv   )
  70. {
  71.     // Always set the interface memory location to NULL.
  72.     *ppv = NULL ;
  73.  
  74.     // If this ID is ours, then return ourselves.
  75.     if ( IID_I* == riid )
  76.     {
  77.         *ppv = (I**)this ;
  78.         return ( NOERROR ) ;
  79.     }
  80.     return ( E_NOINTERFACE ) ;
  81. }
  82.  
  83.  
  84. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. // Place all interface functions here!!
  86.  
  87.