home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / tutsamp / conclien / sink.h < prev   
C/C++ Source or Header  |  1997-08-05  |  5KB  |  131 lines

  1. /*+==========================================================================
  2.   File:      SINK.H
  3.  
  4.   Summary:   Include file for the COBallSink COM object class.
  5.  
  6.              COBallSink offers a main IUnknown interface and the IBallSink
  7.              interface (outgoing connection events from moving COBall
  8.              objects). This multiple interface COM Object Class is
  9.              achieved via the technique of nested classes.  The
  10.              implementation of the IBallSink interface is nested inside of
  11.              the COBallSink Class.
  12.  
  13.              For a comprehensive tutorial code tour of this module's
  14.              contents and offerings see the tutorial CONCLIEN.HTM file.
  15.              For more specific technical details on the internal workings
  16.              see the comments dispersed throughout the module's source code.
  17.  
  18.   Functions:
  19.  
  20.   Classes:   COBallSink.
  21.  
  22.   Origin:    6-3-96: atrent - Editor-inheritance from BALL.H in the
  23.              CONSERVE Tutorial Code Sample.
  24.  
  25. ----------------------------------------------------------------------------
  26.   This file is part of the Microsoft COM Tutorial Code Samples.
  27.  
  28.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  29.  
  30.   This source code is intended only as a supplement to Microsoft
  31.   Development Tools and/or on-line documentation.  See these other
  32.   materials for detailed information regarding Microsoft code samples.
  33.  
  34.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  35.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  36.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  37.   PARTICULAR PURPOSE.
  38. ==========================================================================+*/
  39.  
  40. #if !defined(SINK_H)
  41. #define SINK_H
  42.  
  43. #ifdef __cplusplus
  44.  
  45.  
  46. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  47.   ObjectClass: COBallSink
  48.  
  49.   Summary:     The main Sink COM object class for COBallSink COM objects.
  50.                COM objects of this class offer the IBallSink sink
  51.                interface supporting various ball bounce events. The
  52.                mulitple interfaces on this COM object are constructed via
  53.                the nested interface classes technique.
  54.  
  55.   Interfaces:  IUnknown
  56.                  Standard interface providing COM object features.
  57.                IBallSink
  58.                  Sink interface for Ball events.
  59.  
  60.   Aggregation: Yes, COBall COM Objects are aggregatable by passing
  61.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  62. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  63. class COBallSink : public IUnknown
  64. {
  65.   public:
  66.     // Main Object Constructor & Destructor.
  67.     COBallSink(IUnknown* pUnkOuter, CGuiBall* pGuiBall);
  68.     ~COBallSink(void);
  69.  
  70.     // IUnknown methods. Main object, non-delegating.
  71.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  72.     STDMETHODIMP_(ULONG) AddRef(void);
  73.     STDMETHODIMP_(ULONG) Release(void);
  74.  
  75.   private:
  76.     // We declare nested class interface implementations here.
  77.  
  78.     class CImpIBallSink : public IBallSink
  79.     {
  80.       public:
  81.         // Interface Implementation Constructor & Destructor.
  82.         CImpIBallSink(COBallSink* pBackObj, IUnknown* pUnkOuter);
  83.         ~CImpIBallSink(void);
  84.  
  85.         // IUnknown methods.
  86.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  87.         STDMETHODIMP_(ULONG) AddRef(void);
  88.         STDMETHODIMP_(ULONG) Release(void);
  89.  
  90.         // IBallSink methods.
  91.         STDMETHODIMP         BounceBottom(void);
  92.         STDMETHODIMP         BounceLeft(void);
  93.         STDMETHODIMP         BounceRight(void);
  94.         STDMETHODIMP         BounceTop(void);
  95.  
  96.       private:
  97.         // Data private to this interface implementation of IBallSink.
  98.         COBallSink*  m_pBackObj;     // Parent Object back pointer.
  99.         IUnknown*    m_pUnkOuter;    // Outer unknown for Delegation.
  100.     };
  101.  
  102.     // Make the otherwise private and nested IBallSink interface
  103.     // implementation a friend to COM object instantiations of this
  104.     // COBallSink COM object class.
  105.     friend CImpIBallSink;
  106.  
  107.     // Private data of COBallSink COM objects.
  108.  
  109.     // Nested IBallSink implementation instantiation.  This IBallSink
  110.     // interface is instantiated inside this COBallSink object as a
  111.     // native interface.
  112.     CImpIBallSink    m_ImpIBallSink;
  113.  
  114.     // Main Object reference count.
  115.     ULONG            m_cRefs;
  116.  
  117.     // Outer unknown (aggregation delegation). Used when this COM object
  118.     // is being aggregated.
  119.     IUnknown*        m_pUnkOuter;
  120.  
  121.     // Pointer to the main object that can service the Sink events.
  122.     CGuiBall*        m_pGuiBall;
  123. };
  124.  
  125. typedef COBallSink* PCOBallSink;
  126.  
  127. #endif // __cplusplus
  128.  
  129.  
  130. #endif // SINK_H
  131.