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 / factory.h < prev    next >
C/C++ Source or Header  |  1997-08-05  |  12KB  |  313 lines

  1. /*+==========================================================================
  2.   File:      FACTORY.H
  3.  
  4.   Summary:   Include file for the class factory COM objects: CFCar,
  5.              CFUtilityCar, and CFCruiseCar. These constitute the LOCSERVE
  6.              server's Class Factories for those COM components.
  7.  
  8.              The multiple interface COM Object Classes are achieved via
  9.              the technique of nested classes: the implementation of the
  10.              IClassFactory interfaces are nested inside of the class
  11.              factory COM object classes.
  12.  
  13.              For a comprehensive tutorial code tour of this module's
  14.              contents and offerings see the tutorial LOCSERVE.HTM file.
  15.              For more specific technical details on the internal workings
  16.              see the comments dispersed throughout the module's source code.
  17.  
  18.   Classes:   CFCar, CFUtilityCar, CFCruiseCar.
  19.  
  20.   Functions: .
  21.  
  22.   Origin:    11-14-95: atrent - Editor-inheritance from FACTORY.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(FACTORY_H)
  41. #define FACTORY_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: CFCar
  47.  
  48.   Summary:     Class Factory COM Object Class for Car COM components.
  49.                Used to manufacture COCar COM objects.  The mulitple
  50.                interfaces on this COM object class are constructed via
  51.                the nested interface classes technique.
  52.  
  53.   Interfaces:  IUnknown
  54.                  Standard interface providing COM object features.
  55.                IClassFactory
  56.                  Standard interface providing COM Class Factory features.
  57.  
  58.   Aggregation: Yes, CFCar COM objects are aggregatable by
  59.                passing a non-NULL pUnkOuter IUnknown pointer into the
  60.                constructor.
  61. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  62. class CFCar : public IUnknown
  63. {
  64.   public:
  65.     // Main Object Constructor & Destructor.
  66.     CFCar(IUnknown* pUnkOuter, CServer* pServer);
  67.     ~CFCar(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.     // We implement the IClassFactory interface (of-course) in this class
  78.     // factory COM object class.
  79.     class CImpIClassFactory : public IClassFactory
  80.     {
  81.       public:
  82.         // Interface Implementation Constructor & Destructor.
  83.         CImpIClassFactory(
  84.           CFCar* pBackObj,
  85.           IUnknown* pUnkOuter,
  86.           CServer* pServer);
  87.         ~CImpIClassFactory(void);
  88.  
  89.         // IUnknown methods.
  90.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  91.         STDMETHODIMP_(ULONG) AddRef(void);
  92.         STDMETHODIMP_(ULONG) Release(void);
  93.  
  94.         // IClassFactory methods.
  95.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  96.         STDMETHODIMP         LockServer(BOOL);
  97.  
  98.       private:
  99.         // Data private to this interface implementation of IClassFactory.
  100.         ULONG         m_cRefI;       // Interface Ref Count (for debugging).
  101.         CFCar*        m_pBackObj;    // Parent Object back pointer.
  102.         IUnknown*     m_pUnkOuter;   // Outer unknown for Delegation.
  103.         CServer*      m_pServer;     // Server's control object.
  104.     };
  105.  
  106.     // Make the otherwise private and nested IClassFactory interface
  107.     // implementation a friend to COM object instantiations of this
  108.     // selfsame CFCar COM object class.
  109.     friend CImpIClassFactory;
  110.  
  111.     // Private data of CFCar COM objects.
  112.  
  113.     // Nested IClassFactory implementation instantiation.
  114.     CImpIClassFactory m_ImpIClassFactory;
  115.  
  116.     // Main Object reference count.
  117.     ULONG             m_cRefs;
  118.  
  119.     // Outer unknown (aggregation & delegation). Used when this
  120.     // CFCar object is being aggregated.  Otherwise it is used
  121.     // for delegation if this object is reused via containment.
  122.     IUnknown*         m_pUnkOuter;
  123.  
  124.     // Pointer to this component server's control object.
  125.     CServer*          m_pServer;
  126. };
  127.  
  128. typedef CFCar* PCFCar;
  129.  
  130.  
  131. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  132.   ObjectClass: CFUtilityCar
  133.  
  134.   Summary:     Class Factory COM Object Class for UtilityCar COM
  135.                components.  Used to manufacture COUtilityCar COM
  136.                objects.  The mulitple interfaces on this COM object
  137.                class are constructed via the nested interface
  138.                classes technique.
  139.  
  140.   Interfaces:  IUnknown
  141.                  Standard interface providing COM object features.
  142.                IClassFactory
  143.                  Standard interface providing COM Class Factory features.
  144.  
  145.   Aggregation: Yes, CFUtilityCar COM objects are aggregatable by
  146.                passing a non-NULL pUnkOuter IUnknown pointer into the
  147.                constructor.
  148. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  149. class CFUtilityCar : public IUnknown
  150. {
  151.   public:
  152.     // Main Object Constructor & Destructor.
  153.     CFUtilityCar(IUnknown* pUnkOuter, CServer* pServer);
  154.     ~CFUtilityCar(void);
  155.  
  156.     // A general method for initializing a newly created CFUtilityCar.
  157.     HRESULT Init(void);
  158.  
  159.     // IUnknown methods. Main object, non-delegating.
  160.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  161.     STDMETHODIMP_(ULONG) AddRef(void);
  162.     STDMETHODIMP_(ULONG) Release(void);
  163.  
  164.   private:
  165.     // We declare nested class interface implementations here.
  166.  
  167.     // We implement the IClassFactory interface (ofcourse) in this class
  168.     // factory COM object class.
  169.     class CImpIClassFactory : public IClassFactory
  170.     {
  171.       public:
  172.         // Interface Implementation Constructor & Destructor.
  173.         CImpIClassFactory(
  174.           CFUtilityCar* pBackObj,
  175.           IUnknown* pUnkOuter,
  176.           CServer* pServer);
  177.         ~CImpIClassFactory(void);
  178.  
  179.         // IUnknown methods.
  180.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  181.         STDMETHODIMP_(ULONG) AddRef(void);
  182.         STDMETHODIMP_(ULONG) Release(void);
  183.  
  184.         // IClassFactory methods.
  185.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  186.         STDMETHODIMP         LockServer(BOOL);
  187.  
  188.       private:
  189.         // Data private to this interface implementation of IClassFactory.
  190.         ULONG            m_cRefI;       // Interface Ref Count (debugging).
  191.         CFUtilityCar*    m_pBackObj;    // Parent Object back pointer.
  192.         IUnknown*        m_pUnkOuter;   // Outer unknown for Delegation.
  193.         CServer*         m_pServer;     // Server Control Object.
  194.     };
  195.  
  196.     // Make the otherwise private and nested IClassFactory interface
  197.     // implementation a friend to COM object instantiations of this
  198.     // selfsame CFUtilityCar COM object class.
  199.     friend CImpIClassFactory;
  200.  
  201.     // Private data of CFUtilityCar COM objects.
  202.  
  203.     // Nested IClassFactory implementation instantiation.
  204.     CImpIClassFactory m_ImpIClassFactory;
  205.  
  206.     // Main Object reference count.
  207.     ULONG             m_cRefs;
  208.  
  209.     // Outer unknown (aggregation & delegation). Used when this
  210.     // CFUtilityCar object is being aggregated.  Otherwise it is used
  211.     // for delegation if this object is reused via containment.
  212.     IUnknown*         m_pUnkOuter;
  213.  
  214.     // Pointer to this component server's control object.
  215.     CServer*          m_pServer;
  216. };
  217.  
  218. typedef CFUtilityCar* PCFUtilityCar;
  219.  
  220.  
  221. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  222.   ObjectClass: CFCruiseCar
  223.  
  224.   Summary:     Class Factory COM Object Class for CruiseCar COM
  225.                components.  Used to manufacture COCruiseCar COM objects.
  226.                The mulitple interfaces on this COM object class are
  227.                constructed via the nested interface classes technique.
  228.  
  229.   Interfaces:  IUnknown
  230.                  Standard interface providing COM object features.
  231.                IClassFactory
  232.                  Standard interface providing COM Class Factory features.
  233.  
  234.   Aggregation: Yes, CFCruiseCar COM objects are aggregatable by
  235.                passing a non-NULL pUnkOuter IUnknown pointer into the
  236.                constructor.
  237. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  238. class CFCruiseCar : public IUnknown
  239. {
  240.   public:
  241.     // Main Object Constructor & Destructor.
  242.     CFCruiseCar(IUnknown* pUnkOuter, CServer* pServer);
  243.     ~CFCruiseCar(void);
  244.  
  245.     // A general method for initializing a newly created CFCruiseCar.
  246.     HRESULT Init(void);
  247.  
  248.     // IUnknown methods. Main object, non-delegating.
  249.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  250.     STDMETHODIMP_(ULONG) AddRef(void);
  251.     STDMETHODIMP_(ULONG) Release(void);
  252.  
  253.   private:
  254.     // We declare nested class interface implementations here.
  255.  
  256.     // We implement the IClassFactory interface (ofcourse) in this class
  257.     // factory COM object class.
  258.     class CImpIClassFactory : public IClassFactory
  259.     {
  260.       public:
  261.         // Interface Implementation Constructor & Destructor.
  262.         CImpIClassFactory(
  263.           CFCruiseCar* pBackObj,
  264.           IUnknown* pUnkOuter,
  265.           CServer* pServer);
  266.         ~CImpIClassFactory(void);
  267.  
  268.         // IUnknown methods.
  269.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  270.         STDMETHODIMP_(ULONG) AddRef(void);
  271.         STDMETHODIMP_(ULONG) Release(void);
  272.  
  273.         // IClassFactory methods.
  274.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  275.         STDMETHODIMP         LockServer(BOOL);
  276.  
  277.       private:
  278.         // Data private to this interface implementation of IClassFactory.
  279.         ULONG            m_cRefI;       // Interface Ref Count (debugging).
  280.         CFCruiseCar*     m_pBackObj;    // Parent Object back pointer.
  281.         IUnknown*        m_pUnkOuter;   // Outer unknown for Delegation.
  282.         CServer*         m_pServer;     // Server Control Object.
  283.     };
  284.  
  285.     // Make the otherwise private and nested IClassFactory interface
  286.     // implementation a friend to COM object instantiations of this
  287.     // selfsame CFCruiseCar COM object class.
  288.     friend CImpIClassFactory;
  289.  
  290.     // Private data of CFCruiseCar COM objects.
  291.  
  292.     // Nested IClassFactory implementation instantiation.
  293.     CImpIClassFactory m_ImpIClassFactory;
  294.  
  295.     // Main Object reference count.
  296.     ULONG             m_cRefs;
  297.  
  298.     // Outer unknown (aggregation & delegation). Used when this
  299.     // CFCruiseCar object is being aggregated.  Otherwise it is used
  300.     // for delegation if this object is reused via containment.
  301.     IUnknown*         m_pUnkOuter;
  302.  
  303.     // Pointer to this component server's control object.
  304.     CServer*          m_pServer;
  305. };
  306.  
  307. typedef CFCruiseCar* PCFCruiseCar;
  308.  
  309. #endif // __cplusplus
  310.  
  311.  
  312. #endif // FACTORY_H
  313.