dplayx: Tests for CreatePlayer.
[wine/gsoc_dplay.git] / dlls / winmm / mci.c
blob411d28e0a1e3124d86eba52b050a059556e7fa52
1 /*
2 * MCI internal functions
4 * Copyright 1998/1999 Eric Pouech
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.
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.
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
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
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)
45 #include "config.h"
46 #include "wine/port.h"
48 #include <stdlib.h>
49 #include <stdarg.h>
50 #include <stdio.h>
51 #include <string.h>
53 #include "windef.h"
54 #include "winbase.h"
55 #include "wingdi.h"
56 #include "mmsystem.h"
57 #include "winuser.h"
58 #include "winnls.h"
59 #include "winreg.h"
60 #include "wownt32.h"
62 #include "digitalv.h"
63 #include "winemm.h"
65 #include "wine/debug.h"
66 #include "wine/unicode.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(mci);
70 WINMM_MapType (*pFnMciMapMsg16To32W) (WORD,WORD,DWORD,DWORD_PTR*) = NULL;
71 WINMM_MapType (*pFnMciUnMapMsg16To32W)(WORD,WORD,DWORD,DWORD_PTR) = NULL;
72 WINMM_MapType (*pFnMciMapMsg32WTo16) (WORD,WORD,DWORD,DWORD_PTR*) = NULL;
73 WINMM_MapType (*pFnMciUnMapMsg32WTo16)(WORD,WORD,DWORD,DWORD_PTR) = NULL;
75 /* First MCI valid device ID (0 means error) */
76 #define MCI_MAGIC 0x0001
78 /* MCI settings */
79 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};
80 static const WCHAR wszNull [] = {0};
81 static const WCHAR wszAll [] = {'A','L','L',0};
82 static const WCHAR wszMci [] = {'M','C','I',0};
83 static const WCHAR wszOpen [] = {'o','p','e','n',0};
84 static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
86 static WINE_MCIDRIVER *MciDrivers;
88 /* dup a string and uppercase it */
89 static inline LPWSTR str_dup_upper( LPCWSTR str )
91 INT len = (strlenW(str) + 1) * sizeof(WCHAR);
92 LPWSTR p = HeapAlloc( GetProcessHeap(), 0, len );
93 if (p)
95 memcpy( p, str, len );
96 CharUpperW( p );
98 return p;
101 /**************************************************************************
102 * MCI_GetDriver [internal]
104 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
106 LPWINE_MCIDRIVER wmd = 0;
108 EnterCriticalSection(&WINMM_cs);
109 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
110 if (wmd->wDeviceID == wDevID)
111 break;
113 LeaveCriticalSection(&WINMM_cs);
114 return wmd;
117 /**************************************************************************
118 * MCI_GetDriverFromString [internal]
120 UINT MCI_GetDriverFromString(LPCWSTR lpstrName)
122 LPWINE_MCIDRIVER wmd;
123 UINT ret = 0;
125 if (!lpstrName)
126 return 0;
128 if (!strcmpiW(lpstrName, wszAll))
129 return MCI_ALL_DEVICE_ID;
131 EnterCriticalSection(&WINMM_cs);
132 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
133 if (wmd->lpstrElementName && strcmpW(wmd->lpstrElementName, lpstrName) == 0) {
134 ret = wmd->wDeviceID;
135 break;
137 if (wmd->lpstrDeviceType && strcmpiW(wmd->lpstrDeviceType, lpstrName) == 0) {
138 ret = wmd->wDeviceID;
139 break;
141 if (wmd->lpstrAlias && strcmpiW(wmd->lpstrAlias, lpstrName) == 0) {
142 ret = wmd->wDeviceID;
143 break;
146 LeaveCriticalSection(&WINMM_cs);
148 return ret;
151 /**************************************************************************
152 * MCI_MessageToString [internal]
154 const char* MCI_MessageToString(UINT wMsg)
156 static char buffer[100];
158 #define CASE(s) case (s): return #s
160 switch (wMsg) {
161 CASE(DRV_LOAD);
162 CASE(DRV_ENABLE);
163 CASE(DRV_OPEN);
164 CASE(DRV_CLOSE);
165 CASE(DRV_DISABLE);
166 CASE(DRV_FREE);
167 CASE(DRV_CONFIGURE);
168 CASE(DRV_QUERYCONFIGURE);
169 CASE(DRV_INSTALL);
170 CASE(DRV_REMOVE);
171 CASE(DRV_EXITSESSION);
172 CASE(DRV_EXITAPPLICATION);
173 CASE(DRV_POWER);
174 CASE(MCI_BREAK);
175 CASE(MCI_CLOSE);
176 CASE(MCI_CLOSE_DRIVER);
177 CASE(MCI_COPY);
178 CASE(MCI_CUE);
179 CASE(MCI_CUT);
180 CASE(MCI_DELETE);
181 CASE(MCI_ESCAPE);
182 CASE(MCI_FREEZE);
183 CASE(MCI_PAUSE);
184 CASE(MCI_PLAY);
185 CASE(MCI_GETDEVCAPS);
186 CASE(MCI_INFO);
187 CASE(MCI_LOAD);
188 CASE(MCI_OPEN);
189 CASE(MCI_OPEN_DRIVER);
190 CASE(MCI_PASTE);
191 CASE(MCI_PUT);
192 CASE(MCI_REALIZE);
193 CASE(MCI_RECORD);
194 CASE(MCI_RESUME);
195 CASE(MCI_SAVE);
196 CASE(MCI_SEEK);
197 CASE(MCI_SET);
198 CASE(MCI_SPIN);
199 CASE(MCI_STATUS);
200 CASE(MCI_STEP);
201 CASE(MCI_STOP);
202 CASE(MCI_SYSINFO);
203 CASE(MCI_UNFREEZE);
204 CASE(MCI_UPDATE);
205 CASE(MCI_WHERE);
206 CASE(MCI_WINDOW);
207 /* constants for digital video */
208 CASE(MCI_CAPTURE);
209 CASE(MCI_MONITOR);
210 CASE(MCI_RESERVE);
211 CASE(MCI_SETAUDIO);
212 CASE(MCI_SIGNAL);
213 CASE(MCI_SETVIDEO);
214 CASE(MCI_QUALITY);
215 CASE(MCI_LIST);
216 CASE(MCI_UNDO);
217 CASE(MCI_CONFIGURE);
218 CASE(MCI_RESTORE);
219 #undef CASE
220 default:
221 sprintf(buffer, "MCI_<<%04X>>", wMsg);
222 return buffer;
226 LPWSTR MCI_strdupAtoW( LPCSTR str )
228 LPWSTR ret;
229 INT len;
231 if (!str) return NULL;
232 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
233 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
234 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
235 return ret;
238 LPSTR MCI_strdupWtoA( LPCWSTR str )
240 LPSTR ret;
241 INT len;
243 if (!str) return NULL;
244 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
245 ret = HeapAlloc( GetProcessHeap(), 0, len );
246 if (ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
247 return ret;
250 static int MCI_MapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
252 if (msg < DRV_RESERVED) return 0;
254 switch (msg)
256 case MCI_CLOSE:
257 case MCI_CONFIGURE:
258 case MCI_PLAY:
259 case MCI_SEEK:
260 case MCI_STOP:
261 case MCI_PAUSE:
262 case MCI_GETDEVCAPS:
263 case MCI_SPIN:
264 case MCI_SET:
265 case MCI_STEP:
266 case MCI_RECORD:
267 case MCI_BREAK:
268 case MCI_SOUND:
269 case MCI_STATUS:
270 case MCI_CUE:
271 case MCI_REALIZE:
272 case MCI_PUT:
273 case MCI_WHERE:
274 case MCI_FREEZE:
275 case MCI_UNFREEZE:
276 case MCI_CUT:
277 case MCI_COPY:
278 case MCI_PASTE:
279 case MCI_UPDATE:
280 case MCI_RESUME:
281 case MCI_DELETE:
282 case MCI_MONITOR:
283 case MCI_SETAUDIO:
284 case MCI_SIGNAL:
285 case MCI_SETVIDEO:
286 case MCI_LIST:
287 return 0;
289 case MCI_OPEN:
291 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA*)*dwParam2;
292 MCI_OPEN_PARMSW *mci_openW;
293 DWORD_PTR *ptr;
295 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW) + 2 * sizeof(DWORD));
296 if (!ptr) return -1;
298 *ptr++ = *dwParam2; /* save the previous pointer */
299 *dwParam2 = (DWORD_PTR)ptr;
300 mci_openW = (MCI_OPEN_PARMSW *)ptr;
302 if (dwParam1 & MCI_NOTIFY)
303 mci_openW->dwCallback = mci_openA->dwCallback;
305 if (dwParam1 & MCI_OPEN_TYPE)
307 if (dwParam1 & MCI_OPEN_TYPE_ID)
308 mci_openW->lpstrDeviceType = (LPCWSTR)mci_openA->lpstrDeviceType;
309 else
310 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
312 if (dwParam1 & MCI_OPEN_ELEMENT)
314 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
315 mci_openW->lpstrElementName = (LPCWSTR)mci_openA->lpstrElementName;
316 else
317 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
319 if (dwParam1 & MCI_OPEN_ALIAS)
320 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
321 /* FIXME: this is only needed for specific types of MCI devices, and
322 * may cause a segfault if the two DWORD:s don't exist at the end of
323 * mci_openA
325 memcpy(mci_openW + 1, mci_openA + 1, 2 * sizeof(DWORD));
327 return 1;
329 case MCI_WINDOW:
330 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
332 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
333 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
335 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
336 if (!mci_windowW) return -1;
338 *dwParam2 = (DWORD_PTR)mci_windowW;
340 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
342 if (dwParam1 & MCI_NOTIFY)
343 mci_windowW->dwCallback = mci_windowA->dwCallback;
344 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
345 mci_windowW->hWnd = mci_windowA->hWnd;
346 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
347 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
349 return 1;
351 return 0;
353 case MCI_SYSINFO:
355 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
356 MCI_SYSINFO_PARMSW *mci_sysinfoW;
357 DWORD_PTR *ptr;
359 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
360 if (!ptr) return -1;
362 *ptr++ = *dwParam2; /* save the previous pointer */
363 *dwParam2 = (DWORD_PTR)ptr;
364 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
366 if (dwParam1 & MCI_NOTIFY)
367 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
369 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
370 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize);
371 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
372 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
373 return 1;
375 case MCI_INFO:
377 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
378 MCI_INFO_PARMSW *mci_infoW;
379 DWORD_PTR *ptr;
381 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
382 if (!ptr) return -1;
384 *ptr++ = *dwParam2; /* save the previous pointer */
385 *dwParam2 = (DWORD_PTR)ptr;
386 mci_infoW = (MCI_INFO_PARMSW *)ptr;
388 if (dwParam1 & MCI_NOTIFY)
389 mci_infoW->dwCallback = mci_infoA->dwCallback;
391 mci_infoW->dwRetSize = mci_infoA->dwRetSize * sizeof(WCHAR); /* it's not the same as SYSINFO !!! */
392 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize);
393 return 1;
395 case MCI_SAVE:
397 MCI_SAVE_PARMSA *mci_saveA = (MCI_SAVE_PARMSA *)*dwParam2;
398 MCI_SAVE_PARMSW *mci_saveW;
400 mci_saveW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW));
401 if (!mci_saveW) return -1;
403 *dwParam2 = (DWORD_PTR)mci_saveW;
404 if (dwParam1 & MCI_NOTIFY)
405 mci_saveW->dwCallback = mci_saveA->dwCallback;
406 mci_saveW->lpfilename = MCI_strdupAtoW(mci_saveA->lpfilename);
407 return 1;
409 case MCI_LOAD:
411 MCI_LOAD_PARMSA *mci_loadA = (MCI_LOAD_PARMSA *)*dwParam2;
412 MCI_LOAD_PARMSW *mci_loadW;
414 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
415 if (!mci_loadW) return -1;
417 *dwParam2 = (DWORD_PTR)mci_loadW;
418 if (dwParam1 & MCI_NOTIFY)
419 mci_loadW->dwCallback = mci_loadA->dwCallback;
420 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
421 return 1;
424 case MCI_ESCAPE:
426 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
427 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
429 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
430 if (!mci_vd_escapeW) return -1;
432 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
433 if (dwParam1 & MCI_NOTIFY)
434 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
435 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
436 return 1;
438 default:
439 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
440 return -1;
444 static DWORD MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
445 DWORD result)
447 switch (msg)
449 case MCI_OPEN:
451 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
452 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
453 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)(ptr + 1);
455 mci_openA->wDeviceID = mci_openW->wDeviceID;
457 if (dwParam1 & MCI_OPEN_TYPE)
459 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
460 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrDeviceType);
462 if (dwParam1 & MCI_OPEN_ELEMENT)
464 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
465 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrElementName);
467 if (dwParam1 & MCI_OPEN_ALIAS)
468 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrAlias);
469 HeapFree(GetProcessHeap(), 0, ptr);
471 break;
472 case MCI_WINDOW:
473 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
475 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
477 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
478 HeapFree(GetProcessHeap(), 0, mci_windowW);
480 break;
482 case MCI_SYSINFO:
484 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
485 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
486 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)(ptr + 1);
488 if (!result)
490 mci_sysinfoA->dwNumber = mci_sysinfoW->dwNumber;
491 mci_sysinfoA->wDeviceType = mci_sysinfoW->wDeviceType;
492 if (dwParam1 & MCI_SYSINFO_QUANTITY)
493 *(DWORD*)mci_sysinfoA->lpstrReturn = *(DWORD*)mci_sysinfoW->lpstrReturn;
494 else
495 WideCharToMultiByte(CP_ACP, 0,
496 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
497 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
498 NULL, NULL);
501 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
502 HeapFree(GetProcessHeap(), 0, ptr);
504 break;
505 case MCI_INFO:
507 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
508 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
509 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)(ptr + 1);
511 if (!result)
513 WideCharToMultiByte(CP_ACP, 0,
514 mci_infoW->lpstrReturn, mci_infoW->dwRetSize / sizeof(WCHAR),
515 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
516 NULL, NULL);
519 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
520 HeapFree(GetProcessHeap(), 0, ptr);
522 break;
523 case MCI_SAVE:
525 MCI_SAVE_PARMSW *mci_saveW = (MCI_SAVE_PARMSW *)dwParam2;
527 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW->lpfilename);
528 HeapFree(GetProcessHeap(), 0, mci_saveW);
530 break;
531 case MCI_LOAD:
533 MCI_LOAD_PARMSW *mci_loadW = (MCI_LOAD_PARMSW *)dwParam2;
535 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
536 HeapFree(GetProcessHeap(), 0, mci_loadW);
538 break;
539 case MCI_ESCAPE:
541 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
543 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
544 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
546 break;
548 default:
549 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
550 break;
553 return result;
556 /**************************************************************************
557 * MCI_GetDevTypeFromFileName [internal]
559 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
561 LPCWSTR tmp;
562 HKEY hKey;
563 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
564 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
565 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
566 if ((tmp = strrchrW(fileName, '.'))) {
567 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
568 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
569 DWORD dwLen = len;
570 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
571 RegCloseKey( hKey );
572 if (lRet == ERROR_SUCCESS) return 0;
574 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
576 return MCIERR_EXTENSION_NOT_FOUND;
579 #define MAX_MCICMDTABLE 20
580 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
582 typedef struct tagWINE_MCICMDTABLE {
583 UINT uDevType;
584 const BYTE* lpTable;
585 UINT nVerbs; /* number of verbs in command table */
586 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
587 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
589 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
591 /**************************************************************************
592 * MCI_IsCommandTableValid [internal]
594 static BOOL MCI_IsCommandTableValid(UINT uTbl)
596 const BYTE* lmem;
597 LPCWSTR str;
598 DWORD flg;
599 WORD eid;
600 int idx = 0;
601 BOOL inCst = FALSE;
603 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
604 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
606 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
607 return FALSE;
609 lmem = S_MciCmdTable[uTbl].lpTable;
610 do {
611 str = (LPCWSTR)lmem;
612 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
613 flg = *(const DWORD*)lmem;
614 eid = *(const WORD*)(lmem + sizeof(DWORD));
615 lmem += sizeof(DWORD) + sizeof(WORD);
616 idx ++;
617 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
618 switch (eid) {
619 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
620 case MCI_STRING: if (inCst) return FALSE; break;
621 case MCI_INTEGER: if (!*str) return FALSE; break;
622 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
623 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
624 case MCI_FLAG: if (!*str) return FALSE; break;
625 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
626 case MCI_RECT: if (!*str || inCst) return FALSE; break;
627 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
628 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
629 default: return FALSE;
631 } while (eid != MCI_END_COMMAND_LIST);
632 return TRUE;
635 /**************************************************************************
636 * MCI_DumpCommandTable [internal]
638 static BOOL MCI_DumpCommandTable(UINT uTbl)
640 const BYTE* lmem;
641 LPCWSTR str;
642 DWORD flg;
643 WORD eid;
645 if (!MCI_IsCommandTableValid(uTbl)) {
646 ERR("Ooops: %d is not valid\n", uTbl);
647 return FALSE;
650 lmem = S_MciCmdTable[uTbl].lpTable;
651 do {
652 do {
653 str = (LPCWSTR)lmem;
654 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
655 flg = *(const DWORD*)lmem;
656 eid = *(const WORD*)(lmem + sizeof(DWORD));
657 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
658 lmem += sizeof(DWORD) + sizeof(WORD);
659 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
660 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
661 } while (eid != MCI_END_COMMAND_LIST);
662 return TRUE;
666 /**************************************************************************
667 * MCI_GetCommandTable [internal]
669 static UINT MCI_GetCommandTable(UINT uDevType)
671 UINT uTbl;
672 WCHAR buf[32];
673 LPCWSTR str = NULL;
675 /* first look up existing for existing devType */
676 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
677 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
678 return uTbl;
681 /* well try to load id */
682 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
683 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
684 str = buf;
686 } else if (uDevType == 0) {
687 static const WCHAR wszCore[] = {'C','O','R','E',0};
688 str = wszCore;
690 uTbl = MCI_NO_COMMAND_TABLE;
691 if (str) {
692 HRSRC hRsrc = FindResourceW(hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
693 HANDLE hMem = 0;
695 if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
696 if (hMem) {
697 uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType);
698 } else {
699 WARN("No command table found in resource %p[%s]\n",
700 hWinMM32Instance, debugstr_w(str));
703 TRACE("=> %d\n", uTbl);
704 return uTbl;
707 /**************************************************************************
708 * MCI_SetCommandTable [internal]
710 UINT MCI_SetCommandTable(void *table, UINT uDevType)
712 int uTbl;
713 static BOOL bInitDone = FALSE;
715 /* <HACK>
716 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
717 * can be called with 0 as a uDevType to retrieve it.
718 * </HACK>
720 if (!bInitDone) {
721 bInitDone = TRUE;
722 MCI_GetCommandTable(0);
724 TRACE("(%p, %u)\n", table, uDevType);
725 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
726 if (!S_MciCmdTable[uTbl].lpTable) {
727 const BYTE* lmem;
728 LPCWSTR str;
729 WORD eid;
730 WORD count;
732 S_MciCmdTable[uTbl].uDevType = uDevType;
733 S_MciCmdTable[uTbl].lpTable = table;
735 if (TRACE_ON(mci)) {
736 MCI_DumpCommandTable(uTbl);
739 /* create the verbs table */
740 /* get # of entries */
741 lmem = S_MciCmdTable[uTbl].lpTable;
742 count = 0;
743 do {
744 str = (LPCWSTR)lmem;
745 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
746 eid = *(const WORD*)(lmem + sizeof(DWORD));
747 lmem += sizeof(DWORD) + sizeof(WORD);
748 if (eid == MCI_COMMAND_HEAD)
749 count++;
750 } while (eid != MCI_END_COMMAND_LIST);
752 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
753 S_MciCmdTable[uTbl].nVerbs = count;
755 lmem = S_MciCmdTable[uTbl].lpTable;
756 count = 0;
757 do {
758 str = (LPCWSTR)lmem;
759 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
760 eid = *(const WORD*)(lmem + sizeof(DWORD));
761 lmem += sizeof(DWORD) + sizeof(WORD);
762 if (eid == MCI_COMMAND_HEAD)
763 S_MciCmdTable[uTbl].aVerbs[count++] = str;
764 } while (eid != MCI_END_COMMAND_LIST);
765 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
766 return uTbl;
770 return MCI_NO_COMMAND_TABLE;
773 /**************************************************************************
774 * MCI_DeleteCommandTable [internal]
776 BOOL MCI_DeleteCommandTable(UINT uTbl, BOOL delete)
778 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
779 return FALSE;
781 if (delete) HeapFree(GetProcessHeap(), 0, (void*)S_MciCmdTable[uTbl].lpTable);
782 S_MciCmdTable[uTbl].lpTable = NULL;
783 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
784 S_MciCmdTable[uTbl].aVerbs = 0;
785 return TRUE;
788 /**************************************************************************
789 * MCI_UnLoadMciDriver [internal]
791 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
793 LPWINE_MCIDRIVER* tmp;
795 if (!wmd)
796 return TRUE;
798 CloseDriver(wmd->hDriver, 0, 0);
800 if (wmd->dwPrivate != 0)
801 WARN("Unloading mci driver with non nul dwPrivate field\n");
803 EnterCriticalSection(&WINMM_cs);
804 for (tmp = &MciDrivers; *tmp; tmp = &(*tmp)->lpNext) {
805 if (*tmp == wmd) {
806 *tmp = wmd->lpNext;
807 break;
810 LeaveCriticalSection(&WINMM_cs);
812 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
813 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
814 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
816 HeapFree(GetProcessHeap(), 0, wmd);
817 return TRUE;
820 /**************************************************************************
821 * MCI_OpenMciDriver [internal]
823 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
825 WCHAR libName[128];
827 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
828 return FALSE;
830 wmd->bIs32 = 0xFFFF;
831 /* First load driver */
832 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
833 wmd->bIs32 = TRUE;
834 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32WTo16) {
835 WINMM_MapType res;
837 switch (res = pFnMciMapMsg32WTo16(0, DRV_OPEN, 0, &lp)) {
838 case WINMM_MAP_MSGERROR:
839 TRACE("Not handled yet (DRV_OPEN)\n");
840 break;
841 case WINMM_MAP_NOMEM:
842 TRACE("Problem mapping msg=DRV_OPEN from 32W to 16\n");
843 break;
844 case WINMM_MAP_OK:
845 case WINMM_MAP_OKMEM:
846 if ((wmd->hDriver = OpenDriver(drvTyp, wszMci, lp)))
847 wmd->bIs32 = FALSE;
848 if (res == WINMM_MAP_OKMEM)
849 pFnMciUnMapMsg32WTo16(0, DRV_OPEN, 0, lp);
850 break;
853 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
856 /**************************************************************************
857 * MCI_LoadMciDriver [internal]
859 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
861 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
862 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
863 MCI_OPEN_DRIVER_PARMSW modp;
864 DWORD dwRet = 0;
866 if (!wmd || !strDevTyp) {
867 dwRet = MCIERR_OUT_OF_MEMORY;
868 goto errCleanUp;
871 wmd->lpfnYieldProc = MCI_DefYieldProc;
872 wmd->dwYieldData = VK_CANCEL;
873 wmd->CreatorThread = GetCurrentThreadId();
875 EnterCriticalSection(&WINMM_cs);
876 /* wmd must be inserted in list before sending opening the driver, because it
877 * may want to lookup at wDevID
879 wmd->lpNext = MciDrivers;
880 MciDrivers = wmd;
882 for (modp.wDeviceID = MCI_MAGIC;
883 MCI_GetDriver(modp.wDeviceID) != 0;
884 modp.wDeviceID++);
886 wmd->wDeviceID = modp.wDeviceID;
888 LeaveCriticalSection(&WINMM_cs);
890 TRACE("wDevID=%04X\n", modp.wDeviceID);
892 modp.lpstrParams = NULL;
894 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
895 /* silence warning if all is used... some bogus program use commands like
896 * 'open all'...
898 if (strcmpiW(strDevTyp, wszAll) == 0) {
899 dwRet = MCIERR_CANNOT_USE_ALL;
900 } else {
901 FIXME("Couldn't load driver for type %s.\n"
902 "If you don't have a windows installation accessible from Wine,\n"
903 "you perhaps forgot to create a [mci] section in system.ini\n",
904 debugstr_w(strDevTyp));
905 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
907 goto errCleanUp;
910 /* FIXME: should also check that module's description is of the form
911 * MODULENAME:[MCI] comment
914 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
915 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
916 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
918 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
919 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
921 wmd->lpstrDeviceType = strDevTyp;
922 wmd->wType = modp.wType;
924 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
925 modp.wDeviceID, modp.wType, modp.wDeviceID);
926 *lpwmd = wmd;
927 return 0;
928 errCleanUp:
929 MCI_UnLoadMciDriver(wmd);
930 HeapFree(GetProcessHeap(), 0, strDevTyp);
931 *lpwmd = 0;
932 return dwRet;
935 /**************************************************************************
936 * MCI_FinishOpen [internal]
938 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
939 DWORD dwParam)
941 if (dwParam & MCI_OPEN_ELEMENT)
943 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms->lpstrElementName)+1) * sizeof(WCHAR));
944 strcpyW( wmd->lpstrElementName, lpParms->lpstrElementName );
946 if (dwParam & MCI_OPEN_ALIAS)
948 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms->lpstrAlias)+1) * sizeof(WCHAR));
949 strcpyW( wmd->lpstrAlias, lpParms->lpstrAlias);
951 lpParms->wDeviceID = wmd->wDeviceID;
953 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
954 (DWORD)lpParms);
957 /**************************************************************************
958 * MCI_FindCommand [internal]
960 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
962 UINT idx;
964 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
965 return NULL;
967 /* another improvement would be to have the aVerbs array sorted,
968 * so that we could use a dichotomic search on it, rather than this dumb
969 * array look up
971 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
972 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
973 return S_MciCmdTable[uTbl].aVerbs[idx];
976 return NULL;
979 /**************************************************************************
980 * MCI_GetReturnType [internal]
982 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
984 lpCmd = (LPCWSTR)((const BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
985 if (*lpCmd == '\0' && *(const WORD*)((const BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
986 return *(const DWORD*)(lpCmd + 1);
988 return 0L;
991 /**************************************************************************
992 * MCI_GetMessage [internal]
994 static WORD MCI_GetMessage(LPCWSTR lpCmd)
996 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
999 /**************************************************************************
1000 * MCI_GetDWord [internal]
1002 static BOOL MCI_GetDWord(LPDWORD data, LPWSTR* ptr)
1004 DWORD val;
1005 LPWSTR ret;
1007 val = strtoulW(*ptr, &ret, 0);
1009 switch (*ret) {
1010 case '\0': break;
1011 case ' ': ret++; break;
1012 default: return FALSE;
1015 *data |= val;
1016 *ptr = ret;
1017 return TRUE;
1020 /**************************************************************************
1021 * MCI_GetString [internal]
1023 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
1025 LPWSTR ptr = *args;
1027 /* see if we have a quoted string */
1028 if (*ptr == '"') {
1029 ptr = strchrW(*str = ptr + 1, '"');
1030 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
1031 /* FIXME: shall we escape \" from string ?? */
1032 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1033 *ptr++ = '\0'; /* remove trailing " */
1034 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
1035 } else {
1036 ptr = strchrW(ptr, ' ');
1038 if (ptr) {
1039 *ptr++ = '\0';
1040 } else {
1041 ptr = *args + strlenW(*args);
1043 *str = *args;
1046 *args = ptr;
1047 return 0;
1050 #define MCI_DATA_SIZE 16
1052 /**************************************************************************
1053 * MCI_ParseOptArgs [internal]
1055 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCWSTR lpCmd,
1056 LPWSTR args, LPDWORD dwFlags)
1058 int len, offset;
1059 const char* lmem;
1060 LPCWSTR str;
1061 DWORD dwRet, flg, cflg = 0;
1062 WORD eid;
1063 BOOL inCst, found;
1065 /* loop on arguments */
1066 while (*args) {
1067 lmem = (const char*)lpCmd;
1068 found = inCst = FALSE;
1069 offset = _offset;
1071 /* skip any leading white space(s) */
1072 while (*args == ' ') args++;
1073 TRACE("args=%s offset=%d\n", debugstr_w(args), offset);
1075 do { /* loop on options for command table for the requested verb */
1076 str = (LPCWSTR)lmem;
1077 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1078 flg = *(const DWORD*)lmem;
1079 eid = *(const WORD*)(lmem + sizeof(DWORD));
1080 lmem += sizeof(DWORD) + sizeof(WORD);
1081 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1083 switch (eid) {
1084 case MCI_CONSTANT:
1085 inCst = TRUE; cflg = flg; break;
1086 case MCI_END_CONSTANT:
1087 /* there may be additional integral values after flag in constant */
1088 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1089 *dwFlags |= cflg;
1091 inCst = FALSE; cflg = 0;
1092 break;
1095 if (strncmpiW(args, str, len) == 0 &&
1096 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1097 /* store good values into data[] */
1098 args += len;
1099 while (*args == ' ') args++;
1100 found = TRUE;
1102 switch (eid) {
1103 case MCI_COMMAND_HEAD:
1104 case MCI_RETURN:
1105 case MCI_END_COMMAND:
1106 case MCI_END_COMMAND_LIST:
1107 case MCI_CONSTANT: /* done above */
1108 case MCI_END_CONSTANT: /* done above */
1109 break;
1110 case MCI_FLAG:
1111 *dwFlags |= flg;
1112 break;
1113 case MCI_INTEGER:
1114 if (inCst) {
1115 data[offset] |= flg;
1116 *dwFlags |= cflg;
1117 inCst = FALSE;
1118 } else {
1119 *dwFlags |= flg;
1120 if (!MCI_GetDWord(&(data[offset]), &args)) {
1121 return MCIERR_BAD_INTEGER;
1124 break;
1125 case MCI_RECT:
1126 /* store rect in data (offset...offset+3) */
1127 *dwFlags |= flg;
1128 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1129 !MCI_GetDWord(&(data[offset+1]), &args) ||
1130 !MCI_GetDWord(&(data[offset+2]), &args) ||
1131 !MCI_GetDWord(&(data[offset+3]), &args)) {
1132 ERR("Bad rect %s\n", debugstr_w(args));
1133 return MCIERR_BAD_INTEGER;
1135 break;
1136 case MCI_STRING:
1137 *dwFlags |= flg;
1138 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1139 return dwRet;
1140 break;
1141 default: ERR("oops\n");
1143 /* exit inside while loop, except if just entered in constant area definition */
1144 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1145 } else {
1146 /* have offset incremented if needed */
1147 switch (eid) {
1148 case MCI_COMMAND_HEAD:
1149 case MCI_RETURN:
1150 case MCI_END_COMMAND:
1151 case MCI_END_COMMAND_LIST:
1152 case MCI_CONSTANT:
1153 case MCI_FLAG: break;
1154 case MCI_INTEGER: if (!inCst) offset++; break;
1155 case MCI_END_CONSTANT:
1156 case MCI_STRING: offset++; break;
1157 case MCI_RECT: offset += 4; break;
1158 default: ERR("oops\n");
1161 } while (eid != MCI_END_COMMAND);
1162 if (!found) {
1163 WARN("Optarg %s not found\n", debugstr_w(args));
1164 return MCIERR_UNRECOGNIZED_COMMAND;
1166 if (offset == MCI_DATA_SIZE) {
1167 ERR("Internal data[] buffer overflow\n");
1168 return MCIERR_PARSER_INTERNAL;
1171 return 0;
1174 /**************************************************************************
1175 * MCI_HandleReturnValues [internal]
1177 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1178 LPDWORD data, LPWSTR lpstrRet, UINT uRetLen)
1180 static const WCHAR wszLd [] = {'%','l','d',0};
1181 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1182 static const WCHAR wszCol3[] = {'%','d',':','%','d',':','%','d',0};
1183 static const WCHAR wszCol4[] = {'%','d',':','%','d',':','%','d',':','%','d',0};
1185 if (lpstrRet) {
1186 switch (retType) {
1187 case 0: /* nothing to return */
1188 break;
1189 case MCI_INTEGER:
1190 switch (dwRet & 0xFFFF0000ul) {
1191 case 0:
1192 case MCI_INTEGER_RETURNED:
1193 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1194 break;
1195 case MCI_RESOURCE_RETURNED:
1196 /* return string which ID is HIWORD(data[1]),
1197 * string is loaded from mmsystem.dll */
1198 LoadStringW(hWinMM32Instance, HIWORD(data[1]), lpstrRet, uRetLen);
1199 break;
1200 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1201 /* return string which ID is HIWORD(data[1]),
1202 * string is loaded from driver */
1203 /* FIXME: this is wrong for a 16 bit handle */
1204 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1205 HIWORD(data[1]), lpstrRet, uRetLen);
1206 break;
1207 case MCI_COLONIZED3_RETURN:
1208 snprintfW(lpstrRet, uRetLen, wszCol3,
1209 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1210 LOBYTE(HIWORD(data[1])));
1211 break;
1212 case MCI_COLONIZED4_RETURN:
1213 snprintfW(lpstrRet, uRetLen, wszCol4,
1214 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1215 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1216 break;
1217 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1219 break;
1220 case MCI_STRING:
1221 switch (dwRet & 0xFFFF0000ul) {
1222 case 0:
1223 /* nothing to do data[1] == lpstrRet */
1224 break;
1225 case MCI_INTEGER_RETURNED:
1226 data[1] = *(LPDWORD)lpstrRet;
1227 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1228 break;
1229 default:
1230 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1231 break;
1233 break;
1234 case MCI_RECT:
1235 if (dwRet & 0xFFFF0000ul)
1236 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1237 snprintfW(lpstrRet, uRetLen, wszLd4,
1238 data[1], data[2], data[3], data[4]);
1239 break;
1240 default: ERR("oops\n");
1243 return LOWORD(dwRet);
1246 /**************************************************************************
1247 * mciSendStringW [WINMM.@]
1249 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1250 UINT uRetLen, HWND hwndCallback)
1252 LPWSTR verb, dev, args;
1253 LPWINE_MCIDRIVER wmd = 0;
1254 DWORD dwFlags = 0, dwRet = 0;
1255 int offset = 0;
1256 DWORD data[MCI_DATA_SIZE];
1257 DWORD retType;
1258 LPCWSTR lpCmd = 0;
1259 LPWSTR devAlias = NULL;
1260 static const WCHAR wszNew[] = {'n','e','w',0};
1261 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1262 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1264 TRACE("(%s, %p, %d, %p)\n",
1265 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1267 /* format is <command> <device> <optargs> */
1268 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1269 return MCIERR_OUT_OF_MEMORY;
1270 strcpyW( verb, lpstrCommand );
1271 CharLowerW(verb);
1273 memset(data, 0, sizeof(data));
1275 if (!(args = strchrW(verb, ' '))) {
1276 dwRet = MCIERR_MISSING_DEVICE_NAME;
1277 goto errCleanUp;
1279 *args++ = '\0';
1280 if ((dwRet = MCI_GetString(&dev, &args))) {
1281 goto errCleanUp;
1284 /* Determine devType from open */
1285 if (!strcmpW(verb, wszOpen)) {
1286 LPWSTR devType, tmp;
1287 WCHAR buf[128];
1289 /* case dev == 'new' has to be handled */
1290 if (!strcmpW(dev, wszNew)) {
1291 dev = 0;
1292 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1293 devType += 5;
1294 tmp = strchrW(devType, ' ');
1295 if (tmp) *tmp = '\0';
1296 devType = str_dup_upper(devType);
1297 if (tmp) *tmp = ' ';
1298 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1299 } else {
1300 WARN("open new requires device type\n");
1301 dwRet = MCIERR_MISSING_DEVICE_NAME;
1302 goto errCleanUp;
1304 } else if ((devType = strchrW(dev, '!')) != NULL) {
1305 *devType++ = '\0';
1306 tmp = devType; devType = dev; dev = tmp;
1308 dwFlags |= MCI_OPEN_TYPE;
1309 data[2] = (DWORD)devType;
1310 devType = str_dup_upper(devType);
1311 dwFlags |= MCI_OPEN_ELEMENT;
1312 data[3] = (DWORD)dev;
1313 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1314 /* this is the name of a mci driver's type */
1315 tmp = strchrW(dev, ' ');
1316 if (tmp) *tmp = '\0';
1317 data[2] = (DWORD)dev;
1318 devType = str_dup_upper(dev);
1319 if (tmp) *tmp = ' ';
1320 dwFlags |= MCI_OPEN_TYPE;
1321 } else {
1322 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1323 devType += 5;
1324 tmp = strchrW(devType, ' ');
1325 if (tmp) *tmp = '\0';
1326 devType = str_dup_upper(devType);
1327 if (tmp) *tmp = ' ';
1328 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1329 } else {
1330 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1331 goto errCleanUp;
1333 devType = str_dup_upper(buf);
1335 dwFlags |= MCI_OPEN_ELEMENT;
1336 data[3] = (DWORD)dev;
1338 if ((devAlias = strstrW(args, wszSAliasS))) {
1339 WCHAR* tmp2;
1340 devAlias += 7;
1341 if (!(tmp = strchrW(devAlias,' '))) tmp = devAlias + strlenW(devAlias);
1342 if (tmp) *tmp = '\0';
1343 tmp2 = HeapAlloc(GetProcessHeap(), 0, (tmp - devAlias + 1) * sizeof(WCHAR) );
1344 memcpy( tmp2, devAlias, (tmp - devAlias) * sizeof(WCHAR) );
1345 tmp2[tmp - devAlias] = 0;
1346 data[4] = (DWORD)tmp2;
1347 /* should be done in regular options parsing */
1348 /* dwFlags |= MCI_OPEN_ALIAS; */
1349 } else if (dev == 0) {
1350 /* "open new" requires alias */
1351 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1352 goto errCleanUp;
1355 dwRet = MCI_LoadMciDriver(devType, &wmd);
1356 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1357 dwRet = MCIERR_INVALID_DEVICE_NAME;
1358 HeapFree(GetProcessHeap(), 0, devType);
1359 if (dwRet) {
1360 MCI_UnLoadMciDriver(wmd);
1361 goto errCleanUp;
1363 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1364 /* auto open */
1365 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1366 WCHAR buf[128];
1367 sprintfW(buf, wszOpenWait, dev);
1369 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1370 goto errCleanUp;
1372 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1373 if (!wmd) {
1374 /* FIXME: memory leak, MCI driver is not closed */
1375 dwRet = MCIERR_INVALID_DEVICE_ID;
1376 goto errCleanUp;
1380 /* get the verb in the different command tables */
1381 if (wmd) {
1382 /* try the device specific command table */
1383 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1384 if (!lpCmd) {
1385 /* try the type specific command table */
1386 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1387 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1388 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1389 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1392 /* try core command table */
1393 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1395 if (!lpCmd) {
1396 TRACE("Command %s not found!\n", debugstr_w(verb));
1397 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1398 goto errCleanUp;
1401 /* set up call back */
1402 if (hwndCallback != 0) {
1403 dwFlags |= MCI_NOTIFY;
1404 data[0] = (DWORD)hwndCallback;
1407 /* set return information */
1408 switch (retType = MCI_GetReturnType(lpCmd)) {
1409 case 0: offset = 1; break;
1410 case MCI_INTEGER: offset = 2; break;
1411 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1412 case MCI_RECT: offset = 5; break;
1413 default: ERR("oops\n");
1416 TRACE("verb=%s on dev=%s; offset=%d\n",
1417 debugstr_w(verb), debugstr_w(dev), offset);
1419 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1420 goto errCleanUp;
1422 /* FIXME: the command should get it's own notification window set up and
1423 * ask for device closing while processing the notification mechanism
1425 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1427 TRACE("[%d, %s, %08x, %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s]\n",
1428 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1429 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1430 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1431 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1433 if (strcmpW(verb, wszOpen) == 0) {
1434 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1435 MCI_UnLoadMciDriver(wmd);
1436 /* FIXME: notification is not properly shared across two opens */
1437 } else {
1438 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
1440 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1441 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1442 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1444 errCleanUp:
1445 HeapFree(GetProcessHeap(), 0, verb);
1446 return dwRet;
1449 /**************************************************************************
1450 * mciSendStringA [WINMM.@]
1452 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1453 UINT uRetLen, HWND hwndCallback)
1455 LPWSTR lpwstrCommand;
1456 LPWSTR lpwstrRet = NULL;
1457 UINT ret;
1458 INT len;
1460 /* FIXME: is there something to do with lpstrReturnString ? */
1461 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1462 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1463 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1464 if (lpstrRet)
1466 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1467 if (!lpwstrRet) {
1468 WARN("no memory\n");
1469 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1470 return MCIERR_OUT_OF_MEMORY;
1473 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1474 if (lpwstrRet)
1475 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1476 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1477 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1478 return ret;
1481 /**************************************************************************
1482 * mciExecute [WINMM.@]
1483 * mciExecute [MMSYSTEM.712]
1485 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1487 char strRet[256];
1488 DWORD ret;
1490 TRACE("(%s)!\n", lpstrCommand);
1492 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1493 if (ret != 0) {
1494 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1495 sprintf(strRet, "Unknown MCI error (%d)", ret);
1497 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1499 /* FIXME: what shall I return ? */
1500 return TRUE;
1503 /**************************************************************************
1504 * mciLoadCommandResource [WINMM.@]
1506 * Strangely, this function only exists as an UNICODE one.
1508 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1510 HRSRC hRsrc = 0;
1511 HGLOBAL hMem;
1512 UINT16 ret = MCI_NO_COMMAND_TABLE;
1514 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1516 /* if a file named "resname.mci" exits, then load resource "resname" from it
1517 * otherwise directly from driver
1518 * We don't support it (who uses this feature ?), but we check anyway
1520 if (!type) {
1521 #if 0
1522 /* FIXME: we should put this back into order, but I never found a program
1523 * actually using this feature, so we may not need it
1525 char buf[128];
1526 OFSTRUCT ofs;
1528 strcat(strcpy(buf, resname), ".mci");
1529 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1530 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1532 #endif
1534 if (!(hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA))) {
1535 WARN("No command table found in resource\n");
1536 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1537 ret = MCI_SetCommandTable(LockResource(hMem), type);
1538 } else {
1539 WARN("Couldn't load resource.\n");
1541 TRACE("=> %04x\n", ret);
1542 return ret;
1545 /**************************************************************************
1546 * mciFreeCommandResource [WINMM.@]
1548 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1550 TRACE("(%08x)!\n", uTable);
1552 return MCI_DeleteCommandTable(uTable, FALSE);
1555 /**************************************************************************
1556 * MCI_SendCommandFrom32 [internal]
1558 DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1560 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1561 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1563 if (wmd) {
1564 if (wmd->bIs32) {
1565 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1566 } else if (pFnMciMapMsg32WTo16) {
1567 WINMM_MapType res;
1569 switch (res = pFnMciMapMsg32WTo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1570 case WINMM_MAP_MSGERROR:
1571 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1572 dwRet = MCIERR_DRIVER_INTERNAL;
1573 break;
1574 case WINMM_MAP_NOMEM:
1575 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1576 dwRet = MCIERR_OUT_OF_MEMORY;
1577 break;
1578 case WINMM_MAP_OK:
1579 case WINMM_MAP_OKMEM:
1580 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1581 if (res == WINMM_MAP_OKMEM)
1582 pFnMciUnMapMsg32WTo16(wmd->wType, wMsg, dwParam1, dwParam2);
1583 break;
1587 return dwRet;
1590 /**************************************************************************
1591 * MCI_SendCommandFrom16 [internal]
1593 DWORD MCI_SendCommandFrom16(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1595 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1596 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1598 if (wmd) {
1599 dwRet = MCIERR_INVALID_DEVICE_ID;
1601 if (wmd->bIs32 && pFnMciMapMsg16To32W) {
1602 WINMM_MapType res;
1604 switch (res = pFnMciMapMsg16To32W(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1605 case WINMM_MAP_MSGERROR:
1606 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1607 dwRet = MCIERR_DRIVER_INTERNAL;
1608 break;
1609 case WINMM_MAP_NOMEM:
1610 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1611 dwRet = MCIERR_OUT_OF_MEMORY;
1612 break;
1613 case WINMM_MAP_OK:
1614 case WINMM_MAP_OKMEM:
1615 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1616 if (res == WINMM_MAP_OKMEM)
1617 pFnMciUnMapMsg16To32W(wmd->wType, wMsg, dwParam1, dwParam2);
1618 break;
1620 } else {
1621 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1624 return dwRet;
1627 /**************************************************************************
1628 * MCI_Open [internal]
1630 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1632 WCHAR strDevTyp[128];
1633 DWORD dwRet;
1634 LPWINE_MCIDRIVER wmd = NULL;
1636 TRACE("(%08X, %p)\n", dwParam, lpParms);
1637 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1639 /* only two low bytes are generic, the other ones are dev type specific */
1640 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1641 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1642 MCI_NOTIFY|MCI_WAIT)
1643 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1644 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1646 #undef WINE_MCIDRIVER_SUPP
1648 strDevTyp[0] = 0;
1650 if (dwParam & MCI_OPEN_TYPE) {
1651 if (dwParam & MCI_OPEN_TYPE_ID) {
1652 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
1654 if (uDevType < MCI_DEVTYPE_FIRST ||
1655 uDevType > MCI_DEVTYPE_LAST ||
1656 !LoadStringW(hWinMM32Instance, uDevType,
1657 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1658 dwRet = MCIERR_BAD_INTEGER;
1659 goto errCleanUp;
1661 } else {
1662 LPWSTR ptr;
1663 if (lpParms->lpstrDeviceType == NULL) {
1664 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1665 goto errCleanUp;
1667 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1668 ptr = strchrW(strDevTyp, '!');
1669 if (ptr) {
1670 /* this behavior is not documented in windows. However, since, in
1671 * some occasions, MCI_OPEN handling is translated by WinMM into
1672 * a call to mciSendString("open <type>"); this code shall be correct
1674 if (dwParam & MCI_OPEN_ELEMENT) {
1675 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1676 debugstr_w(lpParms->lpstrElementName),
1677 debugstr_w(strDevTyp));
1678 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1679 goto errCleanUp;
1681 dwParam |= MCI_OPEN_ELEMENT;
1682 *ptr++ = 0;
1683 /* FIXME: not a good idea to write in user supplied buffer */
1684 lpParms->lpstrElementName = ptr;
1688 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1691 if (dwParam & MCI_OPEN_ELEMENT) {
1692 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1694 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1695 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1696 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1697 goto errCleanUp;
1700 if (!lpParms->lpstrElementName) {
1701 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1702 goto errCleanUp;
1705 /* type, if given as a parameter, supersedes file extension */
1706 if (!strDevTyp[0] &&
1707 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1708 strDevTyp, sizeof(strDevTyp))) {
1709 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1710 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1711 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1712 goto errCleanUp;
1714 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1715 strcpyW(strDevTyp, wszCdAudio);
1719 if (strDevTyp[0] == 0) {
1720 FIXME("Couldn't load driver\n");
1721 dwRet = MCIERR_INVALID_DEVICE_NAME;
1722 goto errCleanUp;
1725 if (dwParam & MCI_OPEN_ALIAS) {
1726 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1727 if (!lpParms->lpstrAlias) {
1728 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1729 goto errCleanUp;
1733 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1734 goto errCleanUp;
1737 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1738 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1739 /* FIXME: is dwRet the correct ret code ? */
1740 goto errCleanUp;
1743 /* only handled devices fall through */
1744 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1746 if (dwParam & MCI_NOTIFY)
1747 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1749 return 0;
1750 errCleanUp:
1751 if (wmd) MCI_UnLoadMciDriver(wmd);
1753 if (dwParam & MCI_NOTIFY)
1754 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1755 return dwRet;
1758 /**************************************************************************
1759 * MCI_Close [internal]
1761 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1763 DWORD dwRet;
1764 LPWINE_MCIDRIVER wmd;
1766 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1768 if (wDevID == MCI_ALL_DEVICE_ID) {
1769 /* FIXME: shall I notify once after all is done, or for
1770 * each of the open drivers ? if the latest, which notif
1771 * to return when only one fails ?
1773 while (MciDrivers) {
1774 /* Retrieve the device ID under lock, but send the message without,
1775 * the driver might be calling some winmm functions from another
1776 * thread before being fully stopped.
1778 EnterCriticalSection(&WINMM_cs);
1779 if (!MciDrivers)
1781 LeaveCriticalSection(&WINMM_cs);
1782 break;
1784 wDevID = MciDrivers->wDeviceID;
1785 LeaveCriticalSection(&WINMM_cs);
1786 MCI_Close(wDevID, dwParam, lpParms);
1788 return 0;
1791 if (!(wmd = MCI_GetDriver(wDevID))) {
1792 return MCIERR_INVALID_DEVICE_ID;
1795 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
1797 MCI_UnLoadMciDriver(wmd);
1799 if (dwParam & MCI_NOTIFY)
1800 mciDriverNotify(lpParms ? (HWND)lpParms->dwCallback : 0,
1801 wDevID,
1802 dwRet ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
1804 return dwRet;
1807 /**************************************************************************
1808 * MCI_WriteString [internal]
1810 DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1812 DWORD ret = 0;
1814 if (lpSrcStr) {
1815 dstSize /= sizeof(WCHAR);
1816 if (dstSize <= strlenW(lpSrcStr)) {
1817 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1818 ret = MCIERR_PARAM_OVERFLOW;
1819 } else {
1820 strcpyW(lpDstStr, lpSrcStr);
1822 } else {
1823 *lpDstStr = 0;
1825 return ret;
1828 /**************************************************************************
1829 * MCI_Sysinfo [internal]
1831 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1833 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1834 WCHAR buf[2048], *s = buf, *p;
1835 LPWINE_MCIDRIVER wmd;
1836 HKEY hKey;
1838 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1840 TRACE("(%08x, %08X, %08X[num=%d, wDevTyp=%u])\n",
1841 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1843 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1844 case MCI_SYSINFO_QUANTITY:
1845 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1846 if (dwFlags & MCI_SYSINFO_OPEN) {
1847 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1848 EnterCriticalSection(&WINMM_cs);
1849 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1850 cnt++;
1852 LeaveCriticalSection(&WINMM_cs);
1853 } else {
1854 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1855 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1856 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1857 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1858 RegCloseKey( hKey );
1860 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1861 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1863 } else {
1864 if (dwFlags & MCI_SYSINFO_OPEN) {
1865 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
1866 EnterCriticalSection(&WINMM_cs);
1867 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1868 if (wmd->wType == lpParms->wDeviceType) cnt++;
1870 LeaveCriticalSection(&WINMM_cs);
1871 } else {
1872 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
1873 FIXME("Don't know how to get # of MCI devices of a given type\n");
1874 cnt = 1;
1877 *(DWORD*)lpParms->lpstrReturn = cnt;
1878 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1879 ret = MCI_INTEGER_RETURNED;
1880 break;
1881 case MCI_SYSINFO_INSTALLNAME:
1882 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1883 if ((wmd = MCI_GetDriver(uDevID))) {
1884 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1885 wmd->lpstrDeviceType);
1886 } else {
1887 *lpParms->lpstrReturn = 0;
1888 ret = MCIERR_INVALID_DEVICE_ID;
1890 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1891 break;
1892 case MCI_SYSINFO_NAME:
1893 TRACE("MCI_SYSINFO_NAME\n");
1894 if (dwFlags & MCI_SYSINFO_OPEN) {
1895 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1896 ret = MCIERR_UNRECOGNIZED_COMMAND;
1897 } else {
1898 s = NULL;
1899 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1900 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1901 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1902 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1903 lpParms->dwNumber <= cnt) {
1904 DWORD bufLen = sizeof(buf);
1905 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1906 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1907 s = buf;
1909 RegCloseKey( hKey );
1911 if (!s) {
1912 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1913 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1914 TRACE("%d: %s\n", cnt, debugstr_w(p));
1915 if (cnt == lpParms->dwNumber - 1) {
1916 s = p;
1917 break;
1922 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1924 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1925 break;
1926 default:
1927 TRACE("Unsupported flag value=%08x\n", dwFlags);
1928 ret = MCIERR_UNRECOGNIZED_COMMAND;
1930 return ret;
1933 /**************************************************************************
1934 * MCI_Break [internal]
1936 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1938 DWORD dwRet = 0;
1940 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1942 if (dwFlags & MCI_NOTIFY)
1943 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1944 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1946 return dwRet;
1949 /**************************************************************************
1950 * MCI_Sound [internal]
1952 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1954 DWORD dwRet = 0;
1956 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1958 if (dwFlags & MCI_SOUND_NAME)
1959 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1960 else
1961 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1962 if (dwFlags & MCI_NOTIFY)
1963 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1964 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1966 return dwRet;
1969 /**************************************************************************
1970 * MCI_SendCommand [internal]
1972 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1,
1973 DWORD_PTR dwParam2, BOOL bFrom32)
1975 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1977 switch (wMsg) {
1978 case MCI_OPEN:
1979 if (bFrom32) {
1980 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1981 } else if (pFnMciMapMsg16To32W) {
1982 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
1983 case WINMM_MAP_OK:
1984 case WINMM_MAP_OKMEM:
1985 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1986 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
1987 break;
1988 default: break; /* so that gcc does not bark */
1991 break;
1992 case MCI_CLOSE:
1993 if (bFrom32) {
1994 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1995 } else if (pFnMciMapMsg16To32W) {
1996 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
1997 case WINMM_MAP_OK:
1998 case WINMM_MAP_OKMEM:
1999 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
2000 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
2001 break;
2002 default: break; /* so that gcc does not bark */
2005 break;
2006 case MCI_SYSINFO:
2007 if (bFrom32) {
2008 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
2009 } else if (pFnMciMapMsg16To32W) {
2010 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
2011 case WINMM_MAP_OK:
2012 case WINMM_MAP_OKMEM:
2013 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
2014 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
2015 break;
2016 default: break; /* so that gcc does not bark */
2019 break;
2020 case MCI_BREAK:
2021 if (bFrom32) {
2022 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2023 } else if (pFnMciMapMsg16To32W) {
2024 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
2025 case WINMM_MAP_OK:
2026 case WINMM_MAP_OKMEM:
2027 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2028 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
2029 break;
2030 default: break; /* so that gcc does not bark */
2033 break;
2034 case MCI_SOUND:
2035 if (bFrom32) {
2036 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
2037 } else if (pFnMciMapMsg16To32W) {
2038 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
2039 case WINMM_MAP_OK:
2040 case WINMM_MAP_OKMEM:
2041 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
2042 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
2043 break;
2044 default: break; /* so that gcc does not bark */
2047 break;
2048 default:
2049 if (wDevID == MCI_ALL_DEVICE_ID) {
2050 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2051 dwRet = MCIERR_CANNOT_USE_ALL;
2052 } else {
2053 dwRet = (bFrom32) ?
2054 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
2055 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
2057 break;
2059 return dwRet;
2062 /**************************************************************************
2063 * MCI_CleanUp [internal]
2065 * Some MCI commands need to be cleaned-up (when not called from
2066 * mciSendString), because MCI drivers return extra information for string
2067 * transformation. This function gets rid of them.
2069 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2)
2071 if (LOWORD(dwRet))
2072 return LOWORD(dwRet);
2074 switch (wMsg) {
2075 case MCI_GETDEVCAPS:
2076 switch (dwRet & 0xFFFF0000ul) {
2077 case 0:
2078 case MCI_COLONIZED3_RETURN:
2079 case MCI_COLONIZED4_RETURN:
2080 case MCI_INTEGER_RETURNED:
2081 /* nothing to do */
2082 break;
2083 case MCI_RESOURCE_RETURNED:
2084 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2086 LPMCI_GETDEVCAPS_PARMS lmgp;
2088 lmgp = (LPMCI_GETDEVCAPS_PARMS)(void*)dwParam2;
2089 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
2090 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
2092 break;
2093 default:
2094 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2095 HIWORD(dwRet), MCI_MessageToString(wMsg));
2097 break;
2098 case MCI_STATUS:
2099 switch (dwRet & 0xFFFF0000ul) {
2100 case 0:
2101 case MCI_COLONIZED3_RETURN:
2102 case MCI_COLONIZED4_RETURN:
2103 case MCI_INTEGER_RETURNED:
2104 /* nothing to do */
2105 break;
2106 case MCI_RESOURCE_RETURNED:
2107 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2109 LPMCI_STATUS_PARMS lsp;
2111 lsp = (LPMCI_STATUS_PARMS)(void*)dwParam2;
2112 TRACE("Changing %08x to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
2113 lsp->dwReturn = LOWORD(lsp->dwReturn);
2115 break;
2116 default:
2117 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2118 HIWORD(dwRet), MCI_MessageToString(wMsg));
2120 break;
2121 case MCI_SYSINFO:
2122 switch (dwRet & 0xFFFF0000ul) {
2123 case 0:
2124 case MCI_INTEGER_RETURNED:
2125 /* nothing to do */
2126 break;
2127 default:
2128 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2130 break;
2131 default:
2132 if (HIWORD(dwRet)) {
2133 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2134 dwRet, MCI_MessageToString(wMsg));
2136 break;
2138 return LOWORD(dwRet);
2141 /**************************************************************************
2142 * mciGetErrorStringW [WINMM.@]
2144 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2146 BOOL ret = FALSE;
2148 if (lpstrBuffer != NULL && uLength > 0 &&
2149 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2151 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
2152 ret = TRUE;
2155 return ret;
2158 /**************************************************************************
2159 * mciGetErrorStringA [WINMM.@]
2161 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2163 BOOL ret = FALSE;
2165 if (lpstrBuffer != NULL && uLength > 0 &&
2166 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2168 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2169 ret = TRUE;
2172 return ret;
2175 /**************************************************************************
2176 * mciDriverNotify [WINMM.@]
2178 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2180 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2182 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2185 /**************************************************************************
2186 * mciGetDriverData [WINMM.@]
2188 DWORD WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2190 LPWINE_MCIDRIVER wmd;
2192 TRACE("(%04x)\n", uDeviceID);
2194 wmd = MCI_GetDriver(uDeviceID);
2196 if (!wmd) {
2197 WARN("Bad uDeviceID\n");
2198 return 0L;
2201 return wmd->dwPrivate;
2204 /**************************************************************************
2205 * mciSetDriverData [WINMM.@]
2207 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD data)
2209 LPWINE_MCIDRIVER wmd;
2211 TRACE("(%04x, %08x)\n", uDeviceID, data);
2213 wmd = MCI_GetDriver(uDeviceID);
2215 if (!wmd) {
2216 WARN("Bad uDeviceID\n");
2217 return FALSE;
2220 wmd->dwPrivate = data;
2221 return TRUE;
2224 /**************************************************************************
2225 * mciSendCommandW [WINMM.@]
2228 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2230 DWORD dwRet;
2232 TRACE("(%08x, %s, %08lx, %08lx)\n",
2233 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2235 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, TRUE);
2236 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2237 TRACE("=> %08x\n", dwRet);
2238 return dwRet;
2241 /**************************************************************************
2242 * mciSendCommandA [WINMM.@]
2244 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2246 DWORD ret;
2247 int mapped;
2249 TRACE("(%08x, %s, %08lx, %08lx)\n",
2250 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2252 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2253 if (mapped == -1)
2255 FIXME("message %04x mapping failed\n", wMsg);
2256 return MMSYSERR_NOMEM;
2258 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2259 if (mapped)
2260 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2261 return ret;
2264 /**************************************************************************
2265 * mciGetDeviceIDA [WINMM.@]
2267 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2269 LPWSTR w = MCI_strdupAtoW(lpstrName);
2270 UINT ret = MCIERR_OUT_OF_MEMORY;
2272 if (w)
2274 ret = mciGetDeviceIDW(w);
2275 HeapFree(GetProcessHeap(), 0, w);
2277 return ret;
2280 /**************************************************************************
2281 * mciGetDeviceIDW [WINMM.@]
2283 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2285 return MCI_GetDriverFromString(lpwstrName);
2288 /******************************************************************
2289 * MyUserYield
2291 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
2293 static void MyUserYield(void)
2295 HMODULE mod = GetModuleHandleA( "user32.dll" );
2296 if (mod)
2298 FARPROC proc = GetProcAddress( mod, "UserYield16" );
2299 if (proc) proc();
2303 /**************************************************************************
2304 * MCI_DefYieldProc [internal]
2306 UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2308 INT16 ret;
2310 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2312 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2313 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2314 MyUserYield();
2315 ret = 0;
2316 } else {
2317 MSG msg;
2319 msg.hwnd = HWND_32(HIWORD(data));
2320 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2321 ret = -1;
2323 return ret;
2326 /**************************************************************************
2327 * mciSetYieldProc [WINMM.@]
2329 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2331 LPWINE_MCIDRIVER wmd;
2333 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2335 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2336 WARN("Bad uDeviceID\n");
2337 return FALSE;
2340 wmd->lpfnYieldProc = fpYieldProc;
2341 wmd->dwYieldData = dwYieldData;
2342 wmd->bIs32 = TRUE;
2344 return TRUE;
2347 /**************************************************************************
2348 * mciGetDeviceIDFromElementIDA [WINMM.@]
2350 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2352 LPWSTR w = MCI_strdupAtoW(lpstrType);
2353 UINT ret = 0;
2355 if (w)
2357 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2358 HeapFree(GetProcessHeap(), 0, w);
2360 return ret;
2363 /**************************************************************************
2364 * mciGetDeviceIDFromElementIDW [WINMM.@]
2366 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2368 /* FIXME: that's rather strange, there is no
2369 * mciGetDeviceIDFromElementID32A in winmm.spec
2371 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2372 return 0;
2375 /**************************************************************************
2376 * mciGetYieldProc [WINMM.@]
2378 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2380 LPWINE_MCIDRIVER wmd;
2382 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2384 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2385 WARN("Bad uDeviceID\n");
2386 return NULL;
2388 if (!wmd->lpfnYieldProc) {
2389 WARN("No proc set\n");
2390 return NULL;
2392 if (!wmd->bIs32) {
2393 WARN("Proc is 32 bit\n");
2394 return NULL;
2396 return wmd->lpfnYieldProc;
2399 /**************************************************************************
2400 * mciGetCreatorTask [WINMM.@]
2402 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2404 LPWINE_MCIDRIVER wmd;
2405 HTASK ret = 0;
2407 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
2409 TRACE("(%u) => %p\n", uDeviceID, ret);
2410 return ret;
2413 /**************************************************************************
2414 * mciDriverYield [WINMM.@]
2416 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2418 LPWINE_MCIDRIVER wmd;
2419 UINT ret = 0;
2421 TRACE("(%04x)\n", uDeviceID);
2423 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || !wmd->bIs32) {
2424 MyUserYield();
2425 } else {
2426 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
2429 return ret;