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.

317 lines
7.3 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: cmarshal.cxx
  4. //
  5. // Contents: This file contins the DLL entry points
  6. // LibMain
  7. // DllGetClassObject (Bindings key func)
  8. // CBasicBndCF (class factory)
  9. // CBasicBnd (actual class implementation)
  10. //
  11. // Classes: CBasicBndCF, CBasicBnd
  12. //
  13. //
  14. // History: 30-Nov-92 SarahJ Created
  15. //
  16. //---------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <ole2.h>
  19. #include "app.hxx"
  20. /***************************************************************************/
  21. STDMETHODIMP_(ULONG) CCMarshal::AddRef( THIS )
  22. {
  23. InterlockedIncrement( (long *) &ref_count );
  24. return ref_count;
  25. }
  26. /***************************************************************************/
  27. CCMarshal::CCMarshal()
  28. {
  29. ref_count = 1;
  30. }
  31. /***************************************************************************/
  32. CCMarshal::~CCMarshal()
  33. {
  34. }
  35. /***************************************************************************/
  36. STDMETHODIMP CCMarshal::sick( ULONG val )
  37. {
  38. return proxy->sick( val );
  39. }
  40. /***************************************************************************/
  41. STDMETHODIMP CCMarshal::die_cpp( ULONG val )
  42. {
  43. return proxy->die_cpp( val );
  44. }
  45. /***************************************************************************/
  46. STDMETHODIMP CCMarshal::die_nt( ULONG val )
  47. {
  48. return proxy->die_nt( val );
  49. }
  50. /***************************************************************************/
  51. STDMETHODIMP_(DWORD) CCMarshal::die( ITest *callback, ULONG catch_depth,
  52. ULONG throw_depth, ULONG throw_val )
  53. {
  54. return proxy->die( callback, catch_depth, throw_depth, throw_val );
  55. }
  56. /***************************************************************************/
  57. STDMETHODIMP CCMarshal::interrupt( ITest *param, BOOL go )
  58. {
  59. return proxy->interrupt( param, go );
  60. }
  61. /***************************************************************************/
  62. STDMETHODIMP_(BOOL) CCMarshal::hello()
  63. {
  64. return proxy->hello();
  65. }
  66. /***************************************************************************/
  67. STDMETHODIMP CCMarshal::recurse( ITest *callback, ULONG depth )
  68. {
  69. return proxy->recurse( callback, depth );
  70. }
  71. /***************************************************************************/
  72. STDMETHODIMP CCMarshal::recurse_interrupt( ITest *callback, ULONG depth )
  73. {
  74. return proxy->recurse_interrupt( callback, depth );
  75. }
  76. /***************************************************************************/
  77. STDMETHODIMP CCMarshal::sleep( ULONG time )
  78. {
  79. return proxy->sleep( time );
  80. }
  81. /***************************************************************************/
  82. STDMETHODIMP_(DWORD) CCMarshal::DoTest( ITest *test, ITest *another )
  83. {
  84. return proxy->DoTest( test, another );
  85. }
  86. /***************************************************************************/
  87. STDMETHODIMP CCMarshal::QueryInterface( THIS_ REFIID riid, LPVOID FAR* ppvObj)
  88. {
  89. if (IsEqualIID(riid, IID_IUnknown) ||
  90. IsEqualIID(riid, IID_ITest))
  91. {
  92. *ppvObj = (ITest *) this;
  93. AddRef();
  94. return S_OK;
  95. }
  96. else
  97. {
  98. *ppvObj = NULL;
  99. return E_NOINTERFACE;
  100. }
  101. }
  102. /***************************************************************************/
  103. STDMETHODIMP_(ULONG) CCMarshal::Release( THIS )
  104. {
  105. if (InterlockedDecrement( (long*) &ref_count ) == 0)
  106. {
  107. delete this;
  108. return 0;
  109. }
  110. else
  111. return ref_count;
  112. }
  113. /***************************************************************************/
  114. STDMETHODIMP_(ULONG) CCMarshalCF::AddRef( THIS )
  115. {
  116. InterlockedIncrement( (long *) &ref_count );
  117. return ref_count;
  118. }
  119. /***************************************************************************/
  120. CCMarshalCF::CCMarshalCF()
  121. {
  122. ref_count = 1;
  123. }
  124. /***************************************************************************/
  125. CCMarshalCF::~CCMarshalCF()
  126. {
  127. }
  128. /***************************************************************************/
  129. STDMETHODIMP CCMarshalCF::CreateInstance(
  130. IUnknown FAR* pUnkOuter,
  131. REFIID iidInterface,
  132. void FAR* FAR* ppv)
  133. {
  134. *ppv = NULL;
  135. if (pUnkOuter != NULL)
  136. {
  137. return E_FAIL;
  138. }
  139. if (!IsEqualIID( iidInterface, IID_ITest ))
  140. return E_NOINTERFACE;
  141. CCMarshal *Test = new FAR CCMarshal();
  142. if (Test == NULL)
  143. {
  144. return E_OUTOFMEMORY;
  145. }
  146. *ppv = Test;
  147. return S_OK;
  148. }
  149. /***************************************************************************/
  150. STDMETHODIMP CCMarshalCF::LockServer(BOOL fLock)
  151. {
  152. return E_FAIL;
  153. }
  154. /***************************************************************************/
  155. STDMETHODIMP CCMarshalCF::QueryInterface( THIS_ REFIID riid, LPVOID FAR* ppvObj)
  156. {
  157. if (IsEqualIID(riid, IID_IUnknown) ||
  158. IsEqualIID(riid, IID_IClassFactory))
  159. {
  160. *ppvObj = (IUnknown *) this;
  161. AddRef();
  162. return S_OK;
  163. }
  164. *ppvObj = NULL;
  165. return E_NOINTERFACE;
  166. }
  167. /***************************************************************************/
  168. STDMETHODIMP_(ULONG) CCMarshalCF::Release( THIS )
  169. {
  170. if (InterlockedDecrement( (long*) &ref_count ) == 0)
  171. {
  172. delete this;
  173. return 0;
  174. }
  175. else
  176. return ref_count;
  177. }
  178. CMarshalBase::CMarshalBase()
  179. {
  180. proxy = NULL;
  181. marshaller = NULL;
  182. }
  183. CMarshalBase::~CMarshalBase()
  184. {
  185. if (proxy != NULL)
  186. {
  187. proxy->Release();
  188. proxy = NULL;
  189. }
  190. if (marshaller != NULL)
  191. {
  192. marshaller->Release();
  193. marshaller = NULL;
  194. }
  195. }
  196. // Returns the clsid of the object that created this CMarshalBase.
  197. //
  198. STDMETHODIMP CMarshalBase::GetUnmarshalClass(REFIID riid, LPVOID pv,
  199. DWORD dwDestContext, LPVOID pvDestContext, DWORD mshlflags, CLSID * pCid)
  200. {
  201. *pCid = CLSID_ITest;
  202. return S_OK;
  203. }
  204. STDMETHODIMP CMarshalBase::GetMarshalSizeMax(REFIID riid, LPVOID pv,
  205. DWORD dwDestContext, LPVOID pvDestContext, DWORD mshlflags, DWORD * pSize)
  206. {
  207. SCODE result;
  208. if (marshaller == NULL)
  209. {
  210. result = CoGetStandardMarshal( riid, this, dwDestContext, pvDestContext,
  211. mshlflags, &marshaller );
  212. if (FAILED(result))
  213. return result;
  214. }
  215. return marshaller->GetMarshalSizeMax( riid, this, dwDestContext,
  216. pvDestContext, mshlflags, pSize );
  217. }
  218. STDMETHODIMP CMarshalBase::MarshalInterface(IStream * pStm,
  219. REFIID riid, void * pv,
  220. DWORD dwDestContext, LPVOID pvDestContext, DWORD mshlflags)
  221. {
  222. SCODE result;
  223. if (marshaller == NULL)
  224. return E_FAIL;
  225. result = marshaller->MarshalInterface( pStm, riid, this, dwDestContext,
  226. pvDestContext, mshlflags );
  227. if (SUCCEEDED(result))
  228. {
  229. proxy = (ITest *) pv;
  230. ((IUnknown *) pv)->AddRef();
  231. }
  232. return result;
  233. }
  234. STDMETHODIMP CMarshalBase::UnmarshalInterface(IStream * pStm,
  235. REFIID riid, void * * ppv)
  236. {
  237. SCODE result;
  238. if (marshaller == NULL)
  239. {
  240. result = CoGetStandardMarshal( riid, this, 0, NULL,
  241. MSHLFLAGS_NORMAL, &marshaller );
  242. if (FAILED(result))
  243. return result;
  244. }
  245. result = marshaller->UnmarshalInterface( pStm, riid, (void **) &proxy );
  246. if (SUCCEEDED(result))
  247. {
  248. *ppv = this;
  249. AddRef();
  250. }
  251. else
  252. *ppv = NULL;
  253. return result;
  254. }
  255. STDMETHODIMP CMarshalBase::ReleaseMarshalData(IStream * pStm)
  256. {
  257. return marshaller->ReleaseMarshalData( pStm );
  258. }
  259. STDMETHODIMP CMarshalBase::DisconnectObject(DWORD dwReserved)
  260. {
  261. return marshaller->DisconnectObject( dwReserved );
  262. }