forked from electronicarts/CnC_Remastered_Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DDE.CPP
465 lines (393 loc) · 19.4 KB
/
DDE.CPP
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
//
// Copyright 2020 Electronic Arts Inc.
//
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
// software: you can redistribute it and/or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
// in the hope that it will be useful, but with permitted additional restrictions
// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
// distributed with this program. You should have received a copy of the
// GNU General Public License along with permitted additional restrictions
// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
/***************************************************************************
** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
***************************************************************************
* *
* Project Name : Dynamic Data Encapsulation *
* *
* File Name : DDE.CPP *
* *
* Programmer : Steve Wetherill *
* *
* Start Date : June 1, 1996 *
* *
* Last Update : June 8, 1996 [SW] *
* *
*-------------------------------------------------------------------------*
* Functions: *
* Instance_Class::InstanceClass -- class constructor *
* Instance_Class::InstanceClass -- class destructor *
* Instance_Class::Enable_Callback -- enables local processing of pokes *
* Instance_Class::Register_Servers -- registers a local DDE DNS service *
* Instance_Class::Cleanup_App -- currently does nothing *
* Instance_Class::Test_Server_Running -- does a trial connect to remote *
* Instance_Class::Open_Poke_Connection -- pokes some data to server *
* Instance_Class::Close_Poke_Connectionp -- closes connection to remote *
* Instance_Class::Poke_Server -- sends a chunk of data to remote *
* Instance_Class::dde_callback -- processes DDE transactions *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include <windows.h>
#include "dde.h"
/***************************************************************************
* These are static members of Instance_Class
*=========================================================================*/
DWORD Instance_Class::id_inst; // instance identifier set by DdeInitialize
BOOL Instance_Class::process_pokes; // controls response to pokes
char Instance_Class::ascii_name[32]; // name of server
//PG_TO_FIX ST - 12/20/2018 2:17PM
#if (0)
static BOOL CALLBACK (*Instance_Class::callback) (
LPBYTE pointer, // pointer to received data
long length // length of received data or advisory flag
) = NULL;
#endif
/***************************************************************************
* Instance_Class::InstanceClass -- class constructor *
* *
* INPUT: *
* name1 null terminated ASCII client name *
* name1 null terminated ASCII server name *
* *
* OUTPUT: *
* dde_error = TRUE if error occurs when initializing DDE *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
Instance_Class::Instance_Class( LPSTR name1, LPSTR name2 )
{
name1;
name2;
return;
#if (0) //ST - 1/2/2019 5:35PM
dde_error = FALSE; // no errors
process_pokes = FALSE; // disable pokes in callback
id_inst = 0; // set to 0 for first time through
conv_handle = 0; // conversation handle reset
lstrcpy( ascii_name, name1 ); // keep a record of ASCII name
if ( DdeInitialize(
(LPDWORD) &id_inst, // instance identifier
dde_callback,
APPCLASS_STANDARD | // filter server messages
CBF_FAIL_SELFCONNECTIONS, // prevent from connecting with self
0) != DMLERR_NO_ERROR) { // reserved
dde_error = TRUE; // flag an error
}
local_name = DdeCreateStringHandle(
id_inst, // instance identifier
name1, // string to register
CP_WINANSI); // Windows ANSI code page
remote_name = DdeCreateStringHandle(
id_inst, // instance identifier
name2, // string to register
CP_WINANSI); // Windows ANSI code page
poke_topic = DdeCreateStringHandle(
id_inst, // instance identifier
"POKE TOPIC", // System topic
CP_WINANSI); // Windows ANSI code page
poke_item = DdeCreateStringHandle(
id_inst, // instance identifier
"POKE ITEM", // System topic
CP_WINANSI); // Windows ANSI code page
system_topic = DdeCreateStringHandle(
id_inst, // instance identifier
SZDDESYS_TOPIC, // System topic
CP_WINANSI); // Windows ANSI code page
#endif
}
/***************************************************************************
* Instance_Class::~Instance_Class -- class destructor *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
Instance_Class::~Instance_Class()
{
DdeUninitialize( id_inst );
}
/***************************************************************************
* Instance_Class::Enable_Callback -- enables user callback *
* *
* INPUT: *
* TRUE = enable poke processing *
* FALSE = disable poke processing *
* *
* OUTPUT: *
* echos the input *
* *
* WARNINGS: *
* user callback must be explicitly enabled. Disbabled by default. *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
BOOL Instance_Class::Enable_Callback( BOOL flag ) // enable or disable callback
{
return (process_pokes = flag);
}
/***************************************************************************
* Instance_Class::Register_Server -- registers a local DDE DNS service *
* *
* INPUT: *
* BOOL CALLBACK ( *callback_fnc) ( LPBYTE, DWORD) = user poke callbacl *
* *
* OUTPUT: *
* TRUE == success *
* FALSE == failed *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
#if (0)
BOOL Instance_Class::Register_Server( BOOL (CALLBACK *)(LPBYTE, long));
//BOOL Instance_Class::Register_Server( BOOL CALLBACK ( *callback_fnc) (LPBYTE, long) )
{
if (DdeNameService( id_inst, local_name, 0L, DNS_REGISTER ) != 0L) {
callback = callback_fnc;
return ( TRUE );
} else {
return ( FALSE );
}
}
#endif
/***************************************************************************
* Instance_Class::Test_Server_Running -- does a trial connect to remote *
* *
* INPUT: *
* name = HSZ string handle of server name. *
* *
* OUTPUT: *
* TRUE == successfully connected to remote *
* FALSE == failed to connect *
* *
* WARNINGS: *
* - Can be called for local or remote server but of course will *
* fail if a called for local and local server is not "up". *
* - Disconects before exiting. *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
BOOL Instance_Class::Test_Server_Running( HSZ name )
{
if( Open_Poke_Connection( name ) == TRUE) {
Close_Poke_Connection();
return( TRUE );
} else {
return( FALSE );
}
}
/***************************************************************************
* Instance_Class::Open_Poke_Connection -- open a connection to server *
* *
* INPUT: *
* name = HSZ server name. *
* *
* OUTPUT: *
* TRUE == successfully opened connection *
* FALSE == failed to connect *
* *
* WARNINGS: *
* Can be called for local or remote server but of course will *
* fail if a called for local and local server is not "up". *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
BOOL Instance_Class::Open_Poke_Connection( HSZ name )
{
conv_handle = DdeConnect(
id_inst, // instance identifier
name, // service name string handle
poke_topic, // topic string handle
(PCONVCONTEXT) NULL);// use default context
if (conv_handle == NULL) {
return FALSE;
} else {
return TRUE;
}
}
/***************************************************************************
* Instance_Class::Close_Poke_Connection -- closes poke connection *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* TRUE == successfully closed connection *
* FALSE == failed to close connection for some reason *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
BOOL Instance_Class::Close_Poke_Connection( void )
{
if( conv_handle ) {
HCONV temp_handle = conv_handle;
conv_handle = NULL;
return( DdeDisconnect( temp_handle ));
} else {
return( TRUE );
}
}
/***************************************************************************
* Instance_Class::Poke_Server -- pokes some data to server *
* *
* INPUT: *
* poke_data points to data to send to remote *
* poke_length length of buffer to send *
* *
* OUTPUT: *
* TRUE == successfully poked the data *
* FALSE == failed to connect *
* *
* WARNINGS: *
* has a 3 second timeout (change POKE_TIMEOUT, in milliseconds) *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
#define POKE_TIMEOUT 60*1000 // 60 sec timeout
BOOL Instance_Class::Poke_Server( LPBYTE poke_data, DWORD poke_length )
{
if( DdeClientTransaction(
poke_data, // address of data to pass to server
poke_length, // length of data
conv_handle, // handle of conversation
poke_topic, // handle of item name string
CF_TEXT, // no special clipboard data format
XTYP_POKE, // transaction type
POKE_TIMEOUT, // time-out duration (millisecs)
(LPDWORD) NULL // address of transaction result (don't check)
) == 0) {
return( FALSE);
} else {
return( TRUE );
}
}
/***************************************************************************
* Instance_Class::dde_callback -- callback dde event handler *
* *
* INPUT: *
* dde_event transaction type *
* uFmt clipboard data format *
* hconv handle of the conversation *
* hsz1 handle of a string *
* hsz2 handle of a string *
* hdata handle of a global memory object *
* dwData1 transaction-specific data *
* dwData2 transaction-specific data *
* *
* OUTPUT: *
* context specific HDDEDATA object *
* *
* WARNINGS: *
* NOTE: declared as HDDEDATA CALLBACK which means PASCAL parameters *
* *
* HISTORY: *
* 6/1/1996 SW : Created. *
*=========================================================================*/
HDDEDATA CALLBACK Instance_Class::dde_callback(
UINT dde_event, // transaction type
UINT uFmt, // clipboard data format
HCONV , // handle of the conversation
HSZ hsz1, // handle of a string
HSZ hsz2, // handle of a string
HDDEDATA hdata, // handle of a global memory object
DWORD , // transaction-specific data
DWORD // transaction-specific data
)
{
dde_event;
uFmt;
hsz1;
hsz2;
hdata;
return (HDDEDATA) NULL;
#if (0) //ST - 1/2/2019 5:38PM
if (!Instance_Class::callback){
return (HDDEDATA) NULL;
}
switch ( dde_event ) {
case XTYP_REGISTER:
case XTYP_UNREGISTER:
return (HDDEDATA) NULL;
case XTYP_ADVDATA:
return (HDDEDATA) DDE_FACK;
case XTYP_XACT_COMPLETE:
return (HDDEDATA) NULL;
case XTYP_DISCONNECT:
Instance_Class::callback( NULL, DDE_ADVISE_DISCONNECT);
return (HDDEDATA) NULL;
case XTYP_CONNECT: {
char buffer[32];
DdeQueryString (Instance_Class::id_inst, hsz2, buffer, sizeof (buffer), 0) ;
if (0 != strcmp (buffer, Instance_Class::ascii_name)) {
return (HDDEDATA) NULL;
}
DdeQueryString (Instance_Class::id_inst, hsz1, buffer, sizeof (buffer), 0) ;
if (0 != strcmp (buffer, "POKE TOPIC")) {
return (HDDEDATA) NULL;
}
Instance_Class::callback( NULL, DDE_ADVISE_CONNECT);
return (HDDEDATA) TRUE;
}
case XTYP_POKE:
if (Instance_Class::process_pokes == FALSE ) {
return (HDDEDATA) DDE_FNOTPROCESSED; // processing disabled
} else {
char buffer[32];
DdeQueryString (Instance_Class::id_inst, hsz1, buffer, sizeof (buffer), 0) ;
if (0 != strcmp (buffer, "POKE TOPIC")) {
return (HDDEDATA) DDE_FNOTPROCESSED;
} else if (uFmt == CF_TEXT) { // make sure it's CF_TEXT
BOOL processed;
BYTE FAR *pdata;
DWORD dw_length;
if ( (pdata = DdeAccessData( hdata, &dw_length)) == NULL ) {
return (HDDEDATA) DDE_FNOTPROCESSED;
}
processed = Instance_Class::callback((LPBYTE) pdata, dw_length);
DdeUnaccessData( hdata );
if (processed == TRUE) {
return (HDDEDATA) DDE_FACK;
} else {
return (HDDEDATA) NULL;
}
}
}
default:
return (HDDEDATA) NULL;
}
#endif
}