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.

235 lines
4.7 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. //
  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. // CSimpSvrApp::QueryInterface APP.CPP
  38. //
  39. // Comments:
  40. //
  41. //
  42. //********************************************************************
  43. STDMETHODIMP CClassFactory::QueryInterface ( REFIID riid, LPVOID FAR* ppvObj)
  44. {
  45. TestDebugOut("In CClassFactory::QueryInterface\r\n");
  46. SCODE sc = S_OK;
  47. if ( (riid == IID_IUnknown) ||
  48. (riid == IID_IClassFactory) )
  49. *ppvObj = this;
  50. else
  51. {
  52. *ppvObj = NULL;
  53. sc = E_NOINTERFACE;
  54. }
  55. if (*ppvObj)
  56. ((LPUNKNOWN)*ppvObj)->AddRef();
  57. // pass it on to the Application object
  58. return ResultFromScode(sc);
  59. };
  60. //**********************************************************************
  61. //
  62. // CClassFactory::AddRef
  63. //
  64. // Purpose:
  65. //
  66. // Increments the reference count on CClassFactory and the application
  67. // object.
  68. //
  69. // Parameters:
  70. //
  71. // None
  72. //
  73. // Return Value:
  74. //
  75. // The Reference count on CClassFactory
  76. //
  77. // Function Calls:
  78. // Function Location
  79. //
  80. // OuputDebugString Windows API
  81. //
  82. // Comments:
  83. //
  84. //
  85. //********************************************************************
  86. STDMETHODIMP_(ULONG) CClassFactory::AddRef ()
  87. {
  88. TestDebugOut("In CClassFactory::AddRef\r\n");
  89. return ++m_nCount;
  90. };
  91. //**********************************************************************
  92. //
  93. // CClassFactory::Release
  94. //
  95. // Purpose:
  96. //
  97. // Decrements the reference count of CClassFactory and the
  98. // application object.
  99. //
  100. // Parameters:
  101. //
  102. // None
  103. //
  104. // Return Value:
  105. //
  106. // The new reference count
  107. //
  108. // Function Calls:
  109. // Function Location
  110. //
  111. // TestDebugOut Windows API
  112. //
  113. // Comments:
  114. //
  115. //
  116. //********************************************************************
  117. STDMETHODIMP_(ULONG) CClassFactory::Release ()
  118. {
  119. TestDebugOut("In CClassFactory::Release\r\n");
  120. if (--m_nCount == 0) {
  121. delete this;
  122. return 0;
  123. }
  124. return m_nCount;
  125. };
  126. //**********************************************************************
  127. //
  128. // CClassFactory::CreateInstance
  129. //
  130. // Purpose:
  131. //
  132. // Instantiates a new OLE object
  133. //
  134. // Parameters:
  135. //
  136. // LPUNKNOWN pUnkOuter - Pointer to the controlling unknown
  137. //
  138. // REFIID riid - The interface type to fill in ppvObject
  139. //
  140. // LPVOID FAR* ppvObject - Out pointer for the object
  141. //
  142. // Return Value:
  143. //
  144. // S_OK - Creation was successful
  145. // CLASS_E_NOAGGREGATION - Tried to be created as part of an aggregate
  146. //
  147. //
  148. // Function Calls:
  149. // Function Location
  150. //
  151. // TestDebugOut Windows API
  152. // CSimpSvrDoc::CreateObject DOC.CPP
  153. //
  154. // Comments:
  155. //
  156. //
  157. //********************************************************************
  158. STDMETHODIMP CClassFactory::CreateInstance ( LPUNKNOWN pUnkOuter,
  159. REFIID riid,
  160. LPVOID FAR* ppvObject)
  161. {
  162. HRESULT hErr;
  163. TestDebugOut("In CClassFactory::CreateInstance\r\n");
  164. // need to NULL the out parameter
  165. *ppvObject = NULL;
  166. // we don't support aggregation...
  167. if (pUnkOuter)
  168. {
  169. hErr = ResultFromScode(CLASS_E_NOAGGREGATION);
  170. goto error;
  171. }
  172. hErr = m_lpApp->m_lpDoc->CreateObject(riid, ppvObject);
  173. error:
  174. return hErr;
  175. };
  176. //**********************************************************************
  177. //
  178. // CClassFactory::LockServer
  179. //
  180. // Purpose:
  181. //
  182. //
  183. // Parameters:
  184. //
  185. // BOOL fLock - TRUE to lock the server, FALSE to unlock it
  186. //
  187. // Return Value:
  188. //
  189. // S_OK
  190. //
  191. // Function Calls:
  192. // Function Location
  193. //
  194. // TestDebugOut Windows API
  195. // CoLockObjectExternal OLE API
  196. // ResultFromScode OLE API
  197. //
  198. // Comments:
  199. //
  200. //
  201. //********************************************************************
  202. STDMETHODIMP CClassFactory::LockServer ( BOOL fLock)
  203. {
  204. TestDebugOut("In CClassFactory::LockServer\r\n");
  205. CoLockObjectExternal(m_lpApp, fLock, TRUE);
  206. return ResultFromScode( S_OK);
  207. };