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 / aptserve / car.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-05  |  4.6 KB  |  129 lines

  1. /*+==========================================================================
  2.   File:      CAR.H
  3.  
  4.   Summary:   Include file for the aggregatable COCar COM object class.
  5.  
  6.              COCar offers a main IUnknown interface and the ICar
  7.              interface (Car-related features).  This multiple interface
  8.              COM Object Class is achieved via the technique of nested
  9.              classes--the implementation of the ICar interface is
  10.              nested inside of the COCar Class.
  11.  
  12.              For a comprehensive tutorial code tour of this module's
  13.              contents and offerings see the tutorial APTSERVE.HTM file.
  14.              For more specific technical details on the internal workings
  15.              see the comments dispersed throughout the module's source code.
  16.  
  17.   Classes:   COCar.
  18.  
  19.   Functions:
  20.  
  21.   Origin:    3-20-96: atrent - Editor-inheritance from CAR.H in
  22.                the LOCSERVE Tutorial Code Sample.
  23.  
  24. ----------------------------------------------------------------------------
  25.   This file is part of the Microsoft COM Tutorial Code Samples.
  26.  
  27.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  28.  
  29.   This source code is intended only as a supplement to Microsoft
  30.   Development Tools and/or on-line documentation.  See these other
  31.   materials for detailed information regarding Microsoft code samples.
  32.  
  33.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  34.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  35.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  36.   PARTICULAR PURPOSE.
  37. ==========================================================================+*/
  38.  
  39. #if !defined(CAR_H)
  40. #define CAR_H
  41.  
  42. #ifdef __cplusplus
  43.  
  44. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  45.   ObjectClass: COCar
  46.  
  47.   Summary:     COM object class for COCar COM objects.  COM objects of
  48.                this class offer ICar interface features (Shift, Clutch,
  49.                Speed, and Steer).  The mulitple interfaces on this COM
  50.                object are constructed via the nested interface classes
  51.                technique.
  52.  
  53.   Interfaces:  IUnknown
  54.                  Standard interface providing COM object features.
  55.                ICar
  56.                  Basic Car operation features.
  57.  
  58.   Aggregation: Yes, COCar COM Objects are aggregatable by passing
  59.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  60. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  61. class COCar : public IUnknown
  62. {
  63.   public:
  64.     // Main Object Constructor & Destructor.
  65.     COCar(IUnknown* pUnkOuter, CServer* pServer);
  66.     ~COCar(void);
  67.  
  68.     // IUnknown methods. Main object, non-delegating.
  69.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  70.     STDMETHODIMP_(ULONG) AddRef(void);
  71.     STDMETHODIMP_(ULONG) Release(void);
  72.  
  73.   private:
  74.     // We declare nested class interface implementations here.
  75.  
  76.     class CImpICar : public ICar
  77.     {
  78.       public:
  79.         // Interface Implementation Constructor & Destructor.
  80.         CImpICar(COCar* pBackObj, IUnknown* pUnkOuter);
  81.         ~CImpICar(void);
  82.  
  83.         // IUnknown methods.
  84.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  85.         STDMETHODIMP_(ULONG) AddRef(void);
  86.         STDMETHODIMP_(ULONG) Release(void);
  87.  
  88.         // ICar methods.
  89.         STDMETHODIMP Shift(short nGear);
  90.         STDMETHODIMP Clutch(short nEngaged);
  91.         STDMETHODIMP Speed(short nMph);
  92.         STDMETHODIMP Steer(short nAngle);
  93.  
  94.       private:
  95.         // Data private to this COCar interface implementation of ICar.
  96.         ULONG        m_C;            // Method call counter (tutorial use).
  97.         ULONG        m_cRefI;        // Interface Ref Count (debugging use).
  98.         COCar*       m_pBackObj;     // Parent Object back pointer.
  99.         IUnknown*    m_pUnkOuter;    // Outer unknown for Delegation.
  100.     };
  101.  
  102.     // Make the otherwise private and nested ICar interface implementation
  103.     // a friend to COM object instantiations of this selfsame COCar
  104.     // COM object class.
  105.     friend CImpICar;
  106.  
  107.     // Private data of COCar COM objects.
  108.  
  109.     // Nested ICar implementation instantiation.  This ICar interface
  110.     // is instantiated inside this COCar object as a native interface.
  111.     CImpICar         m_ImpICar;
  112.  
  113.     // Main Object reference count.
  114.     ULONG            m_cRefs;
  115.  
  116.     // Outer unknown (aggregation & delegation).
  117.     IUnknown*        m_pUnkOuter;
  118.  
  119.     // Pointer to this component server's control object.
  120.     CServer*         m_pServer;
  121. };
  122.  
  123. typedef COCar* PCOCar;
  124.  
  125. #endif // __cplusplus
  126.  
  127.  
  128. #endif // CAR_H
  129.