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.

228 lines
5.1 KiB

  1. //**********************************************************************
  2. // File name: ICF.CPP
  3. //
  4. // Implementation file for the CClassFactory Class
  5. //
  6. // Functions:
  7. //
  8. // See icf.h for a list of member functions.
  9. //
  10. // Copyright (c) 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "app.h"
  14. #include "doc.h"
  15. #include "icf.h"
  16. //**********************************************************************
  17. //
  18. // CClassFactory::QueryInterface
  19. //
  20. // Purpose:
  21. // Used for interface negotiation
  22. //
  23. // Parameters:
  24. //
  25. // REFIID riid - Interface being queried for.
  26. //
  27. // LPVOID FAR *ppvObj - Out pointer for the interface.
  28. //
  29. // Return Value:
  30. //
  31. // S_OK - Success
  32. // E_NOINTERFACE - Failure
  33. //
  34. // Function Calls:
  35. // Function Location
  36. //
  37. // CClassFactory::AddRef ICF.CPP
  38. //
  39. //********************************************************************
  40. STDMETHODIMP CClassFactory::QueryInterface ( REFIID riid, LPVOID FAR* ppvObj)
  41. {
  42. TestDebugOut(TEXT("In CClassFactory::QueryInterface\r\n"));
  43. SCODE sc = S_OK;
  44. if (IsEqualIID(riid, IID_IUnknown) ||
  45. IsEqualIID(riid, IID_IClassFactory) )
  46. *ppvObj = this;
  47. else
  48. {
  49. *ppvObj = NULL;
  50. sc = E_NOINTERFACE;
  51. }
  52. if (*ppvObj)
  53. ((LPUNKNOWN)*ppvObj)->AddRef();
  54. // pass it on to the Application object
  55. return ResultFromScode(sc);
  56. }
  57. //**********************************************************************
  58. //
  59. // CClassFactory::AddRef
  60. //
  61. // Purpose:
  62. //
  63. // Increments the reference count on CClassFactory and the application
  64. // object.
  65. //
  66. // Parameters:
  67. //
  68. // None
  69. //
  70. // Return Value:
  71. //
  72. // The Reference count on CClassFactory
  73. //
  74. // Function Calls:
  75. // Function Location
  76. //
  77. // OuputDebugString Windows API
  78. //
  79. //********************************************************************
  80. STDMETHODIMP_(ULONG) CClassFactory::AddRef ()
  81. {
  82. TestDebugOut(TEXT("In CClassFactory::AddRef\r\n"));
  83. return ++m_nCount;
  84. }
  85. //**********************************************************************
  86. //
  87. // CClassFactory::Release
  88. //
  89. // Purpose:
  90. //
  91. // Decrements the reference count of CClassFactory and the
  92. // application object.
  93. //
  94. // Parameters:
  95. //
  96. // None
  97. //
  98. // Return Value:
  99. //
  100. // The new reference count
  101. //
  102. // Function Calls:
  103. // Function Location
  104. //
  105. // TestDebugOut Windows API
  106. //
  107. //********************************************************************
  108. STDMETHODIMP_(ULONG) CClassFactory::Release ()
  109. {
  110. TestDebugOut(TEXT("In CClassFactory::Release\r\n"));
  111. if (--m_nCount== 0)
  112. {
  113. delete this;
  114. return(0);
  115. }
  116. return m_nCount;
  117. }
  118. //**********************************************************************
  119. //
  120. // CClassFactory::CreateInstance
  121. //
  122. // Purpose:
  123. //
  124. // Instantiates a new OLE object
  125. //
  126. // Parameters:
  127. //
  128. // LPUNKNOWN pUnkOuter - Pointer to the controlling unknown
  129. //
  130. // REFIID riid - The interface type to fill in ppvObject
  131. //
  132. // LPVOID FAR* ppvObject - Out pointer for the object
  133. //
  134. // Return Value:
  135. //
  136. // S_OK - Creation was successful
  137. // CLASS_E_NOAGGREGATION - Tried to be created as part of an aggregate
  138. //
  139. //
  140. // Function Calls:
  141. // Function Location
  142. //
  143. // TestDebugOut Windows API
  144. // CSimpSvrDoc::CreateObject DOC.CPP
  145. //
  146. //********************************************************************
  147. STDMETHODIMP CClassFactory::CreateInstance ( LPUNKNOWN pUnkOuter,
  148. REFIID riid,
  149. LPVOID FAR* ppvObject)
  150. {
  151. HRESULT hErr;
  152. TestDebugOut(TEXT("In CClassFactory::CreateInstance\r\n"));
  153. // need to NULL the out parameter
  154. *ppvObject = NULL;
  155. // we don't support aggregation...
  156. if (pUnkOuter)
  157. {
  158. hErr = ResultFromScode(CLASS_E_NOAGGREGATION);
  159. goto error;
  160. }
  161. hErr = m_lpApp->m_lpDoc->CreateObject(riid, ppvObject);
  162. error:
  163. return hErr;
  164. }
  165. //**********************************************************************
  166. //
  167. // CClassFactory::LockServer
  168. //
  169. // Purpose:
  170. // To lock the server and keep an open object application in memory
  171. //
  172. // Parameters:
  173. //
  174. // BOOL fLock - TRUE to lock the server, FALSE to unlock it
  175. //
  176. // Return Value:
  177. //
  178. // S_OK
  179. //
  180. // Function Calls:
  181. // Function Location
  182. //
  183. // TestDebugOut Windows API
  184. // CoLockObjectExternal OLE API
  185. // ResultFromScode OLE API
  186. //
  187. //
  188. //********************************************************************
  189. STDMETHODIMP CClassFactory::LockServer ( BOOL fLock)
  190. {
  191. HRESULT hRes;
  192. TestDebugOut(TEXT("In CClassFactory::LockServer\r\n"));
  193. if ((hRes=CoLockObjectExternal(m_lpApp, fLock, TRUE)) != S_OK)
  194. {
  195. TestDebugOut(TEXT("CClassFactory::LockServer \
  196. CoLockObjectExternal fails\n"));
  197. return(hRes);
  198. }
  199. return ResultFromScode( S_OK);
  200. }