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 / dllserve / utilcar.h < prev   
C/C++ Source or Header  |  1997-08-05  |  7KB  |  175 lines

  1. /*+==========================================================================
  2.   File:      UTILCAR.H
  3.  
  4.   Summary:   Include file for the aggregatable COUtilityCar COM object class.
  5.  
  6.              UTILCAR showcases the construction of the COUtilityCar COM
  7.              object class with the IUnknown, ICar, and IUtility interfaces.
  8.              This is done through Containment reuse of COCar's ICar
  9.              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 IUtility interfaces are nested inside of the
  14.              COUtilityCar COM object class.
  15.  
  16.              For a comprehensive tutorial code tour of this module's
  17.              contents and offerings see the tutorial DLLSERVE.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:   COUtilityCar
  22.  
  23.   Functions: .
  24.  
  25.   Origin:    9-11-95: atrent - Editor-inheritance from UTILCAR.H in
  26.                the COMOBJ 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(UTILCAR_H)
  44. #define UTILCAR_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: COUtilityCar
  50.  
  51.   Summary:     COM Object Class for COUtilityCar 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.                IUtility interface features (Offroad and Winch).  This
  55.                COUtilityCar 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.                IUtility
  65.                  Sport-utility vehicle offroad features.
  66.  
  67.   Aggregation: Yes, COUtilityCar 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 COUtilityCar : public IUnknown
  71. {
  72.   public:
  73.     // Main Object Constructor & Destructor.
  74.     COUtilityCar(IUnknown* pUnkOuter, CServer* pServer);
  75.     ~COUtilityCar(void);
  76.  
  77.     // A general method for initializing a newly created COUtilityCar.
  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 show nested interface class implementations here.
  91.  
  92.     // We implement the basic ICar interface in this COUtilityCar
  93.     // COM object class.
  94.     class CImpICar : public ICar
  95.     {
  96.       public:
  97.         // Interface Implementation Constructor & Destructor.
  98.         CImpICar(COUtilityCar* 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 COUtilityCar interface implementation of ICar.
  114.         ULONG         m_cRefI;       // Interface Ref Count (for debugging).
  115.         COUtilityCar* m_pBackObj;    // Parent Object back pointer.
  116.         IUnknown*     m_pUnkOuter;   // Outer unknown for Delegation.
  117.     };
  118.  
  119.     // We implement the IUtility interface (ofcourse) in this COUtilityCar
  120.     // COM object class.  This is the interface that we are using as an
  121.     // augmentation to the existing COCar COM object class.
  122.     class CImpIUtility : public IUtility
  123.     {
  124.       public:
  125.         // Interface Implementation Constructor & Destructor.
  126.         CImpIUtility(COUtilityCar* pBackObj, IUnknown* pUnkOuter);
  127.         ~CImpIUtility(void);
  128.  
  129.         // IUnknown methods.
  130.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  131.         STDMETHODIMP_(ULONG) AddRef(void);
  132.         STDMETHODIMP_(ULONG) Release(void);
  133.  
  134.         // IUtility methods.
  135.         STDMETHODIMP Offroad(short nGear);
  136.         STDMETHODIMP Winch(short nRpm);
  137.  
  138.       private:
  139.         // Data private to this interface implementation of IUtility.
  140.         ULONG         m_cRefI;       // Interface Ref Count (for debugging).
  141.         COUtilityCar* m_pBackObj;    // Parent Object back pointer.
  142.         IUnknown*     m_pUnkOuter;   // Outer unknown for Delegation.
  143.     };
  144.  
  145.     // Make the otherwise private and nested ICar interface implementation
  146.     // a friend to COM object instantiations of this selfsame COUtilityCar
  147.     // COM object class.
  148.     friend CImpICar;
  149.     friend CImpIUtility;
  150.  
  151.     // Private data of COUtilityCar COM objects.
  152.  
  153.     // Nested ICar implementation instantiation.
  154.     CImpICar        m_ImpICar;
  155.  
  156.     // Nested IUtility implementation instantiation.
  157.     CImpIUtility    m_ImpIUtility;
  158.  
  159.     // Main Object reference count.
  160.     ULONG           m_cRefs;
  161.  
  162.     // Outer unknown (aggregation & delegation).
  163.     IUnknown*       m_pUnkOuter;
  164.  
  165.     // Pointer to this component server's control object.
  166.     CServer*        m_pServer;
  167. };
  168.  
  169. typedef COUtilityCar* PCOUtilityCar;
  170.  
  171. #endif // __cplusplus
  172.  
  173.  
  174. #endif // UTILCAR_H
  175.