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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
/*++
*
* WOW v1.0
*
* Copyright (c) 1991, Microsoft Corporation
*
* WMMSTRU2.C
* WOW32 16-bit MultiMedia structure conversion support
* Contains support for mciSendCommand UnThunk message Parms.
*
* History:
* Created 17-Jul-1992 by Stephen Estrop (stephene)
*
--*/
//
// We define NO_STRICT so that the compiler doesn't moan and groan when
// I use the FARPROC type for the Multi-Media api loading.
//
#define NO_STRICT
#include "precomp.h"
#pragma hdrstop
#if 0
MODNAME(wmmstru2.c);
//
// The following are required for the dynamic linking of Multi-Media code
// from within WOW. They are all defined in wmmedia.c
//
extern FARPROC mmAPIEatCmdEntry;
extern FARPROC mmAPIGetParamSize;
extern FARPROC mmAPIUnlockCmdTable;
extern FARPROC mmAPISendCmdW;
/**********************************************************************\
*
* UnThunkMciCommand16
*
* This function "unthunks" a 32 bit mci send command request.
*
* The ideas behind this function were stolen from UnThunkWMMsg16,
* see wmsg16.c
*
\**********************************************************************/
INT UnThunkMciCommand16( MCIDEVICEID devID, UINT OrigCommand, DWORD OrigFlags,
DWORD OrigParms, DWORD NewParms, LPWSTR lpCommand,
UINT uTable )
{
BOOL fReturnValNotThunked = FALSE;
#if DBG
static LPSTR f_name = "UnThunkMciCommand16: ";
register int i;
int n;
dprintf3(( "UnThunkMciCommand :" ));
n = sizeof(mciMessageNames) / sizeof(MCI_MESSAGE_NAMES);
for ( i = 0; i < n; i++ ) {
if ( mciMessageNames[i].uMsg == OrigCommand ) {
break;
}
}
dprintf3(( "OrigCommand -> %lX", (DWORD)OrigCommand ));
dprintf3(( " Name -> %s", i != n ? mciMessageNames[i].lpstMsgName : "Unkown Name" ));
dprintf5(( " OrigFlags -> %lX", OrigFlags ));
dprintf5(( " OrigParms -> %lX", OrigParms ));
dprintf5(( " NewParms -> %lX", NewParms ));
//
// If NewParms is 0 we shouldn't be here, I haven't got an assert
// macro, but the following we do the same thing.
//
if ( NewParms == 0 ) {
dprintf(( "%scalled with NewParms == NULL !!", f_name ));
dprintf(( "Call StephenE NOW !!" ));
DebugBreak();
}
#endif
//
// We have to do a manual unthunk of MCI_SYSINFO because the
// command table is not consistent. As a command table should be
// available now we can load it and then use it to unthunk MCI_OPEN.
//
switch ( OrigCommand ) {
case MCI_OPEN:
UnThunkOpenCmd( OrigFlags, OrigParms, NewParms );
break;
case MCI_SYSINFO:
UnThunkSysInfoCmd( OrigFlags, OrigParms, NewParms );
break;
case MCI_STATUS:
UnThunkStatusCmd( devID, OrigFlags, OrigParms, NewParms );
break;
default:
fReturnValNotThunked = TRUE;
break;
}
//
// Do we have a command table ? It is possible that we have
// a custom command but we did not find a custom command table, in which
// case we should just free the pNewParms storage.
//
if ( lpCommand != NULL ) {
//
// We now parse the custom command table to see if there is a
// return field in the parms structure.
//
dprintf3(( "%sUnthunking via command table", f_name ));
UnThunkCommandViaTable( lpCommand, OrigFlags, OrigParms,
NewParms, fReturnValNotThunked );
//
// Now we have finished with the command table we should unlock it.
//
dprintf4(( "%sUnlocking custom command table", f_name ));
(*mmAPIUnlockCmdTable)( uTable );
}
//
// All that needs to be done now is to free the storage
// that was allocated during the ThunkXxxCmd function.
//
dprintf4(( "%sFreeing storage.", f_name ));
free_w( (PBYTE)NewParms );
return 0;
}
/**********************************************************************\
* UnThunkOpenCmd
*
* UnThunk the Open mci command parms.
\**********************************************************************/
VOID UnThunkOpenCmd( DWORD OrigFlags, DWORD OrigParms, DWORD NewParms )
{
#if DBG
static LPSTR f_name = "UnThunkOpenCmd: ";
#endif
LPMCI_OPEN_PARMS lpOpeParms = (LPMCI_OPEN_PARMS)NewParms;
PMCI_OPEN_PARMS16 lpOpeParms16;
WORD wDevice;
dprintf4(( "%sCopying Device ID.", f_name ));
GETVDMPTR( OrigParms, sizeof(MCI_OPEN_PARMS16), lpOpeParms16 );
wDevice = LOWORD( lpOpeParms->wDeviceID );
STOREWORD( lpOpeParms16->wDeviceID, wDevice );
FLUSHVDMPTR( OrigParms, sizeof(MCI_OPEN_PARMS16), lpOpeParms16 );
FREEVDMPTR( lpOpeParms16 );
dprintf5(( "wDeviceID -> %u", wDevice ));
if ( (OrigParms & MCI_OPEN_TYPE) && !(OrigParms & MCI_OPEN_TYPE_ID ) ) {
dprintf3(( "%sFreeing a STRING pointer", f_name ));
FREEPSZPTR( lpOpeParms->lpstrDeviceType );
}
if ( (OrigParms & MCI_OPEN_ELEMENT)
&& !(OrigParms & MCI_OPEN_ELEMENT_ID ) ) {
dprintf3(( "%sFreeing a STRING pointer", f_name ));
FREEPSZPTR( lpOpeParms->lpstrElementName );
}
}
/**********************************************************************\
* UnThunkSysInfoCmd
*
* UnThunk the SysInfo mci command parms.
\**********************************************************************/
VOID UnThunkSysInfoCmd( DWORD OrigFlags, DWORD OrigParms, DWORD NewParms )
{
#if DBG
static LPSTR f_name = "UnThunkSysInfoCmd: ";
#endif
LPMCI_SYSINFO_PARMS lpSysParms = (LPMCI_SYSINFO_PARMS)NewParms;
//
// Had better check that we did actually allocate
// a pointer.
//
if ( lpSysParms->lpstrReturn && lpSysParms->dwRetSize ) {
#if DBG
if ( !(OrigFlags & MCI_SYSINFO_QUANTITY) ) {
dprintf5(( "lpstrReturn -> %s", lpSysParms->lpstrReturn ));
}
else {
dprintf5(( "lpstrReturn -> %d", *(LPDWORD)lpSysParms->lpstrReturn ));
}
#endif
//
// Free lpSysParms->lpstrReturn;
//
dprintf4(( "%sFreeing lpstrReturn", f_name ));
FREEVDMPTR( lpSysParms->lpstrReturn );
}
}
/**********************************************************************\
* UnThunkMciStatus
*
* UnThunk the Status mci command parms.
\**********************************************************************/
VOID UnThunkStatusCmd( MCIDEVICEID devID, DWORD OrigFlags,
DWORD OrigParms, DWORD NewParms )
{
#if DBG
static LPSTR f_name = "UnThunkStatusCmd: ";
#endif
MCI_GETDEVCAPS_PARMS GetDevCaps;
DWORD dwRetVal;
DWORD dwParm16;
PDWORD pdwOrig16;
PDWORD pdwParm32;
int iReturnType = MCI_INTEGER;
/*
** If the MCI_STATUS_ITEM flag is not specified don't bother
** doing any unthunking.
*/
if ( !(OrigFlags & MCI_STATUS_ITEM) ) {
return;
}
/*
** We need to determine what type of device we are
** dealing with. We can do this by send an MCI_GETDEVCAPS
** command to the device. (We might as well use the Unicode
** version of mciSendCommand and avoid another thunk).
*/
RtlZeroMemory( &GetDevCaps, sizeof(MCI_GETDEVCAPS_PARMS) );
GetDevCaps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
dwRetVal = (*mmAPISendCmdW)( devID, MCI_GETDEVCAPS, MCI_GETDEVCAPS_ITEM,
(DWORD)&GetDevCaps );
/*
** If we can't get the DevCaps then we are doomed.
*/
if ( dwRetVal ) {
dprintf(("%sFailure to get devcaps", f_name));
return;
}
/*
** Determine the dwReturn type.
*/
switch ( GetDevCaps.dwReturn ) {
case MCI_DEVTYPE_ANIMATION:
switch ( ((LPDWORD)NewParms)[2] ) {
case MCI_ANIM_STATUS_HWND:
iReturnType = MCI_HWND;
break;
case MCI_ANIM_STATUS_HPAL:
iReturnType = MCI_HPAL;
break;
}
break;
case MCI_DEVTYPE_OVERLAY:
if ( ((LPDWORD)NewParms)[2] == MCI_OVLY_STATUS_HWND ) {
iReturnType = MCI_HWND;
}
break;
case MCI_DEVTYPE_DIGITAL_VIDEO:
switch ( ((LPDWORD)NewParms)[2] ) {
case MCI_DGV_STATUS_HWND:
iReturnType = MCI_HWND;
break;
case MCI_DGV_STATUS_HPAL:
iReturnType = MCI_HPAL;
break;
}
break;
}
/*
** Thunk the dwReturn value according to the required type
*/
GETVDMPTR( OrigParms, sizeof( MCI_STATUS_PARMS), pdwOrig16 );
pdwParm32 = (LPDWORD)((LPBYTE)NewParms + 4);
switch ( iReturnType ) {
case MCI_HPAL:
dprintf4(( "%sFound an HPAL return field", f_name ));
dwParm16 = MAKELONG( GETHPALETTE16( (HPALETTE)*pdwParm32 ), 0 );
STOREDWORD( *(LPDWORD)((LPBYTE)pdwOrig16 + 4), dwParm16 );
dprintf5(( "HDC32 -> 0x%lX", *pdwParm32 ));
dprintf5(( "HDC16 -> 0x%lX", dwParm16 ));
break;
case MCI_HWND:
dprintf4(( "%sFound an HWND return field", f_name ));
dwParm16 = MAKELONG( GETHWND16( (HWND)*pdwParm32 ), 0 );
STOREDWORD( *(LPDWORD)((LPBYTE)pdwOrig16 + 4), dwParm16 );
dprintf5(( "HWND32 -> 0x%lX", *pdwParm32 ));
dprintf5(( "HWND16 -> 0x%lX", dwParm16 ));
break;
case MCI_INTEGER:
dprintf4(( "%sFound an INTEGER return field", f_name ));
STOREDWORD( *(LPDWORD)((LPBYTE)pdwOrig16 + 4), *pdwParm32 );
dprintf5(( "INTEGER -> %ld", *pdwParm32 ));
break;
// no default: all possible cases accounted for
}
/*
** Free the VDM pointer as we have finished with it
*/
FLUSHVDMPTR( OrigParms, sizeof( MCI_STATUS_PARMS), pdwOrig16 );
FREEVDMPTR( pdwOrig16 );
}
/**********************************************************************\
* UnThunkCommandViaTable
*
* Thunks the return field if there is one and then frees and pointers
* that were got via GETVDMPTR or GETPSZPTR.
\**********************************************************************/
INT UnThunkCommandViaTable( LPWSTR lpCommand, DWORD dwFlags, DWORD OrigParms,
DWORD pNewParms, BOOL fReturnValNotThunked )
{
#if DBG
static LPSTR f_name = "UnThunkCommandViaTable: ";
#endif
LPWSTR lpFirstParameter;
UINT wID;
DWORD dwValue;
UINT wOffset32, wOffset1stParm32;
DWORD dwParm16;
DWORD Size;
PDWORD pdwOrig16;
PDWORD pdwParm32;
DWORD dwMask = 1;
//
// Calculate the size of this command parameter block in terms
// of bytes, then get a VDM pointer to the OrigParms.
//
Size = GetSizeOfParameter( lpCommand );
//
// Skip past command entry
//
lpCommand = (LPWSTR)((LPBYTE)lpCommand +
(*mmAPIEatCmdEntry)( lpCommand, NULL, NULL ));
//
// Get the next entry
//
lpFirstParameter = lpCommand;
//
// Skip past the DWORD return value
//
wOffset1stParm32 = 4;
lpCommand = (LPWSTR)((LPBYTE)lpCommand +
(*mmAPIEatCmdEntry)( lpCommand, &dwValue, &wID ));
//
// If it is a return value, skip it
//
if ( (wID == MCI_RETURN) && (fReturnValNotThunked) ) {
GETVDMPTR( OrigParms, Size, pdwOrig16 );
pdwParm32 = (LPDWORD)((LPBYTE)pNewParms + 4);
//
// Look for a string return type, these are a special case.
//
switch ( dwValue ) {
case MCI_STRING:
dprintf4(( "%sFound a STRING return field", f_name ));
//
// Get string pointer and length
//
Size = *(LPDWORD)((LPBYTE)pNewParms + 8);
//
// Get the 32 bit string pointer
//
if ( Size > 0 ) {
dprintf4(( "%sFreeing a return STRING pointer", f_name ));
dprintf5(( "STRING -> %s", (LPSTR)*pdwParm32 ));
FREEVDMPTR( (LPSTR)*pdwParm32 );
}
break;
case MCI_RECT:
{
PRECT pRect32 = (PRECT)((LPBYTE)pNewParms + 4);
PRECT16 pRect16 = (PRECT16)((LPBYTE)pdwOrig16 + 4);
dprintf4(( "%sFound a RECT return field", f_name ));
STORESHORT( pRect16->top, (SHORT)pRect32->top );
STORESHORT( pRect16->bottom, (SHORT)pRect32->bottom );
STORESHORT( pRect16->left, (SHORT)pRect32->left );
STORESHORT( pRect16->right, (SHORT)pRect32->right );
}
break;
case MCI_INTEGER:
//
// Get the 32 bit return integer and store it in the
// 16 bit parameter structure.
//
dprintf4(( "%sFound an INTEGER return field", f_name ));
STOREDWORD( *(LPDWORD)((LPBYTE)pdwOrig16 + 4), *pdwParm32 );
dprintf5(( "INTEGER -> %ld", *pdwParm32 ));
break;
case MCI_HWND:
dprintf4(( "%sFound an HWND return field", f_name ));
dwParm16 = MAKELONG( GETHWND16( (HWND)*pdwParm32 ), 0 );
STOREDWORD( *(LPDWORD)((LPBYTE)pdwOrig16 + 4), dwParm16 );
dprintf5(( "HWND32 -> 0x%lX", *pdwParm32 ));
dprintf5(( "HWND16 -> 0x%lX", dwParm16 ));
break;
case MCI_HPAL:
dprintf4(( "%sFound an HPAL return field", f_name ));
dwParm16 = MAKELONG( GETHPALETTE16( (HPALETTE)*pdwParm32 ), 0 );
STOREDWORD( *(LPDWORD)((LPBYTE)pdwOrig16 + 4), dwParm16 );
dprintf5(( "HDC32 -> 0x%lX", *pdwParm32 ));
dprintf5(( "HDC16 -> 0x%lX", dwParm16 ));
break;
case MCI_HDC:
dprintf4(( "%sFound an HDC return field", f_name ));
dwParm16 = MAKELONG( GETHDC16( (HDC)*pdwParm32 ), 0 );
STOREDWORD( *(LPDWORD)((LPBYTE)pdwOrig16 + 4), dwParm16 );
dprintf5(( "HDC32 -> 0x%lX", *pdwParm32 ));
dprintf5(( "HDC16 -> 0x%lX", dwParm16 ));
break;
}
//
// Free the VDM pointer as we have finished with it
//
FLUSHVDMPTR( OrigParms, Size, pdwOrig16 );
FREEVDMPTR( pdwOrig16 );
//
// Adjust the offset of the first parameter.
//
wOffset1stParm32 = (*mmAPIGetParamSize)( dwValue, wID );
//
// Save the new first parameter
//
lpFirstParameter = lpCommand;
}
//
// Walk through each flag looking for strings to free
//
while ( dwMask != 0 ) {
//
// Is this bit set?
//
if ( (dwFlags & dwMask) != 0 ) {
wOffset32 = wOffset1stParm32;
lpCommand = (LPWSTR)((LPBYTE)lpFirstParameter +
(*mmAPIEatCmdEntry)( lpFirstParameter,
&dwValue, &wID ));
//
// What parameter uses this bit?
//
while ( wID != MCI_END_COMMAND && dwValue != dwMask ) {
wOffset32 = (*mmAPIGetParamSize)( dwValue, wID );
if ( wID == MCI_CONSTANT ) {
while ( wID != MCI_END_CONSTANT ) {
lpCommand = (LPWSTR)((LPBYTE)lpCommand +
(*mmAPIEatCmdEntry)( lpCommand, NULL, &wID ));
}
}
lpCommand = (LPWSTR)((LPBYTE)lpCommand +
(*mmAPIEatCmdEntry)( lpCommand, &dwValue, &wID ));
}
if ( wID == MCI_STRING ) {
dprintf4(( "%sFreeing a STRING pointer", f_name ));
pdwParm32 = (LPDWORD)((LPBYTE)pNewParms + wOffset32);
FREEPSZPTR( (LPSTR)*pdwParm32 );
}
}
//
// Go to the next flag
//
dwMask <<= 1;
}
return 0;
}
#endif
|