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.

230 lines
5.8 KiB

  1. //------------------------------------------------------------------------------
  2. //
  3. // File: classfact.cpp
  4. // Copyright (C) 1995-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // Purpose:
  8. // Implementation of CLocImpClassFactory, which provides the IClassFactory
  9. // interface for the parser.
  10. //
  11. // YOU SHOULD NOT NEED TO TOUCH ANYTHING IN THIS FILE. This code contains
  12. // nothing parser-specific and is called only by Espresso.
  13. //
  14. // Owner:
  15. //
  16. //------------------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include "dllvars.h"
  19. #include "resource.h"
  20. #include "impparse.h"
  21. #include "clasfact.h"
  22. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  23. //
  24. // Constructor for class factory implementation.
  25. //------------------------------------------------------------------------------
  26. CLocImpClassFactory::CLocImpClassFactory()
  27. {
  28. m_uiRefCount = 0;
  29. AddRef();
  30. IncrementClassCount();
  31. return;
  32. } // end of CLocImpClassFactory::CLocImpClassFactory()
  33. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  34. //
  35. // Destructor for class factory implementation.
  36. //------------------------------------------------------------------------------
  37. CLocImpClassFactory::~CLocImpClassFactory()
  38. {
  39. LTASSERT(0 == m_uiRefCount);
  40. DEBUGONLY(AssertValid());
  41. DecrementClassCount();
  42. return;
  43. } // end of CLocImpClassFactory::~CLocImpClassFactory()
  44. #ifdef _DEBUG
  45. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46. //
  47. // Assert if object is not valid. Unfortunately, there really isn't anything
  48. // we can check.
  49. //------------------------------------------------------------------------------
  50. void
  51. CLocImpClassFactory::AssertValid()
  52. const
  53. {
  54. CLObject::AssertValid();
  55. return;
  56. } // end of CLocImpClassFactory::AssertValid()
  57. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  58. //
  59. // Dump all internal data to supplied dump context, for debugging purposes.
  60. //------------------------------------------------------------------------------
  61. void
  62. CLocImpClassFactory::Dump(
  63. CDumpContext &dc) // Context to dump to.
  64. const
  65. {
  66. CLObject::Dump(dc);
  67. dc << "NET Parser CLocImpClassFactory:\n\r";
  68. dc << "\tm_uiRefCount: " << m_uiRefCount << "\n\r";
  69. return;
  70. } // end of CLocImpClassFactory::Dump()
  71. #endif // _DEBUG
  72. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  73. //
  74. // Increment reference count for object, return new value.
  75. //------------------------------------------------------------------------------
  76. ULONG
  77. CLocImpClassFactory::AddRef()
  78. {
  79. return ++m_uiRefCount;
  80. } // end of CLocImpClassFactory::AddRef()
  81. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  82. //
  83. // Decrement reference count for object. If goes to 0, delete object. Return
  84. // new reference count.
  85. //------------------------------------------------------------------------------
  86. ULONG
  87. CLocImpClassFactory::Release()
  88. {
  89. LTASSERT(m_uiRefCount != 0);
  90. m_uiRefCount--;
  91. if (0 == m_uiRefCount)
  92. {
  93. delete this;
  94. return 0;
  95. }
  96. return m_uiRefCount;
  97. } // end of CLocImpClassFactory::Release()
  98. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  99. //
  100. // Query whether this object supports a given interface. If it does,
  101. // increment the reference count for this object.
  102. //
  103. // Return values: some sort of result code
  104. // *ppvObj will point to this object if it does support the
  105. // desired interface or be NULL if not.
  106. //------------------------------------------------------------------------------
  107. HRESULT
  108. CLocImpClassFactory::QueryInterface(
  109. REFIID iid, // Type of interface desired.
  110. LPVOID *ppvObj) // Return pointer to object with such interface.
  111. // Note it's a hidden double pointer!
  112. {
  113. LTASSERT(ppvObj != NULL);
  114. SCODE sc = E_NOINTERFACE;
  115. *ppvObj = NULL;
  116. if (IID_IUnknown == iid)
  117. {
  118. *ppvObj = (IUnknown *)this;
  119. sc = S_OK;
  120. }
  121. else if (IID_IClassFactory == iid)
  122. {
  123. *ppvObj = (IClassFactory *)this;
  124. sc = S_OK;
  125. }
  126. if (S_OK == sc)
  127. {
  128. AddRef();
  129. }
  130. return ResultFromScode(sc);
  131. } // end of CLocImpClassFactory::QueryInterface()
  132. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  133. //
  134. // Create an instance of the requested class. All interfaces are implemented
  135. // by the CLocImpParser object.
  136. //
  137. // Return values: some sort of result code
  138. // ppvObj will point to a CLocImpParser object if it does
  139. // support the desired interface or be NULL if not.
  140. //------------------------------------------------------------------------------
  141. HRESULT
  142. CLocImpClassFactory::CreateInstance(
  143. LPUNKNOWN pUnknown, // ???
  144. REFIID iid, // Interface desired on parser object.
  145. LPVOID *ppvObj) // Return pointer to object with interface.
  146. // Note that it's a hidden double pointer!
  147. {
  148. LTASSERT(ppvObj != NULL);
  149. SCODE sc = E_UNEXPECTED;
  150. *ppvObj = NULL;
  151. if (pUnknown != NULL)
  152. {
  153. sc = CLASS_E_NOAGGREGATION;
  154. }
  155. else
  156. {
  157. try
  158. {
  159. CLocImpParser *pParser;
  160. pParser = new CLocImpParser;
  161. sc = pParser->QueryInterface(iid, ppvObj);
  162. pParser->Release();
  163. }
  164. catch (CMemoryException *pMem)
  165. {
  166. sc = E_OUTOFMEMORY;
  167. pMem->Delete();
  168. }
  169. catch (...)
  170. {
  171. }
  172. }
  173. return ResultFromScode(sc);
  174. } // end of CLocImpClassFactory::CreateInstance()
  175. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  176. //
  177. // Not implemented. Always fails.
  178. //------------------------------------------------------------------------------
  179. HRESULT
  180. CLocImpClassFactory::LockServer(
  181. BOOL) // Unused.
  182. {
  183. return E_NOTIMPL;
  184. } // end of CLocImpClassFactory::LockServer()