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

  1. /*+==========================================================================
  2.   File:      FACTORY.H
  3.  
  4.   Summary:   Include file for the class factory COM object: CFDrawPage.
  5.              This constitutes the PERDRAW server's class factory for the
  6.              DrawPage COM component.
  7.  
  8.              The multiple interface COM Object Class is achieved via the
  9.              technique of nested classes: the implementation of the
  10.              standard IClassFactory interface is nested inside of the
  11.              class factory COM object class. APPUTIL's CThreaded OwnThis
  12.              mechanism is used to ensure mutually exclusive access to the
  13.              class factory by contending multiple threads.
  14.  
  15.              For a comprehensive tutorial code tour of this module's
  16.              contents and offerings see the tutorial PERDRAW.HTM
  17.              file. For more specific technical details on the internal
  18.              workings see the comments dispersed throughout the module's
  19.              source code.
  20.  
  21.   Classes:   CFDrawPage.
  22.  
  23.   Functions: .
  24.  
  25.   Origin:    5-20-97: atrent - Editor-inheritance from FACTORY.H in
  26.                the STOSERVE Tutorial Code Sample.
  27.  
  28. ----------------------------------------------------------------------------
  29.   This file is part of the Microsoft COM Tutorial Code Samples.
  30.  
  31.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  32.  
  33.   This source code is intended only as a supplement to Microsoft
  34.   Development Tools and/or on-line documentation.  See these other
  35.   materials for detailed information regarding Microsoft code samples.
  36.  
  37.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  38.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  39.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  40.   PARTICULAR PURPOSE.
  41. ==========================================================================+*/
  42.  
  43. #if !defined(FACTORY_H)
  44. #define FACTORY_H
  45.  
  46. #ifdef __cplusplus
  47.  
  48. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  49.   ObjectClass: CFDrawPage
  50.  
  51.   Summary:     Class Factory COM Object Class for DrawPage COM components.
  52.                Used to manufacture CODrawPage COM objects.  The mulitple
  53.                interfaces on this COM object class are constructed via the
  54.                nested interface classes technique.
  55.  
  56.   Interfaces:  IUnknown
  57.                  Standard interface providing COM object features.
  58.                IClassFactory
  59.                  Standard interface providing COM Class Factory features.
  60.  
  61.   Aggregation: Yes, CFDrawPage 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 CFDrawPage : public IUnknown, public CThreaded
  66. {
  67.   public:
  68.     // Main Object Constructor & Destructor.
  69.     CFDrawPage(IUnknown* pUnkOuter, CServer* pServer);
  70.     ~CFDrawPage(void);
  71.  
  72.     // IUnknown methods. Main object, non-delegating.
  73.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  74.     STDMETHODIMP_(ULONG) AddRef(void);
  75.     STDMETHODIMP_(ULONG) Release(void);
  76.  
  77.     // We declare nested class interface implementations here.
  78.  
  79.     // We implement the IClassFactory interface in this class
  80.     // factory COM object class. Derive also from abstract CThreaded
  81.     // to provide the OwnThis/UnownThis thread-safety mechanism.
  82.     class CImpIClassFactory : public IClassFactory, public CThreaded
  83.     {
  84.       public:
  85.         // Interface Implementation Constructor & Destructor.
  86.         CImpIClassFactory(
  87.           CFDrawPage* pCO,
  88.           IUnknown* pUnkOuter,
  89.           CServer* pServer);
  90.         ~CImpIClassFactory(void);
  91.  
  92.         // IUnknown methods.
  93.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  94.         STDMETHODIMP_(ULONG) AddRef(void);
  95.         STDMETHODIMP_(ULONG) Release(void);
  96.  
  97.         // IClassFactory methods.
  98.         STDMETHODIMP         CreateInstance(IUnknown*, REFIID, PPVOID);
  99.         STDMETHODIMP         LockServer(BOOL);
  100.  
  101.       private:
  102.         // Data private to this interface implementation of IClassFactory.
  103.         CFDrawPage*   m_pCO;         // Parent Object back pointer.
  104.         IUnknown*     m_pUnkOuter;   // Outer unknown for Delegation.
  105.         CServer*      m_pServer;     // Server's control object.
  106.     };
  107.  
  108.     // Make the otherwise private and nested IClassFactory interface
  109.     // implementation a friend to COM object instantiations of this
  110.     // CFDrawPage COM object class.
  111.     friend CImpIClassFactory;
  112.  
  113.   private:
  114.     // Private data of CFDrawPage COM objects.
  115.  
  116.     // Nested IClassFactory implementation instantiation.
  117.     CImpIClassFactory m_ImpIClassFactory;
  118.  
  119.     // Main Object reference count.
  120.     ULONG             m_cRefs;
  121.  
  122.     // Outer unknown (aggregation & delegation). Used when this
  123.     // CFDrawPage object is being aggregated.  Otherwise it is used
  124.     // for delegation if this object is reused via containment.
  125.     IUnknown*         m_pUnkOuter;
  126.  
  127.     // Pointer to this component server's control object.
  128.     CServer*          m_pServer;
  129. };
  130.  
  131.  
  132. #endif // __cplusplus
  133.  
  134.  
  135. #endif // FACTORY_H
  136.