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