[WINMM]
[reactos.git] / reactos / dll / win32 / winmm / mci.c
1 /*
2 * MCI internal functions
3 *
4 * Copyright 1998/1999 Eric Pouech
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 /* TODO:
22 * - implement WINMM (32bit) multitasking and use it in all MCI drivers
23 * instead of the home grown one
24 * - 16bit mmTaskXXX functions are currently broken because the 16
25 * loader does not support binary command lines => provide Wine's
26 * own mmtask.tsk not using binary command line.
27 * - correctly handle the MCI_ALL_DEVICE_ID in functions.
28 * - finish mapping 16 <=> 32 of MCI structures and commands
29 * - implement auto-open feature (ie, when a string command is issued
30 * for a not yet opened device, MCI automatically opens it)
31 * - use a default registry setting to replace the [mci] section in
32 * configuration file (layout of info in registry should be compatible
33 * with all Windows' version - which use different layouts of course)
34 * - implement automatic open
35 * + only works on string interface, on regular devices (don't work on all
36 * nor custom devices)
37 * - command table handling isn't thread safe
38 */
39
40 /* to be cross checked:
41 * - heapalloc for *sizeof(WCHAR) when needed
42 * - size of string in WCHAR or bytes? (#chars for MCI_INFO, #bytes for MCI_SYSINFO)
43 */
44
45 #include "winemm.h"
46
47 #include <mmsystem.h>
48 #include <wownt32.h>
49 #include <digitalv.h>
50
51 WINE_DEFAULT_DEBUG_CHANNEL(mci);
52
53 /* First MCI valid device ID (0 means error) */
54 #define MCI_MAGIC 0x0001
55
56 /* MCI settings */
57 static const WCHAR wszHklmMci [] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','M','C','I',0};
58 static const WCHAR wszNull [] = {0};
59 static const WCHAR wszAll [] = {'A','L','L',0};
60 static const WCHAR wszMci [] = {'M','C','I',0};
61 static const WCHAR wszOpen [] = {'o','p','e','n',0};
62 static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
63
64 static WINE_MCIDRIVER *MciDrivers;
65
66 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
67 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType);
68
69 /* dup a string and uppercase it */
70 static inline LPWSTR str_dup_upper( LPCWSTR str )
71 {
72 INT len = (strlenW(str) + 1) * sizeof(WCHAR);
73 LPWSTR p = HeapAlloc( GetProcessHeap(), 0, len );
74 if (p)
75 {
76 memcpy( p, str, len );
77 CharUpperW( p );
78 }
79 return p;
80 }
81
82 /**************************************************************************
83 * MCI_GetDriver [internal]
84 */
85 static LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
86 {
87 LPWINE_MCIDRIVER wmd = 0;
88
89 EnterCriticalSection(&WINMM_cs);
90 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
91 if (wmd->wDeviceID == wDevID)
92 break;
93 }
94 LeaveCriticalSection(&WINMM_cs);
95 return wmd;
96 }
97
98 /**************************************************************************
99 * MCI_GetDriverFromString [internal]
100 */
101 static UINT MCI_GetDriverFromString(LPCWSTR lpstrName)
102 {
103 LPWINE_MCIDRIVER wmd;
104 UINT ret = 0;
105
106 if (!lpstrName)
107 return 0;
108
109 if (!strcmpiW(lpstrName, wszAll))
110 return MCI_ALL_DEVICE_ID;
111
112 EnterCriticalSection(&WINMM_cs);
113 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
114 if (wmd->lpstrElementName && strcmpW(wmd->lpstrElementName, lpstrName) == 0) {
115 ret = wmd->wDeviceID;
116 break;
117 }
118 if (wmd->lpstrDeviceType && strcmpiW(wmd->lpstrDeviceType, lpstrName) == 0) {
119 ret = wmd->wDeviceID;
120 break;
121 }
122 if (wmd->lpstrAlias && strcmpiW(wmd->lpstrAlias, lpstrName) == 0) {
123 ret = wmd->wDeviceID;
124 break;
125 }
126 }
127 LeaveCriticalSection(&WINMM_cs);
128
129 return ret;
130 }
131
132 /**************************************************************************
133 * MCI_MessageToString [internal]
134 */
135 const char* MCI_MessageToString(UINT wMsg)
136 {
137 static char buffer[100];
138
139 #define CASE(s) case (s): return #s
140
141 switch (wMsg) {
142 CASE(DRV_LOAD);
143 CASE(DRV_ENABLE);
144 CASE(DRV_OPEN);
145 CASE(DRV_CLOSE);
146 CASE(DRV_DISABLE);
147 CASE(DRV_FREE);
148 CASE(DRV_CONFIGURE);
149 CASE(DRV_QUERYCONFIGURE);
150 CASE(DRV_INSTALL);
151 CASE(DRV_REMOVE);
152 CASE(DRV_EXITSESSION);
153 CASE(DRV_EXITAPPLICATION);
154 CASE(DRV_POWER);
155 CASE(MCI_BREAK);
156 CASE(MCI_CLOSE);
157 CASE(MCI_CLOSE_DRIVER);
158 CASE(MCI_COPY);
159 CASE(MCI_CUE);
160 CASE(MCI_CUT);
161 CASE(MCI_DELETE);
162 CASE(MCI_ESCAPE);
163 CASE(MCI_FREEZE);
164 CASE(MCI_PAUSE);
165 CASE(MCI_PLAY);
166 CASE(MCI_GETDEVCAPS);
167 CASE(MCI_INFO);
168 CASE(MCI_LOAD);
169 CASE(MCI_OPEN);
170 CASE(MCI_OPEN_DRIVER);
171 CASE(MCI_PASTE);
172 CASE(MCI_PUT);
173 CASE(MCI_REALIZE);
174 CASE(MCI_RECORD);
175 CASE(MCI_RESUME);
176 CASE(MCI_SAVE);
177 CASE(MCI_SEEK);
178 CASE(MCI_SET);
179 CASE(MCI_SPIN);
180 CASE(MCI_STATUS);
181 CASE(MCI_STEP);
182 CASE(MCI_STOP);
183 CASE(MCI_SYSINFO);
184 CASE(MCI_UNFREEZE);
185 CASE(MCI_UPDATE);
186 CASE(MCI_WHERE);
187 CASE(MCI_WINDOW);
188 /* constants for digital video */
189 CASE(MCI_CAPTURE);
190 CASE(MCI_MONITOR);
191 CASE(MCI_RESERVE);
192 CASE(MCI_SETAUDIO);
193 CASE(MCI_SIGNAL);
194 CASE(MCI_SETVIDEO);
195 CASE(MCI_QUALITY);
196 CASE(MCI_LIST);
197 CASE(MCI_UNDO);
198 CASE(MCI_CONFIGURE);
199 CASE(MCI_RESTORE);
200 #undef CASE
201 default:
202 sprintf(buffer, "MCI_<<%04X>>", wMsg);
203 return buffer;
204 }
205 }
206
207 LPWSTR MCI_strdupAtoW( LPCSTR str )
208 {
209 LPWSTR ret;
210 INT len;
211
212 if (!str) return NULL;
213 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
214 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
215 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
216 return ret;
217 }
218
219 LPSTR MCI_strdupWtoA( LPCWSTR str )
220 {
221 LPSTR ret;
222 INT len;
223
224 if (!str) return NULL;
225 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
226 ret = HeapAlloc( GetProcessHeap(), 0, len );
227 if (ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
228 return ret;
229 }
230
231 static int MCI_MapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
232 {
233 if (msg < DRV_RESERVED) return 0;
234
235 switch (msg)
236 {
237 case MCI_CLOSE:
238 case MCI_CONFIGURE:
239 case MCI_PLAY:
240 case MCI_SEEK:
241 case MCI_STOP:
242 case MCI_PAUSE:
243 case MCI_GETDEVCAPS:
244 case MCI_SPIN:
245 case MCI_SET:
246 case MCI_STEP:
247 case MCI_RECORD:
248 case MCI_BREAK:
249 case MCI_SOUND:
250 case MCI_STATUS:
251 case MCI_CUE:
252 case MCI_REALIZE:
253 case MCI_PUT:
254 case MCI_WHERE:
255 case MCI_FREEZE:
256 case MCI_UNFREEZE:
257 case MCI_CUT:
258 case MCI_COPY:
259 case MCI_PASTE:
260 case MCI_UPDATE:
261 case MCI_RESUME:
262 case MCI_DELETE:
263 case MCI_MONITOR:
264 case MCI_SETAUDIO:
265 case MCI_SIGNAL:
266 case MCI_SETVIDEO:
267 case MCI_LIST:
268 return 0;
269
270 case MCI_OPEN:
271 {
272 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA*)*dwParam2;
273 MCI_OPEN_PARMSW *mci_openW;
274 DWORD_PTR *ptr;
275
276 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW) + 2 * sizeof(DWORD));
277 if (!ptr) return -1;
278
279 *ptr++ = *dwParam2; /* save the previous pointer */
280 *dwParam2 = (DWORD_PTR)ptr;
281 mci_openW = (MCI_OPEN_PARMSW *)ptr;
282
283 if (dwParam1 & MCI_NOTIFY)
284 mci_openW->dwCallback = mci_openA->dwCallback;
285
286 if (dwParam1 & MCI_OPEN_TYPE)
287 {
288 if (dwParam1 & MCI_OPEN_TYPE_ID)
289 mci_openW->lpstrDeviceType = (LPCWSTR)mci_openA->lpstrDeviceType;
290 else
291 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
292 }
293 if (dwParam1 & MCI_OPEN_ELEMENT)
294 {
295 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
296 mci_openW->lpstrElementName = (LPCWSTR)mci_openA->lpstrElementName;
297 else
298 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
299 }
300 if (dwParam1 & MCI_OPEN_ALIAS)
301 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
302 /* FIXME: this is only needed for specific types of MCI devices, and
303 * may cause a segfault if the two DWORD:s don't exist at the end of
304 * mci_openA
305 */
306 memcpy(mci_openW + 1, mci_openA + 1, 2 * sizeof(DWORD));
307 }
308 return 1;
309
310 case MCI_WINDOW:
311 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
312 {
313 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
314 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
315
316 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
317 if (!mci_windowW) return -1;
318
319 *dwParam2 = (DWORD_PTR)mci_windowW;
320
321 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
322
323 if (dwParam1 & MCI_NOTIFY)
324 mci_windowW->dwCallback = mci_windowA->dwCallback;
325 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
326 mci_windowW->hWnd = mci_windowA->hWnd;
327 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
328 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
329
330 return 1;
331 }
332 return 0;
333
334 case MCI_SYSINFO:
335 {
336 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
337 MCI_SYSINFO_PARMSW *mci_sysinfoW;
338 DWORD_PTR *ptr;
339
340 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
341 if (!ptr) return -1;
342
343 *ptr++ = *dwParam2; /* save the previous pointer */
344 *dwParam2 = (DWORD_PTR)ptr;
345 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
346
347 if (dwParam1 & MCI_NOTIFY)
348 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
349
350 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
351 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize);
352 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
353 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
354 return 1;
355 }
356 case MCI_INFO:
357 {
358 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
359 MCI_INFO_PARMSW *mci_infoW;
360 DWORD_PTR *ptr;
361
362 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
363 if (!ptr) return -1;
364
365 *ptr++ = *dwParam2; /* save the previous pointer */
366 *dwParam2 = (DWORD_PTR)ptr;
367 mci_infoW = (MCI_INFO_PARMSW *)ptr;
368
369 if (dwParam1 & MCI_NOTIFY)
370 mci_infoW->dwCallback = mci_infoA->dwCallback;
371
372 mci_infoW->dwRetSize = mci_infoA->dwRetSize * sizeof(WCHAR); /* it's not the same as SYSINFO !!! */
373 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize);
374 return 1;
375 }
376 case MCI_SAVE:
377 {
378 MCI_SAVE_PARMSA *mci_saveA = (MCI_SAVE_PARMSA *)*dwParam2;
379 MCI_SAVE_PARMSW *mci_saveW;
380
381 mci_saveW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW));
382 if (!mci_saveW) return -1;
383
384 *dwParam2 = (DWORD_PTR)mci_saveW;
385 if (dwParam1 & MCI_NOTIFY)
386 mci_saveW->dwCallback = mci_saveA->dwCallback;
387 mci_saveW->lpfilename = MCI_strdupAtoW(mci_saveA->lpfilename);
388 return 1;
389 }
390 case MCI_LOAD:
391 {
392 MCI_LOAD_PARMSA *mci_loadA = (MCI_LOAD_PARMSA *)*dwParam2;
393 MCI_LOAD_PARMSW *mci_loadW;
394
395 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
396 if (!mci_loadW) return -1;
397
398 *dwParam2 = (DWORD_PTR)mci_loadW;
399 if (dwParam1 & MCI_NOTIFY)
400 mci_loadW->dwCallback = mci_loadA->dwCallback;
401 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
402 return 1;
403 }
404
405 case MCI_ESCAPE:
406 {
407 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
408 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
409
410 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
411 if (!mci_vd_escapeW) return -1;
412
413 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
414 if (dwParam1 & MCI_NOTIFY)
415 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
416 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
417 return 1;
418 }
419 default:
420 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
421 return -1;
422 }
423 }
424
425 static DWORD MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
426 DWORD result)
427 {
428 switch (msg)
429 {
430 case MCI_OPEN:
431 {
432 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
433 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
434 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)(ptr + 1);
435
436 mci_openA->wDeviceID = mci_openW->wDeviceID;
437
438 if (dwParam1 & MCI_OPEN_TYPE)
439 {
440 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
441 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrDeviceType);
442 }
443 if (dwParam1 & MCI_OPEN_ELEMENT)
444 {
445 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
446 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrElementName);
447 }
448 if (dwParam1 & MCI_OPEN_ALIAS)
449 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrAlias);
450 HeapFree(GetProcessHeap(), 0, ptr);
451 }
452 break;
453 case MCI_WINDOW:
454 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
455 {
456 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
457
458 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
459 HeapFree(GetProcessHeap(), 0, mci_windowW);
460 }
461 break;
462
463 case MCI_SYSINFO:
464 {
465 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
466 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
467 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)(ptr + 1);
468
469 if (!result)
470 {
471 mci_sysinfoA->dwNumber = mci_sysinfoW->dwNumber;
472 mci_sysinfoA->wDeviceType = mci_sysinfoW->wDeviceType;
473 if (dwParam1 & MCI_SYSINFO_QUANTITY)
474 *(DWORD*)mci_sysinfoA->lpstrReturn = *(DWORD*)mci_sysinfoW->lpstrReturn;
475 else
476 WideCharToMultiByte(CP_ACP, 0,
477 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
478 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
479 NULL, NULL);
480 }
481
482 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
483 HeapFree(GetProcessHeap(), 0, ptr);
484 }
485 break;
486 case MCI_INFO:
487 {
488 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
489 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
490 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)(ptr + 1);
491
492 if (!result)
493 {
494 WideCharToMultiByte(CP_ACP, 0,
495 mci_infoW->lpstrReturn, mci_infoW->dwRetSize / sizeof(WCHAR),
496 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
497 NULL, NULL);
498 }
499
500 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
501 HeapFree(GetProcessHeap(), 0, ptr);
502 }
503 break;
504 case MCI_SAVE:
505 {
506 MCI_SAVE_PARMSW *mci_saveW = (MCI_SAVE_PARMSW *)dwParam2;
507
508 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW->lpfilename);
509 HeapFree(GetProcessHeap(), 0, mci_saveW);
510 }
511 break;
512 case MCI_LOAD:
513 {
514 MCI_LOAD_PARMSW *mci_loadW = (MCI_LOAD_PARMSW *)dwParam2;
515
516 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
517 HeapFree(GetProcessHeap(), 0, mci_loadW);
518 }
519 break;
520 case MCI_ESCAPE:
521 {
522 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
523
524 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
525 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
526 }
527 break;
528
529 default:
530 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
531 break;
532 }
533
534 return result;
535 }
536
537 /**************************************************************************
538 * MCI_GetDevTypeFromFileName [internal]
539 */
540 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
541 {
542 LPCWSTR tmp;
543 HKEY hKey;
544 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
545 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
546 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
547 if ((tmp = strrchrW(fileName, '.'))) {
548 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
549 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
550 DWORD dwLen = len;
551 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
552 RegCloseKey( hKey );
553 if (lRet == ERROR_SUCCESS) return 0;
554 }
555 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
556 }
557 return MCIERR_EXTENSION_NOT_FOUND;
558 }
559
560 #define MAX_MCICMDTABLE 20
561 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
562
563 typedef struct tagWINE_MCICMDTABLE {
564 UINT uDevType;
565 HGLOBAL hMem;
566 const BYTE* lpTable;
567 UINT nVerbs; /* number of verbs in command table */
568 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
569 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
570
571 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
572
573 /**************************************************************************
574 * MCI_IsCommandTableValid [internal]
575 */
576 static BOOL MCI_IsCommandTableValid(UINT uTbl)
577 {
578 const BYTE* lmem;
579 LPCWSTR str;
580 DWORD flg;
581 WORD eid;
582 int idx = 0;
583 BOOL inCst = FALSE;
584
585 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
586 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
587
588 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
589 return FALSE;
590
591 lmem = S_MciCmdTable[uTbl].lpTable;
592 do {
593 str = (LPCWSTR)lmem;
594 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
595 flg = *(const DWORD*)lmem;
596 eid = *(const WORD*)(lmem + sizeof(DWORD));
597 lmem += sizeof(DWORD) + sizeof(WORD);
598 idx ++;
599 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
600 switch (eid) {
601 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
602 case MCI_STRING: if (inCst) return FALSE; break;
603 case MCI_INTEGER: if (!*str) return FALSE; break;
604 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
605 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
606 case MCI_FLAG: if (!*str) return FALSE; break;
607 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
608 case MCI_RECT: if (!*str || inCst) return FALSE; break;
609 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
610 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
611 default: return FALSE;
612 }
613 } while (eid != MCI_END_COMMAND_LIST);
614 return TRUE;
615 }
616
617 /**************************************************************************
618 * MCI_DumpCommandTable [internal]
619 */
620 static BOOL MCI_DumpCommandTable(UINT uTbl)
621 {
622 const BYTE* lmem;
623 LPCWSTR str;
624 DWORD flg;
625 WORD eid;
626
627 if (!MCI_IsCommandTableValid(uTbl)) {
628 ERR("Ooops: %d is not valid\n", uTbl);
629 return FALSE;
630 }
631
632 lmem = S_MciCmdTable[uTbl].lpTable;
633 do {
634 do {
635 str = (LPCWSTR)lmem;
636 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
637 flg = *(const DWORD*)lmem;
638 eid = *(const WORD*)(lmem + sizeof(DWORD));
639 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
640 lmem += sizeof(DWORD) + sizeof(WORD);
641 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
642 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
643 } while (eid != MCI_END_COMMAND_LIST);
644 return TRUE;
645 }
646
647
648 /**************************************************************************
649 * MCI_GetCommandTable [internal]
650 */
651 static UINT MCI_GetCommandTable(UINT uDevType)
652 {
653 UINT uTbl;
654 WCHAR buf[32];
655 LPCWSTR str = NULL;
656
657 /* first look up existing for existing devType */
658 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
659 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
660 return uTbl;
661 }
662
663 /* well try to load id */
664 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
665 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
666 str = buf;
667 }
668 } else if (uDevType == 0) {
669 static const WCHAR wszCore[] = {'C','O','R','E',0};
670 str = wszCore;
671 }
672 uTbl = MCI_NO_COMMAND_TABLE;
673 if (str) {
674 HRSRC hRsrc = FindResourceW(hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
675 HANDLE hMem = 0;
676
677 if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
678 if (hMem) {
679 uTbl = MCI_SetCommandTable(hMem, uDevType);
680 } else {
681 WARN("No command table found in resource %p[%s]\n",
682 hWinMM32Instance, debugstr_w(str));
683 }
684 }
685 TRACE("=> %d\n", uTbl);
686 return uTbl;
687 }
688
689 /**************************************************************************
690 * MCI_SetCommandTable [internal]
691 */
692 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType)
693 {
694 int uTbl;
695 static BOOL bInitDone = FALSE;
696
697 /* <HACK>
698 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
699 * can be called with 0 as a uDevType to retrieve it.
700 * </HACK>
701 */
702 if (!bInitDone) {
703 bInitDone = TRUE;
704 MCI_GetCommandTable(0);
705 }
706 TRACE("(%p, %u)\n", hMem, uDevType);
707 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
708 if (!S_MciCmdTable[uTbl].lpTable) {
709 const BYTE* lmem;
710 LPCWSTR str;
711 WORD eid;
712 WORD count;
713
714 S_MciCmdTable[uTbl].uDevType = uDevType;
715 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
716 S_MciCmdTable[uTbl].hMem = hMem;
717
718 if (TRACE_ON(mci)) {
719 MCI_DumpCommandTable(uTbl);
720 }
721
722 /* create the verbs table */
723 /* get # of entries */
724 lmem = S_MciCmdTable[uTbl].lpTable;
725 count = 0;
726 do {
727 str = (LPCWSTR)lmem;
728 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
729 eid = *(const WORD*)(lmem + sizeof(DWORD));
730 lmem += sizeof(DWORD) + sizeof(WORD);
731 if (eid == MCI_COMMAND_HEAD)
732 count++;
733 } while (eid != MCI_END_COMMAND_LIST);
734
735 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
736 S_MciCmdTable[uTbl].nVerbs = count;
737
738 lmem = S_MciCmdTable[uTbl].lpTable;
739 count = 0;
740 do {
741 str = (LPCWSTR)lmem;
742 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
743 eid = *(const WORD*)(lmem + sizeof(DWORD));
744 lmem += sizeof(DWORD) + sizeof(WORD);
745 if (eid == MCI_COMMAND_HEAD)
746 S_MciCmdTable[uTbl].aVerbs[count++] = str;
747 } while (eid != MCI_END_COMMAND_LIST);
748 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
749 return uTbl;
750 }
751 }
752
753 return MCI_NO_COMMAND_TABLE;
754 }
755
756 /**************************************************************************
757 * MCI_UnLoadMciDriver [internal]
758 */
759 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
760 {
761 LPWINE_MCIDRIVER* tmp;
762
763 if (!wmd)
764 return TRUE;
765
766 CloseDriver(wmd->hDriver, 0, 0);
767
768 if (wmd->dwPrivate != 0)
769 WARN("Unloading mci driver with non nul dwPrivate field\n");
770
771 EnterCriticalSection(&WINMM_cs);
772 for (tmp = &MciDrivers; *tmp; tmp = &(*tmp)->lpNext) {
773 if (*tmp == wmd) {
774 *tmp = wmd->lpNext;
775 break;
776 }
777 }
778 LeaveCriticalSection(&WINMM_cs);
779
780 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
781 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
782 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
783
784 HeapFree(GetProcessHeap(), 0, wmd);
785 return TRUE;
786 }
787
788 /**************************************************************************
789 * MCI_OpenMciDriver [internal]
790 */
791 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
792 {
793 WCHAR libName[128];
794
795 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
796 return FALSE;
797
798 /* First load driver */
799 wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp);
800 return wmd->hDriver != NULL;
801 }
802
803 /**************************************************************************
804 * MCI_LoadMciDriver [internal]
805 */
806 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
807 {
808 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
809 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
810 MCI_OPEN_DRIVER_PARMSW modp;
811 DWORD dwRet = 0;
812
813 if (!wmd || !strDevTyp) {
814 dwRet = MCIERR_OUT_OF_MEMORY;
815 goto errCleanUp;
816 }
817
818 wmd->lpfnYieldProc = MCI_DefYieldProc;
819 wmd->dwYieldData = VK_CANCEL;
820 wmd->CreatorThread = GetCurrentThreadId();
821
822 EnterCriticalSection(&WINMM_cs);
823 /* wmd must be inserted in list before sending opening the driver, because it
824 * may want to lookup at wDevID
825 */
826 wmd->lpNext = MciDrivers;
827 MciDrivers = wmd;
828
829 for (modp.wDeviceID = MCI_MAGIC;
830 MCI_GetDriver(modp.wDeviceID) != 0;
831 modp.wDeviceID++);
832
833 wmd->wDeviceID = modp.wDeviceID;
834
835 LeaveCriticalSection(&WINMM_cs);
836
837 TRACE("wDevID=%04X\n", modp.wDeviceID);
838
839 modp.lpstrParams = NULL;
840
841 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
842 /* silence warning if all is used... some bogus program use commands like
843 * 'open all'...
844 */
845 if (strcmpiW(strDevTyp, wszAll) == 0) {
846 dwRet = MCIERR_CANNOT_USE_ALL;
847 } else {
848 FIXME("Couldn't load driver for type %s.\n",
849 debugstr_w(strDevTyp));
850 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
851 }
852 goto errCleanUp;
853 }
854
855 /* FIXME: should also check that module's description is of the form
856 * MODULENAME:[MCI] comment
857 */
858
859 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
860 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
861 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
862
863 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
864 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
865
866 wmd->lpstrDeviceType = strDevTyp;
867 wmd->wType = modp.wType;
868
869 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
870 modp.wDeviceID, modp.wType, modp.wDeviceID);
871 *lpwmd = wmd;
872 return 0;
873 errCleanUp:
874 MCI_UnLoadMciDriver(wmd);
875 HeapFree(GetProcessHeap(), 0, strDevTyp);
876 *lpwmd = 0;
877 return dwRet;
878 }
879
880 /**************************************************************************
881 * MCI_SendCommandFrom32 [internal]
882 */
883 static DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
884 {
885 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
886 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
887
888 if (wmd) {
889 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
890 }
891 return dwRet;
892 }
893
894 /**************************************************************************
895 * MCI_FinishOpen [internal]
896 */
897 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
898 DWORD dwParam)
899 {
900 if (dwParam & MCI_OPEN_ELEMENT)
901 {
902 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms->lpstrElementName)+1) * sizeof(WCHAR));
903 strcpyW( wmd->lpstrElementName, lpParms->lpstrElementName );
904 }
905 if (dwParam & MCI_OPEN_ALIAS)
906 {
907 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms->lpstrAlias)+1) * sizeof(WCHAR));
908 strcpyW( wmd->lpstrAlias, lpParms->lpstrAlias);
909 }
910 lpParms->wDeviceID = wmd->wDeviceID;
911
912 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
913 (DWORD_PTR)lpParms);
914 }
915
916 /**************************************************************************
917 * MCI_FindCommand [internal]
918 */
919 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
920 {
921 UINT idx;
922
923 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
924 return NULL;
925
926 /* another improvement would be to have the aVerbs array sorted,
927 * so that we could use a dichotomic search on it, rather than this dumb
928 * array look up
929 */
930 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
931 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
932 return S_MciCmdTable[uTbl].aVerbs[idx];
933 }
934
935 return NULL;
936 }
937
938 /**************************************************************************
939 * MCI_GetReturnType [internal]
940 */
941 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
942 {
943 lpCmd = (LPCWSTR)((const BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
944 if (*lpCmd == '\0' && *(const WORD*)((const BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
945 return *(const DWORD*)(lpCmd + 1);
946 }
947 return 0L;
948 }
949
950 /**************************************************************************
951 * MCI_GetMessage [internal]
952 */
953 static WORD MCI_GetMessage(LPCWSTR lpCmd)
954 {
955 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
956 }
957
958 /**************************************************************************
959 * MCI_GetDWord [internal]
960 */
961 static BOOL MCI_GetDWord(DWORD_PTR *data, LPWSTR* ptr)
962 {
963 DWORD val;
964 LPWSTR ret;
965
966 val = strtoulW(*ptr, &ret, 0);
967
968 switch (*ret) {
969 case '\0': break;
970 case ' ': ret++; break;
971 default: return FALSE;
972 }
973
974 *data |= val;
975 *ptr = ret;
976 return TRUE;
977 }
978
979 /**************************************************************************
980 * MCI_GetString [internal]
981 */
982 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
983 {
984 LPWSTR ptr = *args;
985
986 /* see if we have a quoted string */
987 if (*ptr == '"') {
988 ptr = strchrW(*str = ptr + 1, '"');
989 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
990 /* FIXME: shall we escape \" from string ?? */
991 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
992 *ptr++ = '\0'; /* remove trailing " */
993 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
994 } else {
995 ptr = strchrW(ptr, ' ');
996
997 if (ptr) {
998 *ptr++ = '\0';
999 } else {
1000 ptr = *args + strlenW(*args);
1001 }
1002 *str = *args;
1003 }
1004
1005 *args = ptr;
1006 return 0;
1007 }
1008
1009 #define MCI_DATA_SIZE 16
1010
1011 /**************************************************************************
1012 * MCI_ParseOptArgs [internal]
1013 */
1014 static DWORD MCI_ParseOptArgs(DWORD_PTR *data, int _offset, LPCWSTR lpCmd,
1015 LPWSTR args, LPDWORD dwFlags)
1016 {
1017 int len, offset;
1018 const char* lmem;
1019 LPCWSTR str;
1020 DWORD dwRet, flg, cflg = 0;
1021 WORD eid;
1022 BOOL inCst, found;
1023
1024 /* loop on arguments */
1025 while (*args) {
1026 lmem = (const char*)lpCmd;
1027 found = inCst = FALSE;
1028 offset = _offset;
1029
1030 /* skip any leading white space(s) */
1031 while (*args == ' ') args++;
1032 TRACE("args=%s offset=%d\n", debugstr_w(args), offset);
1033
1034 do { /* loop on options for command table for the requested verb */
1035 str = (LPCWSTR)lmem;
1036 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1037 flg = *(const DWORD*)lmem;
1038 eid = *(const WORD*)(lmem + sizeof(DWORD));
1039 lmem += sizeof(DWORD) + sizeof(WORD);
1040 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1041
1042 switch (eid) {
1043 case MCI_CONSTANT:
1044 inCst = TRUE; cflg = flg; break;
1045 case MCI_END_CONSTANT:
1046 /* there may be additional integral values after flag in constant */
1047 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1048 *dwFlags |= cflg;
1049 }
1050 inCst = FALSE; cflg = 0;
1051 break;
1052 }
1053
1054 if (strncmpiW(args, str, len) == 0 &&
1055 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1056 /* store good values into data[] */
1057 args += len;
1058 while (*args == ' ') args++;
1059 found = TRUE;
1060
1061 switch (eid) {
1062 case MCI_COMMAND_HEAD:
1063 case MCI_RETURN:
1064 case MCI_END_COMMAND:
1065 case MCI_END_COMMAND_LIST:
1066 case MCI_CONSTANT: /* done above */
1067 case MCI_END_CONSTANT: /* done above */
1068 break;
1069 case MCI_FLAG:
1070 *dwFlags |= flg;
1071 break;
1072 case MCI_INTEGER:
1073 if (inCst) {
1074 data[offset] |= flg;
1075 *dwFlags |= cflg;
1076 inCst = FALSE;
1077 } else {
1078 *dwFlags |= flg;
1079 if (!MCI_GetDWord(&(data[offset]), &args)) {
1080 return MCIERR_BAD_INTEGER;
1081 }
1082 }
1083 break;
1084 case MCI_RECT:
1085 /* store rect in data (offset..offset+3) */
1086 *dwFlags |= flg;
1087 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1088 !MCI_GetDWord(&(data[offset+1]), &args) ||
1089 !MCI_GetDWord(&(data[offset+2]), &args) ||
1090 !MCI_GetDWord(&(data[offset+3]), &args)) {
1091 ERR("Bad rect %s\n", debugstr_w(args));
1092 return MCIERR_BAD_INTEGER;
1093 }
1094 break;
1095 case MCI_STRING:
1096 *dwFlags |= flg;
1097 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1098 return dwRet;
1099 break;
1100 default: ERR("oops\n");
1101 }
1102 /* exit inside while loop, except if just entered in constant area definition */
1103 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1104 } else {
1105 /* have offset incremented if needed */
1106 switch (eid) {
1107 case MCI_COMMAND_HEAD:
1108 case MCI_RETURN:
1109 case MCI_END_COMMAND:
1110 case MCI_END_COMMAND_LIST:
1111 case MCI_CONSTANT:
1112 case MCI_FLAG: break;
1113 case MCI_INTEGER: if (!inCst) offset++; break;
1114 case MCI_END_CONSTANT:
1115 case MCI_STRING: offset++; break;
1116 case MCI_RECT: offset += 4; break;
1117 default: ERR("oops\n");
1118 }
1119 }
1120 } while (eid != MCI_END_COMMAND);
1121 if (!found) {
1122 WARN("Optarg %s not found\n", debugstr_w(args));
1123 return MCIERR_UNRECOGNIZED_COMMAND;
1124 }
1125 if (offset == MCI_DATA_SIZE) {
1126 ERR("Internal data[] buffer overflow\n");
1127 return MCIERR_PARSER_INTERNAL;
1128 }
1129 }
1130 return 0;
1131 }
1132
1133 /**************************************************************************
1134 * MCI_HandleReturnValues [internal]
1135 */
1136 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1137 DWORD_PTR *data, LPWSTR lpstrRet, UINT uRetLen)
1138 {
1139 static const WCHAR wszLd [] = {'%','l','d',0};
1140 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1141 static const WCHAR wszCol3[] = {'%','d',':','%','d',':','%','d',0};
1142 static const WCHAR wszCol4[] = {'%','d',':','%','d',':','%','d',':','%','d',0};
1143
1144 if (lpstrRet) {
1145 switch (retType) {
1146 case 0: /* nothing to return */
1147 break;
1148 case MCI_INTEGER:
1149 switch (dwRet & 0xFFFF0000ul) {
1150 case 0:
1151 case MCI_INTEGER_RETURNED:
1152 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1153 break;
1154 case MCI_RESOURCE_RETURNED:
1155 /* return string which ID is HIWORD(data[1]),
1156 * string is loaded from mmsystem.dll */
1157 LoadStringW(hWinMM32Instance, HIWORD(data[1]), lpstrRet, uRetLen);
1158 break;
1159 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1160 /* return string which ID is HIWORD(data[1]),
1161 * string is loaded from driver */
1162 /* FIXME: this is wrong for a 16 bit handle */
1163 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1164 HIWORD(data[1]), lpstrRet, uRetLen);
1165 break;
1166 case MCI_COLONIZED3_RETURN:
1167 snprintfW(lpstrRet, uRetLen, wszCol3,
1168 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1169 LOBYTE(HIWORD(data[1])));
1170 break;
1171 case MCI_COLONIZED4_RETURN:
1172 snprintfW(lpstrRet, uRetLen, wszCol4,
1173 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1174 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1175 break;
1176 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1177 }
1178 break;
1179 case MCI_STRING:
1180 switch (dwRet & 0xFFFF0000ul) {
1181 case 0:
1182 /* nothing to do data[1] == lpstrRet */
1183 break;
1184 case MCI_INTEGER_RETURNED:
1185 data[1] = *(LPDWORD)lpstrRet;
1186 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1187 break;
1188 default:
1189 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1190 break;
1191 }
1192 break;
1193 case MCI_RECT:
1194 if (dwRet & 0xFFFF0000ul)
1195 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1196 snprintfW(lpstrRet, uRetLen, wszLd4,
1197 data[1], data[2], data[3], data[4]);
1198 break;
1199 default: ERR("oops\n");
1200 }
1201 }
1202 return LOWORD(dwRet);
1203 }
1204
1205 /**************************************************************************
1206 * mciSendStringW [WINMM.@]
1207 */
1208 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1209 UINT uRetLen, HWND hwndCallback)
1210 {
1211 LPWSTR verb, dev, args;
1212 LPWINE_MCIDRIVER wmd = 0;
1213 DWORD dwFlags = 0, dwRet = 0;
1214 int offset = 0;
1215 DWORD_PTR data[MCI_DATA_SIZE];
1216 DWORD retType;
1217 LPCWSTR lpCmd = 0;
1218 LPWSTR devAlias = NULL;
1219 static const WCHAR wszNew[] = {'n','e','w',0};
1220 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1221 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1222
1223 TRACE("(%s, %p, %d, %p)\n",
1224 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1225
1226 /* format is <command> <device> <optargs> */
1227 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1228 return MCIERR_OUT_OF_MEMORY;
1229 strcpyW( verb, lpstrCommand );
1230 CharLowerW(verb);
1231
1232 memset(data, 0, sizeof(data));
1233
1234 if (!(args = strchrW(verb, ' '))) {
1235 dwRet = MCIERR_MISSING_DEVICE_NAME;
1236 goto errCleanUp;
1237 }
1238 *args++ = '\0';
1239 if ((dwRet = MCI_GetString(&dev, &args))) {
1240 goto errCleanUp;
1241 }
1242
1243 /* Determine devType from open */
1244 if (!strcmpW(verb, wszOpen)) {
1245 LPWSTR devType, tmp;
1246 WCHAR buf[128];
1247
1248 /* case dev == 'new' has to be handled */
1249 if (!strcmpW(dev, wszNew)) {
1250 dev = 0;
1251 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1252 devType += 5;
1253 tmp = strchrW(devType, ' ');
1254 if (tmp) *tmp = '\0';
1255 devType = str_dup_upper(devType);
1256 if (tmp) *tmp = ' ';
1257 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1258 } else {
1259 WARN("open new requires device type\n");
1260 dwRet = MCIERR_MISSING_DEVICE_NAME;
1261 goto errCleanUp;
1262 }
1263 } else if ((devType = strchrW(dev, '!')) != NULL) {
1264 *devType++ = '\0';
1265 tmp = devType; devType = dev; dev = tmp;
1266
1267 dwFlags |= MCI_OPEN_TYPE;
1268 data[2] = (DWORD_PTR)devType;
1269 devType = str_dup_upper(devType);
1270 dwFlags |= MCI_OPEN_ELEMENT;
1271 data[3] = (DWORD_PTR)dev;
1272 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1273 /* this is the name of a mci driver's type */
1274 tmp = strchrW(dev, ' ');
1275 if (tmp) *tmp = '\0';
1276 data[2] = (DWORD_PTR)dev;
1277 devType = str_dup_upper(dev);
1278 if (tmp) *tmp = ' ';
1279 dwFlags |= MCI_OPEN_TYPE;
1280 } else {
1281 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1282 devType += 5;
1283 tmp = strchrW(devType, ' ');
1284 if (tmp) *tmp = '\0';
1285 devType = str_dup_upper(devType);
1286 if (tmp) *tmp = ' ';
1287 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1288 } else {
1289 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1290 goto errCleanUp;
1291
1292 devType = str_dup_upper(buf);
1293 }
1294 dwFlags |= MCI_OPEN_ELEMENT;
1295 data[3] = (DWORD_PTR)dev;
1296 }
1297 if ((devAlias = strstrW(args, wszSAliasS))) {
1298 WCHAR* tmp2;
1299 devAlias += 7;
1300 if (!(tmp = strchrW(devAlias,' '))) tmp = devAlias + strlenW(devAlias);
1301 if (tmp) *tmp = '\0';
1302 tmp2 = HeapAlloc(GetProcessHeap(), 0, (tmp - devAlias + 1) * sizeof(WCHAR) );
1303 memcpy( tmp2, devAlias, (tmp - devAlias) * sizeof(WCHAR) );
1304 tmp2[tmp - devAlias] = 0;
1305 data[4] = (DWORD_PTR)tmp2;
1306 /* should be done in regular options parsing */
1307 /* dwFlags |= MCI_OPEN_ALIAS; */
1308 } else if (dev == 0) {
1309 /* "open new" requires alias */
1310 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1311 goto errCleanUp;
1312 }
1313
1314 dwRet = MCI_LoadMciDriver(devType, &wmd);
1315 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1316 dwRet = MCIERR_INVALID_DEVICE_NAME;
1317 HeapFree(GetProcessHeap(), 0, devType);
1318 if (dwRet) {
1319 MCI_UnLoadMciDriver(wmd);
1320 goto errCleanUp;
1321 }
1322 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1323 /* auto open */
1324 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1325 WCHAR buf[128];
1326 sprintfW(buf, wszOpenWait, dev);
1327
1328 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1329 goto errCleanUp;
1330
1331 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1332 if (!wmd) {
1333 /* FIXME: memory leak, MCI driver is not closed */
1334 dwRet = MCIERR_INVALID_DEVICE_ID;
1335 goto errCleanUp;
1336 }
1337 }
1338
1339 /* get the verb in the different command tables */
1340 if (wmd) {
1341 /* try the device specific command table */
1342 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1343 if (!lpCmd) {
1344 /* try the type specific command table */
1345 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1346 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1347 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1348 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1349 }
1350 }
1351 /* try core command table */
1352 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1353
1354 if (!lpCmd) {
1355 TRACE("Command %s not found!\n", debugstr_w(verb));
1356 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1357 goto errCleanUp;
1358 }
1359
1360 /* set return information */
1361 switch (retType = MCI_GetReturnType(lpCmd)) {
1362 case 0: offset = 1; break;
1363 case MCI_INTEGER: offset = 2; break;
1364 case MCI_STRING: data[1] = (DWORD_PTR)lpstrRet; data[2] = uRetLen; offset = 3; break;
1365 case MCI_RECT: offset = 5; break;
1366 default: ERR("oops\n");
1367 }
1368
1369 TRACE("verb=%s on dev=%s; offset=%d\n",
1370 debugstr_w(verb), debugstr_w(dev), offset);
1371
1372 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1373 goto errCleanUp;
1374
1375 /* set up call back */
1376 if (dwFlags & MCI_NOTIFY) {
1377 data[0] = (DWORD_PTR)hwndCallback;
1378 }
1379
1380 /* FIXME: the command should get it's own notification window set up and
1381 * ask for device closing while processing the notification mechanism
1382 */
1383 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1384
1385 TRACE("[%d, %s, %08x, %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s]\n",
1386 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1387 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1388 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1389 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1390
1391 if (strcmpW(verb, wszOpen) == 0) {
1392 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1393 MCI_UnLoadMciDriver(wmd);
1394 /* FIXME: notification is not properly shared across two opens */
1395 } else {
1396 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD_PTR)data);
1397 }
1398 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1399 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1400 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1401
1402 errCleanUp:
1403 HeapFree(GetProcessHeap(), 0, verb);
1404 return dwRet;
1405 }
1406
1407 /**************************************************************************
1408 * mciSendStringA [WINMM.@]
1409 */
1410 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1411 UINT uRetLen, HWND hwndCallback)
1412 {
1413 LPWSTR lpwstrCommand;
1414 LPWSTR lpwstrRet = NULL;
1415 UINT ret;
1416 INT len;
1417
1418 /* FIXME: is there something to do with lpstrReturnString ? */
1419 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1420 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1421 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1422 if (lpstrRet)
1423 {
1424 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1425 if (!lpwstrRet) {
1426 WARN("no memory\n");
1427 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1428 return MCIERR_OUT_OF_MEMORY;
1429 }
1430 }
1431 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1432 if (!ret && lpwstrRet)
1433 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1434 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1435 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1436 return ret;
1437 }
1438
1439 /**************************************************************************
1440 * mciExecute [WINMM.@]
1441 */
1442 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1443 {
1444 char strRet[256];
1445 DWORD ret;
1446
1447 TRACE("(%s)!\n", lpstrCommand);
1448
1449 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1450 if (ret != 0) {
1451 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1452 sprintf(strRet, "Unknown MCI error (%lu)", ret);
1453 }
1454 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1455 }
1456 /* FIXME: what shall I return ? */
1457 return TRUE;
1458 }
1459
1460 /**************************************************************************
1461 * mciLoadCommandResource [WINMM.@]
1462 *
1463 * Strangely, this function only exists as a UNICODE one.
1464 */
1465 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1466 {
1467 UINT ret = MCI_NO_COMMAND_TABLE;
1468 HRSRC hRsrc = 0;
1469 HGLOBAL hMem;
1470
1471 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1472
1473 /* if a file named "resname.mci" exits, then load resource "resname" from it
1474 * otherwise directly from driver
1475 * We don't support it (who uses this feature ?), but we check anyway
1476 */
1477 if (!type) {
1478 #if 0
1479 /* FIXME: we should put this back into order, but I never found a program
1480 * actually using this feature, so we may not need it
1481 */
1482 char buf[128];
1483 OFSTRUCT ofs;
1484
1485 strcat(strcpy(buf, resname), ".mci");
1486 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1487 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1488 }
1489 #endif
1490 }
1491 if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
1492 (hMem = LoadResource(hInst, hRsrc))) {
1493 ret = MCI_SetCommandTable(hMem, type);
1494 FreeResource(hMem);
1495 }
1496 else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
1497
1498 TRACE("=> %04x\n", ret);
1499 return ret;
1500 }
1501
1502 /**************************************************************************
1503 * mciFreeCommandResource [WINMM.@]
1504 */
1505 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1506 {
1507 TRACE("(%08x)!\n", uTable);
1508
1509 if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
1510 return FALSE;
1511
1512 FreeResource(S_MciCmdTable[uTable].hMem);
1513 S_MciCmdTable[uTable].hMem = NULL;
1514 S_MciCmdTable[uTable].lpTable = NULL;
1515 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
1516 S_MciCmdTable[uTable].aVerbs = 0;
1517 S_MciCmdTable[uTable].nVerbs = 0;
1518 return TRUE;
1519 }
1520
1521 /**************************************************************************
1522 * MCI_Open [internal]
1523 */
1524 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1525 {
1526 WCHAR strDevTyp[128];
1527 DWORD dwRet;
1528 LPWINE_MCIDRIVER wmd = NULL;
1529
1530 TRACE("(%08X, %p)\n", dwParam, lpParms);
1531 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1532
1533 /* only two low bytes are generic, the other ones are dev type specific */
1534 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1535 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1536 MCI_NOTIFY|MCI_WAIT)
1537 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1538 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1539 }
1540 #undef WINE_MCIDRIVER_SUPP
1541
1542 strDevTyp[0] = 0;
1543
1544 if (dwParam & MCI_OPEN_TYPE) {
1545 if (dwParam & MCI_OPEN_TYPE_ID) {
1546 WORD uDevType = LOWORD(lpParms->lpstrDeviceType);
1547
1548 if (uDevType < MCI_DEVTYPE_FIRST ||
1549 uDevType > MCI_DEVTYPE_LAST ||
1550 !LoadStringW(hWinMM32Instance, uDevType,
1551 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1552 dwRet = MCIERR_BAD_INTEGER;
1553 goto errCleanUp;
1554 }
1555 } else {
1556 LPWSTR ptr;
1557 if (lpParms->lpstrDeviceType == NULL) {
1558 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1559 goto errCleanUp;
1560 }
1561 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1562 ptr = strchrW(strDevTyp, '!');
1563 if (ptr) {
1564 /* this behavior is not documented in windows. However, since, in
1565 * some occasions, MCI_OPEN handling is translated by WinMM into
1566 * a call to mciSendString("open <type>"); this code shall be correct
1567 */
1568 if (dwParam & MCI_OPEN_ELEMENT) {
1569 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1570 debugstr_w(lpParms->lpstrElementName),
1571 debugstr_w(strDevTyp));
1572 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1573 goto errCleanUp;
1574 }
1575 dwParam |= MCI_OPEN_ELEMENT;
1576 *ptr++ = 0;
1577 /* FIXME: not a good idea to write in user supplied buffer */
1578 lpParms->lpstrElementName = ptr;
1579 }
1580
1581 }
1582 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1583 }
1584
1585 if (dwParam & MCI_OPEN_ELEMENT) {
1586 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1587
1588 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1589 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1590 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1591 goto errCleanUp;
1592 }
1593
1594 if (!lpParms->lpstrElementName) {
1595 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1596 goto errCleanUp;
1597 }
1598
1599 /* type, if given as a parameter, supersedes file extension */
1600 if (!strDevTyp[0] &&
1601 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1602 strDevTyp, sizeof(strDevTyp))) {
1603 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1604 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1605 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1606 goto errCleanUp;
1607 }
1608 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1609 strcpyW(strDevTyp, wszCdAudio);
1610 }
1611 }
1612
1613 if (strDevTyp[0] == 0) {
1614 FIXME("Couldn't load driver\n");
1615 dwRet = MCIERR_INVALID_DEVICE_NAME;
1616 goto errCleanUp;
1617 }
1618
1619 if (dwParam & MCI_OPEN_ALIAS) {
1620 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1621 if (!lpParms->lpstrAlias) {
1622 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1623 goto errCleanUp;
1624 }
1625 }
1626
1627 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1628 goto errCleanUp;
1629 }
1630
1631 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1632 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1633 /* FIXME: is dwRet the correct ret code ? */
1634 goto errCleanUp;
1635 }
1636
1637 /* only handled devices fall through */
1638 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1639
1640 if (dwParam & MCI_NOTIFY)
1641 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1642
1643 return 0;
1644 errCleanUp:
1645 if (wmd) MCI_UnLoadMciDriver(wmd);
1646
1647 if (dwParam & MCI_NOTIFY)
1648 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1649 return dwRet;
1650 }
1651
1652 /**************************************************************************
1653 * MCI_Close [internal]
1654 */
1655 static DWORD MCI_Close(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1656 {
1657 DWORD dwRet;
1658 LPWINE_MCIDRIVER wmd;
1659
1660 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1661
1662 if (wDevID == MCI_ALL_DEVICE_ID) {
1663 /* FIXME: shall I notify once after all is done, or for
1664 * each of the open drivers ? if the latest, which notif
1665 * to return when only one fails ?
1666 */
1667 while (MciDrivers) {
1668 /* Retrieve the device ID under lock, but send the message without,
1669 * the driver might be calling some winmm functions from another
1670 * thread before being fully stopped.
1671 */
1672 EnterCriticalSection(&WINMM_cs);
1673 if (!MciDrivers)
1674 {
1675 LeaveCriticalSection(&WINMM_cs);
1676 break;
1677 }
1678 wDevID = MciDrivers->wDeviceID;
1679 LeaveCriticalSection(&WINMM_cs);
1680 MCI_Close(wDevID, dwParam, lpParms);
1681 }
1682 return 0;
1683 }
1684
1685 if (!(wmd = MCI_GetDriver(wDevID))) {
1686 return MCIERR_INVALID_DEVICE_ID;
1687 }
1688
1689 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD_PTR)lpParms);
1690
1691 MCI_UnLoadMciDriver(wmd);
1692
1693 if (dwParam & MCI_NOTIFY)
1694 mciDriverNotify(lpParms ? (HWND)lpParms->dwCallback : 0,
1695 wDevID,
1696 dwRet ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
1697
1698 return dwRet;
1699 }
1700
1701 /**************************************************************************
1702 * MCI_WriteString [internal]
1703 */
1704 static DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1705 {
1706 DWORD ret = 0;
1707
1708 if (lpSrcStr) {
1709 dstSize /= sizeof(WCHAR);
1710 if (dstSize <= strlenW(lpSrcStr)) {
1711 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1712 ret = MCIERR_PARAM_OVERFLOW;
1713 } else {
1714 strcpyW(lpDstStr, lpSrcStr);
1715 }
1716 } else {
1717 *lpDstStr = 0;
1718 }
1719 return ret;
1720 }
1721
1722 /**************************************************************************
1723 * MCI_Sysinfo [internal]
1724 */
1725 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1726 {
1727 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1728 WCHAR buf[2048], *s = buf, *p;
1729 LPWINE_MCIDRIVER wmd;
1730 HKEY hKey;
1731
1732 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1733 return MCIERR_NULL_PARAMETER_BLOCK;
1734
1735 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1736 uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1737
1738 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1739 case MCI_SYSINFO_QUANTITY:
1740 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1741 if (dwFlags & MCI_SYSINFO_OPEN) {
1742 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1743 EnterCriticalSection(&WINMM_cs);
1744 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1745 cnt++;
1746 }
1747 LeaveCriticalSection(&WINMM_cs);
1748 } else {
1749 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1750 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1751 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1752 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1753 RegCloseKey( hKey );
1754 }
1755 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1756 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1757 }
1758 } else {
1759 if (dwFlags & MCI_SYSINFO_OPEN) {
1760 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
1761 EnterCriticalSection(&WINMM_cs);
1762 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1763 if (wmd->wType == lpParms->wDeviceType) cnt++;
1764 }
1765 LeaveCriticalSection(&WINMM_cs);
1766 } else {
1767 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
1768 FIXME("Don't know how to get # of MCI devices of a given type\n");
1769 cnt = 1;
1770 }
1771 }
1772 *(DWORD*)lpParms->lpstrReturn = cnt;
1773 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1774 ret = MCI_INTEGER_RETURNED;
1775 break;
1776 case MCI_SYSINFO_INSTALLNAME:
1777 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1778 if ((wmd = MCI_GetDriver(uDevID))) {
1779 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1780 wmd->lpstrDeviceType);
1781 } else {
1782 *lpParms->lpstrReturn = 0;
1783 ret = MCIERR_INVALID_DEVICE_ID;
1784 }
1785 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1786 break;
1787 case MCI_SYSINFO_NAME:
1788 TRACE("MCI_SYSINFO_NAME\n");
1789 if (dwFlags & MCI_SYSINFO_OPEN) {
1790 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1791 ret = MCIERR_UNRECOGNIZED_COMMAND;
1792 } else {
1793 s = NULL;
1794 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1795 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1796 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1797 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1798 lpParms->dwNumber <= cnt) {
1799 DWORD bufLen = sizeof(buf)/sizeof(buf[0]);
1800 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1801 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1802 s = buf;
1803 }
1804 RegCloseKey( hKey );
1805 }
1806 if (!s) {
1807 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1808 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1809 TRACE("%d: %s\n", cnt, debugstr_w(p));
1810 if (cnt == lpParms->dwNumber - 1) {
1811 s = p;
1812 break;
1813 }
1814 }
1815 }
1816 }
1817 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1818 }
1819 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1820 break;
1821 default:
1822 TRACE("Unsupported flag value=%08x\n", dwFlags);
1823 ret = MCIERR_UNRECOGNIZED_COMMAND;
1824 }
1825 return ret;
1826 }
1827
1828 /**************************************************************************
1829 * MCI_Break [internal]
1830 */
1831 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1832 {
1833 DWORD dwRet = 0;
1834
1835 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1836
1837 if (dwFlags & MCI_NOTIFY)
1838 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1839 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1840
1841 return dwRet;
1842 }
1843
1844 /**************************************************************************
1845 * MCI_Sound [internal]
1846 */
1847 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1848 {
1849 DWORD dwRet = 0;
1850
1851 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1852
1853 if (dwFlags & MCI_SOUND_NAME)
1854 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1855 else
1856 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1857 if (dwFlags & MCI_NOTIFY)
1858 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1859 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1860
1861 return dwRet;
1862 }
1863
1864 /**************************************************************************
1865 * MCI_SendCommand [internal]
1866 */
1867 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1868 {
1869 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1870
1871 switch (wMsg) {
1872 case MCI_OPEN:
1873 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1874 break;
1875 case MCI_CLOSE:
1876 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1877 break;
1878 case MCI_SYSINFO:
1879 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1880 break;
1881 case MCI_BREAK:
1882 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1883 break;
1884 case MCI_SOUND:
1885 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
1886 break;
1887 default:
1888 if (wDevID == MCI_ALL_DEVICE_ID) {
1889 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1890 dwRet = MCIERR_CANNOT_USE_ALL;
1891 } else {
1892 dwRet = MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2);
1893 }
1894 break;
1895 }
1896 return dwRet;
1897 }
1898
1899 /**************************************************************************
1900 * MCI_CleanUp [internal]
1901 *
1902 * Some MCI commands need to be cleaned-up (when not called from
1903 * mciSendString), because MCI drivers return extra information for string
1904 * transformation. This function gets rid of them.
1905 */
1906 static LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD_PTR dwParam2)
1907 {
1908 if (LOWORD(dwRet))
1909 return LOWORD(dwRet);
1910
1911 switch (wMsg) {
1912 case MCI_GETDEVCAPS:
1913 switch (dwRet & 0xFFFF0000ul) {
1914 case 0:
1915 case MCI_COLONIZED3_RETURN:
1916 case MCI_COLONIZED4_RETURN:
1917 case MCI_INTEGER_RETURNED:
1918 /* nothing to do */
1919 break;
1920 case MCI_RESOURCE_RETURNED:
1921 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1922 {
1923 LPMCI_GETDEVCAPS_PARMS lmgp;
1924
1925 lmgp = (LPMCI_GETDEVCAPS_PARMS)dwParam2;
1926 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
1927 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1928 }
1929 break;
1930 default:
1931 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1932 HIWORD(dwRet), MCI_MessageToString(wMsg));
1933 }
1934 break;
1935 case MCI_STATUS:
1936 switch (dwRet & 0xFFFF0000ul) {
1937 case 0:
1938 case MCI_COLONIZED3_RETURN:
1939 case MCI_COLONIZED4_RETURN:
1940 case MCI_INTEGER_RETURNED:
1941 /* nothing to do */
1942 break;
1943 case MCI_RESOURCE_RETURNED:
1944 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1945 {
1946 LPMCI_STATUS_PARMS lsp;
1947
1948 lsp = (LPMCI_STATUS_PARMS)dwParam2;
1949 TRACE("Changing %08lx to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
1950 lsp->dwReturn = LOWORD(lsp->dwReturn);
1951 }
1952 break;
1953 default:
1954 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1955 HIWORD(dwRet), MCI_MessageToString(wMsg));
1956 }
1957 break;
1958 case MCI_SYSINFO:
1959 switch (dwRet & 0xFFFF0000ul) {
1960 case 0:
1961 case MCI_INTEGER_RETURNED:
1962 /* nothing to do */
1963 break;
1964 default:
1965 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
1966 }
1967 break;
1968 default:
1969 if (HIWORD(dwRet)) {
1970 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1971 dwRet, MCI_MessageToString(wMsg));
1972 }
1973 break;
1974 }
1975 return LOWORD(dwRet);
1976 }
1977
1978 /**************************************************************************
1979 * mciGetErrorStringW [WINMM.@]
1980 */
1981 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
1982 {
1983 BOOL ret = FALSE;
1984
1985 if (lpstrBuffer != NULL && uLength > 0 &&
1986 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
1987
1988 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
1989 ret = TRUE;
1990 }
1991 }
1992 return ret;
1993 }
1994
1995 /**************************************************************************
1996 * mciGetErrorStringA [WINMM.@]
1997 */
1998 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
1999 {
2000 BOOL ret = FALSE;
2001
2002 if (lpstrBuffer != NULL && uLength > 0 &&
2003 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2004
2005 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2006 ret = TRUE;
2007 }
2008 }
2009 return ret;
2010 }
2011
2012 /**************************************************************************
2013 * mciDriverNotify [WINMM.@]
2014 */
2015 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2016 {
2017 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2018
2019 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2020 }
2021
2022 /**************************************************************************
2023 * mciGetDriverData [WINMM.@]
2024 */
2025 DWORD_PTR WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2026 {
2027 LPWINE_MCIDRIVER wmd;
2028
2029 TRACE("(%04x)\n", uDeviceID);
2030
2031 wmd = MCI_GetDriver(uDeviceID);
2032
2033 if (!wmd) {
2034 WARN("Bad uDeviceID\n");
2035 return 0L;
2036 }
2037
2038 return wmd->dwPrivate;
2039 }
2040
2041 /**************************************************************************
2042 * mciSetDriverData [WINMM.@]
2043 */
2044 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD_PTR data)
2045 {
2046 LPWINE_MCIDRIVER wmd;
2047
2048 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2049
2050 wmd = MCI_GetDriver(uDeviceID);
2051
2052 if (!wmd) {
2053 WARN("Bad uDeviceID\n");
2054 return FALSE;
2055 }
2056
2057 wmd->dwPrivate = data;
2058 return TRUE;
2059 }
2060
2061 /**************************************************************************
2062 * mciSendCommandW [WINMM.@]
2063 *
2064 */
2065 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2066 {
2067 DWORD dwRet;
2068
2069 TRACE("(%08x, %s, %08lx, %08lx)\n",
2070 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2071
2072 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2);
2073 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2074 TRACE("=> %08x\n", dwRet);
2075 return dwRet;
2076 }
2077
2078 /**************************************************************************
2079 * mciSendCommandA [WINMM.@]
2080 */
2081 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2082 {
2083 DWORD ret;
2084 int mapped;
2085
2086 TRACE("(%08x, %s, %08lx, %08lx)\n",
2087 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2088
2089 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2090 if (mapped == -1)
2091 {
2092 FIXME("message %04x mapping failed\n", wMsg);
2093 return MMSYSERR_NOMEM;
2094 }
2095 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2096 if (mapped)
2097 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2098 return ret;
2099 }
2100
2101 /**************************************************************************
2102 * mciGetDeviceIDA [WINMM.@]
2103 */
2104 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2105 {
2106 LPWSTR w = MCI_strdupAtoW(lpstrName);
2107 UINT ret = MCIERR_OUT_OF_MEMORY;
2108
2109 if (w)
2110 {
2111 ret = mciGetDeviceIDW(w);
2112 HeapFree(GetProcessHeap(), 0, w);
2113 }
2114 return ret;
2115 }
2116
2117 /**************************************************************************
2118 * mciGetDeviceIDW [WINMM.@]
2119 */
2120 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2121 {
2122 return MCI_GetDriverFromString(lpwstrName);
2123 }
2124
2125 /******************************************************************
2126 * MyUserYield
2127 *
2128 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
2129 */
2130 static void MyUserYield(void)
2131 {
2132 HMODULE mod = GetModuleHandleA( "user32.dll" );
2133 if (mod)
2134 {
2135 FARPROC proc = GetProcAddress( mod, "UserYield16" );
2136 if (proc) proc();
2137 }
2138 }
2139
2140 /**************************************************************************
2141 * MCI_DefYieldProc [internal]
2142 */
2143 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2144 {
2145 INT16 ret;
2146
2147 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2148
2149 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2150 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2151 MyUserYield();
2152 ret = 0;
2153 } else {
2154 MSG msg;
2155
2156 msg.hwnd = HWND_32(HIWORD(data));
2157 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2158 ret = -1;
2159 }
2160 return ret;
2161 }
2162
2163 /**************************************************************************
2164 * mciSetYieldProc [WINMM.@]
2165 */
2166 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2167 {
2168 LPWINE_MCIDRIVER wmd;
2169
2170 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2171
2172 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2173 WARN("Bad uDeviceID\n");
2174 return FALSE;
2175 }
2176
2177 wmd->lpfnYieldProc = fpYieldProc;
2178 wmd->dwYieldData = dwYieldData;
2179
2180 return TRUE;
2181 }
2182
2183 /**************************************************************************
2184 * mciGetDeviceIDFromElementIDA [WINMM.@]
2185 */
2186 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2187 {
2188 LPWSTR w = MCI_strdupAtoW(lpstrType);
2189 UINT ret = 0;
2190
2191 if (w)
2192 {
2193 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2194 HeapFree(GetProcessHeap(), 0, w);
2195 }
2196 return ret;
2197 }
2198
2199 /**************************************************************************
2200 * mciGetDeviceIDFromElementIDW [WINMM.@]
2201 */
2202 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2203 {
2204 /* FIXME: that's rather strange, there is no
2205 * mciGetDeviceIDFromElementID32A in winmm.spec
2206 */
2207 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2208 return 0;
2209 }
2210
2211 /**************************************************************************
2212 * mciGetYieldProc [WINMM.@]
2213 */
2214 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2215 {
2216 LPWINE_MCIDRIVER wmd;
2217
2218 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2219
2220 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2221 WARN("Bad uDeviceID\n");
2222 return NULL;
2223 }
2224 if (!wmd->lpfnYieldProc) {
2225 WARN("No proc set\n");
2226 return NULL;
2227 }
2228 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
2229 return wmd->lpfnYieldProc;
2230 }
2231
2232 /**************************************************************************
2233 * mciGetCreatorTask [WINMM.@]
2234 */
2235 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2236 {
2237 LPWINE_MCIDRIVER wmd;
2238 HTASK ret = 0;
2239
2240 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
2241
2242 TRACE("(%u) => %p\n", uDeviceID, ret);
2243 return ret;
2244 }
2245
2246 /**************************************************************************
2247 * mciDriverYield [WINMM.@]
2248 */
2249 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2250 {
2251 LPWINE_MCIDRIVER wmd;
2252 UINT ret = 0;
2253
2254 TRACE("(%04x)\n", uDeviceID);
2255
2256 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc) {
2257 MyUserYield();
2258 } else {
2259 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
2260 }
2261
2262 return ret;
2263 }