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 / licserve / factory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-05  |  9.1 KB  |  243 lines

  1. /*+==========================================================================
  2.   File:      FACTORY.H
  3.  
  4.   Summary:   Include file for the class factory COM objects:
  5.              CFLicCruiseCar, and CFLicCarSample.  These constitute the
  6.              LICSERVE 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 LICSERVE.HTM
  15.              file. For more specific technical details on the internal
  16.              workings see the comments dispersed throughout the module's
  17.              source code.
  18.  
  19.   Classes:   CFLicCruiseCar, CFLicCarSample.
  20.  
  21.   Functions: .
  22.  
  23.   Origin:    10-5-95: atrent - Editor-inheritance from CRUCAR.H in
  24.                the DLLSERVE 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.  
  47. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  48.   ObjectClass: CFLicCruiseCar
  49.  
  50.   Summary:     Class Factory COM Object Class for LicCruiseCar COM
  51.                components.  Used to manufacture COLicCruiseCar COM objects.
  52.                The mulitple interfaces on this COM object class are
  53.                constructed via the nested interface classes technique.
  54.  
  55.   Interfaces:  IUnknown
  56.                  Standard interface providing COM object features.
  57.                IClassFactory2
  58.                  Standard interface providing COM Class Factory features
  59.                  that support licensing of these Cruise Car COM components.
  60.  
  61.   Aggregation: Yes, CFLicCruiseCar COM objects are aggregatable by
  62.                passing a non-NULL pUnkOuter IUnknown pointer into the
  63.                constructor.
  64. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  65. class CFLicCruiseCar : public IUnknown
  66. {
  67.   public:
  68.     // Main Object Constructor & Destructor.
  69.     CFLicCruiseCar(IUnknown* pUnkOuter, CServer* pServer);
  70.     ~CFLicCruiseCar(void);
  71.  
  72.     // A general method for initializing a newly created CFLicCruiseCar.
  73.     HRESULT Init(void);
  74.  
  75.     // IUnknown methods. Main object, non-delegating.
  76.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  77.     STDMETHODIMP_(ULONG) AddRef(void);
  78.     STDMETHODIMP_(ULONG) Release(void);
  79.  
  80.   private:
  81.     // A private unconditional create for LicCruiseCar.
  82.     STDMETHODIMP CreateLicCruiseCar(IUnknown*, REFIID, PPVOID);
  83.  
  84.     // We declare nested class interface implementations here.
  85.  
  86.     // We implement the IClassFactory2 interface on this LicCruiseCar
  87.     // Class Factory to license these COM objects.
  88.     class CImpIClassFactory : public IClassFactory2
  89.     {
  90.       public:
  91.         // Interface Implementation Constructor & Destructor.
  92.         CImpIClassFactory(
  93.           CFLicCruiseCar* pBackObj,
  94.           IUnknown* pUnkOuter,
  95.           CServer* pServer);
  96.         ~CImpIClassFactory(void);
  97.  
  98.         // IUnknown methods.
  99.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  100.         STDMETHODIMP_(ULONG) AddRef(void);
  101.         STDMETHODIMP_(ULONG) Release(void);
  102.  
  103.         // IClassFactory methods.
  104.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  105.         STDMETHODIMP         LockServer(BOOL);
  106.  
  107.         // IClassFactory2 methods.
  108.         STDMETHODIMP         GetLicInfo(LPLICINFO);
  109.         STDMETHODIMP         RequestLicKey(DWORD, BSTR*);
  110.         STDMETHODIMP         CreateInstanceLic(
  111.                                IUnknown*,
  112.                                IUnknown*,
  113.                                REFIID,
  114.                                BSTR,
  115.                                PPVOID);
  116.  
  117.       private:
  118.         // Data private to this interface implementation of IClassFactory.
  119.         ULONG            m_cRefI;       // Interface Ref Count (debugging).
  120.         CFLicCruiseCar*  m_pBackObj;    // Parent Object back pointer.
  121.         IUnknown*        m_pUnkOuter;   // Outer unknown for Delegation.
  122.         CServer*         m_pServer;     // Server Control Object.
  123.     };
  124.  
  125.     // Make the otherwise private and nested IClassFactory interface
  126.     // implementation a friend to COM object instantiations of this
  127.     // selfsame CFLicCruiseCar COM object class.
  128.     friend CImpIClassFactory;
  129.  
  130.     // Private data of CFLicCruiseCar COM objects.
  131.  
  132.     // Nested IClassFactory implementation instantiation.
  133.     CImpIClassFactory m_ImpIClassFactory;
  134.  
  135.     // Main Object reference count.
  136.     ULONG             m_cRefs;
  137.  
  138.     // Outer unknown (aggregation & delegation). Used when this
  139.     // CFLicCruiseCar object is being aggregated.  Otherwise it is used
  140.     // for delegation if this object is reused via containment.
  141.     IUnknown*         m_pUnkOuter;
  142.  
  143.     // Pointer to this component server's control object.
  144.     CServer*          m_pServer;
  145. };
  146.  
  147. typedef CFLicCruiseCar* PCFLicCruiseCar;
  148.  
  149.  
  150. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  151.   ObjectClass: CFLicCarSample
  152.  
  153.   Summary:     Class Factory COM Object Class for LicCarSample COM
  154.                components.  Used to manufacture COLicCarSample COM
  155.                objects.  The mulitple interfaces on this COM object
  156.                class are constructed via the nested interface classes
  157.                technique.
  158.  
  159.   Interfaces:  IUnknown
  160.                  Standard interface providing COM object features.
  161.                IClassFactory
  162.                  Standard interface providing COM Class Factory features.
  163.  
  164.   Aggregation: Yes, CFLicCarSample COM objects are aggregatable by
  165.                passing a non-NULL pUnkOuter IUnknown pointer into the
  166.                constructor.
  167. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  168. class CFLicCarSample : public IUnknown
  169. {
  170.   public:
  171.     // Main Object Constructor & Destructor.
  172.     CFLicCarSample(IUnknown* pUnkOuter, CServer* pServer);
  173.     ~CFLicCarSample(void);
  174.  
  175.     // A general method for initializing a newly created CFLicCarSample.
  176.     HRESULT Init(void);
  177.  
  178.     // IUnknown methods. Main object, non-delegating.
  179.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  180.     STDMETHODIMP_(ULONG) AddRef(void);
  181.     STDMETHODIMP_(ULONG) Release(void);
  182.  
  183.   private:
  184.     // We declare nested class interface implementations here.
  185.  
  186.     // We implement the IClassFactory interface (of course) in this Class
  187.     // Factory COM object class.
  188.     class CImpIClassFactory : public IClassFactory
  189.     {
  190.       public:
  191.         // Interface Implementation Constructor & Destructor.
  192.         CImpIClassFactory(
  193.           CFLicCarSample* pBackObj,
  194.           IUnknown* pUnkOuter,
  195.           CServer* pServer);
  196.         ~CImpIClassFactory(void);
  197.  
  198.         // IUnknown methods.
  199.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  200.         STDMETHODIMP_(ULONG) AddRef(void);
  201.         STDMETHODIMP_(ULONG) Release(void);
  202.  
  203.         // IClassFactory methods.
  204.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  205.         STDMETHODIMP         LockServer(BOOL);
  206.  
  207.       private:
  208.         // Data private to this interface implementation of IClassFactory.
  209.         ULONG           m_cRefI;     // Interface Ref Count (for debugging).
  210.         CFLicCarSample* m_pBackObj;  // Parent Object back pointer.
  211.         IUnknown*       m_pUnkOuter; // Outer unknown for Delegation.
  212.         CServer*        m_pServer;   // Server Control Object.
  213.     };
  214.  
  215.     // Make the otherwise private and nested IClassFactory interface
  216.     // implementation a friend to COM object instantiations of this
  217.     // selfsame CFLicCarSample COM object class.
  218.     friend CImpIClassFactory;
  219.  
  220.     // Private data of CFLicCarSample COM objects.
  221.  
  222.     // Nested IClassFactory implementation instantiation.
  223.     CImpIClassFactory m_ImpIClassFactory;
  224.  
  225.     // Main Object reference count.
  226.     ULONG             m_cRefs;
  227.  
  228.     // Outer unknown (aggregation & delegation). Used when this
  229.     // CFLicCarSample object is being aggregated.  Otherwise it is used
  230.     // for delegation if this object is reused via containment.
  231.     IUnknown*         m_pUnkOuter;
  232.  
  233.     // Pointer to this component server's control object.
  234.     CServer*          m_pServer;
  235. };
  236.  
  237. typedef CFLicCarSample* PCFLicCarSample;
  238.  
  239. #endif // __cplusplus
  240.  
  241.  
  242. #endif // FACTORY_H
  243.