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.

314 lines
6.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: cubes.cxx
  7. //
  8. // Contents: implementations for CCube
  9. //
  10. // Functions:
  11. // CCube::CCube
  12. // CCube::~CCube
  13. // CCube::QueryInterface
  14. // CCube::CreateCube
  15. // CCube::MoveCube
  16. // CCube::GetCubePos
  17. //
  18. // History: 06-Aug-92 Ricksa Created
  19. //
  20. //--------------------------------------------------------------------------
  21. #include <pch.cxx>
  22. #pragma hdrstop
  23. #include <ccubes.hxx> // class definition
  24. #include <iballs.h> // IBalls interface definiton
  25. #define CUBE_WIDTH 20
  26. //+-------------------------------------------------------------------------
  27. //
  28. // Method: CCube::CCube
  29. //
  30. // Synopsis: Creates the application window
  31. //
  32. // Arguments: [pisb] - ISysBind instance
  33. //
  34. // History: 06-Aug-92 Ricksa Created
  35. //
  36. //--------------------------------------------------------------------------
  37. CCube::CCube(void)
  38. : _xPos(CUBE_UNDEF),
  39. _yPos(CUBE_UNDEF)
  40. {
  41. CreateCube(0,0);
  42. GlobalRefs(TRUE);
  43. ENLIST_TRACKING(CCube);
  44. }
  45. //+-------------------------------------------------------------------------
  46. //
  47. // Method: CCube::~CCube
  48. //
  49. // Synopsis: Cleans up object
  50. //
  51. // History: 06-Aug-92 Ricksa Created
  52. //
  53. //--------------------------------------------------------------------------
  54. CCube::~CCube(void)
  55. {
  56. GlobalRefs(FALSE);
  57. // automatic actions are enough
  58. }
  59. //+-------------------------------------------------------------------------
  60. //
  61. // Method: CCube::QueryInterface
  62. //
  63. // Synopsis: Gets called when a WM_COMMAND message received.
  64. //
  65. // Arguments: [ifid] - interface instance requested
  66. // [ppunk] - where to put pointer to interface instance
  67. //
  68. // Returns: S_OK or ERROR_BAD_COMMAND
  69. //
  70. // History: 06-Aug-92 Ricksa Created
  71. //
  72. //--------------------------------------------------------------------------
  73. STDMETHODIMP CCube::QueryInterface(REFIID riid, void **ppunk)
  74. {
  75. SCODE sc = E_NOINTERFACE;
  76. *ppunk = NULL;
  77. if (IsEqualIID(riid, IID_IUnknown) ||
  78. IsEqualIID(riid, IID_ICube))
  79. {
  80. // Increase the reference count
  81. *ppunk = (void *)(ICube *) this;
  82. AddRef();
  83. // Set to success
  84. sc = S_OK;
  85. }
  86. return sc;
  87. }
  88. //+-------------------------------------------------------------------------
  89. //
  90. // Method: CCube::CreateCube
  91. //
  92. // Synopsis: Creates a Cube on the screen
  93. //
  94. // Arguments: [xPos] - x position for new Cube
  95. // [yPos] - y position for new Cube
  96. //
  97. // Returns: S_OK or ERROR_BAD_COMMAND
  98. //
  99. // History: 06-Aug-92 Ricksa Created
  100. //
  101. //--------------------------------------------------------------------------
  102. STDMETHODIMP CCube::CreateCube(ULONG xPos, ULONG yPos)
  103. {
  104. SCODE sc = E_FAIL;
  105. if (xPos != (ULONG) -1)
  106. {
  107. // Update data
  108. _xPos = xPos;
  109. _yPos = yPos;
  110. sc = S_OK;
  111. // Format message for the screen
  112. Display(TEXT("Create Cube xPos = %ld yPos = %ld\n"), xPos, yPos);
  113. }
  114. return sc;
  115. }
  116. //+-------------------------------------------------------------------------
  117. //
  118. // Function: CCube::MoveCube
  119. //
  120. // Synopsis: Move the Cube from one position to another
  121. //
  122. // Arguments: [xPos] - new x position for the Cube
  123. // [yPos] - new y position for the Cube
  124. //
  125. // Returns: S_OK
  126. //
  127. // History: 06-Aug-92 Ricksa Created
  128. //
  129. //--------------------------------------------------------------------------
  130. STDMETHODIMP CCube::MoveCube(ULONG xPos, ULONG yPos)
  131. {
  132. // Set the position
  133. _xPos = xPos;
  134. _yPos = yPos;
  135. // Format message for the screen
  136. Display(TEXT("Move Cube xPos = %ld yPos = %ld\n"), xPos, yPos);
  137. return S_OK;
  138. }
  139. //+-------------------------------------------------------------------------
  140. //
  141. // Function: CCube::GetCubePos
  142. //
  143. // Synopsis: Get the current position of the Cube
  144. //
  145. // Arguments: [hWindow] - handle for the window
  146. //
  147. // Returns: S_OK
  148. //
  149. // History: 06-Aug-92 Ricksa Created
  150. //
  151. //--------------------------------------------------------------------------
  152. STDMETHODIMP CCube::GetCubePos(ULONG *pxPos, ULONG *pyPos)
  153. {
  154. *pxPos = _xPos;
  155. *pyPos = _yPos;
  156. // Format message for the screen
  157. Display(TEXT("Get Cube Pos xPos = %ld yPos = %ld\n"), _xPos, _yPos);
  158. return S_OK;
  159. }
  160. //+-------------------------------------------------------------------------
  161. //
  162. // Function: CCube::Contains
  163. //
  164. // Synopsis: Check if this Cube is contained in the given cube.
  165. //
  166. // Arguments: [hWindow] - handle for the window
  167. // [pICube] - cube to compare with
  168. //
  169. // Returns: S_OK
  170. //
  171. // History: 06-Aug-92 Ricksa Created
  172. //
  173. //--------------------------------------------------------------------------
  174. STDMETHODIMP CCube::Contains(IBalls *pIBall)
  175. {
  176. ULONG xPos, yPos;
  177. SCODE sc = pIBall->GetBallPos(&xPos, &yPos);
  178. if (SUCCEEDED(sc))
  179. {
  180. if ((abs(xPos - _xPos) < CUBE_WIDTH) &&
  181. (abs(yPos - _yPos) < CUBE_WIDTH))
  182. {
  183. // Format message for the screen
  184. Display(TEXT("Cube contains in Ball. xPos = %ld yPos = %ld\n"), xPos, yPos);
  185. }
  186. else
  187. {
  188. // Format message for the screen
  189. Display(TEXT("Ball Outside Cube. xPos = %ld yPos = %ld\n"), xPos, yPos);
  190. }
  191. }
  192. return sc;
  193. }
  194. //+-------------------------------------------------------------------------
  195. //
  196. // Function: CCube::SimpleCall
  197. //
  198. // Synopsis: checks the TID and LID to make sure they match the callers.
  199. //
  200. // Arguments:
  201. //
  202. // Returns: S_OK
  203. //
  204. // History: 16-Jan-96 RickHi Created
  205. //
  206. //--------------------------------------------------------------------------
  207. STDMETHODIMP CCube::SimpleCall(DWORD pidCaller, DWORD tidCaller, GUID lidCaller)
  208. {
  209. HRESULT hr = S_OK;
  210. GUID lid;
  211. HRESULT hr2 = CoGetCurrentLogicalThreadId(&lid);
  212. if (SUCCEEDED(hr2))
  213. {
  214. if (!IsEqualGUID(lid, lidCaller))
  215. {
  216. // LIDs dont match, error
  217. hr |= 0x80000001;
  218. }
  219. }
  220. else
  221. {
  222. return hr2;
  223. }
  224. DWORD tid;
  225. hr2 = CoGetCallerTID(&tid);
  226. if (SUCCEEDED(hr2))
  227. {
  228. if (pidCaller == GetCurrentProcessId())
  229. {
  230. // if in same process, CoGetCallerTID should return S_OK
  231. if (hr2 != S_OK)
  232. {
  233. hr |= 0x80000002;
  234. }
  235. }
  236. else
  237. {
  238. // if in different process, CoGetCallerTID should return S_FALSE
  239. if (hr2 != S_FALSE)
  240. {
  241. hr |= 0x80000004;
  242. }
  243. }
  244. }
  245. else
  246. {
  247. return hr2;
  248. }
  249. return hr;
  250. }
  251. STDMETHODIMP CCube::PrepForInputSyncCall(IUnknown *pUnkIn)
  252. {
  253. // just remember the input ptr
  254. _pUnkIn = pUnkIn;
  255. _pUnkIn->AddRef();
  256. return S_OK;
  257. }
  258. STDMETHODIMP CCube::InputSyncCall()
  259. {
  260. // just attempt to release an Interface Pointer inside an InputSync
  261. // method.
  262. if (_pUnkIn)
  263. {
  264. if (_pUnkIn->Release() != 0)
  265. return RPC_E_CANTCALLOUT_ININPUTSYNCCALL;
  266. }
  267. return S_OK;
  268. }