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 / car.h < prev    next >
C/C++ Source or Header  |  1997-08-05  |  5KB  |  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 LOCSERVE.HTM file.
  14.              For more specific technical details on the internal workings
  15.              see the comments dispersed throughout the module's source
  16.              code.
  17.  
  18.   Classes:   COCar.
  19.  
  20.   Functions:
  21.  
  22.   Origin:    11-14-95: atrent - Editor-inheritance from CAR.H in
  23.                the DLLSERVE Tutorial Code Sample.
  24.  
  25. ----------------------------------------------------------------------------
  26.   This file is part of the Microsoft COM Tutorial Code Samples.
  27.  
  28.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  29.  
  30.   This source code is intended only as a supplement to Microsoft
  31.   Development Tools and/or on-line documentation.  See these other
  32.   materials for detailed information regarding Microsoft code samples.
  33.  
  34.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  35.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  36.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  37.   PARTICULAR PURPOSE.
  38. ==========================================================================+*/
  39.  
  40. #if !defined(CAR_H)
  41. #define CAR_H
  42.  
  43. #ifdef __cplusplus
  44.  
  45. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  46.   ObjectClass: COCar
  47.  
  48.   Summary:     COM object class for COCar COM objects.  COM objects of
  49.                this class offer ICar interface features (Shift, Clutch,
  50.                Speed, and Steer).  The mulitple interfaces on this COM
  51.                object are constructed via the nested interface classes
  52.                technique.
  53.  
  54.   Interfaces:  IUnknown
  55.                  Standard interface providing COM object features.
  56.                ICar
  57.                  Basic Car operation features.
  58.  
  59.   Aggregation: Yes, COCar COM Objects are aggregatable by passing
  60.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  61. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  62. class COCar : public IUnknown
  63. {
  64.   public:
  65.     // Main Object Constructor & Destructor.
  66.     COCar(IUnknown* pUnkOuter, CServer* pServer);
  67.     ~COCar(void);
  68.  
  69.     // IUnknown methods. Main object, non-delegating.
  70.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  71.     STDMETHODIMP_(ULONG) AddRef(void);
  72.     STDMETHODIMP_(ULONG) Release(void);
  73.  
  74.   private:
  75.     // We declare nested class interface implementations here.
  76.  
  77.     class CImpICar : public ICar
  78.     {
  79.       public:
  80.         // Interface Implementation Constructor & Destructor.
  81.         CImpICar(COCar* pBackObj, IUnknown* pUnkOuter);
  82.         ~CImpICar(void);
  83.  
  84.         // IUnknown methods.
  85.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  86.         STDMETHODIMP_(ULONG) AddRef(void);
  87.         STDMETHODIMP_(ULONG) Release(void);
  88.  
  89.         // ICar methods.
  90.         STDMETHODIMP Shift(short nGear);
  91.         STDMETHODIMP Clutch(short nEngaged);
  92.         STDMETHODIMP Speed(short nMph);
  93.         STDMETHODIMP Steer(short nAngle);
  94.  
  95.       private:
  96.         // Data private to this COCar interface implementation of ICar.
  97.         ULONG        m_cRefI;        // Interface Ref Count (for debugging).
  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.