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.

401 lines
9.4 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: embed.cxx
  4. //
  5. // Contents:
  6. //
  7. // Classes: CTestEmbedCF - IClassFactory
  8. //
  9. // History: 7-Dec-92 DeanE Created
  10. //---------------------------------------------------------------------
  11. #include <pch.cxx>
  12. #pragma hdrstop
  13. #pragma optimize("",off)
  14. class CTestServerApp;
  15. class CDataObject;
  16. class COleObject;
  17. class CPersistStorage;
  18. #include <embed.hxx>
  19. #include <dataobj.hxx>
  20. #include <oleobj.hxx>
  21. #include <persist.hxx>
  22. #include <csrvapp.hxx>
  23. extern HWND g_hwndMain;
  24. //+-------------------------------------------------------------------
  25. // Member: CTestEmbedCF::CTestEmbedCF()
  26. //
  27. // Synopsis: The constructor for CTestEmbedCF.
  28. //
  29. // Arguments: None
  30. //
  31. // History: 7-Dec-92 DeanE Created
  32. //--------------------------------------------------------------------
  33. CTestEmbedCF::CTestEmbedCF(CTestServerApp *ptsaServer) : _cRef(1)
  34. {
  35. _ptsaServer = ptsaServer;
  36. return;
  37. }
  38. //+-------------------------------------------------------------------
  39. // Member: CTestEmbedCF::~CTestEmbedCF()
  40. //
  41. // Synopsis: The destructor for CTestEmbedCF.
  42. //
  43. // History: 7-Dec-92 DeanE Created
  44. //--------------------------------------------------------------------
  45. CTestEmbedCF::~CTestEmbedCF()
  46. {
  47. _ptsaServer = NULL;
  48. }
  49. //+-------------------------------------------------------------------
  50. // Member: CTestEmbedCF::Create()
  51. //
  52. // Synopsis: Creates a new CTestEmbedCF object.
  53. //
  54. // Arguments: None
  55. //
  56. // History: 7-Dec-92 DeanE Created
  57. //--------------------------------------------------------------------
  58. IClassFactory FAR* CTestEmbedCF::Create(CTestServerApp *ptsaServer)
  59. {
  60. CTestEmbedCF FAR* pteCF = new FAR CTestEmbedCF(ptsaServer);
  61. return(pteCF);
  62. }
  63. //+-------------------------------------------------------------------
  64. // Method: CTestEmbedCF::QueryInterface
  65. //
  66. // Synopsis: Only IUnknown and IClassFactory supported
  67. // return pointer to the actual object
  68. //
  69. // Parameters: [iid] - Interface ID to return.
  70. // [ppv] - Pointer to pointer to object.
  71. //
  72. // Returns: S_OK if iid is supported, or E_NOINTERFACE if not.
  73. //
  74. // History: 7-Dec-92 DeanE Created
  75. //--------------------------------------------------------------------
  76. STDMETHODIMP CTestEmbedCF::QueryInterface(REFIID iid, void FAR * FAR * ppv)
  77. {
  78. if (IsEqualIID(iid, IID_IUnknown) || IsEqualIID(iid, IID_IClassFactory))
  79. {
  80. *ppv = this;
  81. AddRef();
  82. return(S_OK);
  83. }
  84. else
  85. {
  86. *ppv = NULL;
  87. return(E_NOINTERFACE);
  88. }
  89. }
  90. STDMETHODIMP_(ULONG) CTestEmbedCF::AddRef(void)
  91. {
  92. return ++_cRef;
  93. }
  94. STDMETHODIMP_(ULONG) CTestEmbedCF::Release(void)
  95. {
  96. if (--_cRef == 0)
  97. {
  98. delete this;
  99. return 0;
  100. }
  101. return _cRef;
  102. }
  103. //+-------------------------------------------------------------------
  104. // Method: CTestEmbedCF::CreateInstance
  105. //
  106. // Synopsis: This is called by Binding process to create the
  107. // actual class object.
  108. //
  109. // Parameters: [pUnkOuter] - Ignored. Affects aggregation.
  110. // [iidInterface] - Interface ID object should support.
  111. // [ppv] - Pointer to the object.
  112. //
  113. // Returns: S_OOM if object couldn't be created, or SCODE from
  114. // QueryInterface call.
  115. //
  116. // History: 7-Dec-92 DeanE Created
  117. //--------------------------------------------------------------------
  118. STDMETHODIMP CTestEmbedCF::CreateInstance(
  119. IUnknown FAR *pUnkOuter,
  120. REFIID iidInterface,
  121. void FAR* FAR *ppv)
  122. {
  123. CTestEmbed FAR *pteObj;
  124. SCODE sc;
  125. pteObj = new FAR CTestEmbed();
  126. if (pteObj == NULL)
  127. {
  128. return(E_OUTOFMEMORY);
  129. }
  130. sc = pteObj->InitObject(_ptsaServer, g_hwndMain);
  131. if (S_OK != sc)
  132. {
  133. delete pteObj;
  134. return(E_OUTOFMEMORY);
  135. }
  136. // Having created the actual object, ensure desired
  137. // interfaces are available.
  138. //
  139. sc = pteObj->QueryInterface(iidInterface, ppv);
  140. // We are done with the CTestEmbed instance - it's now referenced by ppv
  141. pteObj->Release();
  142. return(sc);
  143. }
  144. //+-------------------------------------------------------------------
  145. // Method: CTestEmbedCF::LockServer
  146. //
  147. // Synopsis: What does this do?
  148. //
  149. // Parameters: [fLock] - ???
  150. //
  151. // Returns: ???
  152. //
  153. // History: 7-Dec-92 DeanE Created
  154. //--------------------------------------------------------------------
  155. STDMETHODIMP CTestEmbedCF::LockServer(BOOL fLock)
  156. {
  157. // BUGBUG - What does this do?
  158. return(E_FAIL);
  159. }
  160. //+-------------------------------------------------------------------
  161. // Method: CTestEmbed::CTestEmbed
  162. //
  163. // Synopsis: Constructor for CTestEmbed objects
  164. //
  165. // Parameters: None
  166. //
  167. // Returns: None
  168. //
  169. // History: 7-Dec-92 DeanE Created
  170. //--------------------------------------------------------------------
  171. CTestEmbed::CTestEmbed() : _cRef(1)
  172. {
  173. _ptsaServer = NULL;
  174. _pDataObject = NULL;
  175. _pOleObject = NULL;
  176. _pPersStg = NULL;
  177. _hwnd = NULL;
  178. }
  179. //+-------------------------------------------------------------------
  180. // Method: CTestEmbed::~CTestEmbed
  181. //
  182. // Synopsis: Performs cleanup for CTestEmbed objects by releasing
  183. // internal pointers.
  184. //
  185. // Parameters: None
  186. //
  187. // Returns: None
  188. //
  189. // History: 7-Dec-92 DeanE Created
  190. //--------------------------------------------------------------------
  191. CTestEmbed::~CTestEmbed()
  192. {
  193. // Inform controlling server app this object is gone
  194. _ptsaServer->DecEmbeddedCount();
  195. // Delete all of this objects interface classes
  196. delete _pDataObject;
  197. delete _pOleObject;
  198. delete _pPersStg;
  199. }
  200. //+-------------------------------------------------------------------
  201. // Method: CTestEmbed::InitObject
  202. //
  203. // Synopsis: Initialize this CTestEmbed object - ie, set everything
  204. // up for actual use.
  205. //
  206. // Parameters: None
  207. //
  208. // Returns: S_OK if everything is okay to use, or an error code
  209. //
  210. // History: 7-Dec-92 DeanE Created
  211. //
  212. // Notes: The state of the object must be cleaned up in case of
  213. // failure - so the destructor will not blow up.
  214. //--------------------------------------------------------------------
  215. SCODE CTestEmbed::InitObject(CTestServerApp *ptsaServer, HWND hwnd)
  216. {
  217. SCODE sc = S_OK;
  218. // Initialize controlling server app
  219. if (NULL != ptsaServer)
  220. {
  221. _ptsaServer = ptsaServer;
  222. }
  223. else
  224. {
  225. sc = E_ABORT;
  226. }
  227. // Initilize this objects window handle
  228. _hwnd = hwnd;
  229. // Create a CDataObject
  230. if (SUCCEEDED(sc))
  231. {
  232. _pDataObject = new CDataObject(this);
  233. if (NULL == _pDataObject)
  234. {
  235. sc = E_ABORT;
  236. }
  237. }
  238. // Create a COleObject
  239. if (SUCCEEDED(sc))
  240. {
  241. _pOleObject = new COleObject(this);
  242. if (NULL == _pOleObject)
  243. {
  244. sc = E_ABORT;
  245. }
  246. }
  247. // Create a CPersistStorage
  248. if (SUCCEEDED(sc))
  249. {
  250. _pPersStg = new CPersistStorage(this);
  251. if (NULL == _pPersStg)
  252. {
  253. sc = E_ABORT;
  254. }
  255. }
  256. if (FAILED(sc))
  257. {
  258. delete _pDataObject;
  259. delete _pOleObject;
  260. delete _pPersStg;
  261. _pDataObject = NULL;
  262. _pOleObject = NULL;
  263. _pPersStg = NULL;
  264. _ptsaServer = NULL;
  265. _hwnd = NULL;
  266. }
  267. // Inform controlling server we are a new embedded object
  268. if (SUCCEEDED(sc))
  269. {
  270. _ptsaServer->IncEmbeddedCount();
  271. }
  272. return(sc);
  273. }
  274. //+-------------------------------------------------------------------
  275. // Method: CTestEmbed::QueryInterface
  276. //
  277. // Synopsis: IUnknown, IOleObject, IPersist, IPersistStorage supported
  278. // return pointer to the actual object
  279. //
  280. // Parameters: [iid] - Interface ID to return.
  281. // [ppv] - Pointer to pointer to object.
  282. //
  283. // Returns: S_OK if iid is supported, or E_NOINTERFACE if not.
  284. //
  285. // History: 7-Dec-92 DeanE Created
  286. //--------------------------------------------------------------------
  287. STDMETHODIMP CTestEmbed::QueryInterface(REFIID iid, void FAR * FAR * ppv)
  288. {
  289. SCODE scRet;
  290. if (IsEqualIID(IID_IUnknown, iid))
  291. {
  292. *ppv = (IUnknown *)this;
  293. AddRef();
  294. scRet = S_OK;
  295. }
  296. else
  297. if (IsEqualIID(IID_IOleObject, iid))
  298. {
  299. *ppv = _pOleObject;
  300. AddRef();
  301. scRet = S_OK;
  302. }
  303. else
  304. if (IsEqualIID(IID_IPersist, iid) || IsEqualIID(IID_IPersistStorage, iid))
  305. {
  306. *ppv = _pPersStg;
  307. AddRef();
  308. scRet = S_OK;
  309. }
  310. else
  311. if (IsEqualIID(IID_IDataObject, iid))
  312. {
  313. *ppv = _pDataObject;
  314. AddRef();
  315. scRet = S_OK;
  316. }
  317. else
  318. {
  319. *ppv = NULL;
  320. scRet = E_NOINTERFACE;
  321. }
  322. return(scRet);
  323. }
  324. STDMETHODIMP_(ULONG) CTestEmbed::AddRef(void)
  325. {
  326. return ++_cRef;
  327. }
  328. STDMETHODIMP_(ULONG) CTestEmbed::Release(void)
  329. {
  330. if (--_cRef == 0)
  331. {
  332. delete this;
  333. return 0;
  334. }
  335. return _cRef;
  336. }
  337. SCODE CTestEmbed::GetWindow(HWND *phwnd)
  338. {
  339. if (NULL != phwnd)
  340. {
  341. *phwnd = _hwnd;
  342. return(S_OK);
  343. }
  344. else
  345. {
  346. return(E_ABORT);
  347. }
  348. }