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.

341 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. wamccf.cxx
  5. Abstract:
  6. This module implements the WAM Custom Class Factory
  7. which creates WAM objects regardless of passed class id
  8. Author:
  9. Dmitry Robsman ( dmitryr ) 07-Apr-1997
  10. Environment:
  11. User Mode - Win32
  12. Project:
  13. Wam DLL
  14. --*/
  15. /************************************************************
  16. * Include Headers
  17. ************************************************************/
  18. #include <isapip.hxx>
  19. #include "setable.hxx"
  20. #include "wamobj.hxx"
  21. #include "wamccf.hxx"
  22. /************************************************************
  23. * W A M C C F
  24. ************************************************************/
  25. WAM_CCF::WAM_CCF()
  26. /*++
  27. Routine Description:
  28. WAM_CCF Constructor
  29. Arguments:
  30. Return Value:
  31. --*/
  32. :
  33. m_cRef(0),
  34. m_pcfAtl(NULL)
  35. {
  36. // Query ATL's class factory for WAM
  37. _Module.GetClassObject
  38. (
  39. CLSID_Wam,
  40. IID_IClassFactory,
  41. (void **)(&m_pcfAtl)
  42. );
  43. }
  44. /*----------------------------------------------------------*/
  45. WAM_CCF::~WAM_CCF()
  46. /*++
  47. Routine Description:
  48. WAM_CCF Destructor
  49. Arguments:
  50. Return Value:
  51. --*/
  52. {
  53. if (m_pcfAtl)
  54. m_pcfAtl->Release();
  55. }
  56. /*----------------------------------------------------------*/
  57. STDMETHODIMP
  58. WAM_CCF::QueryInterface
  59. (
  60. REFIID riid,
  61. LPVOID *ppv
  62. )
  63. /*++
  64. Routine Description:
  65. WAM_CCF implementation of IUnknown::QueryInterface
  66. Arguments:
  67. REFIID riid interface id
  68. LPVOID *ppv [out]
  69. Return Value:
  70. HRESULT
  71. --*/
  72. {
  73. if (!ppv)
  74. return E_POINTER;
  75. if (!m_pcfAtl) // must have original CF to create WAMs
  76. return E_NOINTERFACE;
  77. *ppv = NULL;
  78. if (IID_IUnknown == riid || IID_IClassFactory == riid)
  79. *ppv = this;
  80. if (*ppv)
  81. {
  82. ((LPUNKNOWN)*ppv)->AddRef();
  83. return NOERROR;
  84. }
  85. return E_NOINTERFACE;
  86. }
  87. /*----------------------------------------------------------*/
  88. STDMETHODIMP_(ULONG)
  89. WAM_CCF::AddRef()
  90. /*++
  91. Routine Description:
  92. WAM_CCF implementation of IUnknown::AddRef
  93. Arguments:
  94. Return Value:
  95. ref count
  96. --*/
  97. {
  98. return (ULONG)InterlockedIncrement((LPLONG)(&m_cRef));
  99. }
  100. /*----------------------------------------------------------*/
  101. STDMETHODIMP_(ULONG)
  102. WAM_CCF::Release()
  103. /*++
  104. Routine Description:
  105. WAM_CCF implementation of IUnknown::Release
  106. Arguments:
  107. Return Value:
  108. ref count
  109. --*/
  110. {
  111. ULONG cRef = (ULONG)InterlockedDecrement((LPLONG)(&m_cRef));
  112. if (cRef > 0)
  113. return cRef;
  114. delete this;
  115. return 0;
  116. }
  117. /*----------------------------------------------------------*/
  118. STDMETHODIMP
  119. WAM_CCF::CreateInstance
  120. (
  121. LPUNKNOWN pUnkOuter,
  122. REFIID riid,
  123. LPVOID *ppvObj
  124. )
  125. /*++
  126. Routine Description:
  127. WAM_CCF implementation of IClassFactory::CreateInstance
  128. Delegate to default ATL CF
  129. Arguments:
  130. LPUNKNOWN pUnkOuter outer object
  131. REFIID riid interface id to query
  132. LPVOID *ppvObj [out]
  133. Return Value:
  134. HRESULT
  135. --*/
  136. {
  137. if (!m_pcfAtl)
  138. return E_UNEXPECTED;
  139. return m_pcfAtl->CreateInstance(pUnkOuter, riid, ppvObj);
  140. }
  141. /*----------------------------------------------------------*/
  142. STDMETHODIMP
  143. WAM_CCF::LockServer
  144. (
  145. BOOL fLock
  146. )
  147. /*++
  148. Routine Description:
  149. WAM_CCF implementation of IClassFactory::LockServer
  150. Delegate to default ATL CF
  151. Arguments:
  152. BOOL fLock flag (lock/unlock)
  153. Return Value:
  154. HRESULT
  155. --*/
  156. {
  157. if (!m_pcfAtl)
  158. return E_UNEXPECTED;
  159. m_pcfAtl->LockServer(fLock);
  160. return NOERROR;
  161. }
  162. /************************************************************
  163. * W A M C C F M O D U L E
  164. ************************************************************/
  165. WAM_CCF_MODULE::WAM_CCF_MODULE()
  166. /*++
  167. Routine Description:
  168. WAM_CCF_MODULE Constructor
  169. Arguments:
  170. Return Value:
  171. --*/
  172. :
  173. m_pCF(NULL)
  174. {
  175. }
  176. /*----------------------------------------------------------*/
  177. WAM_CCF_MODULE::~WAM_CCF_MODULE()
  178. /*++
  179. Routine Description:
  180. WAM_CCF_MODULE Destructor
  181. Arguments:
  182. Return Value:
  183. --*/
  184. {
  185. }
  186. /*----------------------------------------------------------*/
  187. HRESULT
  188. WAM_CCF_MODULE::Init()
  189. /*++
  190. Routine Description:
  191. Initialize WAM_CCF_MODULE. Create Custom Class Factory.
  192. Arguments:
  193. Return Value:
  194. HRESULT
  195. --*/
  196. {
  197. m_pCF = new WAM_CCF;
  198. if (!m_pCF)
  199. return E_OUTOFMEMORY;
  200. m_pCF->AddRef(); // keep AddRef()'d
  201. return NOERROR;
  202. }
  203. /*----------------------------------------------------------*/
  204. HRESULT
  205. WAM_CCF_MODULE::Term()
  206. /*++
  207. Routine Description:
  208. UnInitialize WAM_CCF_MODULE. Remove Custom Class Factory.
  209. Arguments:
  210. Return Value:
  211. HRESULT
  212. --*/
  213. {
  214. if (m_pCF)
  215. {
  216. m_pCF->Release();
  217. m_pCF = NULL;
  218. }
  219. return NOERROR;
  220. }
  221. /*----------------------------------------------------------*/
  222. HRESULT
  223. WAM_CCF_MODULE::GetClassObject
  224. (
  225. REFCLSID rclsid,
  226. REFIID riid,
  227. LPVOID *ppv
  228. )
  229. /*++
  230. Routine Description:
  231. Gives out to the called an addref'd Custom Class Library
  232. Arguments:
  233. REFCLSID rclsid Class Id (ignored)
  234. REFIID riid QI CCF for this
  235. LPVOID *ppv [out] returned CCF pointer
  236. Return Value:
  237. HRESULT
  238. --*/
  239. {
  240. if (!m_pCF)
  241. return CLASS_E_CLASSNOTAVAILABLE;
  242. // CONSIDER: verify rclsid somehow
  243. return m_pCF->QueryInterface(riid, ppv);
  244. }
  245. /************************ End of File ***********************/