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 / locserve / crucar.h < prev    next >
C/C++ Source or Header  |  1997-08-05  |  6KB  |  148 lines

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