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.

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