Source code of Windows XP (NT5)
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.

229 lines
4.4 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 "impresob.H"
  21. #include "clasfact.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26. #define new DEBUG_NEW
  27. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  28. //
  29. // Constructor - Member Data Init
  30. //
  31. //------------------------------------------------------------------------------
  32. CLocImpClassFactory::CLocImpClassFactory()
  33. {
  34. m_uiRefCount = 0;
  35. AddRef();
  36. IncrementClassCount();
  37. }
  38. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  39. //
  40. // Destructor - Object clean up
  41. //
  42. //------------------------------------------------------------------------------
  43. CLocImpClassFactory::~CLocImpClassFactory()
  44. {
  45. LTASSERT(m_uiRefCount == 0);
  46. DEBUGONLY(AssertValid());
  47. DecrementClassCount();
  48. }
  49. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  50. //
  51. // Increase Reference count on the object
  52. //
  53. //------------------------------------------------------------------------------
  54. ULONG
  55. CLocImpClassFactory::AddRef(void)
  56. {
  57. return ++m_uiRefCount;
  58. }
  59. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  60. //
  61. // Decrease Reference count on the object - destroy the object on the last
  62. // release
  63. //
  64. //------------------------------------------------------------------------------
  65. ULONG
  66. CLocImpClassFactory::Release(void)
  67. {
  68. LTASSERT(m_uiRefCount != 0);
  69. m_uiRefCount--;
  70. if (m_uiRefCount == 0)
  71. {
  72. delete this;
  73. return 0;
  74. }
  75. return m_uiRefCount;
  76. }
  77. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  78. //
  79. // Query for other interfaces
  80. //
  81. //------------------------------------------------------------------------------
  82. HRESULT
  83. CLocImpClassFactory::QueryInterface(
  84. REFIID iid,
  85. LPVOID *ppvObj)
  86. {
  87. SCODE sc = E_NOINTERFACE;
  88. *ppvObj = NULL;
  89. if (iid == IID_IUnknown)
  90. {
  91. *ppvObj = (IUnknown *)this;
  92. sc = S_OK;
  93. }
  94. else if (iid == IID_IClassFactory)
  95. {
  96. *ppvObj = (IClassFactory *)this;
  97. sc = S_OK;
  98. }
  99. if (sc == S_OK)
  100. {
  101. AddRef();
  102. }
  103. return ResultFromScode(sc);
  104. }
  105. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  106. //
  107. // Create a instance of the object with the given IID
  108. //
  109. //------------------------------------------------------------------------------
  110. HRESULT
  111. CLocImpClassFactory::CreateInstance(
  112. LPUNKNOWN pUnknown,
  113. REFIID iid,
  114. LPVOID *ppvObj)
  115. {
  116. SCODE sc = E_UNEXPECTED;
  117. *ppvObj = NULL;
  118. if (pUnknown != NULL)
  119. {
  120. sc = CLASS_E_NOAGGREGATION;
  121. }
  122. else
  123. {
  124. try
  125. {
  126. CLocImpResObj *pResObj = new CLocImpResObj;
  127. sc = pResObj->QueryInterface(iid, ppvObj);
  128. pResObj->Release();
  129. }
  130. catch (CMemoryException *pMem)
  131. {
  132. sc = E_OUTOFMEMORY;
  133. pMem->Delete();
  134. }
  135. catch (...)
  136. {
  137. sc = E_UNEXPECTED;
  138. }
  139. }
  140. return ResultFromScode(sc);
  141. }
  142. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143. //
  144. // Not implemented
  145. //
  146. //------------------------------------------------------------------------------
  147. HRESULT
  148. CLocImpClassFactory::LockServer(
  149. BOOL)
  150. {
  151. return E_NOTIMPL;
  152. }
  153. #ifdef _DEBUG
  154. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  155. //
  156. //
  157. //
  158. //------------------------------------------------------------------------------
  159. void
  160. CLocImpClassFactory::AssertValid(void)
  161. const
  162. {
  163. CLObject::AssertValid();
  164. //More than 100 refs would probably mean an error somewhere.
  165. //Bump this up if needed.
  166. LTASSERT(m_uiRefCount >= 0 || m_uiRefCount < 100);
  167. }
  168. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  169. //
  170. // Dump the contents of this object
  171. //
  172. //------------------------------------------------------------------------------
  173. void
  174. CLocImpClassFactory::Dump(
  175. CDumpContext &dc)
  176. const
  177. {
  178. CLObject::Dump(dc);
  179. dc << _T("Reference Count ");
  180. dc << m_uiRefCount;
  181. dc << _T("\n");
  182. }
  183. #endif // _DEBUG