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 / licserve / crucar.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-05  |  5.9 KB  |  151 lines

  1. /*+==========================================================================
  2.   File:      CRUCAR.H
  3.  
  4.   Summary:   Include file for the aggregatable COLicCruiseCar COM object
  5.              class.
  6.  
  7.              CRUCAR showcases the construction of the COLicCruiseCar COM
  8.              object class with the IUnknown, ICar, and ICruise interfaces.
  9.              This is done through Aggregation reuse of a COCar COM
  10.              object (specifically providing its ICar interface features).
  11.  
  12.              This multiple interface COM Object Class is achieved via
  13.              the technique of nested classes: the implementation of the
  14.              ICar and ICruise interfaces are nested inside of the
  15.              COLicCruiseCar COM object class.
  16.  
  17.              For a comprehensive tutorial code tour of this module's
  18.              contents and offerings see the tutorial LICSERVE.HTM
  19.              file. For more specific technical details on the internal
  20.              workings see the comments dispersed throughout the module's
  21.              source code.
  22.  
  23.   Classes:   COLicCruiseCar.
  24.  
  25.   Functions: .
  26.  
  27.   Origin:    10-5-95: atrent - Editor-inheritance from CRUCAR.H in
  28.                the DLLSERVE Tutorial Code Sample.
  29.  
  30. ----------------------------------------------------------------------------
  31.   This file is part of the Microsoft COM Tutorial Code Samples.
  32.  
  33.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  34.  
  35.   This source code is intended only as a supplement to Microsoft
  36.   Development Tools and/or on-line documentation.  See these other
  37.   materials for detailed information regarding Microsoft code samples.
  38.  
  39.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  40.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  41.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  42.   PARTICULAR PURPOSE.
  43. ==========================================================================+*/
  44.  
  45. #if !defined(CRUCAR_H)
  46. #define CRUCAR_H
  47.  
  48. #ifdef __cplusplus
  49.  
  50. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  51.   ObjectClass: COLicCruiseCar
  52.  
  53.   Summary:     COM Object Class for COLicCruiseCar COM Objects.  COM
  54.                objects of this class augment COCar COM objects (which
  55.                offer ICar interface features of Shift, Clutch, Speed, and
  56.                Steer) with ICruise interface features (Engage and Adjust).
  57.                This COLicCruiseCar COM object class is constructed by
  58.                aggregation reuse of the COCar COM object class.  The
  59.                mulitple interfaces on this COM object class are
  60.                constructed via the nested interface classes technique.
  61.  
  62.   Interfaces:  IUnknown
  63.                  Standard interface providing COM object features.
  64.                ICar
  65.                  Basic Car operation features.
  66.                ICruise
  67.                  Cruise control features.
  68.  
  69.   Aggregation: Yes, COLicCruiseCar COM objects are aggregatable by passing
  70.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  71. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  72. class COLicCruiseCar : public IUnknown
  73. {
  74.   public:
  75.     // Main Object Constructor & Destructor.
  76.     COLicCruiseCar(IUnknown* pUnkOuter, CServer* pServer);
  77.     ~COLicCruiseCar(void);
  78.  
  79.     // A general method for initializing a newly created COLicCruiseCar.
  80.     HRESULT Init(void);
  81.  
  82.     // IUnknown methods. Main object, non-delegating.
  83.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  84.     STDMETHODIMP_(ULONG) AddRef(void);
  85.     STDMETHODIMP_(ULONG) Release(void);
  86.  
  87.   private:
  88.     // We declare nested class interface implementations here.
  89.  
  90.     // We implement the ICruise interface (ofcourse) in this COLicCruiseCar
  91.     // COM object class.  This is the interface that we are using as an
  92.     // augmentation to the existing COCar COM object class.
  93.     class CImpICruise : public ICruise
  94.     {
  95.       public:
  96.         // Interface Implementation Constructor & Destructor.
  97.         CImpICruise(COLicCruiseCar* pBackObj, IUnknown* pUnkOuter);
  98.         ~CImpICruise(void);
  99.  
  100.         // IUnknown methods.
  101.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  102.         STDMETHODIMP_(ULONG) AddRef(void);
  103.         STDMETHODIMP_(ULONG) Release(void);
  104.  
  105.         // ICruise methods.
  106.         STDMETHODIMP Engage(BOOL bOnOff);
  107.         STDMETHODIMP Adjust(BOOL bUpDown);
  108.  
  109.       private:
  110.         // Data private to this interface implementation of ICruise.
  111.         ULONG            m_cRefI;       // Interface Ref Count (debugging).
  112.         COLicCruiseCar*  m_pBackObj;    // Parent Object back pointer.
  113.         IUnknown*        m_pUnkOuter;   // Outer unknown for Delegation.
  114.     };
  115.  
  116.     // Make the otherwise private and nested ICar interface implementation
  117.     // a friend to COM object instantiations of this selfsame COLicCruiseCar
  118.     // COM object class.
  119.     friend CImpICruise;
  120.  
  121.     // Private data of COLicCruiseCar COM objects.
  122.  
  123.     // Nested ICruise implementation instantiation.  This ICruise interface
  124.     // is implemented inside this COLicCruiseCar object as a native
  125.     // interface.
  126.     CImpICruise     m_ImpICruise;
  127.  
  128.     // Main Object reference count.
  129.     ULONG           m_cRefs;
  130.  
  131.     // Outer unknown (aggregation & delegation). Used when this
  132.     // COLicCruiseCar object is being aggregated.  Otherwise it is used for
  133.     // delegation if this object is reused via containment.
  134.     IUnknown*       m_pUnkOuter;
  135.  
  136.     // We need to save the IUnknown interface pointer on the COCar
  137.     // object that we aggregate.  We use this when we need to delegate
  138.     // IUnknown calls to this aggregated inner object.
  139.     IUnknown*       m_pUnkCar;
  140.  
  141.     // Pointer to this component server's control object.
  142.     CServer*        m_pServer;
  143. };
  144.  
  145. typedef COLicCruiseCar* PCOLicCruiseCar;
  146.  
  147. #endif // __cplusplus
  148.  
  149.  
  150. #endif // CRUCAR_H
  151.