OBJECT.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:6k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * OBJECT.H
  3.  *
  4.  * Definition of the classes CConnObject, CImpIConnPtCont, and
  5.  * CEnumConnectionPoints for the connectable object;
  6.  * CConnectionPoint, CImpIConnectionPoint, CImpIDuckEvents, and
  7.  * CEnumConnections for the connection point.
  8.  *
  9.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  10.  *
  11.  * Kraig Brockschmidt, Microsoft
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15. #ifndef _OBJECT_H_
  16. #define _OBJECT_H_
  17. //Number of connection points in this implementation
  18. #define CCONNPOINTS     1
  19. /*
  20.  * The connectable object itself implements IUnknown and
  21.  * IConnectionPointContainer.  It is closely associated with
  22.  * the connection point enumerator, CEnumConnectionPoints.
  23.  */
  24. class CConnectionPoint;
  25. typedef CConnectionPoint *PCConnectionPoint;
  26. //ID's for triggering events
  27. enum
  28.     {
  29.     EVENT_QUACK=1, EVENT_FLAP, EVENT_PADDLE
  30.     };
  31. class CConnObject : public IConnectionPointContainer
  32.     {
  33.     private:
  34.         DWORD             m_cRef;         //Object reference count
  35.         //Array holding all the points we have.
  36.         PCConnectionPoint m_rgpConnPt[CCONNPOINTS];
  37.     public:
  38.         CConnObject(void);
  39.         ~CConnObject(void);
  40.         BOOL Init(void);
  41.         //IUnknown members
  42.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  43.         STDMETHODIMP_(DWORD) AddRef(void);
  44.         STDMETHODIMP_(DWORD) Release(void);
  45.         //IConnectionPointContainer members
  46.         STDMETHODIMP EnumConnectionPoints(IEnumConnectionPoints **);
  47.     STDMETHODIMP FindConnectionPoint(REFIID, IConnectionPoint **);
  48.         //Other members
  49.         BOOL TriggerEvent(UINT);
  50.     };
  51. typedef CConnObject *PCConnObject;
  52. //Enumerator class for EnumConnectionPoints
  53. class CEnumConnectionPoints : public IEnumConnectionPoints
  54.     {
  55.     private:
  56.         ULONG           m_cRef;     //Object reference count
  57.         LPUNKNOWN       m_pUnkRef;  //IUnknown for ref counting
  58.         ULONG           m_iCur;     //Current element
  59.         ULONG           m_cPoints;  //Number of conn points
  60.         IConnectionPoint **m_rgpCP; //Source of conn points
  61.     public:
  62.         CEnumConnectionPoints(LPUNKNOWN, ULONG, IConnectionPoint **);
  63.         ~CEnumConnectionPoints(void);
  64.         //IUnknown members that delegate to m_pUnkRef.
  65.         STDMETHODIMP         QueryInterface(REFIID, LPVOID *);
  66.         STDMETHODIMP_(ULONG) AddRef(void);
  67.         STDMETHODIMP_(ULONG) Release(void);
  68.         //IEnumConnectionPoints members
  69.         STDMETHODIMP Next(ULONG, IConnectionPoint **, ULONG *);
  70.         STDMETHODIMP Skip(ULONG);
  71.         STDMETHODIMP Reset(void);
  72.         STDMETHODIMP Clone(IEnumConnectionPoints **);
  73.     };
  74. typedef CEnumConnectionPoints *PCEnumConnectionPoints;
  75. /*
  76.  * The connection point object iself is contained within the
  77.  * connection point container, which is the connectable object.
  78.  * It therefore manages a back pointer to that connectable object,
  79.  * and implement IConnectionPoint.  This object has a few
  80.  * member functions besides those in IConnectionPoint that are
  81.  * used to fire the outgoing calls.
  82.  */
  83. #define CCONNMAX    2
  84. class CConnectionPoint : public IConnectionPoint
  85.     {
  86.     private:
  87.         ULONG           m_cRef;     //Object reference count
  88.         PCConnObject    m_pObj;     //Containing object
  89.         IID             m_iid;      //Our relevant interface
  90.         /*
  91.          * To keep things simple we'll only support two
  92.          * advise connections at most.  Production quality
  93.          * connection points should supprt any number of
  94.          * connections.  For each connection we need to maintain
  95.          * the sink pointer and the cookie assigned to it.
  96.          */
  97.         IUnknown       *m_rgpIUnknown[CCONNMAX];
  98.         DWORD           m_rgdwCookies[CCONNMAX];
  99.         UINT            m_cConn;
  100.         DWORD           m_dwCookieNext; //Counter
  101.     public:
  102.         CConnectionPoint(PCConnObject, REFIID);
  103.         ~CConnectionPoint(void);
  104.         //IUnknown members
  105.         STDMETHODIMP         QueryInterface(REFIID, LPVOID *);
  106.         STDMETHODIMP_(ULONG) AddRef(void);
  107.         STDMETHODIMP_(ULONG) Release(void);
  108.         //IConnectionPoint members
  109.         STDMETHODIMP GetConnectionInterface(IID *);
  110.         STDMETHODIMP GetConnectionPointContainer
  111.             (IConnectionPointContainer **);
  112.         STDMETHODIMP Advise(LPUNKNOWN, DWORD *);
  113.         STDMETHODIMP Unadvise(DWORD);
  114.         STDMETHODIMP EnumConnections(IEnumConnections **);
  115.     };
  116. //Enumeration clas for EnumConnections
  117. class CEnumConnections : public IEnumConnections
  118.     {
  119.     private:
  120.         ULONG           m_cRef;     //Object reference count
  121.         LPUNKNOWN       m_pUnkRef;  //IUnknown for ref counting
  122.         ULONG           m_iCur;     //Current element
  123.         ULONG           m_cConn;    //Number of connections
  124.         LPCONNECTDATA   m_rgConnData; //Source of connections
  125.     public:
  126.         CEnumConnections(LPUNKNOWN, ULONG, LPCONNECTDATA);
  127.         ~CEnumConnections(void);
  128.         //IUnknown members that delegate to m_pUnkRef.
  129.         STDMETHODIMP         QueryInterface(REFIID, LPVOID *);
  130.         STDMETHODIMP_(ULONG) AddRef(void);
  131.         STDMETHODIMP_(ULONG) Release(void);
  132.         //IEnumConnections members
  133.         STDMETHODIMP Next(ULONG, LPCONNECTDATA, ULONG *);
  134.         STDMETHODIMP Skip(ULONG);
  135.         STDMETHODIMP Reset(void);
  136.         STDMETHODIMP Clone(IEnumConnections **);
  137.     };
  138. typedef CEnumConnections *PCEnumConnections;
  139. #endif _OBJECT_H_