home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / COMOBJ / CAR.H < prev    next >
C/C++ Source or Header  |  1996-12-29  |  5KB  |  127 lines

  1. /*+==========================================================================
  2.   File:      CAR.H
  3.  
  4.   Summary:   Include file for the aggregatable COCar COM object class.
  5.  
  6.              Of particular interest for an COM application, CAR
  7.              showcases a COM Object Class offering a main IUnknown
  8.              interface and the ICar interface (Car-related features).
  9.              This multiple interface COM Object Class is achieved via
  10.              the technique of nested classes.  The implementation of the
  11.              ICar interface is nested inside of the COCar Class.
  12.  
  13.              For a comprehensive tutorial code tour of this module's
  14.              contents and offerings see the tutorial COMOBJ.HTM
  15.              file.  For more specific technical details on the internal
  16.              workings see the comments dispersed throughout the
  17.              module's source code.
  18.  
  19.   Classes:   COCar
  20.  
  21.   Functions:
  22.  
  23.   Origin:    8-17-95: atrent - Created.
  24.  
  25. ----------------------------------------------------------------------------
  26.   This file is part of the Microsoft ActiveX 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.  
  41. #if !defined(CAR_H)
  42. #define CAR_H
  43.  
  44. #ifdef __cplusplus
  45.  
  46. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  47.   ObjectClass: COCar
  48.  
  49.   Summary:     COM object class for COCar COM objects.  COM objects of
  50.                this class offer ICar interface features (Shift, Clutch,
  51.                Speed, and Steer).  The mulitple interfaces on this COM
  52.                object are constructed via the nested interface classes
  53.                technique.
  54.  
  55.   Interfaces:  IUnknown
  56.                  Standard interface providing COM object features.
  57.                ICar
  58.                  Basic Car operation features.
  59.  
  60.   Aggregation: Yes, COCar COM Objects are aggregatable by passing
  61.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  62. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  63. class COCar : public IUnknown
  64. {
  65.   public:
  66.     // Main Object Constructor & Destructor.
  67.     COCar(IUnknown* pUnkOuter);
  68.     ~COCar(void);
  69.  
  70.     // IUnknown methods. Main object, non-delegating.
  71.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  72.     STDMETHODIMP_(ULONG) AddRef(void);
  73.     STDMETHODIMP_(ULONG) Release(void);
  74.  
  75.   private:
  76.     // We declare nested class interface implementations here.
  77.  
  78.     class CImpICar : public ICar
  79.     {
  80.       public:
  81.         // Interface Implementation Constructor & Destructor.
  82.         CImpICar(COCar* pBackObj, IUnknown* pUnkOuter);
  83.         ~CImpICar(void);
  84.  
  85.         // IUnknown methods.
  86.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  87.         STDMETHODIMP_(ULONG) AddRef(void);
  88.         STDMETHODIMP_(ULONG) Release(void);
  89.  
  90.         // ICar methods.
  91.         STDMETHODIMP Shift(short nGear);
  92.         STDMETHODIMP Clutch(short nEngaged);
  93.         STDMETHODIMP Speed(short nMph);
  94.         STDMETHODIMP Steer(short nAngle);
  95.  
  96.       private:
  97.         // Data private to this COCar interface implementation of ICar.
  98.         ULONG        m_cRefI;        // Interface Ref Count (for debugging).
  99.         COCar*       m_pBackObj;     // Parent Object back pointer.
  100.         IUnknown*    m_pUnkOuter;    // Outer unknown for Delegation.
  101.     };
  102.  
  103.     // Make the otherwise private and nested ICar interface implementation
  104.     // a friend to COM object instantiations of this selfsame COCar
  105.     // COM object class.
  106.     friend CImpICar;
  107.  
  108.     // Private data of COCar COM objects.
  109.  
  110.     // Nested ICar implementation instantiation.  This ICar interface
  111.     // is instantiated inside this COCar object as a native interface.
  112.     CImpICar         m_ImpICar;
  113.  
  114.     // Main Object reference count.
  115.     ULONG            m_cRefs;
  116.  
  117.     // Outer unknown (aggregation & delegation).
  118.     IUnknown*        m_pUnkOuter;
  119. };
  120.  
  121. typedef COCar* PCOCar;
  122.  
  123. #endif // __cplusplus
  124.  
  125.  
  126. #endif // CAR_H
  127.