home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / APTSERVE / CRUCAR.H < prev    next >
C/C++ Source or Header  |  1996-12-29  |  7KB  |  178 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 Containment 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 APTSERVE.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:    3-20-95: atrent - Editor-inheritance from CRUCAR.H in
  26.                the LOCSERVE Tutorial Code Sample.
  27.  
  28. ----------------------------------------------------------------------------
  29.   This file is part of the Microsoft ActiveX 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 containment
  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.     // We get this ICar interface pointer via containment reuse of the
  86.     // ICar interface in an instantiated COCar.
  87.     ICar*           m_pICar;
  88.  
  89.   private:
  90.     // We declare nested class interface implementations here.
  91.  
  92.     // We implement the basic ICar interface in this COCruiseCar
  93.     // COM object class.
  94.     class CImpICar : public ICar
  95.     {
  96.       public:
  97.         // Interface Implementation Constructor & Destructor.
  98.         CImpICar(COCruiseCar* pBackObj, IUnknown* pUnkOuter);
  99.         ~CImpICar(void);
  100.  
  101.         // IUnknown methods.
  102.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  103.         STDMETHODIMP_(ULONG) AddRef(void);
  104.         STDMETHODIMP_(ULONG) Release(void);
  105.  
  106.         // ICar methods.
  107.         STDMETHODIMP Shift(short nGear);
  108.         STDMETHODIMP Clutch(short nEngaged);
  109.         STDMETHODIMP Speed(short nMph);
  110.         STDMETHODIMP Steer(short nAngle);
  111.  
  112.       private:
  113.         // Data private to this COCruiseCar interface implementation of ICar.
  114.         ULONG         m_cRefI;       // Interface Ref Count (for debugging).
  115.         COCruiseCar*  m_pBackObj;    // Parent Object back pointer.
  116.         IUnknown*     m_pUnkOuter;   // Outer unknown for Delegation.
  117.     };
  118.  
  119.     // We implement the ICruise interface (ofcourse) in this COCruiseCar
  120.     // COM object class.  This is the native interface that we are using
  121.     // as an augmentation to the existing COCar COM object class.
  122.     class CImpICruise : public ICruise
  123.     {
  124.       public:
  125.         // Interface Implementation Constructor & Destructor.
  126.         CImpICruise(COCruiseCar* pBackObj, IUnknown* pUnkOuter);
  127.         ~CImpICruise(void);
  128.  
  129.         // IUnknown methods.
  130.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  131.         STDMETHODIMP_(ULONG) AddRef(void);
  132.         STDMETHODIMP_(ULONG) Release(void);
  133.  
  134.         // ICruise methods.
  135.         STDMETHODIMP Engage(BOOL bOnOff);
  136.         STDMETHODIMP Adjust(BOOL bUpDown);
  137.  
  138.       private:
  139.         // Data private to this interface implementation of ICruise.
  140.         ULONG         m_cRefI;       // Interface Ref Count (for debugging).
  141.         COCruiseCar*  m_pBackObj;    // Parent Object back pointer.
  142.         IUnknown*     m_pUnkOuter;   // Outer unknown for Delegation.
  143.     };
  144.  
  145.     // Make the otherwise private and nested ICar and ICruise interface
  146.     // implementations a friend to COM object instantiations of this
  147.     // selfsame COCruiseCar COM object class.
  148.     friend CImpICar;
  149.     friend CImpICruise;
  150.  
  151.     // Private data of COCruiseCar COM objects.
  152.  
  153.     // Nested ICar implementation instantiation.
  154.     CImpICar        m_ImpICar;
  155.  
  156.     // Nested ICruise implementation instantiation.  This ICruise interface
  157.     // is implemented inside this COCruiseCar object as a native interface.
  158.     CImpICruise     m_ImpICruise;
  159.  
  160.     // Main Object reference count.
  161.     ULONG           m_cRefs;
  162.  
  163.     // Outer unknown (aggregation & delegation). Used when this COCruiseCar
  164.     // object is being aggregated.  Otherwise it is used for delegation
  165.     // if this object is reused via containment.
  166.     IUnknown*       m_pUnkOuter;
  167.  
  168.     // Pointer to this component server's control object.
  169.     CServer*        m_pServer;
  170. };
  171.  
  172. typedef COCruiseCar* PCOCruiseCar;
  173.  
  174. #endif // __cplusplus
  175.  
  176.  
  177. #endif // CRUCAR_H
  178.