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 / connect.h < prev    next >
C/C++ Source or Header  |  1997-08-05  |  9KB  |  255 lines

  1. /*+==========================================================================
  2.   File:      CONNECT.H
  3.  
  4.   Summary:   Include file declaring COM object classes and constants for
  5.              managing the connection points (and their connections)
  6.              exposed by the connectable objects in the PERDRAW server.
  7.  
  8.              For a comprehensive tutorial code tour of this module's
  9.              contents and offerings see the tutorial PERDRAW.HTM
  10.              file. For more specific technical details on the internal
  11.              workings see the comments dispersed throughout the module's
  12.              source code.
  13.  
  14.   Functions: .
  15.  
  16.   Classes:   COEnumConnectionPoints, COConnectionPoint, and
  17.              COEnumConnections.
  18.  
  19.   Origin:    5-20-97: atrent - Editor inheritance from the STOSERVE COM
  20.              Tutorial Code Sample. Very little change was required.
  21.  
  22. ----------------------------------------------------------------------------
  23.   This file is part of the Microsoft COM Tutorial Code Samples.
  24.  
  25.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  26.  
  27.   This source code is intended only as a supplement to Microsoft
  28.   Development Tools and/or on-line documentation.  See these other
  29.   materials for detailed information regarding Microsoft code samples.
  30.  
  31.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  32.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  33.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  34.   PARTICULAR PURPOSE.
  35. ==========================================================================+*/
  36.  
  37. #if !defined(CONNECT_H)
  38. #define CONNECT_H
  39.  
  40. #ifdef __cplusplus
  41.  
  42.  
  43. // An enumeration giving symbol names for the connection
  44. // points offered by the DrawPage component in this server.
  45. enum
  46. {
  47.   CONNPOINT_DRAWPAGESINK = 0
  48. };
  49.  
  50. enum
  51. {
  52.   // The maximum number of connection points offered by the DrawPage
  53.   // component in this PERDRAW server.  The number of items in the
  54.   // connection point enumeration above.
  55.   MAX_CONNECTION_POINTS = 1,
  56.  
  57.   // A constant for the number of connections to add to the allocation
  58.   // of the dynamic connection array.
  59.   ALLOC_CONNECTIONS = 8,
  60.  
  61.   // The start value for the connection key (cookie) counter.
  62.   COOKIE_START_VALUE = 500
  63. };
  64.  
  65.  
  66. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  67.   ObjectClass: COEnumConnectionPoints
  68.  
  69.   Summary:     COM object class for enumerating the Connection Points
  70.                offered by a connectable object.
  71.  
  72.   Interfaces:  IUnknown
  73.                  Standard interface providing COM object features.
  74.                IEnumConnectionPoints
  75.                  Interface for connection point enumeration.
  76.  
  77.   Aggregation: COEnumConnectionPoints COM Objects are not aggregatable.
  78. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  79. class COEnumConnectionPoints : public IEnumConnectionPoints
  80. {
  81.   public:
  82.     // Main Object Constructor & Destructor.
  83.     COEnumConnectionPoints(IUnknown* pHostObj);
  84.     ~COEnumConnectionPoints(void);
  85.  
  86.     // A general method for initializing this newly created object.
  87.     // Creates any subordinate arrays, structures, or objects.
  88.     HRESULT Init(
  89.               ULONG cConnPts,
  90.               IConnectionPoint** paConnPts,
  91.               ULONG iEnumIndex);
  92.  
  93.     // IUnknown methods. Main object, non-delegating.
  94.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  95.     STDMETHODIMP_(ULONG) AddRef(void);
  96.     STDMETHODIMP_(ULONG) Release(void);
  97.  
  98.     // IEnumConnectionPoints methods.
  99.     STDMETHODIMP         Next(ULONG, IConnectionPoint**, ULONG*);
  100.     STDMETHODIMP         Skip(ULONG);
  101.     STDMETHODIMP         Reset(void);
  102.     STDMETHODIMP         Clone(IEnumConnectionPoints**);
  103.  
  104.   private:
  105.     // Private data of COEnumConnectionPoints COM objects.
  106.  
  107.     // Main Object reference count.
  108.     ULONG              m_cRefs;
  109.  
  110.     // IUnknown pointer to host COM object being enumerated.
  111.     IUnknown*          m_pHostObj;
  112.  
  113.     // Connection Point index variable.
  114.     ULONG              m_iEnumIndex;
  115.  
  116.     // Number of Connection Points being enumerated.
  117.     ULONG              m_cConnPts;
  118.  
  119.     // Allocated array of Connection Point interface pointers.
  120.     IConnectionPoint** m_paConnPts;
  121. };
  122.  
  123.  
  124. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  125.   ObjectClass: COConnectionPoint
  126.  
  127.   Summary:     Connection Point COM object class. Implements a native
  128.                IConnectionPoint interface.
  129.  
  130.   Interfaces:  IUnknown
  131.                  Standard interface providing COM object features.
  132.                IConnectionPoint
  133.                  Interface for connection point features.
  134.  
  135.   Aggregation: COConnectionPoint COM Objects are not aggregatable.
  136. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  137. class COConnectionPoint : public IConnectionPoint
  138. {
  139.   public:
  140.     // Main Object Constructor & Destructor.
  141.     COConnectionPoint(IUnknown* pHostObj);
  142.     ~COConnectionPoint(void);
  143.  
  144.     // A general method for initializing this newly created object.
  145.     // Creates any subordinate arrays, structures, or objects.
  146.     HRESULT Init(REFIID riid);
  147.  
  148.     // IUnknown methods. Main object, non-delegating.
  149.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  150.     STDMETHODIMP_(ULONG) AddRef(void);
  151.     STDMETHODIMP_(ULONG) Release(void);
  152.  
  153.     // IConnectionPoint methods.
  154.     STDMETHODIMP GetConnectionInterface(IID*);
  155.     STDMETHODIMP GetConnectionPointContainer(IConnectionPointContainer**);
  156.     STDMETHODIMP Advise(IUnknown*, DWORD*);
  157.     STDMETHODIMP Unadvise(DWORD);
  158.     STDMETHODIMP EnumConnections(IEnumConnections**);
  159.  
  160.   private:
  161.     // Private utility methods of COConnectionPoint.
  162.     HRESULT GetSlot(UINT* puiFreeSlot);
  163.     HRESULT FindSlot(DWORD dwCookie, UINT* puiSlot);
  164.  
  165.     // Private data of COConnectionPoint COM objects.
  166.  
  167.     // Main Object reference count.
  168.     ULONG          m_cRefs;
  169.  
  170.     // IUnknown pointer to host COM object offering this connection point.
  171.     IUnknown*      m_pHostObj;
  172.  
  173.     // The IID of the sink interface associated with this connection point.
  174.     IID            m_iidSink;
  175.  
  176.     // The current connection cookie (key) counter.
  177.     DWORD          m_dwNextCookie;
  178.  
  179.     // The current number of live sink connections to this connection point.
  180.     UINT           m_cConnections;
  181.  
  182.     // The current maximum index into the dynamic connection array.
  183.     UINT           m_uiMaxIndex;
  184.  
  185.     // The dynamic array of sink connections to this connection point.
  186.     CONNECTDATA*   m_paConnections;
  187. };
  188.  
  189. typedef COConnectionPoint* PCOConnectionPoint;
  190.  
  191.  
  192. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  193.   ObjectClass: COEnumConnections
  194.  
  195.   Summary:     COM object class for enumerating the connections of a
  196.                connection point of a connectable object.
  197.  
  198.   Interfaces:  IUnknown
  199.                  Standard interface providing COM object features.
  200.                IEnumConnections
  201.                  Interface for connection enumeration features.
  202.  
  203.   Aggregation: COEnumConnections COM Objects are not aggregatable.
  204. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  205. class COEnumConnections : public IEnumConnections
  206. {
  207.   public:
  208.     // Main Object Constructor & Destructor.
  209.     COEnumConnections(IUnknown* pHostObj);
  210.     ~COEnumConnections(void);
  211.  
  212.     // A general method for initializing this newly created object.
  213.     // Creates any subordinate arrays, structures, or objects.
  214.     HRESULT Init(
  215.               ULONG cConnections,
  216.               CONNECTDATA* paConnections,
  217.               ULONG iEnumIndex);
  218.  
  219.     // IUnknown methods. Main object, non-delegating.
  220.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  221.     STDMETHODIMP_(ULONG) AddRef(void);
  222.     STDMETHODIMP_(ULONG) Release(void);
  223.  
  224.     // IEnumConnections methods.
  225.     STDMETHODIMP         Next(ULONG, CONNECTDATA*, ULONG*);
  226.     STDMETHODIMP         Skip(ULONG);
  227.     STDMETHODIMP         Reset(void);
  228.     STDMETHODIMP         Clone(IEnumConnections**);
  229.  
  230.   private:
  231.     // Private data of COEnumConnections COM objects.
  232.  
  233.     // Main Object reference count.
  234.     ULONG            m_cRefs;
  235.  
  236.     // IUnknown pointer to host connection point COM object being
  237.     // enumerated.
  238.     IUnknown*        m_pHostObj;
  239.  
  240.     // Connection index variable.
  241.     ULONG            m_iEnumIndex;
  242.  
  243.     // Number of Connections being enumerated.
  244.     ULONG            m_cConnections;
  245.  
  246.     // Allocated array of live Connections only.
  247.     CONNECTDATA*     m_paConnections;
  248. };
  249.  
  250.  
  251. #endif // __cplusplus
  252.  
  253.  
  254. #endif // CONNECT_H
  255.