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 / car.h < prev    next >
C/C++ Source or Header  |  1997-08-05  |  5KB  |  128 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 DLLSERVE.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:    9-11-95: atrent - Editor-inheritance from CAR.H in
  22.                the COMOBJ 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_cRefI;        // Interface Ref Count (for debugging).
  97.         COCar*       m_pBackObj;     // Parent Object back pointer.
  98.         IUnknown*    m_pUnkOuter;    // Outer unknown for Delegation.
  99.     };
  100.  
  101.     // Make the otherwise private and nested ICar interface implementation
  102.     // a friend to COM object instantiations of this selfsame COCar
  103.     // COM object class.
  104.     friend CImpICar;
  105.  
  106.     // Private data of COCar COM objects.
  107.  
  108.     // Nested ICar implementation instantiation.  This ICar interface
  109.     // is instantiated inside this COCar object as a native interface.
  110.     CImpICar         m_ImpICar;
  111.  
  112.     // Main Object reference count.
  113.     ULONG            m_cRefs;
  114.  
  115.     // Outer unknown (aggregation & delegation).
  116.     IUnknown*        m_pUnkOuter;
  117.  
  118.     // Pointer to this component server's control object.
  119.     CServer*         m_pServer;
  120. };
  121.  
  122. typedef COCar* PCOCar;
  123.  
  124. #endif // __cplusplus
  125.  
  126.  
  127. #endif // CAR_H
  128.