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.

482 lines
9.0 KiB

  1. #include <windows.h>
  2. #include <ole2.h>
  3. #include <stdio.h>
  4. #include <tunk.h>
  5. CTestUnk::CTestUnk(void) : _cRefs(1)
  6. {
  7. }
  8. CTestUnk::~CTestUnk(void)
  9. {
  10. }
  11. STDMETHODIMP CTestUnk::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  12. {
  13. HRESULT hRslt = S_OK;
  14. if (IsEqualIID(riid, IID_IUnknown) ||
  15. IsEqualIID(riid, IID_IParseDisplayName))
  16. {
  17. *ppvObj = (void *)(IParseDisplayName *)this;
  18. AddRef();
  19. }
  20. else if (IsEqualIID(riid, IID_ICube))
  21. {
  22. *ppvObj = (void *) new CTestUnkCube((IUnknown *)(IParseDisplayName *)this);
  23. if (*ppvObj == NULL)
  24. {
  25. hRslt = E_NOINTERFACE;
  26. }
  27. }
  28. else if (IsEqualIID(riid, IID_IOleWindow))
  29. {
  30. *ppvObj = (void *)(IOleWindow *)this;
  31. AddRef();
  32. }
  33. else if (IsEqualIID(riid, IID_IAdviseSink))
  34. {
  35. *ppvObj = (void *)(IAdviseSink *)this;
  36. AddRef();
  37. }
  38. else
  39. {
  40. *ppvObj = NULL;
  41. hRslt = E_NOINTERFACE;
  42. }
  43. return hRslt;
  44. }
  45. STDMETHODIMP_(ULONG) CTestUnk::AddRef(void)
  46. {
  47. _cRefs++;
  48. return _cRefs;
  49. }
  50. STDMETHODIMP_(ULONG) CTestUnk::Release(void)
  51. {
  52. _cRefs--;
  53. if (_cRefs == 0)
  54. {
  55. delete this;
  56. return 0;
  57. }
  58. else
  59. {
  60. return _cRefs;
  61. }
  62. }
  63. STDMETHODIMP CTestUnk::ParseDisplayName(LPBC pbc, LPOLESTR lpszDisplayName,
  64. ULONG *pchEaten, LPMONIKER *ppmkOut)
  65. {
  66. return S_OK;
  67. }
  68. STDMETHODIMP CTestUnk::GetWindow(HWND *phwnd)
  69. {
  70. *phwnd = NULL;
  71. return S_OK;
  72. }
  73. STDMETHODIMP CTestUnk::ContextSensitiveHelp(BOOL fEnterMode)
  74. {
  75. return S_OK;
  76. }
  77. STDMETHODIMP_(void) CTestUnk::OnDataChange(FORMATETC *pFormatetc,
  78. STGMEDIUM *pStgmed)
  79. {
  80. return;
  81. }
  82. STDMETHODIMP_(void) CTestUnk::OnViewChange(DWORD dwAspect,
  83. LONG lindex)
  84. {
  85. return;
  86. }
  87. STDMETHODIMP_(void) CTestUnk::OnRename(IMoniker *pmk)
  88. {
  89. return;
  90. }
  91. STDMETHODIMP_(void) CTestUnk::OnSave()
  92. {
  93. return;
  94. }
  95. STDMETHODIMP_(void) CTestUnk::OnClose()
  96. {
  97. return;
  98. }
  99. CTestUnkCube::CTestUnkCube(IUnknown *pUnkCtrl) :
  100. _cRefs(1),
  101. _pUnkCtrl(pUnkCtrl),
  102. _pUnkIn(NULL)
  103. {
  104. _pUnkCtrl->AddRef();
  105. }
  106. CTestUnkCube::~CTestUnkCube(void)
  107. {
  108. _pUnkCtrl->Release();
  109. }
  110. STDMETHODIMP CTestUnkCube::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  111. {
  112. return _pUnkCtrl->QueryInterface(riid, ppvObj);
  113. }
  114. STDMETHODIMP_(ULONG) CTestUnkCube::AddRef(void)
  115. {
  116. _cRefs++;
  117. return _cRefs;
  118. }
  119. STDMETHODIMP_(ULONG) CTestUnkCube::Release(void)
  120. {
  121. _cRefs--;
  122. if (_cRefs == 0)
  123. {
  124. delete this;
  125. return 0;
  126. }
  127. else
  128. {
  129. return _cRefs;
  130. }
  131. }
  132. // these methods dont really have to do anything, we are just testing that
  133. // they are callable.
  134. STDMETHODIMP CTestUnkCube::MoveCube(ULONG xPos, ULONG yPos)
  135. {
  136. if (_cRefs > 0)
  137. return S_OK;
  138. return E_UNEXPECTED;
  139. }
  140. STDMETHODIMP CTestUnkCube::GetCubePos(ULONG *xPos, ULONG *yPos)
  141. {
  142. if (_cRefs > 0)
  143. return S_OK;
  144. return E_UNEXPECTED;
  145. }
  146. STDMETHODIMP CTestUnkCube::Contains(IBalls *pIFDb)
  147. {
  148. if (_cRefs > 0)
  149. return S_OK;
  150. return E_UNEXPECTED;
  151. }
  152. STDMETHODIMP CTestUnkCube::SimpleCall(DWORD pidCaller, DWORD tidCaller, GUID lidCaller)
  153. {
  154. HRESULT hr = S_OK;
  155. GUID lid;
  156. HRESULT hr2 = CoGetCurrentLogicalThreadId(&lid);
  157. if (SUCCEEDED(hr2))
  158. {
  159. if (!IsEqualGUID(lid, lidCaller))
  160. {
  161. // LIDs dont match, error
  162. hr |= 0x80000001;
  163. }
  164. }
  165. else
  166. {
  167. return hr2;
  168. }
  169. DWORD tid;
  170. hr2 = CoGetCallerTID(&tid);
  171. if (SUCCEEDED(hr2))
  172. {
  173. if (pidCaller == GetCurrentProcessId())
  174. {
  175. // if in same process, CoGetCallerTID should return S_OK
  176. if (hr2 != S_OK)
  177. {
  178. hr |= 0x80000002;
  179. }
  180. }
  181. else
  182. {
  183. // if in different process, CoGetCallerTID should return S_FALSE
  184. if (hr2 != S_FALSE)
  185. {
  186. hr |= 0x80000004;
  187. }
  188. }
  189. }
  190. else
  191. {
  192. return hr2;
  193. }
  194. return hr;
  195. }
  196. STDMETHODIMP CTestUnkCube::PrepForInputSyncCall(IUnknown *pUnkIn)
  197. {
  198. // just remember the input ptr
  199. _pUnkIn = pUnkIn;
  200. _pUnkIn->AddRef();
  201. return S_OK;
  202. }
  203. STDMETHODIMP CTestUnkCube::InputSyncCall()
  204. {
  205. // just attempt to release an Interface Pointer inside an InputSync
  206. // method.
  207. if (_pUnkIn)
  208. {
  209. if (_pUnkIn->Release() != 0)
  210. return RPC_E_CANTCALLOUT_ININPUTSYNCCALL;
  211. }
  212. return S_OK;
  213. }
  214. //+-------------------------------------------------------------------
  215. //
  216. // Member: CTestUnkCF::CTestUnkCF, public
  217. //
  218. // Algorithm:
  219. //
  220. // History: 23-Nov-92 Rickhi Created
  221. //
  222. //--------------------------------------------------------------------
  223. CTestUnkCF::CTestUnkCF()
  224. {
  225. _cRefs = 1;
  226. }
  227. //+-------------------------------------------------------------------
  228. //
  229. // Member: CTestUnkCF::QueryInterface, public
  230. //
  231. // Algorithm: if the interface is not one implemented by us,
  232. // pass the request to the proxy manager
  233. //
  234. // History: 23-Nov-92 Rickhi Created
  235. //
  236. //--------------------------------------------------------------------
  237. STDMETHODIMP CTestUnkCF::QueryInterface(REFIID riid, void **ppUnk)
  238. {
  239. if (IsEqualIID(riid, IID_IUnknown) ||
  240. IsEqualIID(riid, IID_IClassFactory))
  241. {
  242. *ppUnk = (void *)(IClassFactory *) this;
  243. AddRef();
  244. return S_OK;
  245. }
  246. *ppUnk = NULL;
  247. return E_NOINTERFACE;
  248. }
  249. STDMETHODIMP_(ULONG) CTestUnkCF::AddRef(void)
  250. {
  251. _cRefs++;
  252. return _cRefs;
  253. }
  254. STDMETHODIMP_(ULONG) CTestUnkCF::Release(void)
  255. {
  256. _cRefs--;
  257. if (_cRefs == 0)
  258. {
  259. delete this;
  260. return 0;
  261. }
  262. return _cRefs;
  263. }
  264. //+-------------------------------------------------------------------
  265. //
  266. // Member: CTestUnkCF::CreateInstance, public
  267. //
  268. // Synopsis: create a new object with the same class
  269. //
  270. // History: 23-Nov-92 Rickhi Created
  271. //
  272. //--------------------------------------------------------------------
  273. STDMETHODIMP CTestUnkCF::CreateInstance(IUnknown *punkOuter,
  274. REFIID riid,
  275. void **ppunkObject)
  276. {
  277. SCODE sc = E_OUTOFMEMORY;
  278. *ppunkObject = NULL; // in case of failure
  279. // create an instance object.
  280. IUnknown *punk = (IUnknown *)(IParseDisplayName *) new CTestUnk();
  281. if (punk)
  282. {
  283. // get the interface the caller wants to use
  284. sc = punk->QueryInterface(riid, ppunkObject);
  285. // release our hold, since the QI got a hold for the client.
  286. punk->Release();
  287. }
  288. return sc;
  289. }
  290. //+-------------------------------------------------------------------
  291. //
  292. // Member: CTestUnkCF::LockServer, public
  293. //
  294. // Synopsis:
  295. //
  296. // History: 23-Nov-92 Rickhi Created
  297. //
  298. //--------------------------------------------------------------------
  299. STDMETHODIMP CTestUnkCF::LockServer(BOOL fLock)
  300. {
  301. return S_OK;
  302. }
  303. CTestUnkMarshal::CTestUnkMarshal(void) : _cRefs(1), _pIM(NULL)
  304. {
  305. }
  306. CTestUnkMarshal::~CTestUnkMarshal(void)
  307. {
  308. if (_pIM)
  309. {
  310. _pIM->Release();
  311. }
  312. }
  313. STDMETHODIMP CTestUnkMarshal::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  314. {
  315. HRESULT hRslt = S_OK;
  316. if (IsEqualIID(riid, IID_IUnknown) ||
  317. IsEqualIID(riid, IID_IMarshal))
  318. {
  319. *ppvObj = (void *)(IMarshal *)this;
  320. AddRef();
  321. }
  322. else
  323. {
  324. *ppvObj = NULL;
  325. hRslt = E_NOINTERFACE;
  326. }
  327. return hRslt;
  328. }
  329. STDMETHODIMP_(ULONG) CTestUnkMarshal::AddRef(void)
  330. {
  331. _cRefs++;
  332. return _cRefs;
  333. }
  334. STDMETHODIMP_(ULONG) CTestUnkMarshal::Release(void)
  335. {
  336. _cRefs--;
  337. if (_cRefs == 0)
  338. {
  339. delete this;
  340. return 0;
  341. }
  342. else
  343. {
  344. return _cRefs;
  345. }
  346. }
  347. STDMETHODIMP CTestUnkMarshal::GetUnmarshalClass(REFIID riid, LPVOID pv,
  348. DWORD dwDestCtx, LPVOID pvDestCtx, DWORD mshlflags, LPCLSID pClsid)
  349. {
  350. if (GetStdMarshal() == NULL)
  351. return E_OUTOFMEMORY;
  352. return _pIM->GetUnmarshalClass(riid, pv, dwDestCtx, pvDestCtx,
  353. (mshlflags | MSHLFLAGS_NOPING), pClsid);
  354. }
  355. STDMETHODIMP CTestUnkMarshal::GetMarshalSizeMax(REFIID riid, LPVOID pv,
  356. DWORD dwDestCtx, LPVOID pvDestCtx, DWORD mshlflags, LPDWORD pSize)
  357. {
  358. if (GetStdMarshal() == NULL)
  359. return E_OUTOFMEMORY;
  360. return _pIM->GetMarshalSizeMax(riid, pv, dwDestCtx, pvDestCtx,
  361. (mshlflags | MSHLFLAGS_NOPING), pSize);
  362. }
  363. STDMETHODIMP CTestUnkMarshal::MarshalInterface(LPSTREAM pStm, REFIID riid,
  364. LPVOID pv, DWORD dwDestCtx, LPVOID pvDestCtx, DWORD mshlflags)
  365. {
  366. if (GetStdMarshal() == NULL)
  367. return E_OUTOFMEMORY;
  368. return _pIM->MarshalInterface(pStm, riid, pv, dwDestCtx, pvDestCtx,
  369. (mshlflags | MSHLFLAGS_NOPING));
  370. }
  371. STDMETHODIMP CTestUnkMarshal::UnmarshalInterface(LPSTREAM pStm, REFIID riid,
  372. LPVOID *ppv)
  373. {
  374. return CoUnmarshalInterface(pStm, riid, ppv);
  375. }
  376. STDMETHODIMP CTestUnkMarshal::ReleaseMarshalData(LPSTREAM pStm)
  377. {
  378. return CoReleaseMarshalData(pStm);
  379. }
  380. STDMETHODIMP CTestUnkMarshal::DisconnectObject(DWORD dwReserved)
  381. {
  382. if (GetStdMarshal() == NULL)
  383. return E_OUTOFMEMORY;
  384. return _pIM->DisconnectObject(dwReserved);
  385. }
  386. IMarshal *CTestUnkMarshal::GetStdMarshal(void)
  387. {
  388. if (_pIM == NULL)
  389. {
  390. HRESULT hr = CoGetStandardMarshal(IID_IUnknown, (IUnknown *)this, 0,
  391. 0, MSHLFLAGS_NOPING, &_pIM);
  392. }
  393. return _pIM;
  394. }