Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.9 KiB

  1. #ifndef __CNCTNPT_H__
  2. #define __CNCTNPT_H__
  3. //
  4. // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  5. //
  6. // This class is shared between DLLs, and DLLs that use it have already
  7. // shipped as part of IE4 (specifically, shell32). This means that
  8. // any changes you make must be done EXTREMELY CAREFULLY and TESTED
  9. // FOR INTEROPERABILITY WITH IE4! For one thing, you have to make sure
  10. // that none of your changes alter the vtbl used by IE4's shell32.
  11. //
  12. // If you change CIE4ConnectionPoint, you must build SHDOC401 and
  13. // test it on IE4!
  14. //
  15. // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  16. //
  17. //
  18. // First, the class as it was defined in IE4. All virtual functions
  19. // must be be listed in exactly the same order as they were in IE4.
  20. // Fortunately, no cross-component users mucked with the member
  21. // variables.
  22. //
  23. // Change any of these at your own risk.
  24. //
  25. class CIE4ConnectionPoint : public IConnectionPoint {
  26. public:
  27. // IUnknown methods
  28. //
  29. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj) PURE;
  30. virtual STDMETHODIMP_(ULONG) AddRef(void) PURE;
  31. virtual STDMETHODIMP_(ULONG) Release(void) PURE;
  32. // IConnectionPoint methods
  33. //
  34. virtual STDMETHODIMP GetConnectionInterface(IID FAR* pIID) PURE;
  35. virtual STDMETHODIMP GetConnectionPointContainer(IConnectionPointContainer FAR* FAR* ppCPC) PURE;
  36. virtual STDMETHODIMP Advise(LPUNKNOWN pUnkSink, DWORD FAR* pdwCookie) PURE;
  37. virtual STDMETHODIMP Unadvise(DWORD dwCookie) PURE;
  38. virtual STDMETHODIMP EnumConnections(LPENUMCONNECTIONS FAR* ppEnum) PURE;
  39. // This is how you actually fire the events
  40. // Those called by shell32 are virtual
  41. // (Renamed to DoInvokeIE4)
  42. virtual HRESULT DoInvokeIE4(LPBOOL pf, LPVOID *ppv, DISPID dispid, DISPPARAMS *pdispparams) PURE;
  43. // This helper function does work that callers of DoInvoke often need done
  44. virtual HRESULT DoInvokePIDLIE4(DISPID dispid, LPCITEMIDLIST pidl, BOOL fCanCancel) PURE;
  45. };
  46. //
  47. // CConnectionPoint is an implementation of a conection point.
  48. // To get the rest of the implementation, you also have to include
  49. // lib\cnctnpt.cpp in your project.
  50. //
  51. // Embed an instance of CConnectionPoint in an object that needs to
  52. // implement a connectionpoint and call SetOwner to initialize it.
  53. //
  54. // Fire events to anyone connected to this connectionpoint via DoInvoke
  55. // or DoOnChanged. External clients should use the shlwapi functions
  56. // like IConnectionPoint_Invoke or IConnectionPoint_OnChanged.
  57. //
  58. class CConnectionPoint : public CIE4ConnectionPoint {
  59. friend class CConnectionPointEnum;
  60. public:
  61. // IUnknown methods
  62. //
  63. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  64. virtual STDMETHODIMP_(ULONG) AddRef(void)
  65. { return m_punk->AddRef(); }
  66. virtual STDMETHODIMP_(ULONG) Release(void)
  67. { return m_punk->Release(); }
  68. // IConnectionPoint methods
  69. //
  70. virtual STDMETHODIMP GetConnectionInterface(IID * pIID);
  71. virtual STDMETHODIMP GetConnectionPointContainer(IConnectionPointContainer ** ppCPC);
  72. virtual STDMETHODIMP Advise(LPUNKNOWN pUnkSink, DWORD * pdwCookie);
  73. virtual STDMETHODIMP Unadvise(DWORD dwCookie);
  74. virtual STDMETHODIMP EnumConnections(LPENUMCONNECTIONS * ppEnum);
  75. // CIE4ConnectionPoint methods - called by IE4's shell32
  76. virtual HRESULT DoInvokeIE4(LPBOOL pf, LPVOID *ppv, DISPID dispid, DISPPARAMS *pdispparams);
  77. // DoInvokePidlIE4 is strange in that shell32 linked to it but never
  78. // actually called it. This makes the implementation particularly simple.
  79. virtual HRESULT DoInvokePIDLIE4(DISPID dispid, LPCITEMIDLIST pidl, BOOL fCanCancel)
  80. { return E_NOTIMPL; }
  81. public:
  82. // Additional helper methods
  83. // Performs a basic DISPID Invoke on the object
  84. inline HRESULT InvokeDispid(DISPID dispid) {
  85. return IConnectionPoint_SimpleInvoke(this, dispid, NULL);
  86. }
  87. // Performs an OnChanged on the object
  88. inline HRESULT OnChanged(DISPID dispid) {
  89. return IConnectionPoint_OnChanged(this, dispid);
  90. }
  91. // A couple functions to setup and destroy this subclass object
  92. ~CConnectionPoint(); // not virtual: nobody inherits from this class
  93. //
  94. // The containing object must call SetOwner to initialize the
  95. // connection point.
  96. //
  97. // punk - The IUnknown of the object this ConnectionPoint is
  98. // embedded in; it will be treated as the connection
  99. // point container.
  100. //
  101. // piid - The IID that the sinks are expected to support.
  102. // If you call DoInvoke, then it must be derived from
  103. // IID_IDispatch. If you call DoOnChanged, then it must
  104. // be exactly &IID_IPropertyNotifySink.
  105. //
  106. void SetOwner(IUnknown* punk, const IID* piid)
  107. {
  108. // Validate the special requirement on the piid parameter.
  109. if (*piid == IID_IPropertyNotifySink)
  110. {
  111. ASSERT(piid == &IID_IPropertyNotifySink);
  112. }
  113. // don't AddRef -- we're a member variable of the object punk points to
  114. m_punk = punk;
  115. m_piid = piid;
  116. }
  117. // The underline version is inline
  118. BOOL _HasSinks() { return (BOOL)m_cSinks; }
  119. // We are empty if there are no sinks
  120. BOOL IsEmpty() { return !_HasSinks(); }
  121. HRESULT UnadviseAll(void);
  122. // A lot of people need to convert a CConnectionPoint into an
  123. // IConnectionPoint. We used to be multiply inherited, hence the
  124. // need for this member, but that's gone now.
  125. IConnectionPoint *CastToIConnectionPoint()
  126. { return SAFECAST(this, IConnectionPoint*); }
  127. private:
  128. IUnknown **m_rgSinks;
  129. int m_cSinks;
  130. int m_cSinksAlloc;
  131. IUnknown *m_punk; // IUnknown of object containing us
  132. const IID *m_piid; // IID of this connection point
  133. };
  134. #endif