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.

270 lines
7.6 KiB

  1. /*****************************************************************/
  2. /** Microsoft **/
  3. /** Copyright (C) Microsoft Corp., 1991-1998 **/
  4. /*****************************************************************/
  5. //
  6. // FACTORY.CPP -
  7. //
  8. // HISTORY:
  9. //
  10. // 07/28/98 donaldm created
  11. //
  12. #include "pre.h"
  13. #include "webvwids.h"
  14. /*---------------------------------------------------------------------------
  15. Implementation the ClassFactory Class Factory. CFWebView is the COM
  16. object class for the Class Factory that can manufacture CLSID_ICWWEBVIEW
  17. COM Components.
  18. ---------------------------------------------------------------------------*/
  19. /*---------------------------------------------------------------------------
  20. Method: ClassFactory::ClassFactory
  21. Summary:
  22. Args:
  23. CServer* pServer)
  24. Pointer to the server's control object.
  25. Modifies: m_cRefs
  26. Returns: void
  27. ---------------------------------------------------------------------------*/
  28. ClassFactory::ClassFactory
  29. (
  30. CServer * pServer,
  31. CLSID const* pclsid
  32. )
  33. {
  34. // Zero the COM object's reference count.
  35. m_cRefs = 0;
  36. // Init the pointer to the server control object.
  37. m_pServer = pServer;
  38. // Keep track of the class type we need to create
  39. m_pclsid = pclsid;
  40. return;
  41. }
  42. /*---------------------------------------------------------------------------
  43. Method: ClassFactory::~ClassFactory
  44. Summary: ClassFactory Destructor.
  45. Args: void
  46. Modifies: .
  47. Returns: void
  48. ---------------------------------------------------------------------------*/
  49. ClassFactory::~ClassFactory(void)
  50. {
  51. return;
  52. }
  53. /*---------------------------------------------------------------------------
  54. Method: ClassFactory::QueryInterface
  55. Summary: QueryInterface of the ClassFactory non-delegating
  56. IUnknown implementation.
  57. Args: REFIID riid,
  58. [in] GUID of the Interface being requested.
  59. void ** ppv)
  60. [out] Address of the caller's pointer variable that will
  61. receive the requested interface pointer.
  62. Modifies: .
  63. Returns: HRESULT
  64. ---------------------------------------------------------------------------*/
  65. STDMETHODIMP ClassFactory::QueryInterface
  66. (
  67. REFIID riid,
  68. void ** ppv
  69. )
  70. {
  71. HRESULT hr = E_NOINTERFACE;
  72. *ppv = NULL;
  73. if (IID_IUnknown == riid)
  74. {
  75. *ppv = this;
  76. }
  77. else if (IID_IClassFactory == riid)
  78. {
  79. *ppv = static_cast<IClassFactory*>(this);
  80. }
  81. if (NULL != *ppv)
  82. {
  83. // We've handed out a pointer to the interface so obey the COM rules
  84. // and AddRef the reference count.
  85. ((LPUNKNOWN)*ppv)->AddRef();
  86. hr = NOERROR;
  87. }
  88. return (hr);
  89. }
  90. /*---------------------------------------------------------------------------
  91. Method: ClassFactory::AddRef
  92. Summary: AddRef of the ClassFactory non-delegating IUnknown implementation.
  93. Args: void
  94. Modifies: m_cRefs.
  95. Returns: ULONG
  96. New value of m_cRefs (COM object's reference count).
  97. ---------------------------------------------------------------------------*/
  98. STDMETHODIMP_(ULONG) ClassFactory::AddRef(void)
  99. {
  100. return InterlockedIncrement(&m_cRefs);
  101. return m_cRefs;
  102. }
  103. /*---------------------------------------------------------------------------
  104. Method: ClassFactory::Release
  105. Summary: Release of the ClassFactory non-delegating IUnknown implementation.
  106. Args: void
  107. Modifies: m_cRefs.
  108. Returns: ULONG
  109. New value of m_cRefs (COM object's reference count).
  110. ---------------------------------------------------------------------------*/
  111. STDMETHODIMP_(ULONG) ClassFactory::Release(void)
  112. {
  113. if (InterlockedDecrement(&m_cRefs) == 0)
  114. {
  115. // We've reached a zero reference count for this COM object.
  116. // So we tell the server housing to decrement its global object
  117. // count so that the server will be unloaded if appropriate.
  118. if (NULL != m_pServer)
  119. m_pServer->ObjectsDown();
  120. delete this;
  121. return 0 ;
  122. }
  123. TraceMsg(TF_CLASSFACTORY, "CFactory::Release %d", m_cRefs);
  124. return m_cRefs;
  125. }
  126. /*---------------------------------------------------------------------------
  127. Method: ClassFactory::CreateInstance
  128. Summary: The CreateInstance member method of this IClassFactory interface
  129. implementation. Creates an instance of the CICWWebView COM
  130. component.
  131. Args: IUnknown* pUnkOuter,
  132. [in] Pointer to the controlling IUnknown.
  133. REFIID riid,
  134. [in] GUID of the Interface being requested.
  135. void ** ppvCob)
  136. [out] Address of the caller's pointer variable that will
  137. receive the requested interface pointer.
  138. Modifies: .
  139. Returns: HRESULT
  140. Standard OLE result code.
  141. ---------------------------------------------------------------------------*/
  142. STDMETHODIMP ClassFactory::CreateInstance
  143. (
  144. IUnknown* pUnkOuter,
  145. REFIID riid,
  146. void ** ppv
  147. )
  148. {
  149. HRESULT hr = E_FAIL;
  150. IUnknown * pCob = NULL;
  151. // NULL the output pointer.
  152. *ppv = NULL;
  153. // We don't support aggregation
  154. if (NULL != pUnkOuter)
  155. hr = CLASS_E_NOAGGREGATION;
  156. else
  157. {
  158. // Instantiate a COM Object, based on the clsid requsted by GetClassObject
  159. if (IsEqualGUID(CLSID_ICWWEBVIEW, *m_pclsid))
  160. pCob = (IUnknown *) new CICWWebView(m_pServer);
  161. else if (IsEqualGUID(CLSID_ICWWALKER, *m_pclsid))
  162. pCob = (IUnknown *) new CICWWalker(m_pServer);
  163. else if (IsEqualGUID(CLSID_ICWGIFCONVERT, *m_pclsid))
  164. pCob = (IUnknown *) new CICWGifConvert(m_pServer);
  165. else if (IsEqualGUID(CLSID_ICWISPDATA, *m_pclsid))
  166. pCob = (IUnknown *) new CICWISPData(m_pServer);
  167. else
  168. pCob = NULL;
  169. if (NULL != pCob)
  170. {
  171. // We initially created the new COM object so tell the server
  172. // to increment its global server object count to help ensure
  173. // that the server remains loaded until this partial creation
  174. // of a COM component is completed.
  175. m_pServer->ObjectsUp();
  176. // We QueryInterface this new COM Object not only to deposit the
  177. // main interface pointer to the caller's pointer variable, but to
  178. // also automatically bump the Reference Count on the new COM
  179. // Object after handing out this reference to it.
  180. hr = pCob->QueryInterface(riid, (void **)ppv);
  181. if (FAILED(hr))
  182. {
  183. m_pServer->ObjectsDown();
  184. delete pCob;
  185. }
  186. }
  187. else
  188. hr = E_OUTOFMEMORY;
  189. }
  190. return hr;
  191. }
  192. /*---------------------------------------------------------------------------
  193. Method: ClassFactory::LockServer
  194. Summary: The LockServer member method of this IClassFactory interface
  195. implementation.
  196. Args: BOOL fLock)
  197. [in] Flag determining whether to Lock or Unlock the server.
  198. Modifies: .
  199. Returns: HRESULT
  200. Standard OLE result code.
  201. ---------------------------------------------------------------------------*/
  202. STDMETHODIMP ClassFactory::LockServer
  203. (
  204. BOOL fLock
  205. )
  206. {
  207. HRESULT hr = NOERROR;
  208. if (fLock)
  209. m_pServer->Lock();
  210. else
  211. m_pServer->Unlock();
  212. return hr;
  213. }