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.

236 lines
5.9 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: classfac.cpp
  5. // Content: This file contains the class factory object.
  6. // History:
  7. // Tue 08-Oct-1996 08:56:46 -by- Viroon Touranachun [viroont]
  8. //
  9. // Copyright (c) Microsoft Corporation 1996-1997
  10. //
  11. //****************************************************************************
  12. #include "ulsp.h"
  13. #include "culs.h"
  14. //****************************************************************************
  15. // Initialize GUIDs (should be done only and at-least once per DLL/EXE)
  16. //****************************************************************************
  17. #define INITGUID
  18. #include <initguid.h>
  19. #include <ilsguid.h>
  20. #include "classfac.h"
  21. //****************************************************************************
  22. // Global Parameters
  23. //****************************************************************************
  24. //
  25. CClassFactory* g_pClassFactory = NULL;
  26. //****************************************************************************
  27. // CClassFactory::CClassFactory (void)
  28. //
  29. // History:
  30. // Tue 08-Oct-1996 09:00:10 -by- Viroon Touranachun [viroont]
  31. // Created.
  32. //****************************************************************************
  33. CClassFactory::
  34. CClassFactory (void)
  35. {
  36. cRef = 0;
  37. return;
  38. }
  39. //****************************************************************************
  40. // STDMETHODIMP
  41. // CClassFactory::QueryInterface (REFIID riid, void **ppv)
  42. //
  43. // History:
  44. // Tue 08-Oct-1996 09:00:18 -by- Viroon Touranachun [viroont]
  45. // Created.
  46. //****************************************************************************
  47. STDMETHODIMP
  48. CClassFactory::QueryInterface (REFIID riid, void **ppv)
  49. {
  50. if (riid == IID_IClassFactory || riid == IID_IUnknown)
  51. {
  52. *ppv = (IClassFactory *) this;
  53. AddRef();
  54. return S_OK;
  55. }
  56. *ppv = NULL;
  57. return ILS_E_NO_INTERFACE;
  58. }
  59. //****************************************************************************
  60. // STDMETHODIMP_(ULONG)
  61. // CClassFactory::AddRef (void)
  62. //
  63. // History:
  64. // Tue 08-Oct-1996 09:00:26 -by- Viroon Touranachun [viroont]
  65. // Created.
  66. //****************************************************************************
  67. STDMETHODIMP_(ULONG)
  68. CClassFactory::AddRef (void)
  69. {
  70. DllLock();
  71. ASSERT (this == g_pClassFactory);
  72. MyDebugMsg ((DM_REFCOUNT, "CClassFactory::AddRef: ref=%ld\r\n", cRef));
  73. ::InterlockedIncrement ((LONG *) &cRef);
  74. return cRef;
  75. }
  76. //****************************************************************************
  77. // STDMETHODIMP_(ULONG)
  78. // CClassFactory::Release (void)
  79. //
  80. // History:
  81. // Tue 08-Oct-1996 09:00:33 -by- Viroon Touranachun [viroont]
  82. // Created.
  83. //****************************************************************************
  84. STDMETHODIMP_(ULONG)
  85. CClassFactory::Release (void)
  86. {
  87. DllRelease();
  88. ASSERT (this == g_pClassFactory);
  89. ASSERT (cRef > 0);
  90. MyDebugMsg ((DM_REFCOUNT, "CClassFactory::Release: ref=%ld\r\n", cRef));
  91. if (::InterlockedDecrement ((LONG *) &cRef) == 0)
  92. {
  93. delete this;
  94. g_pClassFactory = NULL;
  95. };
  96. return cRef;
  97. }
  98. //****************************************************************************
  99. // STDMETHODIMP
  100. // CClassFactory::CreateInstance (LPUNKNOWN punkOuter, REFIID riid, void **ppv)
  101. //
  102. // History:
  103. // Tue 08-Oct-1996 09:00:40 -by- Viroon Touranachun [viroont]
  104. // Created.
  105. //****************************************************************************
  106. STDMETHODIMP
  107. CClassFactory::CreateInstance (LPUNKNOWN punkOuter, REFIID riid, void **ppv)
  108. {
  109. CIlsMain *pcu;
  110. HRESULT hr;
  111. if (ppv == NULL)
  112. {
  113. return ILS_E_POINTER;
  114. };
  115. *ppv = NULL;
  116. if (punkOuter != NULL)
  117. {
  118. return CLASS_E_NOAGGREGATION;
  119. };
  120. // Allow only on instance of the ULS object
  121. //
  122. if (g_pCIls != NULL)
  123. {
  124. return ILS_E_FAIL;
  125. };
  126. pcu = new CIlsMain;
  127. if (pcu != NULL)
  128. {
  129. hr = pcu->Init();
  130. if (SUCCEEDED(hr))
  131. {
  132. *ppv = (IIlsMain *)pcu;
  133. pcu->AddRef();
  134. }
  135. else
  136. {
  137. delete pcu;
  138. };
  139. }
  140. else
  141. {
  142. hr = ILS_E_MEMORY;
  143. };
  144. return hr;
  145. }
  146. //****************************************************************************
  147. // STDMETHODIMP
  148. // CClassFactory::LockServer (BOOL fLock)
  149. //
  150. // History:
  151. // Tue 08-Oct-1996 09:00:48 -by- Viroon Touranachun [viroont]
  152. // Created.
  153. //****************************************************************************
  154. STDMETHODIMP
  155. CClassFactory::LockServer (BOOL fLock)
  156. {
  157. if (fLock)
  158. {
  159. DllLock();
  160. MyDebugMsg ((DM_REFCOUNT, "CClassFactory::LockServer\r\n"));
  161. }
  162. else
  163. {
  164. DllRelease();
  165. MyDebugMsg ((DM_REFCOUNT, "CClassFactory::UNLockServer\r\n"));
  166. };
  167. return S_OK;
  168. }
  169. //****************************************************************************
  170. // STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  171. //
  172. // History:
  173. // Tue 08-Oct-1996 09:00:55 -by- Viroon Touranachun [viroont]
  174. // Created.
  175. //****************************************************************************
  176. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  177. {
  178. if (riid == IID_IClassFactory || riid == IID_IUnknown)
  179. {
  180. // Check the requested class
  181. //
  182. if (rclsid == CLSID_InternetLocationServices)
  183. {
  184. if (g_pClassFactory == NULL)
  185. {
  186. g_pClassFactory = new CClassFactory;
  187. }
  188. ASSERT (g_pClassFactory != NULL);
  189. if ((*ppv = (void *) g_pClassFactory) != NULL)
  190. {
  191. g_pClassFactory->AddRef ();
  192. return NOERROR;
  193. }
  194. else
  195. {
  196. return E_OUTOFMEMORY;
  197. }
  198. };
  199. }
  200. *ppv = NULL;
  201. return CLASS_E_CLASSNOTAVAILABLE;
  202. }