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.

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