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.

233 lines
7.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: cdispmgr.cxx
  7. //
  8. // Contents: The dispatch manager -- a class to manage
  9. // multiple IDispatch-callable interfaces.
  10. //
  11. // History: ??-???-?? KrishnaG created
  12. // 07-Sep-97 t-blakej Commented, cleaned up, made
  13. // independent of ADSI.
  14. //
  15. //----------------------------------------------------------------------------
  16. //
  17. // Dispatch manager description:
  18. //
  19. //
  20. // The dispatch manager is a way to invoke methods on an object that has
  21. // more than one COM interface. The regular GetIDsOfNames and Invoke
  22. // methods assume only a single ITypeInfo to look up and call names from;
  23. // if an object has more than one interface, it has multiple ITypeInfo's,
  24. // and it has to explicitly check each one. The dispatch manager implements
  25. // the IDispatch methods, and keeps track of as many ITypeInfos as necessary.
  26. //
  27. // To use the dispatch manager, an object should store a pointer to a
  28. // CAggregateeDispMgr object and delegate all IDispatch calls to it, or perhaps
  29. // inherit from it directly. The method
  30. //
  31. // HRESULT CAggregateeDispMgr::LoadTypeInfoEntry(
  32. // REFIID libid, REFIID iid, void *pIntf, DISPID SpecialId)
  33. //
  34. // is used to load the type information for the object into the dispatch
  35. // manager. The arguments to this method are:
  36. //
  37. // REFIID libid - IID of the type library to load from
  38. // REFIID iid - IID of the interface to load
  39. // void *pIntf - pointer to the interface on the containing
  40. // object
  41. // DISPID SpecialId - DISPID_REGULAR for most things (see below);
  42. // DISPID_VALUE for interfaces which implement
  43. // the containing object's "value" property;
  44. // DISPID_NEWENUM for interfaces which implement
  45. // the containing object's "NewEnum" method
  46. //
  47. // DISPID_REGULAR is defined to be 1 by all ADSI providers, but not in
  48. // any top-level include file. So
  49. // non-ADSI users of the dispatch manager will probably have to define it
  50. // explicitly.
  51. //
  52. // The LoadTypeInfoEntry method should be called at constructor time of
  53. // the containing object. After all the type information is loaded, the
  54. // dispatch manager can start servicing GetIDsOfNames and Invoke calls.
  55. //
  56. //
  57. // For ADSI, there are two other calls to load information into the dispatch
  58. // manager:
  59. //
  60. // void CAggregateeDispMgr::RegisterPropertyCache(IPropertyCache *pPropertyCache);
  61. // void CAggregateeDispMgr::RegisterBaseDispatchPtr(IDispatch *pDispatch);
  62. //
  63. // The first method registers a property cache of the containing object;
  64. // this is used in the ADSI providers to cache attributes of a directory
  65. // server object. See iprops.hxx for more information.
  66. //
  67. // The second method is a hack used to get around a lack of inheritance.
  68. // If an object A implements IDispatch and some other dual interfaces,
  69. // and an object B derives from A and also implements IDispatch and some
  70. // other dual interfaces, this method can be used in object B to use A's
  71. // dispatch manager as a "backup" to its own. This way B doesn't have to
  72. // load the type information about the interfaces it inherits from A.
  73. // (Also, if A has an ADSI property cache, then callers of B's IDispatch
  74. // methods can get at the underlying property cache.)
  75. //
  76. // The function
  77. //
  78. // void FreeTypeInfoTable();
  79. //
  80. // should be called at global destructor or library-unload time. Currently,
  81. // all the ADSI libraries do it separately; should make an object to do it
  82. // automatically in the dispatch manager.
  83. //
  84. //
  85. // The DISPIDs returned by GetIDsOfNames are 32 bit values laid out
  86. // as follows:
  87. //
  88. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
  89. // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  90. // +-+-------------+---------------+-------------------------------+
  91. // |X| DispMgrId | TypeInfoId | DispId |
  92. // +-+-------------+---------------+-------------------------------+
  93. //
  94. // where
  95. //
  96. // X - is reserved and never set. This would turn the value negative
  97. // (which would overlap with some Automation-reserved DISPIDs.)
  98. //
  99. // DispMgrId - identifies the dispatch manager (used when stringing
  100. // dispatch managers together via RegisterBaseDispatchPtr).
  101. //
  102. // TypeInfoId - uniquely identifies the interface within this
  103. // dispatch manager.
  104. //
  105. // DispId - uniquely identifies the name within the interface.
  106. //
  107. // So if an object uses the dispatch manager, it shouldn't try to only use
  108. // it for just GetIDsOfNames or just Invoke, since the DISPIDs returned are
  109. // not necessarily the ones in the type library.
  110. //
  111. //////////////////////////////////////////////////////////////////////////////
  112. /*
  113. // Forward declarations:
  114. struct IPropertyCache;
  115. typedef struct _typeinfoentry
  116. {
  117. LONG TypeInfoId;
  118. void *ptypeinfo;
  119. void *pInterfacePointer;
  120. struct _typeinfoentry *pNext;
  121. } TYPEINFOENTRY, *PTYPEINFOENTRY;
  122. */
  123. class CAggregateeDispMgr
  124. {
  125. public:
  126. CAggregateeDispMgr::CAggregateeDispMgr();
  127. CAggregateeDispMgr::~CAggregateeDispMgr();
  128. //
  129. // The IDispatch methods are the main interface of the Dispatch Manager.
  130. //
  131. STDMETHOD(GetTypeInfoCount)(THIS_ UINT FAR* pctinfo);
  132. STDMETHOD(GetTypeInfo)(THIS_ UINT itinfo, LCID lcid, ITypeInfo **pptinfo);
  133. STDMETHOD(GetIDsOfNames)(THIS_ REFIID riid, LPWSTR *rgszNames,
  134. UINT cNames, LCID lcid, DISPID *rgdispid);
  135. STDMETHOD(Invoke)(THIS_ DISPID dispidMember, REFIID riid, LCID lcid,
  136. WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult,
  137. EXCEPINFO *pexcepinfo, UINT *puArgErr);
  138. //
  139. // Methods for initializing the dispatch manager.
  140. //
  141. void
  142. CAggregateeDispMgr::RegisterPropertyCache(IPropertyCache* pPropertyCache);
  143. HRESULT
  144. CAggregateeDispMgr::LoadTypeInfoEntry(
  145. REFIID libid,
  146. REFIID iid,
  147. void * pIntf,
  148. DISPID SpecialId
  149. );
  150. HRESULT
  151. CAggregateeDispMgr::InitializeDispMgr(
  152. DWORD dwExtensionID
  153. );
  154. private:
  155. void *
  156. CAggregateeDispMgr::getInterfacePtr(LONG TypeInfoId);
  157. ITypeInfo *
  158. CAggregateeDispMgr::getTypeInfo(LONG TypeInfoId);
  159. PTYPEINFOENTRY
  160. CAggregateeDispMgr::FindTypeInfoEntry(LONG TypeInfoId);
  161. HRESULT
  162. CAggregateeDispMgr::AddTypeInfo(void FAR *ptypeinfo, void * pIntfptr);
  163. STDMETHODIMP
  164. CAggregateeDispMgr::TypeInfoInvoke(DISPID dispidMember, REFIID iid, LCID lcid,
  165. unsigned short wFlags, DISPPARAMS FAR* pdispparams,
  166. VARIANT FAR* pvarResult, EXCEPINFO FAR* pexcepinfo,
  167. unsigned int FAR* puArgErr);
  168. HRESULT
  169. CAggregateeDispMgr::MarkAsNewEnum(void *pTypeInfo);
  170. HRESULT
  171. CAggregateeDispMgr::MarkAsItem(void *pTypeInfo);
  172. PTYPEINFOENTRY
  173. CAggregateeDispMgr::FindTypeInfo(void *pTypeInfo);
  174. LONG
  175. CAggregateeDispMgr::gentypeinfoid();
  176. protected:
  177. LONG _dwTypeInfoId;
  178. PTYPEINFOENTRY _pTypeInfoEntry;
  179. PTYPEINFOENTRY _pDispidNewEnum;
  180. PTYPEINFOENTRY _pDispidValue;
  181. IPropertyCache *_pPropertyCache;
  182. LONG _dwPropCacheID;
  183. DWORD _dwExtensionID;
  184. };
  185. #define BAIL_IF_ERROR(hr) if (FAILED(hr)) { goto cleanup; }
  186. // deprecated
  187. HRESULT
  188. AggregateeLoadTypeInfoEntry(
  189. CAggregateeDispMgr * pDispMgr,
  190. REFIID libid,
  191. REFIID iid,
  192. void * pIntf,
  193. DISPID SpecialId
  194. );
  195. HRESULT
  196. AggregateeDynamicDispidInvoke(
  197. IPropertyCache * pPropertyCache,
  198. DISPID dispid,
  199. unsigned short wFlags,
  200. DISPPARAMS *pdispparams,
  201. VARIANT * pvarResult
  202. );
  203.