home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / COMOBJ / UTILCAR.CPP < prev    next >
C/C++ Source or Header  |  1996-12-16  |  24KB  |  728 lines

  1. /*+==========================================================================
  2.   File:      UTILCAR.CPP
  3.  
  4.   Summary:   Implementation file for the aggregatable COUtilityCar COM
  5.              object class.
  6.  
  7.              UTILCAR showcases the construction of the COUtilityCar COM
  8.              object class with the IUnknown, ICar, and IUtility interfaces.
  9.              This is done through Containment reuse of COCar's ICar
  10.              interface features.
  11.  
  12.              For a comprehensive tutorial code tour of this module's
  13.              contents and offerings see the accompanying COMOBJ.TXT
  14.              file.  For more specific technical details on the internal
  15.              workings see the comments dispersed throughout the
  16.              module's source code.
  17.  
  18.   Classes:   COUtilityCar
  19.  
  20.   Functions: none.
  21.  
  22.   Origin:    8-23-95: atrent - Created.
  23.  
  24. ----------------------------------------------------------------------------
  25.   This file is part of the Microsoft ActiveX 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. /*---------------------------------------------------------------------------
  40.   We include WINDOWS.H for all Win32 applications.
  41.   We include OLE2.H because we will make calls to the COM/OLE Libraries.
  42.   We include APPUTIL.H because we will be building this application using
  43.     the convenient Virtual Window and Dialog classes and other
  44.     utility functions in the APPUTIL Library (ie, APPUTIL.LIB).
  45.   We include ICARS.H and CARGUIDS.H for the common car-related Interface
  46.     class, GUID, and CLSID specifications.
  47.   We include COMOBJI.H because it has internal class declarations and
  48.     resource ID definitions specific for this DLL.
  49.   We include COMOBJ.H because it has the interface declarations.
  50.   We include CAR.H because it has the class COCar declarations.
  51.   We include UTILCAR.H because it has the class COUtilityCar declarations.
  52. ---------------------------------------------------------------------------*/
  53. #include <windows.h>
  54. #include <ole2.h>
  55. #include <apputil.h>
  56. #include <icars.h>
  57. #include <carguids.h>
  58. #include "comobji.h"
  59. #include "comobj.h"
  60. #include "car.h"
  61. #include "utilcar.h"
  62.  
  63.  
  64. /*---------------------------------------------------------------------------
  65.   COUtilityCar's implementation of its main COM object class including
  66.   Constructor, Destructor, QueryInterface, AddRef, and Release.
  67. ---------------------------------------------------------------------------*/
  68.  
  69. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  70.   Method:   COUtilityCar::COUtilityCar
  71.  
  72.   Summary:  COUtilityCar Constructor. Note the member initializers:
  73.             "m_ImpICar(this, pUnkOuter)" and "m_ImpIUtility(this,
  74.             pUnkOuter)" which are used to pass the 'this' and
  75.             pUnkOuter pointers of this constructor function to the
  76.             constructors that instantiate the implementations of
  77.             the CImpICar and CImpIUtility interfaces (which are both
  78.             nested inside this present COUtilityCar Object Class.
  79.  
  80.   Args:     IUnknown* pUnkOuter)
  81.               Pointer to the the outer Unknown.  NULL means this COM Object
  82.               is not being Aggregated.  Non NULL means it is being created
  83.               on behalf of an outside COM object that is reusing it via
  84.               aggregation.
  85.  
  86.   Modifies: m_cRefs, m_pUnkOuter.
  87.  
  88.   Returns:  void
  89. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  90. COUtilityCar::COUtilityCar(
  91.   IUnknown* pUnkOuter) :
  92.   m_ImpICar(this, pUnkOuter),
  93.   m_ImpIUtility(this, pUnkOuter)
  94. {
  95.   // Zero the COM object's reference count.
  96.   m_cRefs = 0;
  97.  
  98.   // No AddRef necessary if non-NULL, as we're nested.
  99.   m_pUnkOuter = pUnkOuter;
  100.  
  101.   // Zero the pointer to the contained COCar object's ICar interface.
  102.   m_pICar = NULL;
  103.  
  104.   LOGF1("D: COUtilityCar Constructor. m_pUnkOuter=0x%X.", m_pUnkOuter);
  105.  
  106.   return;
  107. }
  108.  
  109.  
  110. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  111.   Method:   COUtilityCar::~COUtilityCar
  112.  
  113.   Summary:  COUtilityCar Destructor.
  114.  
  115.   Args:     void
  116.  
  117.   Modifies: .
  118.  
  119.   Returns:  void
  120. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  121. COUtilityCar::~COUtilityCar(void)
  122. {
  123.   LOG("D: COUtilityCar::Destructor.");
  124.  
  125.   m_pICar->Release();
  126.  
  127.   return;
  128. }
  129.  
  130.  
  131. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  132.   Method:   COUtilityCar::Init
  133.  
  134.   Summary:  COUtilityCar Initialization method.
  135.  
  136.   Args:     void
  137.  
  138.   Modifies: m_pUnkCar, m_pICar, m_cRefs.
  139.  
  140.   Returns:  HRESULT
  141.               Standard result code. NOERROR for success.
  142. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  143. HRESULT COUtilityCar::Init(void)
  144. {
  145.   HRESULT hr;
  146.  
  147.   LOG("D: COUtilityCar::Init.");
  148.  
  149.   // Create an instance of the COCar object and ask for its ICar
  150.   // interface directly.  We pass NULL for the pUnkOuter because we
  151.   // are not aggregating.  It is here that we are reusing the COCar
  152.   // COM Object through the Containment technique.  We cache the
  153.   // pointer to the ICar interface for later delegation use.  We
  154.   // don't need to AddRef it here because CreateCar does that for us.
  155.   hr = CreateCar(NULL, IID_ICar, (PPVOID) &m_pICar);
  156.  
  157.   return (hr);
  158. }
  159.  
  160.  
  161. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  162.   Method:   COUtilityCar::QueryInterface
  163.  
  164.   Summary:  QueryInterface of the COUtilityCar non-delegating
  165.             IUnknown implementation.
  166.  
  167.   Args:     REFIID riid,
  168.               [in] GUID of the Interface being requested.
  169.             PPVOID ppv)
  170.               [out] Address of the caller's pointer variable that will
  171.               receive the requested interface pointer.
  172.  
  173.   Modifies: .
  174.  
  175.   Returns:  HRESULT
  176. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  177. STDMETHODIMP COUtilityCar::QueryInterface(
  178.                REFIID riid,
  179.                PPVOID ppv)
  180. {
  181.   HRESULT hr = E_NOINTERFACE;
  182.   *ppv = NULL;
  183.  
  184.   if (IID_IUnknown == riid)
  185.   {
  186.     *ppv = this;
  187.     LOG("D: COUtilityCar::QueryInterface. 'this' pIUnknown returned");
  188.   }
  189.   else if (IID_ICar == riid)
  190.   {
  191.     *ppv = &m_ImpICar;
  192.     LOG("D: COUtilityCar::QueryInterface. pICar returned");
  193.   }
  194.   else if (IID_IUtility == riid)
  195.   {
  196.     *ppv = &m_ImpIUtility;
  197.     LOG("D: COUtilityCar::QueryInterface. pIUtility returned");
  198.   }
  199.  
  200.   if (NULL != *ppv)
  201.   {
  202.     // We've handed out a pointer to the interface so obey the COM rules
  203.     //   and AddRef the reference count.
  204.     ((LPUNKNOWN)*ppv)->AddRef();
  205.     hr = NOERROR;
  206.   }
  207.  
  208.   return (hr);
  209. }
  210.  
  211.  
  212. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  213.   Method:   COUtilityCar::AddRef
  214.  
  215.   Summary:  AddRef of the COUtilityCar non-delegating IUnknown implementation.
  216.  
  217.   Args:     void
  218.  
  219.   Modifies: m_cRefs.
  220.  
  221.   Returns:  ULONG
  222.               New value of m_cRefs (COM object's reference count).
  223. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  224. STDMETHODIMP_(ULONG) COUtilityCar::AddRef(void)
  225. {
  226.   m_cRefs++;
  227.  
  228.   LOGF1("D: COUtilityCar::AddRef. New cRefs=%i.", m_cRefs);
  229.  
  230.   return m_cRefs;
  231. }
  232.  
  233.  
  234. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  235.   Method:   COUtilityCar::Release
  236.  
  237.   Summary:  Release of the COUtilityCar non-delegating IUnknown implementation.
  238.  
  239.   Args:     void
  240.  
  241.   Modifies: m_cRefs.
  242.  
  243.   Returns:  ULONG
  244.               New value of m_cRefs (COM object's reference count).
  245. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  246. STDMETHODIMP_(ULONG) COUtilityCar::Release(void)
  247. {
  248.   m_cRefs--;
  249.  
  250.   LOGF1("D: COUtilityCar::Release. New cRefs=%i.", m_cRefs);
  251.  
  252.   if (0 == m_cRefs)
  253.   {
  254.     // We artificially bump the main ref count to prevent reentrancy
  255.     // via the main object destructor.
  256.     m_cRefs++;
  257.     delete this;
  258.   }
  259.  
  260.   return m_cRefs;;
  261. }
  262.  
  263.  
  264. /*---------------------------------------------------------------------------
  265.   COUtilityCar's nested implementation of the ICar interface including
  266.   Constructor, Destructor, QueryInterface, AddRef, Release,
  267.   Shift, Clutch, Speed, and Steer.
  268. ---------------------------------------------------------------------------*/
  269.  
  270. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  271.   Method:   COUtilityCar::CImpICar::CImpICar
  272.  
  273.   Summary:  Constructor for the CImpICar interface instantiation.
  274.  
  275.   Args:     COUtilityCar* pBackObj,
  276.               Back pointer to the parent outer object.
  277.             IUnknown* pUnkOuter)
  278.               Pointer to the outer Unknown.  For delegation.
  279.  
  280.   Modifies: m_cRefI, m_pBackObj, m_pUnkOuter.
  281.  
  282.   Returns:  void
  283. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  284. COUtilityCar::CImpICar::CImpICar(
  285.   COUtilityCar* pBackObj,
  286.   IUnknown* pUnkOuter)
  287. {
  288.   // Init the Interface Ref Count (used for debugging only).
  289.   m_cRefI=0;
  290.  
  291.   // Init the Back Object Pointer to point to the outer object.
  292.   m_pBackObj=pBackObj;
  293.  
  294.   // Init the CImpICar interface's delegating Unknown pointer.  We use
  295.   // the Back Object pointer for IUnknown delegation here if we are not
  296.   // being aggregated.  If we are being aggregated we use the supplied
  297.   // pUnkOuter for IUnknown delegation.  In either case the pointer
  298.   // assignment requires no AddRef because the CImpICar lifetime is
  299.   // quaranteed by the lifetime of the parent object in which
  300.   // CImpICar is nested.
  301.   if (NULL == pUnkOuter)
  302.   {
  303.     m_pUnkOuter = pBackObj;
  304.     LOG("D: COUtilityCar::CImpICar Constructor. Non-Aggregating");
  305.   }
  306.   else
  307.   {
  308.     m_pUnkOuter = pUnkOuter;
  309.     LOG("D: COUtilityCar::CImpICar Constructor. Aggregating");
  310.   }
  311.  
  312.   return;
  313. }
  314.  
  315.  
  316. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  317.   Method:   COUtilityCar::CImpICar::~CImpICar
  318.  
  319.   Summary:  Destructor for the CImpICar interface instantiation.
  320.  
  321.   Args:     void
  322.  
  323.   Modifies: .
  324.  
  325.   Returns:  void
  326. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  327. COUtilityCar::CImpICar::~CImpICar(void)
  328. {
  329.   LOG("D: COUtilityCar::CImpICar Destructor.");
  330.  
  331.   return;
  332. }
  333.  
  334.  
  335. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  336.   Method:   COUtilityCar::CImpICar::QueryInterface
  337.  
  338.   Summary:  The QueryInterface IUnknown member of this ICar interface
  339.             implementation that delegates to m_pUnkOuter, whatever it is.
  340.  
  341.   Args:     REFIID riid,
  342.               [in] GUID of the Interface being requested.
  343.             PPVOID ppv)
  344.               [out] Address of the caller's pointer variable that will
  345.               receive the requested interface pointer.
  346.  
  347.   Modifies: .
  348.  
  349.   Returns:  HRESULT
  350.               Returned by the delegated outer QueryInterface call.
  351. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  352. STDMETHODIMP COUtilityCar::CImpICar::QueryInterface(
  353.                REFIID riid,
  354.                PPVOID ppv)
  355. {
  356.   LOG("D: COUtilityCar::CImpICar::QueryInterface. Delegating.");
  357.  
  358.   // Delegate this call to the outer object's QueryInterface.
  359.   return m_pUnkOuter->QueryInterface(riid, ppv);
  360. }
  361.  
  362.  
  363. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  364.   Method:   COUtilityCar::CImpICar::AddRef
  365.  
  366.   Summary:  The AddRef IUnknown member of this ICar interface
  367.             implementation that delegates to m_pUnkOuter, whatever it is.
  368.  
  369.   Args:     void
  370.  
  371.   Modifies: m_cRefI.
  372.  
  373.   Returns:  ULONG
  374.               Returned by the delegated outer AddRef call.
  375. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  376. STDMETHODIMP_(ULONG) COUtilityCar::CImpICar::AddRef(void)
  377. {
  378.   // Increment the Interface Reference Count.
  379.   ++m_cRefI;
  380.  
  381.   LOGF1("D: COUtilityCar::CImpICar::Addref. Delegating. New cI=%i.", m_cRefI);
  382.  
  383.   // Delegate this call to the outer object's AddRef.
  384.   return m_pUnkOuter->AddRef();
  385. }
  386.  
  387.  
  388. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  389.   Method:   COUtilityCar::CImpICar::Release
  390.  
  391.   Summary:  The Release IUnknown member of this ICar interface
  392.             implementation that delegates to m_pUnkOuter, whatever it is.
  393.  
  394.   Args:     void
  395.  
  396.   Modifies: .
  397.  
  398.   Returns:  ULONG
  399.               Returned by the delegated outer Release call.
  400. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  401. STDMETHODIMP_(ULONG) COUtilityCar::CImpICar::Release(void)
  402. {
  403.   // Decrement the Interface Reference Count.
  404.   --m_cRefI;
  405.  
  406.   LOGF1("D: COUtilityCar::CImpICar::Release. Delegating. New cI=%i.", m_cRefI);
  407.  
  408.   // Delegate this call to the outer object's Release.
  409.   return m_pUnkOuter->Release();
  410. }
  411.  
  412.  
  413. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  414.   Method:   COUtilityCar::CImpICar::Shift
  415.  
  416.   Summary:  The Shift member method of this ICar interface implementation.
  417.             A simple empty method on a COUtilityCar COM object for tutorial
  418.             purposes.  Presumably if this Car object were modeling
  419.             a real Car then the Shift method would shift to the specified
  420.             gear.
  421.  
  422.   Args:     short nGear
  423.               0 - Neutral; 1 - 5 First 5 forward gears; 6 - Reverse.
  424.  
  425.   Modifies: .
  426.  
  427.   Returns:  HRESULT
  428.               NOERROR
  429. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  430. STDMETHODIMP COUtilityCar::CImpICar::Shift(
  431.                short nGear)
  432. {
  433.   LOGF1("D: COUtilityCar::CImpICar::Shift. Delegating. nGear=%i.",nGear);
  434.  
  435.   m_pBackObj->m_pICar->Shift(nGear);
  436.  
  437.   return NOERROR;
  438. }
  439.  
  440.  
  441. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  442.   Method:   COUtilityCar::CImpICar::Clutch
  443.  
  444.   Summary:  The Clutch member method of this ICar interface implementation.
  445.             A simple empty method on a COUtilityCar COM object for tutorial
  446.             purposes.  Presumably if this Car object were modeling
  447.             a real Car then the Clutch method would engage the clutch the
  448.             specified amount.
  449.  
  450.   Args:     short nEngaged)
  451.               Percent clutch is engaged (0 to 100%).
  452.  
  453.   Modifies: .
  454.  
  455.   Returns:  HRESULT
  456.               NOERROR
  457. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  458. STDMETHODIMP COUtilityCar::CImpICar::Clutch(
  459.                short nEngaged)
  460. {
  461.   LOGF1("D: COUtilityCar::CImpICar::Clutch. Delegating. nEngaged=%i.",nEngaged);
  462.  
  463.   m_pBackObj->m_pICar->Clutch(nEngaged);
  464.  
  465.   return NOERROR;
  466. }
  467.  
  468.  
  469. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  470.   Method:   COUtilityCar::CImpICar::Speed
  471.  
  472.   Summary:  The Propel member method of this ICar interface implementation.
  473.             A simple empty method on a COUtilityCar COM object for tutorial
  474.             purposes.  Presumably if this Car object were modeling
  475.             a real Car then this method would accelerate/brake to bring
  476.             the car to the specified speed.
  477.  
  478.   Args:     short nMph
  479.               New speed in miles per hour.
  480.  
  481.   Modifies: .
  482.  
  483.   Returns:  HRESULT
  484.               NOERROR
  485. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  486. STDMETHODIMP COUtilityCar::CImpICar::Speed(
  487.                short nMph)
  488. {
  489.   LOGF1("D: COUtilityCar::CImpICar::Speed. Delegating. nMph=%i.",nMph);
  490.  
  491.   m_pBackObj->m_pICar->Speed(nMph);
  492.  
  493.   return NOERROR;
  494. }
  495.  
  496.  
  497. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  498.   Method:   COUtilityCar::CImpICar::Steer
  499.  
  500.   Summary:  The Steer member method of this ICar interface implementation.
  501.             A simple empty method on a COUtilityCar COM object for tutorial
  502.             purposes.  Presumably if this Car object were modeling
  503.             a real Car then the Steer method would set the steering
  504.             angle of the Car.
  505.  
  506.   Args:     short nAngle)
  507.               0 degrees straight ahead, -45 Full left, +45 Full right.
  508.  
  509.   Modifies: .
  510.  
  511.   Returns:  HRESULT
  512.               NOERROR
  513. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  514. STDMETHODIMP COUtilityCar::CImpICar::Steer(
  515.                short nAngle)
  516. {
  517.  LOGF1("D: COUtilityCar::CImpICar::Steer. Delegating. nAngle=%i.",nAngle);
  518.  
  519.   m_pBackObj->m_pICar->Steer(nAngle);
  520.  
  521.   return NOERROR;
  522. }
  523.  
  524.  
  525. /*---------------------------------------------------------------------------
  526.   COUtilityCar's nested implementation of the IUtility interface including
  527.   Constructor, Destructor, QueryInterface, AddRef, Release,
  528.   Offroad, and Winch.
  529. ---------------------------------------------------------------------------*/
  530.  
  531. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  532.   Method:   COUtilityCar::CImpIUtility::CImpIUtility
  533.  
  534.   Summary:  Constructor for the CImpIUtility interface instantiation.
  535.  
  536.   Args:     COUtilityCar* pBackObj,
  537.               Back pointer to the parent outer object.
  538.             IUnknown* pUnkOuter)
  539.               Pointer to the outer Unknown.  For delegation.
  540.  
  541.   Modifies: m_cRefI, m_pBackObj, m_pUnkOuter.
  542.  
  543.   Returns:  void
  544. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  545. COUtilityCar::CImpIUtility::CImpIUtility(
  546.   COUtilityCar* pBackObj,
  547.   IUnknown* pUnkOuter)
  548. {
  549.   // Init the Interface Ref Count (used for debugging only).
  550.   m_cRefI = 0;
  551.  
  552.   // Init the Back Object Pointer to point to the outer object.
  553.   m_pBackObj = pBackObj;
  554.  
  555.   // Init the CImpIUtility interface's delegating Unknown pointer.  We use
  556.   // the Back Object pointer for IUnknown delegation here if we are not
  557.   // being aggregated.  If we are being aggregated we use the supplied
  558.   // pUnkOuter for IUnknown delegation.  In either case the pointer
  559.   // assignment requires no AddRef because the CImpIUtility lifetime is
  560.   // quaranteed by the lifetime of the parent object in which
  561.   // CImpIUtility is nested.
  562.   if (NULL == pUnkOuter)
  563.   {
  564.     m_pUnkOuter = pBackObj;
  565.     LOG("D: COUtilityCar::CImpIUtility Constructor. Non-Aggregating.");
  566.   }
  567.   else
  568.   {
  569.     m_pUnkOuter = pUnkOuter;
  570.     LOG("D: COUtilityCar::CImpIUtility Constructor. Aggregating.");
  571.   }
  572.  
  573.   return;
  574. }
  575.  
  576.  
  577. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  578.   Method:   COUtilityCar::CImpIUtility::~CImpIUtility
  579.  
  580.   Summary:  Destructor for the CImpIUtility interface instantiation.
  581.  
  582.   Args:     void
  583.  
  584.   Modifies: .
  585.  
  586.   Returns:  void
  587. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  588. COUtilityCar::CImpIUtility::~CImpIUtility(void)
  589. {
  590.   LOG("D: COUtilityCar::CImpIUtility Destructor.");
  591.  
  592.   return;
  593. }
  594.  
  595.  
  596. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  597.   Method:   COUtilityCar::CImpIUtility::QueryInterface
  598.  
  599.   Summary:  The QueryInterface IUnknown member of this IUtility interface
  600.             implementation that delegates to m_pUnkOuter, whatever it is.
  601.  
  602.   Args:     REFIID riid,
  603.               [in] GUID of the Interface being requested.
  604.             PPVOID ppv)
  605.               [out] Address of the caller's pointer variable that will
  606.               receive the requested interface pointer.
  607.  
  608.   Modifies: .
  609.  
  610.   Returns:  HRESULT
  611.               Returned by the delegated outer QueryInterface call.
  612. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  613. STDMETHODIMP COUtilityCar::CImpIUtility::QueryInterface(
  614.                REFIID riid,
  615.                PPVOID ppv)
  616. {
  617.   LOG("D: COUtilityCar::CImpIUtility::QueryInterface. Delegating.");
  618.  
  619.   // Delegate this call to the outer object's QueryInterface.
  620.   return m_pUnkOuter->QueryInterface(riid, ppv);
  621. }
  622.  
  623.  
  624. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  625.   Method:   COUtilityCar::CImpIUtility::AddRef
  626.  
  627.   Summary:  The AddRef IUnknown member of this IUtility interface
  628.             implementation that delegates to m_pUnkOuter, whatever it is.
  629.  
  630.   Args:     void
  631.  
  632.   Modifies: m_cRefI.
  633.  
  634.   Returns:  ULONG
  635.               Returned by the delegated outer AddRef call.
  636. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  637. STDMETHODIMP_(ULONG) COUtilityCar::CImpIUtility::AddRef(void)
  638. {
  639.   // Increment the Interface Reference Count.
  640.   ++m_cRefI;
  641.  
  642.   LOGF1("D: COUtilityCar::CImpIUtility::Addref. Delegating. New cI=%i.", m_cRefI);
  643.  
  644.   // Delegate this call to the outer object's AddRef.
  645.   return m_pUnkOuter->AddRef();
  646. }
  647.  
  648.  
  649. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  650.   Method:   COUtilityCar::CImpIUtility::Release
  651.  
  652.   Summary:  The Release IUnknown member of this IUtility interface
  653.             implementation that delegates to m_pUnkOuter, whatever it is.
  654.  
  655.   Args:     void
  656.  
  657.   Modifies: .
  658.  
  659.   Returns:  ULONG
  660.               Returned by the delegated outer Release call.
  661. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  662. STDMETHODIMP_(ULONG) COUtilityCar::CImpIUtility::Release(void)
  663. {
  664.   // Decrement the Interface Reference Count.
  665.   --m_cRefI;
  666.  
  667.   LOGF1("D: COUtilityCar::CImpIUtility::Release. Delegating. New cI=%i.", m_cRefI);
  668.  
  669.   // Delegate this call to the outer object's Release.
  670.   return m_pUnkOuter->Release();
  671. }
  672.  
  673.  
  674. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  675.   Method:   COUtilityCar::CImpIUtility::Offroad
  676.  
  677.   Summary:  The Offroad member method of this IUtility interface
  678.             implementation.  A simple empty method on a COUtilityCar
  679.             COM object for tutorial purposes.  Presumably if this
  680.             UtilityCar object were modeling a real Car then the Offroad
  681.             method would function the 4-wheel drive transfer case and
  682.             shift it to the specified 4-wheel drive mode.
  683.  
  684.   Args:     short nGear
  685.               0 = 2H or regular 2-wheel drive;
  686.               1 = 4H or 4-wheel drive high speed;
  687.               2 = neutral; and
  688.               3 = 4L or 4-wheel drive low speed).
  689.  
  690.   Modifies: .
  691.  
  692.   Returns:  HRESULT
  693.               NOERROR
  694. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  695. STDMETHODIMP COUtilityCar::CImpIUtility::Offroad(
  696.                short nGear)
  697. {
  698.   LOGF1("D: COUtilityCar::CImpIUtility::Offroad. Called. nGear=%i.",nGear);
  699.  
  700.   return NOERROR;
  701. }
  702.  
  703.  
  704. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  705.   Method:   COUtilityCar::CImpIUtility::Winch
  706.  
  707.   Summary:  The Winch member method of this IUtility interface
  708.             implementation.  A simple empty method on a COUtilityCar COM
  709.             object for tutorial purposes.  Presumably if this UtilityCar
  710.             object were modeling a real Car then the Winch method would
  711.             turn on/off the front-mounted Winch to the specified RPMs.
  712.  
  713.   Args:     short nRpm
  714.               0 = off; 1 - 50 RPM.
  715.  
  716.   Modifies: .
  717.  
  718.   Returns:  HRESULT
  719.               NOERROR
  720. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  721. STDMETHODIMP COUtilityCar::CImpIUtility::Winch(
  722.                short nRpm)
  723. {
  724.   LOGF1("D: COUtilityCar::CImpIUtility::Winch. Called. nRpm=%i.",nRpm);
  725.  
  726.   return NOERROR;
  727. }
  728.