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.

235 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. // CAggregatorDispMgr object and delegate all IDispatch calls to it, or perhaps
  29. // inherit from it directly. The method
  30. //
  31. // HRESULT CAggregatorDispMgr::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 non-ADSI users of the dispatch manager
  49. // will probably have to define it explicitly.
  50. //
  51. // The LoadTypeInfoEntry method should be called at constructor time of
  52. // the containing object. After all the type information is loaded, the
  53. // dispatch manager can start servicing GetIDsOfNames and Invoke calls.
  54. //
  55. //
  56. // For ADSI, there are two other calls to load information into the dispatch
  57. // manager:
  58. //
  59. // void CAggregatorDispMgr::RegisterPropertyCache(IPropertyCache *pPropertyCache);
  60. // void CAggregatorDispMgr::RegisterBaseDispatchPtr(IDispatch *pDispatch);
  61. //
  62. // The first method registers a property cache of the containing object;
  63. // this is used in the ADSI providers to cache attributes of a directory
  64. // server object. See iprops.hxx for more information.
  65. //
  66. // The second method is a hack used to get around a lack of inheritance.
  67. // If an object A implements IDispatch and some other dual interfaces,
  68. // and an object B derives from A and also implements IDispatch and some
  69. // other dual interfaces, this method can be used in object B to use A's
  70. // dispatch manager as a "backup" to its own. This way B doesn't have to
  71. // load the type information about the interfaces it inherits from A.
  72. // (Also, if A has an ADSI property cache, then callers of B's IDispatch
  73. // methods can get at the underlying property cache.)
  74. //
  75. // The function
  76. //
  77. // void AggregatorFreeTypeInfoTable();
  78. //
  79. // should be called at global destructor or library-unload time. Currently,
  80. // all the ADSI libraries do it separately
  81. //
  82. //
  83. // The DISPIDs returned by GetIDsOfNames are 32 bit values laid out
  84. // as follows:
  85. //
  86. // 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
  87. // 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
  88. // +-+-------------+---------------+-------------------------------+
  89. // |X| DispMgrId | TypeInfoId | DispId |
  90. // +-+-------------+---------------+-------------------------------+
  91. //
  92. // where
  93. //
  94. // X - is reserved and never set. This would turn the value negative
  95. // (which would overlap with some Automation-reserved DISPIDs.)
  96. //
  97. // DispMgrId - identifies the dispatch manager (used when stringing
  98. // dispatch managers together via RegisterBaseDispatchPtr).
  99. //
  100. // TypeInfoId - uniquely identifies the interface within this
  101. // dispatch manager.
  102. //
  103. // DispId - uniquely identifies the name within the interface.
  104. //
  105. // So if an object uses the dispatch manager, it shouldn't try to only use
  106. // it for just GetIDsOfNames or just Invoke, since the DISPIDs returned are
  107. // not necessarily the ones in the type library.
  108. //
  109. //////////////////////////////////////////////////////////////////////////////
  110. // Forward declarations:
  111. struct IPropertyCache;
  112. /*
  113. typedef struct _typeinfoentry
  114. {
  115. LONG TypeInfoId;
  116. void *ptypeinfo;
  117. void *pInterfacePointer;
  118. struct _typeinfoentry *pNext;
  119. } TYPEINFOENTRY, *PTYPEINFOENTRY;*/
  120. class CAggregatorDispMgr
  121. {
  122. public:
  123. CAggregatorDispMgr::CAggregatorDispMgr(CCredentials &Credentials);
  124. CAggregatorDispMgr::CAggregatorDispMgr();
  125. CAggregatorDispMgr::~CAggregatorDispMgr();
  126. //
  127. // The IDispatch methods are the main interface of the Dispatch Manager.
  128. //
  129. STDMETHOD(GetTypeInfoCount)(THIS_ UINT FAR* pctinfo);
  130. STDMETHOD(GetTypeInfo)(THIS_ UINT itinfo, LCID lcid, ITypeInfo **pptinfo);
  131. STDMETHOD(GetIDsOfNames)(THIS_ REFIID riid, LPWSTR *rgszNames,
  132. UINT cNames, LCID lcid, DISPID *rgdispid);
  133. STDMETHOD(Invoke)(THIS_ DISPID dispidMember, REFIID riid, LCID lcid,
  134. WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult,
  135. EXCEPINFO *pexcepinfo, UINT *puArgErr);
  136. //
  137. // Methods for initializing the dispatch manager.
  138. //
  139. void
  140. CAggregatorDispMgr::RegisterPropertyCache(IPropertyCache* pPropertyCache);
  141. void
  142. CAggregatorDispMgr::RegisterBaseDispatchPtr(IDispatch *pDispatch);
  143. HRESULT
  144. CAggregatorDispMgr::LoadTypeInfoEntry(
  145. REFIID libid,
  146. REFIID iid,
  147. void * pIntf,
  148. DISPID SpecialId
  149. );
  150. private:
  151. void *
  152. CAggregatorDispMgr::getInterfacePtr(LONG TypeInfoId);
  153. ITypeInfo *
  154. CAggregatorDispMgr::getTypeInfo(LONG TypeInfoId);
  155. PTYPEINFOENTRY
  156. CAggregatorDispMgr::FindTypeInfoEntry(LONG TypeInfoId);
  157. HRESULT
  158. CAggregatorDispMgr::AddTypeInfo(void FAR *ptypeinfo, void * pIntfptr);
  159. STDMETHODIMP
  160. CAggregatorDispMgr::TypeInfoInvoke(DISPID dispidMember, REFIID iid, LCID lcid,
  161. unsigned short wFlags, DISPPARAMS FAR* pdispparams,
  162. VARIANT FAR* pvarResult, EXCEPINFO FAR* pexcepinfo,
  163. unsigned int FAR* puArgErr);
  164. HRESULT
  165. CAggregatorDispMgr::MarkAsNewEnum(void *pTypeInfo);
  166. HRESULT
  167. CAggregatorDispMgr::MarkAsItem(void *pTypeInfo);
  168. PTYPEINFOENTRY
  169. CAggregatorDispMgr::FindTypeInfo(void *pTypeInfo);
  170. LONG
  171. CAggregatorDispMgr::gentypeinfoid();
  172. protected:
  173. LONG _dwTypeInfoId;
  174. PTYPEINFOENTRY _pTypeInfoEntry;
  175. PTYPEINFOENTRY _pDispidNewEnum;
  176. PTYPEINFOENTRY _pDispidValue;
  177. IPropertyCache *_pPropertyCache;
  178. LONG _dwPropCacheID;
  179. CCredentials _Credentials;
  180. };
  181. #define BAIL_IF_ERROR(hr) if (FAILED(hr)) { goto cleanup; }
  182. // deprecated
  183. HRESULT
  184. LoadTypeInfoEntry(
  185. CAggregatorDispMgr * pDispMgr,
  186. REFIID libid,
  187. REFIID iid,
  188. void * pIntf,
  189. DISPID SpecialId
  190. );
  191. void
  192. AggregatorFreeTypeInfoTable();
  193. HRESULT
  194. AggregatorDynamicDispidInvoke(
  195. IPropertyCache * pPropertyCache,
  196. CCredentials &Credentials,
  197. DISPID dispid,
  198. unsigned short wFlags,
  199. DISPPARAMS *pdispparams,
  200. VARIANT * pvarResult
  201. );
  202. BOOL
  203. AggregatorDllCanUnload();