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

  1. /*+==========================================================================
  2.   File:      FACTORY.H
  3.  
  4.   Summary:   Include file for the class factory COM objects:
  5.              CFCar, CFUtilityCar, CFCruiseCar, and CFCarSample.
  6.              These constitute the DLLSERVE server's Class Factorys for
  7.              those COM components.
  8.  
  9.              The multiple interface COM Object Classes are achieved via
  10.              the technique of nested classes: the implementation of the
  11.              IClassFactory interfaces are nested inside of the class
  12.              factory COM object classes.
  13.  
  14.              For a comprehensive tutorial code tour of this module's
  15.              contents and offerings see the tutorial DLLSERVE.HTM file.
  16.              For more specific technical details on the internal workings
  17.              see the comments dispersed throughout the module's source code.
  18.  
  19.   Classes:   CFCar, CFUtilityCar, CFCruiseCar, CFCarSample.
  20.  
  21.   Functions: .
  22.  
  23.   Origin:    9-11-95: atrent - Editor-inheritance from CRUCAR.H in
  24.                the COMOBJ Tutorial Code Sample.
  25.  
  26. ----------------------------------------------------------------------------
  27.   This file is part of the Microsoft COM Tutorial Code Samples.
  28.  
  29.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  30.  
  31.   This source code is intended only as a supplement to Microsoft
  32.   Development Tools and/or on-line documentation.  See these other
  33.   materials for detailed information regarding Microsoft code samples.
  34.  
  35.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  36.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  37.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  38.   PARTICULAR PURPOSE.
  39. ==========================================================================+*/
  40.  
  41. #if !defined(FACTORY_H)
  42. #define FACTORY_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: CFCar
  48.  
  49.   Summary:     Class Factory COM Object Class for Car COM components.
  50.                Used to manufacture COCar COM objects.  The mulitple
  51.                interfaces on this COM object class are constructed via
  52.                the nested interface classes technique.
  53.  
  54.   Interfaces:  IUnknown
  55.                  Standard interface providing COM object features.
  56.                IClassFactory
  57.                  Standard interface providing COM Class Factory features.
  58.  
  59.   Aggregation: Yes, CFCar COM objects are aggregatable by
  60.                passing a non-NULL pUnkOuter IUnknown pointer into the
  61.                constructor.
  62. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  63. class CFCar : public IUnknown
  64. {
  65.   public:
  66.     // Main Object Constructor & Destructor.
  67.     CFCar(IUnknown* pUnkOuter, CServer* pServer);
  68.     ~CFCar(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.     // We implement the IClassFactory interface (ofcourse) in this class
  79.     // factory COM object class.
  80.     class CImpIClassFactory : public IClassFactory
  81.     {
  82.       public:
  83.         // Interface Implementation Constructor & Destructor.
  84.         CImpIClassFactory(
  85.           CFCar* pBackObj,
  86.           IUnknown* pUnkOuter,
  87.           CServer* pServer);
  88.         ~CImpIClassFactory(void);
  89.  
  90.         // IUnknown methods.
  91.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  92.         STDMETHODIMP_(ULONG) AddRef(void);
  93.         STDMETHODIMP_(ULONG) Release(void);
  94.  
  95.         // IClassFactory methods.
  96.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  97.         STDMETHODIMP         LockServer(BOOL);
  98.  
  99.       private:
  100.         // Data private to this interface implementation of IClassFactory.
  101.         ULONG         m_cRefI;       // Interface Ref Count (for debugging).
  102.         CFCar*        m_pBackObj;    // Parent Object back pointer.
  103.         IUnknown*     m_pUnkOuter;   // Outer unknown for Delegation.
  104.         CServer*      m_pServer;     // Server's control object.
  105.     };
  106.  
  107.     // Make the otherwise private and nested IClassFactory interface
  108.     // implementation a friend to COM object instantiations of this
  109.     // selfsame CFCar COM object class.
  110.     friend CImpIClassFactory;
  111.  
  112.     // Private data of CFCar COM objects.
  113.  
  114.     // Nested IClassFactory implementation instantiation.
  115.     CImpIClassFactory m_ImpIClassFactory;
  116.  
  117.     // Main Object reference count.
  118.     ULONG             m_cRefs;
  119.  
  120.     // Outer unknown (aggregation & delegation). Used when this
  121.     // CFCar object is being aggregated.  Otherwise it is used
  122.     // for delegation if this object is reused via containment.
  123.     IUnknown*         m_pUnkOuter;
  124.  
  125.     // Pointer to this component server's control object.
  126.     CServer*          m_pServer;
  127. };
  128.  
  129. typedef CFCar* PCFCar;
  130.  
  131.  
  132. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  133.   ObjectClass: CFUtilityCar
  134.  
  135.   Summary:     Class Factory COM Object Class for UtilityCar COM
  136.                components.  Used to manufacture COUtilityCar COM
  137.                objects.  The mulitple interfaces on this COM object
  138.                class are constructed via the nested interface
  139.                classes technique.
  140.  
  141.   Interfaces:  IUnknown
  142.                  Standard interface providing COM object features.
  143.                IClassFactory
  144.                  Standard interface providing COM Class Factory features.
  145.  
  146.   Aggregation: Yes, CFUtilityCar COM objects are aggregatable by
  147.                passing a non-NULL pUnkOuter IUnknown pointer into the
  148.                constructor.
  149. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  150. class CFUtilityCar : public IUnknown
  151. {
  152.   public:
  153.     // Main Object Constructor & Destructor.
  154.     CFUtilityCar(IUnknown* pUnkOuter, CServer* pServer);
  155.     ~CFUtilityCar(void);
  156.  
  157.     // A general method for initializing a newly created CFUtilityCar.
  158.     HRESULT Init(void);
  159.  
  160.     // IUnknown methods. Main object, non-delegating.
  161.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  162.     STDMETHODIMP_(ULONG) AddRef(void);
  163.     STDMETHODIMP_(ULONG) Release(void);
  164.  
  165.   private:
  166.     // We declare nested class interface implementations here.
  167.  
  168.     // We implement the IClassFactory interface (ofcourse) in this class
  169.     // factory COM object class.
  170.     class CImpIClassFactory : public IClassFactory
  171.     {
  172.       public:
  173.         // Interface Implementation Constructor & Destructor.
  174.         CImpIClassFactory(
  175.           CFUtilityCar* pBackObj,
  176.           IUnknown* pUnkOuter,
  177.           CServer* pServer);
  178.         ~CImpIClassFactory(void);
  179.  
  180.         // IUnknown methods.
  181.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  182.         STDMETHODIMP_(ULONG) AddRef(void);
  183.         STDMETHODIMP_(ULONG) Release(void);
  184.  
  185.         // IClassFactory methods.
  186.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  187.         STDMETHODIMP         LockServer(BOOL);
  188.  
  189.       private:
  190.         // Data private to this interface implementation of IClassFactory.
  191.         ULONG            m_cRefI;       // Interface Ref Count (debugging).
  192.         CFUtilityCar*    m_pBackObj;    // Parent Object back pointer.
  193.         IUnknown*        m_pUnkOuter;   // Outer unknown for Delegation.
  194.         CServer*         m_pServer;     // Server Control Object.
  195.     };
  196.  
  197.     // Make the otherwise private and nested IClassFactory interface
  198.     // implementation a friend to COM object instantiations of this
  199.     // selfsame CFUtilityCar COM object class.
  200.     friend CImpIClassFactory;
  201.  
  202.     // Private data of CFUtilityCar COM objects.
  203.  
  204.     // Nested IClassFactory implementation instantiation.
  205.     CImpIClassFactory m_ImpIClassFactory;
  206.  
  207.     // Main Object reference count.
  208.     ULONG             m_cRefs;
  209.  
  210.     // Outer unknown (aggregation & delegation). Used when this
  211.     // CFUtilityCar object is being aggregated.  Otherwise it is used
  212.     // for delegation if this object is reused via containment.
  213.     IUnknown*         m_pUnkOuter;
  214.  
  215.     // Pointer to this component server's control object.
  216.     CServer*          m_pServer;
  217. };
  218.  
  219. typedef CFUtilityCar* PCFUtilityCar;
  220.  
  221.  
  222. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  223.   ObjectClass: CFCruiseCar
  224.  
  225.   Summary:     Class Factory COM Object Class for CruiseCar COM
  226.                components.  Used to manufacture COCruiseCar COM objects.
  227.                The mulitple interfaces on this COM object class are
  228.                constructed via the nested interface classes technique.
  229.  
  230.   Interfaces:  IUnknown
  231.                  Standard interface providing COM object features.
  232.                IClassFactory
  233.                  Standard interface providing COM Class Factory features.
  234.  
  235.   Aggregation: Yes, CFCruiseCar COM objects are aggregatable by
  236.                passing a non-NULL pUnkOuter IUnknown pointer into the
  237.                constructor.
  238. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  239. class CFCruiseCar : public IUnknown
  240. {
  241.   public:
  242.     // Main Object Constructor & Destructor.
  243.     CFCruiseCar(IUnknown* pUnkOuter, CServer* pServer);
  244.     ~CFCruiseCar(void);
  245.  
  246.     // A general method for initializing a newly created CFCruiseCar.
  247.     HRESULT Init(void);
  248.  
  249.     // IUnknown methods. Main object, non-delegating.
  250.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  251.     STDMETHODIMP_(ULONG) AddRef(void);
  252.     STDMETHODIMP_(ULONG) Release(void);
  253.  
  254.   private:
  255.     // We declare nested class interface implementations here.
  256.  
  257.     // We implement the IClassFactory interface (ofcourse) in this class
  258.     // factory COM object class.
  259.     class CImpIClassFactory : public IClassFactory
  260.     {
  261.       public:
  262.         // Interface Implementation Constructor & Destructor.
  263.         CImpIClassFactory(
  264.           CFCruiseCar* pBackObj,
  265.           IUnknown* pUnkOuter,
  266.           CServer* pServer);
  267.         ~CImpIClassFactory(void);
  268.  
  269.         // IUnknown methods.
  270.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  271.         STDMETHODIMP_(ULONG) AddRef(void);
  272.         STDMETHODIMP_(ULONG) Release(void);
  273.  
  274.         // IClassFactory methods.
  275.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  276.         STDMETHODIMP         LockServer(BOOL);
  277.  
  278.       private:
  279.         // Data private to this interface implementation of IClassFactory.
  280.         ULONG            m_cRefI;       // Interface Ref Count (debugging).
  281.         CFCruiseCar*     m_pBackObj;    // Parent Object back pointer.
  282.         IUnknown*        m_pUnkOuter;   // Outer unknown for Delegation.
  283.         CServer*         m_pServer;     // Server Control Object.
  284.     };
  285.  
  286.     // Make the otherwise private and nested IClassFactory interface
  287.     // implementation a friend to COM object instantiations of this
  288.     // selfsame CFCruiseCar COM object class.
  289.     friend CImpIClassFactory;
  290.  
  291.     // Private data of CFCruiseCar COM objects.
  292.  
  293.     // Nested IClassFactory implementation instantiation.
  294.     CImpIClassFactory m_ImpIClassFactory;
  295.  
  296.     // Main Object reference count.
  297.     ULONG             m_cRefs;
  298.  
  299.     // Outer unknown (aggregation & delegation). Used when this
  300.     // CFCruiseCar object is being aggregated.  Otherwise it is used
  301.     // for delegation if this object is reused via containment.
  302.     IUnknown*         m_pUnkOuter;
  303.  
  304.     // Pointer to this component server's control object.
  305.     CServer*          m_pServer;
  306. };
  307.  
  308. typedef CFCruiseCar* PCFCruiseCar;
  309.  
  310.  
  311. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  312.   ObjectClass: CFCarSample
  313.  
  314.   Summary:     Class Factory COM Object Class for CarSample COM
  315.                components.  Used to manufacture COCarSample COM
  316.                objects.  The mulitple interfaces on this COM object
  317.                class are constructed via the nested interface classes
  318.                technique.
  319.  
  320.   Interfaces:  IUnknown
  321.                  Standard interface providing COM object features.
  322.                IClassFactory
  323.                  Standard interface providing COM Class Factory features.
  324.  
  325.   Aggregation: Yes, CFCarSample COM objects are aggregatable by
  326.                passing a non-NULL pUnkOuter IUnknown pointer into the
  327.                constructor.
  328. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  329. class CFCarSample : public IUnknown
  330. {
  331.   public:
  332.     // Main Object Constructor & Destructor.
  333.     CFCarSample(IUnknown* pUnkOuter, CServer* pServer);
  334.     ~CFCarSample(void);
  335.  
  336.     // A general method for initializing a newly created CFCarSample.
  337.     HRESULT Init(void);
  338.  
  339.     // IUnknown methods. Main object, non-delegating.
  340.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  341.     STDMETHODIMP_(ULONG) AddRef(void);
  342.     STDMETHODIMP_(ULONG) Release(void);
  343.  
  344.   private:
  345.     // We declare nested class interface implementations here.
  346.  
  347.     // We implement the IClassFactory interface (ofcourse) in this Class
  348.     // Factory COM object class.
  349.     class CImpIClassFactory : public IClassFactory
  350.     {
  351.       public:
  352.         // Interface Implementation Constructor & Destructor.
  353.         CImpIClassFactory(
  354.           CFCarSample* pBackObj,
  355.           IUnknown* pUnkOuter,
  356.           CServer* pServer);
  357.         ~CImpIClassFactory(void);
  358.  
  359.         // IUnknown methods.
  360.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  361.         STDMETHODIMP_(ULONG) AddRef(void);
  362.         STDMETHODIMP_(ULONG) Release(void);
  363.  
  364.         // IClassFactory methods.
  365.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  366.         STDMETHODIMP         LockServer(BOOL);
  367.  
  368.       private:
  369.         // Data private to this interface implementation of IClassFactory.
  370.         ULONG           m_cRefI;     // Interface Ref Count (for debugging).
  371.         CFCarSample*    m_pBackObj;  // Parent Object back pointer.
  372.         IUnknown*       m_pUnkOuter; // Outer unknown for Delegation.
  373.         CServer*        m_pServer;   // Server Control Object.
  374.     };
  375.  
  376.     // Make the otherwise private and nested IClassFactory interface
  377.     // implementation a friend to COM object instantiations of this
  378.     // selfsame CFCarSample COM object class.
  379.     friend CImpIClassFactory;
  380.  
  381.     // Private data of CFCarSample COM objects.
  382.  
  383.     // Nested IClassFactory implementation instantiation.
  384.     CImpIClassFactory m_ImpIClassFactory;
  385.  
  386.     // Main Object reference count.
  387.     ULONG             m_cRefs;
  388.  
  389.     // Outer unknown (aggregation & delegation). Used when this
  390.     // CFCarSample object is being aggregated.  Otherwise it is used
  391.     // for delegation if this object is reused via containment.
  392.     IUnknown*         m_pUnkOuter;
  393.  
  394.     // Pointer to this component server's control object.
  395.     CServer*          m_pServer;
  396. };
  397.  
  398. typedef CFCarSample* PCFCarSample;
  399.  
  400. #endif // __cplusplus
  401.  
  402.  
  403. #endif // FACTORY_H
  404.