Source code of Windows XP (NT5)
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.

266 lines
8.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: cthkmgr.hxx
  7. //
  8. // Contents: CThkMgr deklaration
  9. //
  10. // Classes: CThkMgr
  11. //
  12. // Functions:
  13. //
  14. // History: 5-18-94 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __CTHKMGR_HXX__
  18. #define __CTHKMGR_HXX__
  19. //
  20. // Describes a request for a custom interface
  21. //
  22. typedef struct tagIIDNODE IIDNODE, *PIIDNODE;
  23. struct tagIIDNODE
  24. {
  25. IID *piid;
  26. PIIDNODE pNextNode;
  27. };
  28. //
  29. // state of thunk call - before or after the 32 or 16 bit call
  30. //
  31. typedef enum
  32. {
  33. THKSTATE_NOCALL = 0x0000,
  34. THKSTATE_INVOKETHKIN32 = 0x0001,
  35. THKSTATE_INVOKETHKOUT32 = 0x0002,
  36. THKSTATE_INVOKETHKIN16 = 0x0004,
  37. THKSTATE_INVOKETHKOUT16 = 0x0008,
  38. THKSTATE_INVOKETHKOUT16_CLIENTSITE = 0x0010,
  39. THKSTATE_VERIFY16INPARAM = 0x0020,
  40. THKSTATE_VERIFY32INPARAM = 0x0040
  41. } THKSTATE;
  42. #define THKSTATE_OUT (THKSTATE_INVOKETHKOUT32 | THKSTATE_INVOKETHKOUT16 | \
  43. THKSTATE_INVOKETHKOUT16_CLIENTSITE)
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Class: CThkMgr ()
  47. //
  48. // Purpose:
  49. //
  50. // Interface: QueryInterface --
  51. // AddRef --
  52. // Release --
  53. // IsIIDRequested --
  54. // SetThkState --
  55. // IsIIDSupported --
  56. // AddIIDRequest --
  57. // RemoveIIDRequest --
  58. // ResetThkState --
  59. // GetThkState --
  60. // IsOutParamObj --
  61. // IsProxy1632 --
  62. // FreeProxy1632 --
  63. // QueryInterfaceProxy1632 --
  64. // AddRefProxy1632 --
  65. // ReleaseProxy1632 --
  66. // IsProxy3216 --
  67. // FreeProxy3216 --
  68. // QueryInterfaceProxy3216 --
  69. // AddRefProxy3216 --
  70. // ReleaseProxy3216 --
  71. // PrepareForCleanup --
  72. // DebugDump3216 --
  73. // Create --
  74. // ~CThkMgr --
  75. // CThkMgr --
  76. // _cRefs --
  77. // _thkstate --
  78. // _pProxyTbl3216 --
  79. // _pProxyTbl1632 --
  80. // _pCFL1632 --
  81. // _pCFL3216 --
  82. // _piidnode --
  83. //
  84. // History: 6-01-94 JohannP (Johann Posch) Created
  85. //
  86. // Notes:
  87. //
  88. //----------------------------------------------------------------------------
  89. // Returns from FindProxy
  90. #define FST_ERROR 0
  91. #define FST_CREATED_NEW 1
  92. #define FST_USED_EXISTING 2
  93. #define FST_SHORTCUT 4
  94. #define CALLBACK_ALLOWED 1
  95. #define FST_PROXY_STATUS (FST_CREATED_NEW | FST_USED_EXISTING)
  96. #define FST_OBJECT_STATUS (FST_SHORTCUT)
  97. class CThkMgr : public IThunkManager
  98. {
  99. public:
  100. // *** IUnknown methods ***
  101. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj);
  102. STDMETHOD_(ULONG,AddRef) (THIS);
  103. STDMETHOD_(ULONG,Release) (THIS);
  104. // *** IThunkManager methods ***
  105. STDMETHOD_(BOOL, IsIIDRequested) (THIS_ REFIID riid);
  106. STDMETHOD_(BOOL, IsCustom3216Proxy) (THIS_ IUnknown *punk,
  107. REFIID riid);
  108. // private methods
  109. THKSTATE GetThkState(void)
  110. {
  111. return _thkstate;
  112. };
  113. void SetThkState(THKSTATE thkstate)
  114. {
  115. _thkstate = thkstate;
  116. };
  117. BOOL IsOutParamObj(void)
  118. {
  119. return (_thkstate & THKSTATE_OUT) != 0;
  120. }
  121. BOOL IsIIDSupported (REFIID riid);
  122. BOOL AddIIDRequest (REFIID riid);
  123. void RemoveIIDRequest (REFIID riid);
  124. void LockProxy(CProxy *pprx);
  125. BOOL LookupIdentity(VPVOID vpvUnk, PROXYHOLDER *&pph) {
  126. return(_pHolderTbl->Lookup(vpvUnk, (void *&)pph));
  127. }
  128. VPVOID CanGetNewProxy1632(IIDIDX iidx);
  129. void FreeNewProxy1632(VPVOID vpv, IIDIDX iidx);
  130. IUnknown *IsProxy1632(VPVOID vpvObj16);
  131. VPVOID LookupProxy1632(IUnknown *punkThis32)
  132. {
  133. VPVOID vpv;
  134. if (_pProxyTbl1632->Lookup((DWORD)punkThis32, (void*&)vpv))
  135. {
  136. return vpv;
  137. }
  138. else
  139. {
  140. return 0;
  141. }
  142. }
  143. SCODE Object32Identity(IUnknown *punkThis32, PROXYPTR *pProxy, DWORD *pfst);
  144. VPVOID CreateOuter16(IUnknown *punkOuter32, PROXYHOLDER **ppAggHolder, DWORD *pfst);
  145. VPVOID FindProxy1632(VPVOID vpvPrealloc,
  146. IUnknown *punkThis32,
  147. PROXYHOLDER *pgHolder,
  148. IIDIDX iidx,
  149. DWORD *pfst);
  150. VPVOID FindAggregate1632(VPVOID vpvPrealloc,
  151. IUnknown *punkOuter32,
  152. IUnknown *punkThis32,
  153. IIDIDX iidx,
  154. PROXYHOLDER *pAggHolder,
  155. DWORD *pfst);
  156. SCODE QueryInterfaceProxy1632(VPVOID vpvThis16,
  157. REFIID refiid,
  158. LPVOID *ppv);
  159. DWORD TransferLocalRefs1632(VPVOID vpvProxy);
  160. DWORD AddRefProxy1632(VPVOID vpvThis16);
  161. DWORD ReleaseProxy1632(VPVOID vpvThis16);
  162. THUNK3216OBJ *CanGetNewProxy3216(IIDIDX iidx);
  163. void FreeNewProxy3216(THUNK3216OBJ *ptoProxy, IIDIDX iidx);
  164. VPVOID IsProxy3216(IUnknown *punkObj);
  165. THUNK3216OBJ *LookupProxy3216(VPVOID vpvObj16)
  166. {
  167. THUNK3216OBJ *pto;
  168. if (_pProxyTbl3216->Lookup((DWORD)vpvObj16, (void *&)pto))
  169. {
  170. return pto;
  171. }
  172. else
  173. {
  174. return NULL;
  175. }
  176. }
  177. SCODE Object16Identity(VPVOID vpvThis16, PROXYPTR *pProxy, DWORD *pfst, BOOL bCallQI, BOOL bExtraAddRef);
  178. IUnknown *CreateOuter32(VPVOID vpvOuter16, PROXYHOLDER **ppAggHolder, DWORD *pfst);
  179. IUnknown *FindProxy3216(THUNK3216OBJ *ptoPrealloc,
  180. VPVOID vpvThis16,
  181. PROXYHOLDER *pgHolder,
  182. IIDIDX iidx,
  183. BOOL bExtraAddRef,
  184. DWORD *pfst);
  185. IUnknown *FindAggregate3216(THUNK3216OBJ *ptoPrealloc,
  186. VPVOID vpvOuter16,
  187. VPVOID vpvThis16,
  188. IIDIDX iidx,
  189. PROXYHOLDER *pAggHolder,
  190. DWORD *fst);
  191. SCODE QueryInterfaceProxy3216(THUNK3216OBJ *pto,
  192. REFIID refiid,
  193. LPVOID *ppv);
  194. DWORD TransferLocalRefs3216(VPVOID vpvProxy);
  195. DWORD AddRefProxy3216(THUNK3216OBJ *pto);
  196. DWORD ReleaseProxy3216(THUNK3216OBJ *pto);
  197. void ReleaseUnreferencedProxy3216(THUNK3216OBJ *pto);
  198. void PrepareForCleanup( void );
  199. void RemoveAllProxies(void);
  200. BOOL AreCallbacksAllowed() {
  201. return(_dwState & CALLBACK_ALLOWED);
  202. }
  203. #if DBG == 1
  204. void DebugDump1632(void);
  205. void DebugDump3216(void);
  206. #endif
  207. // creation
  208. static CThkMgr * Create(void);
  209. ~CThkMgr();
  210. private:
  211. CThkMgr(CMapDwordPtr *pPT1632, CMapDwordPtr *pPT3216, CMapDwordPtr *pHolderTbl);
  212. LONG _cRefs;
  213. THKSTATE _thkstate;
  214. DWORD _dwState;
  215. CMapDwordPtr *_pProxyTbl3216;
  216. CMapDwordPtr *_pProxyTbl1632;
  217. CMapDwordPtr *_pHolderTbl;
  218. // list of requested iids
  219. PIIDNODE _piidnode;
  220. // List of proxy holders for controlling unknowns
  221. PROXYHOLDER *_pphHolders;
  222. // Holder manipulation routines
  223. PROXYHOLDER *NewHolder(VPVOID pUnk, PROXYPTR unkProxy, DWORD dwFlags);
  224. void ReleaseHolder(PROXYHOLDER *pph, DWORD ProxyType);
  225. inline void AddRefHolder(PROXYHOLDER *pph);
  226. void AddProxyToHolder(PROXYHOLDER *pph,
  227. CProxy *pprxReal,
  228. PROXYPTR &pprx);
  229. // Private methods
  230. void RemoveProxy1632(VPVOID vpv, THUNK1632OBJ *pto);
  231. void RemoveProxy3216(THUNK3216OBJ *pto);
  232. void DisableCallbacks() {
  233. _dwState &= ~CALLBACK_ALLOWED;
  234. }
  235. };
  236. #endif // ifndef __CTHKMGR_HXX__