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.

311 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: urlcf.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12-22-95 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <urlint.h>
  18. #include <stdio.h>
  19. #include "urlcf.hxx"
  20. extern GUID CLSID_ResProtocol;
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Method: CUrlClsFact::Create
  24. //
  25. // Synopsis:
  26. //
  27. // Arguments: [clsid] --
  28. // [ppCF] --
  29. //
  30. // Returns:
  31. //
  32. // History: 12-22-95 JohannP (Johann Posch) Created
  33. //
  34. // Notes:
  35. //
  36. //----------------------------------------------------------------------------
  37. HRESULT CUrlClsFact::Create(REFCLSID clsid, CUrlClsFact **ppCF)
  38. {
  39. UrlMkDebugOut((DEB_URLMON, "NULL _IN CUrlClsFact::Create\n"));
  40. HRESULT hr = NOERROR;
  41. CUrlClsFact * pCF = NULL;
  42. if ( (clsid == CLSID_ResProtocol) )
  43. {
  44. pCF = (CUrlClsFact *) new CUrlClsFact(clsid);
  45. }
  46. if (pCF == NULL)
  47. {
  48. UrlMkAssert((pCF));
  49. hr = E_OUTOFMEMORY;
  50. }
  51. else
  52. {
  53. *ppCF = pCF;
  54. }
  55. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::Create (hr:%lx\n", pCF,hr));
  56. return hr;
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // Method: CUrlClsFact::CUrlClsFact
  61. //
  62. // Synopsis: constructor
  63. //
  64. // Arguments: [clsid] --
  65. //
  66. // Returns:
  67. //
  68. // History: 12-22-95 JohannP (Johann Posch) Created
  69. //
  70. // Notes: we need to keep a refcount on the dll if for each object given to
  71. // outside, including ClassFactories.
  72. // The corresponding DllRelease is in the destructor
  73. //
  74. //----------------------------------------------------------------------------
  75. CUrlClsFact::CUrlClsFact(REFCLSID clsid) : _CRefs(), _CLocks(0)
  76. {
  77. _ClsID = clsid;
  78. DllAddRef();
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Method: CUrlClsFact::~CUrlClsFact
  83. //
  84. // Synopsis:
  85. //
  86. // Arguments: (none)
  87. //
  88. // Returns:
  89. //
  90. // History: 12-22-95 JohannP (Johann Posch) Created
  91. //
  92. // Notes:
  93. //
  94. //----------------------------------------------------------------------------
  95. CUrlClsFact::~CUrlClsFact()
  96. {
  97. DllRelease();
  98. }
  99. //+---------------------------------------------------------------------------
  100. //
  101. // Method: CUrlClsFact::CreateInstance
  102. //
  103. // Synopsis: creates an instance of an Explode Object
  104. //
  105. // Arguments: [pUnkOuter] -- controlling unknown (must be NULL)
  106. // [riid] -- id of desired interface
  107. // [ppv] -- pointer to receive the interface
  108. //
  109. // Returns:
  110. //
  111. // History: 12-22-95 JohannP (Johann Posch) Created
  112. //
  113. // Notes: S_OK - success
  114. // CLASS_E_NOAGGREATION - the caller tried to aggregate
  115. // CLASS_E_CLASSNOTAVAILABLE - couldn't initialize the class
  116. // E_OUTOFMEMORY - not enough memory to instantiate class
  117. //
  118. //----------------------------------------------------------------------------
  119. STDMETHODIMP CUrlClsFact::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID * ppv)
  120. {
  121. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::CreateInstance\n", this));
  122. HRESULT hr = NOERROR;
  123. // Class factory init time, the pointer to the creation function of
  124. // the object is given. Use that to create the object
  125. //DumpIID(riid);
  126. //DumpIID(_rClsID);
  127. if (riid == IID_IClassFactory)
  128. {
  129. *ppv = (IClassFactory *)this;
  130. AddRef();
  131. }
  132. else if (_ClsID == CLSID_ResProtocol)
  133. {
  134. hr = CreateAPP(_ClsID, pUnkOuter, riid, (IUnknown **)ppv);
  135. }
  136. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::CreateInstance (hr:%lx)\n", this,hr));
  137. return hr;
  138. }
  139. //+---------------------------------------------------------------------------
  140. //
  141. // Method: CUrlClsFact::LockServer
  142. //
  143. // Synopsis: locks the server, preventing it from being unloaded
  144. //
  145. // Arguments: [fLock] -- TRUE to lock, FALSE to unlock
  146. //
  147. // Returns:
  148. //
  149. // History: 12-22-95 JohannP (Johann Posch) Created
  150. //
  151. // Notes:
  152. //
  153. //----------------------------------------------------------------------------
  154. STDMETHODIMP CUrlClsFact::LockServer(BOOL fLock)
  155. {
  156. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::LockServer\n", this));
  157. HRESULT hr = NOERROR;
  158. if (fLock)
  159. {
  160. if (++_CLocks == 1)
  161. {
  162. DllAddRef();
  163. }
  164. }
  165. else
  166. {
  167. UrlMkAssert((_CLocks > 0));
  168. if (_CLocks > 0)
  169. {
  170. if (--_CLocks == 0)
  171. {
  172. DllRelease();
  173. }
  174. }
  175. }
  176. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::LockServer (hr:%lx)\n", this,hr));
  177. return hr;
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // Method: CUrlClsFact::QueryInterface
  182. //
  183. // Synopsis:
  184. //
  185. // Arguments: [riid] --
  186. // [ppvObj] --
  187. //
  188. // Returns:
  189. //
  190. // History: 12-22-95 JohannP (Johann Posch) Created
  191. //
  192. // Notes:
  193. //
  194. //----------------------------------------------------------------------------
  195. STDMETHODIMP CUrlClsFact::QueryInterface(REFIID riid, void **ppvObj)
  196. {
  197. VDATEPTROUT(ppvObj, void *);
  198. HRESULT hr = NOERROR;
  199. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::QueryInterface\n", this));
  200. if ( riid == IID_IUnknown
  201. || riid == IID_IClassFactory)
  202. {
  203. *ppvObj = this;
  204. }
  205. else
  206. {
  207. *ppvObj = NULL;
  208. hr = E_NOINTERFACE;
  209. }
  210. if (hr == NOERROR)
  211. {
  212. AddRef();
  213. }
  214. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::QueryInterface (hr:%lx\n", this,hr));
  215. return hr;
  216. }
  217. //+---------------------------------------------------------------------------
  218. //
  219. // Function: CUrlClsFact::AddRef
  220. //
  221. // Synopsis:
  222. //
  223. // Arguments: [ULONG] --
  224. //
  225. // Returns:
  226. //
  227. // History: 12-22-95 JohannP (Johann Posch) Created
  228. //
  229. // Notes:
  230. //
  231. //----------------------------------------------------------------------------
  232. STDMETHODIMP_(ULONG) CUrlClsFact::AddRef(void)
  233. {
  234. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::AddRef\n", this));
  235. LONG lRet = ++_CRefs;
  236. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::AddRef (cRefs:%ld)\n", this,lRet));
  237. return lRet;
  238. }
  239. //+---------------------------------------------------------------------------
  240. //
  241. // Function: CUrlClsFact::Release
  242. //
  243. // Synopsis:
  244. //
  245. // Arguments: [ULONG] --
  246. //
  247. // Returns:
  248. //
  249. // History: 12-22-95 JohannP (Johann Posch) Created
  250. //
  251. // Notes:
  252. //
  253. //----------------------------------------------------------------------------
  254. STDMETHODIMP_(ULONG) CUrlClsFact::Release(void)
  255. {
  256. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::Release\n", this));
  257. LONG lRet = --_CRefs;
  258. if (_CRefs == 0)
  259. {
  260. delete this;
  261. }
  262. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::Release (cRefs:%ld)\n", this,lRet));
  263. return lRet;
  264. }
  265. #if DBG==1
  266. HRESULT DumpIID(REFIID riid)
  267. {
  268. HRESULT hr;
  269. LPOLESTR pszStr = NULL;
  270. hr = StringFromCLSID(riid, &pszStr);
  271. UrlMkDebugOut((DEB_BINDING, "API >>> DumpIID (riid:%ws) \n", pszStr));
  272. if (pszStr)
  273. {
  274. delete pszStr;
  275. }
  276. return hr;
  277. }
  278. #endif