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 / aptclien / utcrucar.h < prev   
C/C++ Source or Header  |  1997-08-05  |  9KB  |  228 lines

  1. /*+==========================================================================
  2.   File:      UTCRUCAR.H
  3.  
  4.   Summary:   Include file for the aggregatable COUtilityCruiseCar COM
  5.              object class.
  6.  
  7.              UTCRUCAR showcases the construction of the COUtilityCruiseCar
  8.              COM object class with the IUnknown, ICar, ICruise, and
  9.              IUtility interfaces.  This is done through Containment reuse
  10.              of a COCruiseCar COM object (specifically providing its ICar
  11.              and ICruise interface features).  COUtilityCruiseCar adds its
  12.              own native implementation of the IUtility interface.  The
  13.              contained CruiseCar object is implemented in an outside
  14.              APTSERVE.EXE local server.
  15.  
  16.              This multiple interface COM Object Class is achieved via
  17.              the technique of nested classes: the implementation of the
  18.              IUtility interface is nested inside of the COUtilityCruiseCar
  19.              COM object class.
  20.  
  21.              For a comprehensive tutorial code tour of this module's
  22.              contents and offerings see the tutorial APTCLIEN.HTM file.
  23.              For more specific technical details on the internal workings
  24.              see the comments dispersed throughout the module's source
  25.              code.
  26.  
  27.   Classes:   COUtilityCruiseCar.
  28.  
  29.   Functions: .
  30.  
  31.   Origin:    3-20-96: atrent - Editor inheritance from LOCCLIEN source.
  32.  
  33. ----------------------------------------------------------------------------
  34.   This file is part of the Microsoft COM Tutorial Code Samples.
  35.  
  36.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  37.  
  38.   This source code is intended only as a supplement to Microsoft
  39.   Development Tools and/or on-line documentation.  See these other
  40.   materials for detailed information regarding Microsoft code samples.
  41.  
  42.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  43.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  44.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  45.   PARTICULAR PURPOSE.
  46. ==========================================================================+*/
  47.  
  48. #if !defined(UTCRUCAR_H)
  49. #define UTCRUCAR_H
  50.  
  51. #ifdef __cplusplus
  52.  
  53. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  54.   ObjectClass: COUtilityCruiseCar
  55.  
  56.   Summary:     COM Object Class for COUtilityCruiseCar COM Objects.
  57.                COM objects of this class augment COCruiseCar COM objects
  58.                with the IUtility interface features of Offroad and Winch.
  59.                COCruiseCar is reused to offer this COUtilityCruiseCar COM
  60.                Object the ICar interface features of Shift, Clutch, Speed,
  61.                Steer and the ICruise interface features of Engage and
  62.                Adjust.  This COUtilityCruiseCar COM object class is
  63.                constructed by containment reuse of the COCruiseCar COM
  64.                object class.  The mulitple interfaces on this COM object
  65.                class are constructed via the nested class interfaces
  66.                technique.
  67.  
  68.   Interfaces:  IUnknown
  69.                  Standard interface providing COM object features.
  70.                ICar
  71.                  Basic car features.
  72.                ICruise
  73.                  Cruise control system features.
  74.                IUtility
  75.                  Sport-utility Car operation features.  Implemented in
  76.                  this COM object.
  77.  
  78.   Aggregation: Yes, COUtilityCruiseCar COM objects are aggregatable by
  79.                passing a non-NULL pUnkOuter IUnknown pointer into
  80.                the constructor.
  81. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  82. class COUtilityCruiseCar : public IUnknown
  83. {
  84.   public:
  85.     // Main Object Constructor & Destructor.
  86.     COUtilityCruiseCar(IUnknown* pUnkOuter);
  87.     ~COUtilityCruiseCar(void);
  88.  
  89.     // A general method for initializing a newly created UtilityCruiseCar.
  90.     HRESULT Init(void);
  91.  
  92.     // IUnknown members. Main object, non-delegating.
  93.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  94.     STDMETHODIMP_(ULONG) AddRef(void);
  95.     STDMETHODIMP_(ULONG) Release(void);
  96.  
  97.     // We get this ICar interface pointer via containment reuse of the
  98.     // ICar interface in an instantiated COCruiseCar.
  99.     ICar*                m_pICar;
  100.  
  101.     // We get this ICruise interface pointer via containment reuse of the
  102.     // ICruise interface in an instantiated COCruisecar.
  103.     ICruise*             m_pICruise;
  104.  
  105.   private:
  106.     // We declare nested class interface implementations here.
  107.  
  108.     // We implement the ICar interface in this COUtilityCruiseCar COM
  109.     // object class.  This is a delegating interface for the one
  110.     // in the contained COCruiseCar COM object.
  111.     class CImpICar : public ICar
  112.     {
  113.       public:
  114.         // Interface Implementation Constructor & Destructor.
  115.         CImpICar(COUtilityCruiseCar* pBackObj, IUnknown* pUnkOuter);
  116.         ~CImpICar(void);
  117.  
  118.         // IUnknown methods.
  119.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  120.         STDMETHODIMP_(ULONG) AddRef(void);
  121.         STDMETHODIMP_(ULONG) Release(void);
  122.  
  123.         // ICar methods.
  124.         STDMETHODIMP         Shift(short nGear);
  125.         STDMETHODIMP         Clutch(short nEngaged);
  126.         STDMETHODIMP         Speed(short nMph);
  127.         STDMETHODIMP         Steer(short nAngle);
  128.  
  129.       private:
  130.         // Data private to this COUtilityCar interface implementation of ICar.
  131.         ULONG                m_cRefI;     // Interface Ref Count (debugging).
  132.         COUtilityCruiseCar*  m_pBackObj;  // Parent Object back pointer.
  133.         IUnknown*            m_pUnkOuter; // Outer unknown for Delegation.
  134.     };
  135.  
  136.     // We implement the ICruise interface in this COUtilityCruiseCar COM
  137.     // object class.  This ICruise implementation is a delegating
  138.     // interface for the one provided in the contained COCruiseCar COM
  139.     // object.
  140.     class CImpICruise : public ICruise
  141.     {
  142.       public:
  143.         // Interface Implementation Constructor & Destructor.
  144.         CImpICruise(COUtilityCruiseCar* pBackObj, IUnknown* pUnkOuter);
  145.         ~CImpICruise(void);
  146.  
  147.         // IUnknown methods.
  148.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  149.         STDMETHODIMP_(ULONG) AddRef(void);
  150.         STDMETHODIMP_(ULONG) Release(void);
  151.  
  152.         // ICruise methods.
  153.         STDMETHODIMP Engage(BOOL bOnOff);
  154.         STDMETHODIMP Adjust(BOOL bUpDown);
  155.  
  156.       private:
  157.         // Data private to this interface implementation of ICruise.
  158.         ULONG                m_cRefI;     // Interface Ref Count (debugging).
  159.         COUtilityCruiseCar*  m_pBackObj;  // Parent Object back pointer.
  160.         IUnknown*            m_pUnkOuter; // Outer unknown for Delegation.
  161.     };
  162.  
  163.     // We implement the IUtility interface in this COUtilityCruiseCar COM
  164.     // object class.  This is the native interface that we are using as an
  165.     // augmentation to the existing COCruiseCar COM object class.
  166.     class CImpIUtility : public IUtility
  167.     {
  168.       public:
  169.         // Interface Implementation Constructor & Destructor.
  170.         CImpIUtility(COUtilityCruiseCar* pBackObj, IUnknown* pUnkOuter);
  171.         ~CImpIUtility(void);
  172.  
  173.         // IUnknown members.
  174.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  175.         STDMETHODIMP_(ULONG) AddRef(void);
  176.         STDMETHODIMP_(ULONG) Release(void);
  177.  
  178.         // IUtility members.
  179.         STDMETHODIMP Offroad(short nGear);
  180.         STDMETHODIMP Winch(short nRpm);
  181.  
  182.       private:
  183.         // Data private to this interface implementation of IUtility.
  184.         ULONG                m_cRefI;     // Interface Ref Count (debugging).
  185.         COUtilityCruiseCar*  m_pBackObj;  // Parent Object back pointer.
  186.         IUnknown*            m_pUnkOuter; // Outer unknown for Delegation.
  187.     };
  188.  
  189.     // Make the otherwise private and nested IUtility, ICruise, and ICar
  190.     // interface implementations friend instantiations of this class.
  191.     friend CImpICar;
  192.     friend CImpICruise;
  193.     friend CImpIUtility;
  194.  
  195.     // Private data of COUtilityCruiseCar COM objects.
  196.  
  197.     // Nested ICar implementation instantiation.
  198.     CImpICar        m_ImpICar;
  199.  
  200.     // Nested ICruise implementation instantiation.
  201.     CImpICruise     m_ImpICruise;
  202.  
  203.     // Nested IUtility implementation instantiation.  This IUtility
  204.     // interface is implemented inside this COUtilityCruiseCar object
  205.     // as a native interface.
  206.     CImpIUtility    m_ImpIUtility;
  207.  
  208.     // Main Object reference count.
  209.     ULONG           m_cRefs;
  210.  
  211.     // Outer unknown (aggregation & delegation). Used when this
  212.     // COUtilityCruiseCar object is being aggregated.
  213.     IUnknown*       m_pUnkOuter;
  214. };
  215.  
  216. typedef COUtilityCruiseCar* PCOUtilityCruiseCar;
  217.  
  218. // Here is a prototpye for the UtilityCruiseCar Creation function.
  219. HRESULT CreateUtilityCruiseCar(
  220.           IUnknown* pUnkOuter,
  221.           REFIID riid,
  222.           PPVOID ppv);
  223.  
  224. #endif // __cplusplus
  225.  
  226.  
  227. #endif // UTCRUCAR_H
  228.