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.

240 lines
10 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: stdcf.cxx
  4. //
  5. // Contents: class implementing standard CF for internal OLE classes
  6. //
  7. // Classes: CStdClassFactory
  8. //
  9. // History: Rickhi 06-24-97 Created
  10. //
  11. //+-------------------------------------------------------------------
  12. #include <ole2int.h>
  13. #include <stdcf.hxx>
  14. // CreateInstance functions for each of the internal classes.
  15. extern HRESULT CGIPTableCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppv);
  16. extern HRESULT CAccessControlCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppv);
  17. extern HRESULT CAsyncActManagerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppv);
  18. extern HRESULT CComCatCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  19. extern HRESULT CComCatCSCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  20. extern HRESULT CItemMonikerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  21. extern HRESULT CCompositeMonikerCF_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);
  22. extern HRESULT CPackagerMonikerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  23. extern HRESULT CAntiMonikerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  24. extern HRESULT CPointerMonikerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  25. extern HRESULT CErrorObjectCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  26. extern HRESULT CRpcHelperCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  27. extern HRESULT CObjectContextCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  28. extern HRESULT CComCatalogCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  29. extern HRESULT CStdEventCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  30. extern HRESULT CManualResetEventCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  31. extern HRESULT CSynchronizeContainerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  32. extern HRESULT CFreeThreadedMarshalerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  33. extern HRESULT CActivationPropertiesInCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  34. extern HRESULT CActivationPropertiesOutCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  35. extern HRESULT CInprocActpropsUnmarshallerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  36. extern HRESULT CComActivatorCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  37. extern HRESULT CAddrControlCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  38. //+-------------------------------------------------------------------
  39. // Entry in the global calss objects table. Contains a ptr to a clsid
  40. // and a ptr to the corresponding CreateInstance function for that
  41. // clsid.
  42. //+-------------------------------------------------------------------
  43. typedef struct tagCFEntry
  44. {
  45. const CLSID *pclsid; // ptr to clsid
  46. LPFNCREATEINSTANCE pfnCI; // ptr to CreateInstance fn
  47. DWORD dwFlags; // misc flags. see CCF_FLAGS
  48. } CFEntry;
  49. typedef enum tagCCF_FLAGS
  50. {
  51. CCF_NONE = 0x0,
  52. CCF_AGGREGATABLE = 0x1, // class is aggregatable
  53. } CCF_FLAGS;
  54. //+-------------------------------------------------------------------
  55. //
  56. // gInternalClassObjects - table of clsids and the corresponding
  57. // CreateInstance functions for those clsids. The CI function is
  58. // passed to the standard implementation of the class factory object.
  59. //
  60. //+-------------------------------------------------------------------
  61. const CFEntry gInternalClassObjects[] =
  62. {
  63. {&CLSID_StdEvent, CStdEventCF_CreateInstance, CCF_AGGREGATABLE},
  64. {&CLSID_ManualResetEvent, CManualResetEventCF_CreateInstance, CCF_AGGREGATABLE},
  65. {&CLSID_SynchronizeContainer, CSynchronizeContainerCF_CreateInstance, CCF_AGGREGATABLE},
  66. {&CLSID_StdGlobalInterfaceTable, CGIPTableCF_CreateInstance, CCF_NONE},
  67. {&CLSID_DCOMAccessControl, CAccessControlCF_CreateInstance, CCF_AGGREGATABLE},
  68. {&CLSID_ErrorObject, CErrorObjectCF_CreateInstance, CCF_NONE},
  69. {&CLSID_COMCatalog, CComCatalogCF_CreateInstance, CCF_NONE},
  70. {&CLSID_ItemMoniker, CItemMonikerCF_CreateInstance, CCF_NONE},
  71. {&CLSID_CompositeMoniker, CCompositeMonikerCF_CreateInstance, CCF_NONE},
  72. {&CLSID_PackagerMoniker, CPackagerMonikerCF_CreateInstance, CCF_NONE},
  73. {&CLSID_AntiMoniker, CAntiMonikerCF_CreateInstance, CCF_NONE},
  74. {&CLSID_PointerMoniker, CPointerMonikerCF_CreateInstance, CCF_NONE},
  75. {&CLSID_StdComponentCategoriesMgr, CComCatCF_CreateInstance, CCF_AGGREGATABLE},
  76. {&CLSID_GblComponentCategoriesMgr, CComCatCSCF_CreateInstance, CCF_AGGREGATABLE},
  77. {&CLSID_RpcHelper, CRpcHelperCF_CreateInstance, CCF_NONE},
  78. {&CLSID_ObjectContext, CObjectContextCF_CreateInstance, CCF_NONE},
  79. {&CLSID_InProcFreeMarshaler, CFreeThreadedMarshalerCF_CreateInstance, CCF_AGGREGATABLE},
  80. {&CLSID_ActivationPropertiesIn, CActivationPropertiesInCF_CreateInstance, CCF_NONE},
  81. {&CLSID_ActivationPropertiesOut, CActivationPropertiesOutCF_CreateInstance, CCF_NONE},
  82. {&CLSID_InprocActpropsUnmarshaller, CInprocActpropsUnmarshallerCF_CreateInstance, CCF_NONE},
  83. {&CLSID_ComActivator, CComActivatorCF_CreateInstance, CCF_NONE},
  84. {&CLSID_AddrControl, CAddrControlCF_CreateInstance, CCF_NONE},
  85. {NULL, NULL}
  86. };
  87. //+-------------------------------------------------------------------
  88. //
  89. // Function: ComDllGetClassObject
  90. //
  91. // Synopsis: Function to return internal class objects.
  92. //
  93. // Notes: Uses the gInternalClassObjects table and the
  94. // CStdClassFactory implementation.
  95. //
  96. //+-------------------------------------------------------------------
  97. INTERNAL ComDllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  98. {
  99. ComDebOut((DEB_ACTIVATE, "ComDllGetClassObject rclsid:%I riid:%I ppv:%x\n",
  100. &rclsid, &riid, ppv));
  101. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  102. int i=0;
  103. while (gInternalClassObjects[i].pclsid)
  104. {
  105. if (InlineIsEqualGUID(*gInternalClassObjects[i].pclsid, rclsid))
  106. {
  107. // found a matching CLSID. Create an instance of the std class factory
  108. // passing in the creatinstance function from the table.
  109. hr = E_OUTOFMEMORY;
  110. CStdClassFactory *pCF = new CStdClassFactory(i);
  111. if (pCF)
  112. {
  113. hr = pCF->QueryInterface(riid, ppv);
  114. pCF->Release();
  115. }
  116. break;
  117. }
  118. i++;
  119. }
  120. ComDebOut((DEB_ACTIVATE, "ComDllGetClassObject hr:%x pv:%x\n", hr, *ppv));
  121. return hr;
  122. }
  123. //+-------------------------------------------------------------------
  124. //
  125. // Member: CStdClassFactory::AddRef, public
  126. //
  127. // Synopsis: Adds a reference to an interface
  128. //
  129. //--------------------------------------------------------------------
  130. STDMETHODIMP_(ULONG) CStdClassFactory::AddRef(void)
  131. {
  132. return InterlockedIncrement((LONG *)&_cRefs);
  133. }
  134. //+-------------------------------------------------------------------
  135. //
  136. // Member: CStdClassFactory::Release, public
  137. //
  138. // Synopsis: Adds a reference to an interface
  139. //
  140. //--------------------------------------------------------------------
  141. STDMETHODIMP_(ULONG) CStdClassFactory::Release(void)
  142. {
  143. ULONG cRefs = (ULONG) InterlockedDecrement((LONG *)&_cRefs);
  144. if (cRefs == 0)
  145. {
  146. delete this;
  147. }
  148. return cRefs;
  149. }
  150. //+-------------------------------------------------------------------
  151. //
  152. // Member: CStdClassFactory::QueryInterface, public
  153. //
  154. // Synopsis: Returns a pointer to the requested interface.
  155. //
  156. //--------------------------------------------------------------------
  157. STDMETHODIMP CStdClassFactory::QueryInterface(REFIID riid, void **ppv)
  158. {
  159. if (IsEqualIID(riid, IID_IClassFactory) ||
  160. IsEqualIID(riid, IID_IUnknown))
  161. {
  162. *ppv = (IClassFactory *) this;
  163. AddRef();
  164. return S_OK;
  165. }
  166. *ppv = NULL;
  167. return E_NOINTERFACE;
  168. }
  169. //+-------------------------------------------------------------------
  170. //
  171. // Member: CStdClassFactory::CreateInstance, public
  172. //
  173. // Synopsis: Create an instance of the requested class by calling
  174. // the creation function member variable.
  175. //
  176. // Notes: Does the parameter checking here to avoid having to
  177. // replicate it in all the creation functions.
  178. //
  179. //--------------------------------------------------------------------
  180. STDMETHODIMP CStdClassFactory::CreateInstance(IUnknown *pUnkOuter,
  181. REFIID riid,
  182. void **ppv)
  183. {
  184. ComDebOut((DEB_ACTIVATE,
  185. "CStdClassFactory::CreateInstance _dwIndex:%x pUnkOuter:%x riid:%I ppv:%x\n",
  186. _dwIndex, pUnkOuter, &riid, ppv));
  187. // Validate the parameters.
  188. HRESULT hr = E_INVALIDARG;
  189. if (ppv != NULL)
  190. {
  191. *ppv = NULL;
  192. // If the caller wants to aggregate, only IID_IUnknown may be requested.
  193. if (pUnkOuter == NULL || IsEqualGUID(IID_IUnknown, riid))
  194. {
  195. // check if aggregation desired and supported.
  196. hr = CLASS_E_NOAGGREGATION;
  197. if ( pUnkOuter == NULL ||
  198. (gInternalClassObjects[_dwIndex].dwFlags & CCF_AGGREGATABLE))
  199. {
  200. // Create the object instance
  201. IUnknown *pUnk=NULL;
  202. hr = (gInternalClassObjects[_dwIndex].pfnCI)(pUnkOuter, riid, (void **)&pUnk);
  203. if (SUCCEEDED(hr))
  204. {
  205. // get the requested interface
  206. hr = pUnk->QueryInterface(riid, ppv);
  207. pUnk->Release();
  208. }
  209. }
  210. }
  211. }
  212. ComDebOut((DEB_ACTIVATE, "CStdClassFactory::CreateInstance hr:%x *ppv:%x\n",
  213. hr, *ppv));
  214. return hr;
  215. }