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.

233 lines
4.6 KiB

  1. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2. //
  3. // clsfact.cpp
  4. //
  5. // Class factory for ineticon.
  6. //
  7. // History:
  8. //
  9. // 3/16/97 edwardp Created.
  10. //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Includes
  14. //
  15. #include "stdinc.h"
  16. #include "clsfact.h"
  17. #include "cdfidl.h"
  18. #include "persist.h"
  19. #include "cdfview.h"
  20. #include "iconhand.h"
  21. #include "chanmgrp.h"
  22. #include "chanmgri.h"
  23. #include "chanmenu.h"
  24. #include "proppgs.h"
  25. #include "dll.h" // DllAddRef, DllRelease.
  26. //
  27. // Constructor and destructor.
  28. //
  29. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  30. //
  31. // *** CCdfClassFactory::CCdfClassFactory ***
  32. //
  33. // Class factory constructor.
  34. //
  35. ////////////////////////////////////////////////////////////////////////////////
  36. CCdfClassFactory::CCdfClassFactory (
  37. CREATEPROC pfn
  38. )
  39. : m_cRef(1),
  40. m_Create(pfn)
  41. {
  42. ASSERT(m_Create != NULL);
  43. //
  44. // As long as this class is around the dll should stay loaded.
  45. //
  46. TraceMsg(TF_OBJECTS, "+ IClassFactory");
  47. DllAddRef();
  48. return;
  49. }
  50. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  51. //
  52. // *** CCdfClassFactory::~CCdfClassFactory ***
  53. //
  54. // Class factory destructor.
  55. //
  56. ////////////////////////////////////////////////////////////////////////////////
  57. CCdfClassFactory::~CCdfClassFactory (
  58. void
  59. )
  60. {
  61. //
  62. // Matching Release for the constructor Addref.
  63. //
  64. TraceMsg(TF_OBJECTS, "- IClassFactory");
  65. DllRelease();
  66. return;
  67. }
  68. //
  69. // IUnknown methods.
  70. //
  71. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  72. //
  73. // *** CCdfClassFactory::QueryInterface ***
  74. //
  75. // Class factory QI.
  76. //
  77. ////////////////////////////////////////////////////////////////////////////////
  78. STDMETHODIMP
  79. CCdfClassFactory::QueryInterface (
  80. REFIID riid,
  81. void **ppv
  82. )
  83. {
  84. ASSERT(ppv);
  85. HRESULT hr;
  86. if (IID_IUnknown == riid || IID_IClassFactory == riid)
  87. {
  88. AddRef();
  89. *ppv = (IClassFactory*)this;
  90. hr = S_OK;
  91. }
  92. else
  93. {
  94. *ppv = NULL;
  95. hr = E_NOINTERFACE;
  96. }
  97. ASSERT((SUCCEEDED(hr) && *ppv) || (FAILED(hr) && NULL == *ppv));
  98. return hr;
  99. }
  100. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  101. //
  102. // *** CCdfClassFactory::AddRef ***
  103. //
  104. // Class factory AddRef.
  105. //
  106. ////////////////////////////////////////////////////////////////////////////////
  107. STDMETHODIMP_(ULONG)
  108. CCdfClassFactory::AddRef (
  109. void
  110. )
  111. {
  112. ASSERT(m_cRef != 0);
  113. ASSERT(m_cRef < (ULONG)-1);
  114. return ++m_cRef;
  115. }
  116. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  117. //
  118. // *** CCdfClassFactory::Release ***
  119. //
  120. // Class factory Release.
  121. //
  122. ////////////////////////////////////////////////////////////////////////////////
  123. STDMETHODIMP_(ULONG)
  124. CCdfClassFactory::Release (
  125. void
  126. )
  127. {
  128. ASSERT (m_cRef != 0);
  129. ULONG cRef = --m_cRef;
  130. if (0 == cRef)
  131. delete this;
  132. return cRef;
  133. }
  134. //
  135. // IClassFactory methods.
  136. //
  137. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  138. //
  139. // *** CCdfClassFactory::CreateInstance ***
  140. //
  141. // Creates a cdf view object.
  142. //
  143. ////////////////////////////////////////////////////////////////////////////////
  144. STDMETHODIMP
  145. CCdfClassFactory::CreateInstance (
  146. IUnknown* pOuterUnknown,
  147. REFIID riid,
  148. void **ppvObj
  149. )
  150. {
  151. ASSERT(ppvObj);
  152. HRESULT hr;
  153. *ppvObj = NULL;
  154. if (NULL == pOuterUnknown)
  155. {
  156. IUnknown* pIUnknown;
  157. hr = m_Create(&pIUnknown);
  158. if (SUCCEEDED(hr))
  159. {
  160. ASSERT(pIUnknown)
  161. hr = pIUnknown->QueryInterface(riid, ppvObj);
  162. pIUnknown->Release();
  163. }
  164. }
  165. else
  166. {
  167. //
  168. // This object doesn't support aggregation.
  169. //
  170. hr = CLASS_E_NOAGGREGATION;
  171. }
  172. ASSERT((SUCCEEDED(hr) && *ppvObj) || (FAILED(hr) && NULL == *ppvObj));
  173. return hr;
  174. }
  175. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  176. //
  177. // *** LockServer ***
  178. //
  179. // Increments/decrements the class factory ref count.
  180. //
  181. ////////////////////////////////////////////////////////////////////////////////
  182. STDMETHODIMP
  183. CCdfClassFactory::LockServer (
  184. BOOL bLock
  185. )
  186. {
  187. if (bLock)
  188. AddRef();
  189. else
  190. Release();
  191. return S_OK;
  192. }