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.

227 lines
5.1 KiB

  1. //+-------------------------------------------------------------------
  2. // File: ctestemb.cxx
  3. //
  4. // Contents: CTestEmbed class implementation.
  5. //
  6. // Classes: CTestEmbed
  7. //
  8. // History: 7-Dec-92 DeanE Created
  9. //---------------------------------------------------------------------
  10. #pragma optimize("",off)
  11. #include <windows.h>
  12. #include <ole2.h>
  13. #include "testsrv.hxx"
  14. //+-------------------------------------------------------------------
  15. // Method: CTestEmbed::CTestEmbed
  16. //
  17. // Synopsis: Constructor for CTestEmbed objects
  18. //
  19. // Parameters: None
  20. //
  21. // Returns: None
  22. //
  23. // History: 7-Dec-92 DeanE Created
  24. //--------------------------------------------------------------------
  25. CTestEmbed::CTestEmbed() : _cRef(1)
  26. {
  27. _ptsaServer = NULL;
  28. _pDataObject = NULL;
  29. _pOleObject = NULL;
  30. _pPersStg = NULL;
  31. _hwnd = NULL;
  32. }
  33. //+-------------------------------------------------------------------
  34. // Method: CTestEmbed::~CTestEmbed
  35. //
  36. // Synopsis: Performs cleanup for CTestEmbed objects by releasing
  37. // internal pointers.
  38. //
  39. // Parameters: None
  40. //
  41. // Returns: None
  42. //
  43. // History: 7-Dec-92 DeanE Created
  44. //--------------------------------------------------------------------
  45. CTestEmbed::~CTestEmbed()
  46. {
  47. // Inform controlling server app this object is gone
  48. _ptsaServer->DecEmbeddedCount();
  49. // Delete all of this objects interface classes
  50. delete _pDataObject;
  51. delete _pOleObject;
  52. delete _pPersStg;
  53. }
  54. //+-------------------------------------------------------------------
  55. // Method: CTestEmbed::InitObject
  56. //
  57. // Synopsis: Initialize this CTestEmbed object - ie, set everything
  58. // up for actual use.
  59. //
  60. // Parameters: None
  61. //
  62. // Returns: S_OK if everything is okay to use, or an error code
  63. //
  64. // History: 7-Dec-92 DeanE Created
  65. //
  66. // Notes: The state of the object must be cleaned up in case of
  67. // failure - so the destructor will not blow up.
  68. //--------------------------------------------------------------------
  69. SCODE CTestEmbed::InitObject(CTestServerApp *ptsaServer, HWND hwnd)
  70. {
  71. SCODE sc = S_OK;
  72. // Initialize controlling server app
  73. if (NULL != ptsaServer)
  74. {
  75. _ptsaServer = ptsaServer;
  76. }
  77. else
  78. {
  79. sc = E_ABORT;
  80. }
  81. // Initilize this objects window handle
  82. _hwnd = hwnd;
  83. // Create a CDataObject
  84. if (SUCCEEDED(sc))
  85. {
  86. _pDataObject = new CDataObject(this);
  87. if (NULL == _pDataObject)
  88. {
  89. sc = E_ABORT;
  90. }
  91. }
  92. // Create a COleObject
  93. if (SUCCEEDED(sc))
  94. {
  95. _pOleObject = new COleObject(this);
  96. if (NULL == _pOleObject)
  97. {
  98. sc = E_ABORT;
  99. }
  100. }
  101. // Create a CPersistStorage
  102. if (SUCCEEDED(sc))
  103. {
  104. _pPersStg = new CPersistStorage(this);
  105. if (NULL == _pPersStg)
  106. {
  107. sc = E_ABORT;
  108. }
  109. }
  110. if (FAILED(sc))
  111. {
  112. delete _pDataObject;
  113. delete _pOleObject;
  114. delete _pPersStg;
  115. _pDataObject = NULL;
  116. _pOleObject = NULL;
  117. _pPersStg = NULL;
  118. _ptsaServer = NULL;
  119. _hwnd = NULL;
  120. }
  121. // Inform controlling server we are a new embedded object
  122. if (SUCCEEDED(sc))
  123. {
  124. _ptsaServer->IncEmbeddedCount();
  125. }
  126. return(sc);
  127. }
  128. //+-------------------------------------------------------------------
  129. // Method: CTestEmbed::QueryInterface
  130. //
  131. // Synopsis: IUnknown, IOleObject, IPersist, IPersistStorage supported
  132. // return pointer to the actual object
  133. //
  134. // Parameters: [iid] - Interface ID to return.
  135. // [ppv] - Pointer to pointer to object.
  136. //
  137. // Returns: S_OK if iid is supported, or E_NOINTERFACE if not.
  138. //
  139. // History: 7-Dec-92 DeanE Created
  140. //--------------------------------------------------------------------
  141. STDMETHODIMP CTestEmbed::QueryInterface(REFIID iid, void FAR * FAR * ppv)
  142. {
  143. SCODE scRet;
  144. if (GuidEqual(IID_IUnknown, iid))
  145. {
  146. *ppv = (IUnknown *)this;
  147. AddRef();
  148. scRet = S_OK;
  149. }
  150. else
  151. if (GuidEqual(IID_IOleObject, iid))
  152. {
  153. *ppv = _pOleObject;
  154. AddRef();
  155. scRet = S_OK;
  156. }
  157. else
  158. if (GuidEqual(IID_IPersist, iid) || GuidEqual(IID_IPersistStorage, iid))
  159. {
  160. *ppv = _pPersStg;
  161. AddRef();
  162. scRet = S_OK;
  163. }
  164. else
  165. if (GuidEqual(IID_IDataObject, iid))
  166. {
  167. *ppv = _pDataObject;
  168. AddRef();
  169. scRet = S_OK;
  170. }
  171. else
  172. {
  173. *ppv = NULL;
  174. scRet = E_NOINTERFACE;
  175. }
  176. return(scRet);
  177. }
  178. STDMETHODIMP_(ULONG) CTestEmbed::AddRef(void)
  179. {
  180. return ++_cRef;
  181. }
  182. STDMETHODIMP_(ULONG) CTestEmbed::Release(void)
  183. {
  184. ULONG cRefs = --_cRef;
  185. if (cRefs == 0)
  186. {
  187. delete this;
  188. }
  189. return cRefs;
  190. }
  191. SCODE CTestEmbed::GetWindow(HWND *phwnd)
  192. {
  193. if (NULL != phwnd)
  194. {
  195. *phwnd = _hwnd;
  196. return(S_OK);
  197. }
  198. else
  199. {
  200. return(E_ABORT);
  201. }
  202. }