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
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
37 * - command table handling isn't thread safe
41 #include "wine/port.h"
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(mci);
65 /* First MCI valid device ID (0 means error) */
66 #define MCI_MAGIC 0x0001
69 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};
70 static const WCHAR wszNull [] = {0};
71 static const WCHAR wszAll [] = {'A','L','L',0};
72 static const WCHAR wszMci [] = {'M','C','I',0};
73 static const WCHAR wszOpen [] = {'o','p','e','n',0};
74 static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
76 static WINE_MCIDRIVER *MciDrivers;
78 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
79 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType);
81 /* dup a string and uppercase it */
82 static inline LPWSTR str_dup_upper( LPCWSTR str )
84 INT len = (strlenW(str) + 1) * sizeof(WCHAR);
85 LPWSTR p = HeapAlloc( GetProcessHeap(), 0, len );
88 memcpy( p, str, len );
94 /**************************************************************************
95 * MCI_GetDriver [internal]
97 static LPWINE_MCIDRIVER MCI_GetDriver(UINT wDevID)
99 LPWINE_MCIDRIVER wmd = 0;
101 EnterCriticalSection(&WINMM_cs);
102 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
103 if (wmd->wDeviceID == wDevID)
106 LeaveCriticalSection(&WINMM_cs);
110 /**************************************************************************
111 * MCI_GetDriverFromString [internal]
113 static UINT MCI_GetDriverFromString(LPCWSTR lpstrName)
115 LPWINE_MCIDRIVER wmd;
121 if (!strcmpiW(lpstrName, wszAll))
122 return MCI_ALL_DEVICE_ID;
124 EnterCriticalSection(&WINMM_cs);
125 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
126 if (wmd->lpstrAlias && strcmpiW(wmd->lpstrAlias, lpstrName) == 0) {
127 ret = wmd->wDeviceID;
130 if (wmd->lpstrDeviceType && strcmpiW(wmd->lpstrDeviceType, lpstrName) == 0) {
131 ret = wmd->wDeviceID;
135 LeaveCriticalSection(&WINMM_cs);
140 /**************************************************************************
141 * MCI_MessageToString [internal]
143 static const char* MCI_MessageToString(UINT wMsg)
145 #define CASE(s) case (s): return #s
155 CASE(DRV_QUERYCONFIGURE);
158 CASE(DRV_EXITSESSION);
159 CASE(DRV_EXITAPPLICATION);
163 CASE(MCI_CLOSE_DRIVER);
172 CASE(MCI_GETDEVCAPS);
176 CASE(MCI_OPEN_DRIVER);
194 /* constants for digital video */
208 return wine_dbg_sprintf("MCI_<<%04X>>", wMsg);
212 static LPWSTR MCI_strdupAtoW( LPCSTR str )
217 if (!str) return NULL;
218 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
219 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
220 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
224 static int MCI_MapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
226 if (msg < DRV_RESERVED) return 0;
261 { /* MCI_ANIM_OPEN_PARMS is the largest known MCI_OPEN_PARMS
262 * structure, larger than MCI_WAVE_OPEN_PARMS */
263 MCI_ANIM_OPEN_PARMSA *mci_openA = (MCI_ANIM_OPEN_PARMSA*)*dwParam2;
264 MCI_ANIM_OPEN_PARMSW *mci_openW;
267 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW));
270 *ptr++ = *dwParam2; /* save the previous pointer */
271 *dwParam2 = (DWORD_PTR)ptr;
272 mci_openW = (MCI_ANIM_OPEN_PARMSW *)ptr;
274 if (dwParam1 & MCI_NOTIFY)
275 mci_openW->dwCallback = mci_openA->dwCallback;
277 if (dwParam1 & MCI_OPEN_TYPE)
279 if (dwParam1 & MCI_OPEN_TYPE_ID)
280 mci_openW->lpstrDeviceType = (LPCWSTR)mci_openA->lpstrDeviceType;
282 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
284 if (dwParam1 & MCI_OPEN_ELEMENT)
286 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
287 mci_openW->lpstrElementName = (LPCWSTR)mci_openA->lpstrElementName;
289 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
291 if (dwParam1 & MCI_OPEN_ALIAS)
292 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
293 /* We don't know how many DWORD follow, as
294 * the structure depends on the device. */
295 if (HIWORD(dwParam1))
296 memcpy(&mci_openW->dwStyle, &mci_openA->dwStyle, sizeof(MCI_ANIM_OPEN_PARMSW) - sizeof(MCI_OPEN_PARMSW));
301 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
303 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
304 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
306 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
307 if (!mci_windowW) return -1;
309 *dwParam2 = (DWORD_PTR)mci_windowW;
311 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
313 if (dwParam1 & MCI_NOTIFY)
314 mci_windowW->dwCallback = mci_windowA->dwCallback;
315 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
316 mci_windowW->hWnd = mci_windowA->hWnd;
317 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
318 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
325 if (dwParam1 & (MCI_SYSINFO_INSTALLNAME | MCI_SYSINFO_NAME))
327 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
328 MCI_SYSINFO_PARMSW *mci_sysinfoW;
331 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
334 *ptr++ = *dwParam2; /* save the previous pointer */
335 *dwParam2 = (DWORD_PTR)ptr;
336 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
338 if (dwParam1 & MCI_NOTIFY)
339 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
341 /* Size is measured in numbers of characters, despite what MSDN says. */
342 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
343 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize * sizeof(WCHAR));
344 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
345 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
351 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
352 MCI_INFO_PARMSW *mci_infoW;
355 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
358 *ptr++ = *dwParam2; /* save the previous pointer */
359 *dwParam2 = (DWORD_PTR)ptr;
360 mci_infoW = (MCI_INFO_PARMSW *)ptr;
362 if (dwParam1 & MCI_NOTIFY)
363 mci_infoW->dwCallback = mci_infoA->dwCallback;
365 /* Size is measured in numbers of characters. */
366 mci_infoW->dwRetSize = mci_infoA->dwRetSize;
367 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize * sizeof(WCHAR));
374 { /* All these commands have the same layout: callback + string + optional rect */
375 MCI_OVLY_LOAD_PARMSA *mci_loadA = (MCI_OVLY_LOAD_PARMSA *)*dwParam2;
376 MCI_OVLY_LOAD_PARMSW *mci_loadW;
378 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
379 if (!mci_loadW) return -1;
381 *dwParam2 = (DWORD_PTR)mci_loadW;
382 if (dwParam1 & MCI_NOTIFY)
383 mci_loadW->dwCallback = mci_loadA->dwCallback;
384 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
385 if ((MCI_SAVE == msg && dwParam1 & MCI_DGV_RECT) ||
386 (MCI_LOAD == msg && dwParam1 & MCI_OVLY_RECT) ||
387 (MCI_CAPTURE == msg && dwParam1 & MCI_DGV_CAPTURE_AT) ||
388 (MCI_RESTORE == msg && dwParam1 & MCI_DGV_RESTORE_AT))
389 mci_loadW->rc = mci_loadA->rc;
394 { /* All these commands have the same layout: callback + string */
395 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
396 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
398 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
399 if (!mci_vd_escapeW) return -1;
401 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
402 if (dwParam1 & MCI_NOTIFY)
403 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
404 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
409 if (!(dwParam1 & (MCI_DGV_SETVIDEO_QUALITY | MCI_DGV_SETVIDEO_ALG
410 | MCI_DGV_SETAUDIO_QUALITY | MCI_DGV_SETAUDIO_ALG)))
412 /* fall through to default */
417 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
418 return 0; /* pass through untouched */
422 static void MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
429 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
430 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
431 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)dwParam2;
433 mci_openA->wDeviceID = mci_openW->wDeviceID;
435 if (dwParam1 & MCI_OPEN_TYPE)
437 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
438 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrDeviceType);
440 if (dwParam1 & MCI_OPEN_ELEMENT)
442 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
443 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrElementName);
445 if (dwParam1 & MCI_OPEN_ALIAS)
446 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrAlias);
447 HeapFree(GetProcessHeap(), 0, ptr);
451 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
453 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
455 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
456 HeapFree(GetProcessHeap(), 0, mci_windowW);
461 if (dwParam1 & (MCI_SYSINFO_INSTALLNAME | MCI_SYSINFO_NAME))
463 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
464 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
465 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)dwParam2;
469 WideCharToMultiByte(CP_ACP, 0,
470 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
471 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
475 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
476 HeapFree(GetProcessHeap(), 0, ptr);
481 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
482 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
483 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)dwParam2;
487 WideCharToMultiByte(CP_ACP, 0,
488 mci_infoW->lpstrReturn, mci_infoW->dwRetSize,
489 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
493 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
494 HeapFree(GetProcessHeap(), 0, ptr);
501 { /* All these commands have the same layout: callback + string + optional rect */
502 MCI_OVLY_LOAD_PARMSW *mci_loadW = (MCI_OVLY_LOAD_PARMSW *)dwParam2;
504 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
505 HeapFree(GetProcessHeap(), 0, mci_loadW);
510 { /* All these commands have the same layout: callback + string */
511 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
513 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
514 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
519 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
524 /**************************************************************************
525 * MCI_GetDevTypeFromFileName [internal]
527 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
531 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
532 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
533 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
534 if ((tmp = strrchrW(fileName, '.'))) {
535 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
536 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
538 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
540 if (lRet == ERROR_SUCCESS) return 0;
542 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
544 return MCIERR_EXTENSION_NOT_FOUND;
547 #define MAX_MCICMDTABLE 20
548 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
550 typedef struct tagWINE_MCICMDTABLE {
554 UINT nVerbs; /* number of verbs in command table */
555 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
556 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
558 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
560 /**************************************************************************
561 * MCI_IsCommandTableValid [internal]
563 static BOOL MCI_IsCommandTableValid(UINT uTbl)
572 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
573 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
575 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
578 lmem = S_MciCmdTable[uTbl].lpTable;
581 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
582 flg = *(const DWORD*)lmem;
583 eid = *(const WORD*)(lmem + sizeof(DWORD));
584 lmem += sizeof(DWORD) + sizeof(WORD);
586 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
588 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
589 case MCI_STRING: if (inCst) return FALSE; break;
590 case MCI_INTEGER: if (!*str) return FALSE; break;
591 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
592 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
593 case MCI_FLAG: if (!*str) return FALSE; break;
594 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
595 case MCI_RECT: if (!*str || inCst) return FALSE; break;
596 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
597 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
598 default: return FALSE;
600 } while (eid != MCI_END_COMMAND_LIST);
604 /**************************************************************************
605 * MCI_DumpCommandTable [internal]
607 static BOOL MCI_DumpCommandTable(UINT uTbl)
614 if (!MCI_IsCommandTableValid(uTbl)) {
615 ERR("Ooops: %d is not valid\n", uTbl);
619 lmem = S_MciCmdTable[uTbl].lpTable;
623 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
624 flg = *(const DWORD*)lmem;
625 eid = *(const WORD*)(lmem + sizeof(DWORD));
626 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
627 lmem += sizeof(DWORD) + sizeof(WORD);
628 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
629 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
630 } while (eid != MCI_END_COMMAND_LIST);
635 /**************************************************************************
636 * MCI_GetCommandTable [internal]
638 static UINT MCI_GetCommandTable(UINT uDevType)
644 /* first look up existing for existing devType */
645 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
646 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
650 /* well try to load id */
651 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
652 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
655 } else if (uDevType == 0) {
656 static const WCHAR wszCore[] = {'C','O','R','E',0};
659 uTbl = MCI_NO_COMMAND_TABLE;
661 HRSRC hRsrc = FindResourceW(hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
664 if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
666 uTbl = MCI_SetCommandTable(hMem, uDevType);
668 WARN("No command table found in resource %p[%s]\n",
669 hWinMM32Instance, debugstr_w(str));
672 TRACE("=> %d\n", uTbl);
676 /**************************************************************************
677 * MCI_SetCommandTable [internal]
679 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType)
682 static BOOL bInitDone = FALSE;
685 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
686 * can be called with 0 as a uDevType to retrieve it.
691 MCI_GetCommandTable(0);
693 TRACE("(%p, %u)\n", hMem, uDevType);
694 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
695 if (!S_MciCmdTable[uTbl].lpTable) {
701 S_MciCmdTable[uTbl].uDevType = uDevType;
702 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
703 S_MciCmdTable[uTbl].hMem = hMem;
706 MCI_DumpCommandTable(uTbl);
709 /* create the verbs table */
710 /* get # of entries */
711 lmem = S_MciCmdTable[uTbl].lpTable;
715 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
716 eid = *(const WORD*)(lmem + sizeof(DWORD));
717 lmem += sizeof(DWORD) + sizeof(WORD);
718 if (eid == MCI_COMMAND_HEAD)
720 } while (eid != MCI_END_COMMAND_LIST);
722 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
723 S_MciCmdTable[uTbl].nVerbs = count;
725 lmem = S_MciCmdTable[uTbl].lpTable;
729 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
730 eid = *(const WORD*)(lmem + sizeof(DWORD));
731 lmem += sizeof(DWORD) + sizeof(WORD);
732 if (eid == MCI_COMMAND_HEAD)
733 S_MciCmdTable[uTbl].aVerbs[count++] = str;
734 } while (eid != MCI_END_COMMAND_LIST);
735 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
740 return MCI_NO_COMMAND_TABLE;
743 /**************************************************************************
744 * MCI_UnLoadMciDriver [internal]
746 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
748 LPWINE_MCIDRIVER* tmp;
753 CloseDriver(wmd->hDriver, 0, 0);
755 if (wmd->dwPrivate != 0)
756 WARN("Unloading mci driver with non nul dwPrivate field\n");
758 EnterCriticalSection(&WINMM_cs);
759 for (tmp = &MciDrivers; *tmp; tmp = &(*tmp)->lpNext) {
765 LeaveCriticalSection(&WINMM_cs);
767 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
768 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
770 HeapFree(GetProcessHeap(), 0, wmd);
774 /**************************************************************************
775 * MCI_OpenMciDriver [internal]
777 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
781 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
784 /* First load driver */
785 wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp);
786 return wmd->hDriver != NULL;
789 /**************************************************************************
790 * MCI_LoadMciDriver [internal]
792 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
794 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
795 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
796 MCI_OPEN_DRIVER_PARMSW modp;
799 if (!wmd || !strDevTyp) {
800 dwRet = MCIERR_OUT_OF_MEMORY;
804 wmd->lpfnYieldProc = MCI_DefYieldProc;
805 wmd->dwYieldData = VK_CANCEL;
806 wmd->CreatorThread = GetCurrentThreadId();
808 EnterCriticalSection(&WINMM_cs);
809 /* wmd must be inserted in list before sending opening the driver, because it
810 * may want to lookup at wDevID
812 wmd->lpNext = MciDrivers;
815 for (modp.wDeviceID = MCI_MAGIC;
816 MCI_GetDriver(modp.wDeviceID) != 0;
819 wmd->wDeviceID = modp.wDeviceID;
821 LeaveCriticalSection(&WINMM_cs);
823 TRACE("wDevID=%04X\n", modp.wDeviceID);
825 modp.lpstrParams = NULL;
827 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
828 /* silence warning if all is used... some bogus program use commands like
831 if (strcmpiW(strDevTyp, wszAll) == 0) {
832 dwRet = MCIERR_CANNOT_USE_ALL;
834 FIXME("Couldn't load driver for type %s.\n",
835 debugstr_w(strDevTyp));
836 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
841 /* FIXME: should also check that module's description is of the form
842 * MODULENAME:[MCI] comment
845 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
846 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
847 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
849 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
850 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
852 wmd->lpstrDeviceType = strDevTyp;
853 wmd->wType = modp.wType;
855 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
856 modp.wDeviceID, modp.wType, modp.wDeviceID);
860 MCI_UnLoadMciDriver(wmd);
861 HeapFree(GetProcessHeap(), 0, strDevTyp);
866 /**************************************************************************
867 * MCI_SendCommandFrom32 [internal]
869 static DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
871 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
872 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
875 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
880 /**************************************************************************
881 * MCI_FinishOpen [internal]
883 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
886 LPCWSTR alias = NULL;
887 /* Open always defines an alias for further reference */
888 if (dwParam & MCI_OPEN_ALIAS) /* open ... alias */
889 alias = lpParms->lpstrAlias;
891 if ((dwParam & MCI_OPEN_ELEMENT) /* open file.wav */
892 && !(dwParam & MCI_OPEN_ELEMENT_ID))
893 alias = lpParms->lpstrElementName;
894 else if (dwParam & MCI_OPEN_TYPE ) /* open cdaudio */
895 alias = wmd->lpstrDeviceType;
898 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(alias)+1) * sizeof(WCHAR));
899 if (!wmd->lpstrAlias) return MCIERR_OUT_OF_MEMORY;
900 strcpyW( wmd->lpstrAlias, alias);
901 /* In most cases, natives adds MCI_OPEN_ALIAS to the flags passed to the driver.
902 * Don't. The drivers don't care about the winmm alias. */
904 lpParms->wDeviceID = wmd->wDeviceID;
906 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
910 /**************************************************************************
911 * MCI_FindCommand [internal]
913 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
917 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
920 /* another improvement would be to have the aVerbs array sorted,
921 * so that we could use a dichotomic search on it, rather than this dumb
924 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
925 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
926 return S_MciCmdTable[uTbl].aVerbs[idx];
932 /**************************************************************************
933 * MCI_GetReturnType [internal]
935 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
937 lpCmd = (LPCWSTR)((const BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
938 if (*lpCmd == '\0' && *(const WORD*)((const BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
939 return *(const DWORD*)(lpCmd + 1);
944 /**************************************************************************
945 * MCI_GetMessage [internal]
947 static WORD MCI_GetMessage(LPCWSTR lpCmd)
949 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
952 /**************************************************************************
953 * MCI_GetDWord [internal]
955 static BOOL MCI_GetDWord(DWORD_PTR* data, LPWSTR* ptr)
960 val = strtoulW(*ptr, &ret, 0);
964 case ' ': ret++; break;
965 default: return FALSE;
973 /**************************************************************************
974 * MCI_GetString [internal]
976 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
980 /* see if we have a quoted string */
982 ptr = strchrW(*str = ptr + 1, '"');
983 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
984 /* FIXME: shall we escape \" from string ?? */
985 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
986 *ptr++ = '\0'; /* remove trailing " */
987 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
989 ptr = strchrW(ptr, ' ');
994 ptr = *args + strlenW(*args);
1003 #define MCI_DATA_SIZE 16
1005 /**************************************************************************
1006 * MCI_ParseOptArgs [internal]
1008 static DWORD MCI_ParseOptArgs(DWORD_PTR* data, int _offset, LPCWSTR lpCmd,
1009 LPWSTR args, LPDWORD dwFlags)
1014 DWORD dwRet, flg, cflg = 0;
1018 /* loop on arguments */
1020 lmem = (const char*)lpCmd;
1021 found = inCst = FALSE;
1024 /* skip any leading white space(s) */
1025 while (*args == ' ') args++;
1026 TRACE("args=%s\n", debugstr_w(args));
1028 do { /* loop on options for command table for the requested verb */
1029 str = (LPCWSTR)lmem;
1030 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1031 flg = *(const DWORD*)lmem;
1032 eid = *(const WORD*)(lmem + sizeof(DWORD));
1033 lmem += sizeof(DWORD) + sizeof(WORD);
1034 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1038 inCst = TRUE; cflg = flg; break;
1039 case MCI_END_CONSTANT:
1040 /* there may be additional integral values after flag in constant */
1041 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1044 inCst = FALSE; cflg = 0;
1047 if (offset != _offset) {
1048 ERR("MCI_RETURN not in first position\n");
1049 return MCIERR_PARSER_INTERNAL;
1053 if (strncmpiW(args, str, len) == 0 &&
1054 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1055 /* store good values into data[] */
1057 while (*args == ' ') args++;
1061 case MCI_COMMAND_HEAD:
1063 case MCI_END_COMMAND:
1064 case MCI_END_COMMAND_LIST:
1065 case MCI_CONSTANT: /* done above */
1066 case MCI_END_CONSTANT: /* done above */
1070 TRACE("flag=%08x\n", flg);
1074 data[offset] |= flg;
1077 TRACE("flag=%08x constant=%08x\n", cflg, flg);
1080 if (!MCI_GetDWord(&(data[offset]), &args)) {
1081 return MCIERR_BAD_INTEGER;
1083 TRACE("flag=%08x int=%ld\n", flg, data[offset]);
1087 /* store rect in data (offset..offset+3) */
1089 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1090 !MCI_GetDWord(&(data[offset+1]), &args) ||
1091 !MCI_GetDWord(&(data[offset+2]), &args) ||
1092 !MCI_GetDWord(&(data[offset+3]), &args)) {
1093 ERR("Bad rect %s\n", debugstr_w(args));
1094 return MCIERR_BAD_INTEGER;
1096 TRACE("flag=%08x for rectangle\n", flg);
1100 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1102 TRACE("flag=%08x string=%s\n", flg, debugstr_w((LPWSTR)data[offset]));
1104 default: ERR("oops\n");
1106 /* exit inside while loop, except if just entered in constant area definition */
1107 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1109 /* have offset incremented if needed */
1111 case MCI_COMMAND_HEAD:
1113 case MCI_END_COMMAND:
1114 case MCI_END_COMMAND_LIST:
1116 case MCI_FLAG: break;
1117 case MCI_INTEGER: if (!inCst) offset++; break;
1118 case MCI_END_CONSTANT:
1119 case MCI_STRING: offset++; break;
1120 case MCI_RECT: offset += 4; break;
1121 default: ERR("oops\n");
1124 } while (eid != MCI_END_COMMAND);
1126 WARN("Optarg %s not found\n", debugstr_w(args));
1127 return MCIERR_UNRECOGNIZED_COMMAND;
1129 if (offset == MCI_DATA_SIZE) {
1130 ERR("Internal data[] buffer overflow\n");
1131 return MCIERR_PARSER_INTERNAL;
1137 /**************************************************************************
1138 * MCI_HandleReturnValues [internal]
1140 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1141 DWORD_PTR* data, LPWSTR lpstrRet, UINT uRetLen)
1143 static const WCHAR wszLd [] = {'%','l','d',0};
1144 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1145 static const WCHAR wszCol3[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1146 static const WCHAR wszCol4[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1150 case 0: /* nothing to return */
1153 switch (dwRet & 0xFFFF0000ul) {
1155 case MCI_INTEGER_RETURNED:
1156 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1158 case MCI_RESOURCE_RETURNED:
1159 /* return string which ID is HIWORD(data[1]),
1160 * string is loaded from mmsystem.dll */
1161 LoadStringW(hWinMM32Instance, HIWORD(data[1]), lpstrRet, uRetLen);
1163 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1164 /* return string which ID is HIWORD(data[1]),
1165 * string is loaded from driver */
1166 /* FIXME: this is wrong for a 16 bit handle */
1167 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1168 HIWORD(data[1]), lpstrRet, uRetLen);
1170 case MCI_COLONIZED3_RETURN:
1171 snprintfW(lpstrRet, uRetLen, wszCol3,
1172 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1173 LOBYTE(HIWORD(data[1])));
1175 case MCI_COLONIZED4_RETURN:
1176 snprintfW(lpstrRet, uRetLen, wszCol4,
1177 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1178 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1180 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1184 switch (dwRet & 0xFFFF0000ul) {
1186 /* nothing to do data[1] == lpstrRet */
1188 case MCI_INTEGER_RETURNED:
1189 data[1] = *(LPDWORD)lpstrRet;
1190 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1193 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1198 if (dwRet & 0xFFFF0000ul)
1199 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1200 snprintfW(lpstrRet, uRetLen, wszLd4,
1201 data[1], data[2], data[3], data[4]);
1203 default: ERR("oops\n");
1206 return LOWORD(dwRet);
1209 /**************************************************************************
1210 * mciSendStringW [WINMM.@]
1212 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1213 UINT uRetLen, HWND hwndCallback)
1215 LPWSTR verb, dev, args;
1216 LPWINE_MCIDRIVER wmd = 0;
1217 MCIDEVICEID uDevID, auto_open = 0;
1218 DWORD dwFlags = 0, dwRet = 0;
1220 DWORD_PTR data[MCI_DATA_SIZE];
1224 static const WCHAR wszNew[] = {'n','e','w',0};
1225 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1226 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1227 static const WCHAR wszSysinfo[] = {'s','y','s','i','n','f','o',0};
1228 static const WCHAR wszSound[] = {'s','o','u','n','d',0};
1229 static const WCHAR wszBreak[] = {'b','r','e','a','k',0};
1231 TRACE("(%s, %p, %d, %p)\n",
1232 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1233 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1235 /* format is <command> <device> <optargs> */
1236 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1237 return MCIERR_OUT_OF_MEMORY;
1238 strcpyW( verb, lpstrCommand );
1241 memset(data, 0, sizeof(data));
1243 if (!(args = strchrW(verb, ' '))) {
1244 dwRet = MCIERR_MISSING_DEVICE_NAME;
1248 if ((dwRet = MCI_GetString(&dev, &args))) {
1251 uDevID = strcmpiW(dev, wszAll) ? 0 : MCI_ALL_DEVICE_ID;
1253 /* Determine devType from open */
1254 if (!strcmpW(verb, wszOpen)) {
1255 LPWSTR devType, tmp;
1258 /* case dev == 'new' has to be handled */
1259 if (!strcmpW(dev, wszNew)) {
1261 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1263 tmp = strchrW(devType, ' ');
1264 if (tmp) *tmp = '\0';
1265 devType = str_dup_upper(devType);
1266 if (tmp) *tmp = ' ';
1267 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1269 WARN("open new requires device type\n");
1270 dwRet = MCIERR_MISSING_DEVICE_NAME;
1273 } else if ((devType = strchrW(dev, '!')) != NULL) {
1275 tmp = devType; devType = dev; dev = tmp;
1277 dwFlags |= MCI_OPEN_TYPE;
1278 data[2] = (DWORD_PTR)devType;
1279 devType = str_dup_upper(devType);
1280 dwFlags |= MCI_OPEN_ELEMENT;
1281 data[3] = (DWORD_PTR)dev;
1282 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1283 /* this is the name of a mci driver's type */
1284 tmp = strchrW(dev, ' ');
1285 if (tmp) *tmp = '\0';
1286 data[2] = (DWORD_PTR)dev;
1287 devType = str_dup_upper(dev);
1288 if (tmp) *tmp = ' ';
1289 dwFlags |= MCI_OPEN_TYPE;
1291 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1293 tmp = strchrW(devType, ' ');
1294 if (tmp) *tmp = '\0';
1295 devType = str_dup_upper(devType);
1296 if (tmp) *tmp = ' ';
1297 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1299 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1302 devType = str_dup_upper(buf);
1304 dwFlags |= MCI_OPEN_ELEMENT;
1305 data[3] = (DWORD_PTR)dev;
1307 if (MCI_ALL_DEVICE_ID == uDevID) {
1308 dwRet = MCIERR_CANNOT_USE_ALL;
1311 if (!strstrW(args, wszSAliasS) && !dev) {
1312 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1316 dwRet = MCI_LoadMciDriver(devType, &wmd);
1317 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1318 dwRet = MCIERR_INVALID_DEVICE_NAME;
1319 HeapFree(GetProcessHeap(), 0, devType);
1322 } else if (!strcmpW(verb, wszSysinfo)) {
1323 /* System commands are not subject to auto-open. */
1324 /* It's too early to handle Sysinfo here because the
1325 * requirements on dev depend on the flags:
1326 * alias with INSTALLNAME, name like "waveaudio"
1327 * with QUANTITY and NAME. */
1328 data[4] = MCI_ALL_DEVICE_ID;
1329 if (MCI_ALL_DEVICE_ID != uDevID) {
1330 /* FIXME: Map device name like waveaudio to MCI_DEVTYPE_xyz */
1331 uDevID = mciGetDeviceIDW(dev);
1332 wmd = MCI_GetDriver(uDevID);
1334 data[4] = wmd->wType;
1336 } else if (!strcmpW(verb, wszSound) || !strcmpW(verb, wszBreak)) {
1337 /* Prevent auto-open for system commands. */
1338 } else if ((MCI_ALL_DEVICE_ID != uDevID) && !(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1340 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1341 WCHAR buf[138], retbuf[6];
1342 snprintfW(buf, sizeof(buf)/sizeof(WCHAR), wszOpenWait, dev);
1343 /* open via mciSendString handles quoting, dev!file syntax and alias creation */
1344 if ((dwRet = mciSendStringW(buf, retbuf, sizeof(retbuf)/sizeof(WCHAR), 0)) != 0)
1346 auto_open = strtoulW(retbuf, NULL, 10);
1347 TRACE("auto-opened %u\n", auto_open);
1349 /* FIXME: test for notify flag (how to preparse?) before opening */
1350 /* FIXME: Accept only core commands yet parse them with the specific table */
1351 wmd = MCI_GetDriver(auto_open);
1353 ERR("No auto-open device %d for %s\n", auto_open, debugstr_w(dev));
1354 dwRet = MCIERR_INVALID_DEVICE_ID;
1359 /* get the verb in the different command tables */
1361 /* try the device specific command table */
1362 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1364 /* try the type specific command table */
1365 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1366 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1367 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1368 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1371 /* try core command table */
1372 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1375 TRACE("Command %s not found!\n", debugstr_w(verb));
1376 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1379 wMsg = MCI_GetMessage(lpCmd);
1381 /* set return information */
1382 switch (retType = MCI_GetReturnType(lpCmd)) {
1383 case 0: offset = 1; break;
1384 case MCI_INTEGER: offset = 2; break;
1385 case MCI_STRING: data[1] = (DWORD_PTR)lpstrRet; data[2] = uRetLen; offset = 3; break;
1386 case MCI_RECT: offset = 5; break;
1387 default: ERR("oops\n");
1390 TRACE("verb=%s on dev=%s; offset=%d\n",
1391 debugstr_w(verb), debugstr_w(dev), offset);
1393 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1396 /* set up call back */
1398 if (dwFlags & MCI_NOTIFY) {
1399 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1402 /* FIXME: the command should get its own notification window set up and
1403 * ask for device closing while processing the notification mechanism.
1404 * hwndCallback = ...
1405 * dwFlags |= MCI_NOTIFY;
1406 * In the meantime special-case all commands but PLAY and RECORD below. */
1408 if (dwFlags & MCI_NOTIFY) {
1409 data[0] = (DWORD_PTR)hwndCallback;
1412 if (wMsg == MCI_OPEN && strcmpW(verb, wszOpen)) {
1413 ERR("Cannot open with command %s\n", debugstr_w(verb));
1414 dwRet = MCIERR_INTERNAL;
1419 TRACE("[%d, %s, %08x, %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx]\n",
1420 wmd ? wmd->wDeviceID : uDevID, MCI_MessageToString(wMsg), dwFlags,
1421 data[0], data[1], data[2], data[3], data[4],
1422 data[5], data[6], data[7], data[8], data[9]);
1424 if (wMsg == MCI_OPEN) {
1425 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1427 /* FIXME: notification is not properly shared across two opens */
1429 dwRet = MCI_SendCommand(wmd ? wmd->wDeviceID : uDevID, wMsg, dwFlags, (DWORD_PTR)data);
1431 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1432 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1433 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1437 /* PLAY and RECORD are the only known non-immediate commands */
1438 if (LOWORD(dwRet) || !(wMsg == MCI_PLAY || wMsg == MCI_RECORD))
1439 MCI_SendCommand(auto_open, MCI_CLOSE, 0, 0);
1441 FIXME("leaking auto-open device %u\n", auto_open);
1443 if (wMsg == MCI_OPEN && LOWORD(dwRet) && wmd)
1444 MCI_UnLoadMciDriver(wmd);
1445 HeapFree(GetProcessHeap(), 0, verb);
1449 /**************************************************************************
1450 * mciSendStringA [WINMM.@]
1452 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1453 UINT uRetLen, HWND hwndCallback)
1455 LPWSTR lpwstrCommand;
1456 LPWSTR lpwstrRet = NULL;
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 );
1466 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
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 (!ret && lpwstrRet)
1475 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1476 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1477 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1481 /**************************************************************************
1482 * mciExecute [WINMM.@]
1484 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1489 TRACE("(%s)!\n", lpstrCommand);
1491 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1493 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1494 sprintf(strRet, "Unknown MCI error (%d)", ret);
1496 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1498 /* FIXME: what shall I return ? */
1502 /**************************************************************************
1503 * mciLoadCommandResource [WINMM.@]
1505 * Strangely, this function only exists as a UNICODE one.
1507 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1509 UINT ret = MCI_NO_COMMAND_TABLE;
1513 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1515 /* if a file named "resname.mci" exits, then load resource "resname" from it
1516 * otherwise directly from driver
1517 * We don't support it (who uses this feature ?), but we check anyway
1521 /* FIXME: we should put this back into order, but I never found a program
1522 * actually using this feature, so we may not need it
1527 strcat(strcpy(buf, resname), ".mci");
1528 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1529 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1533 if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
1534 (hMem = LoadResource(hInst, hRsrc))) {
1535 ret = MCI_SetCommandTable(hMem, type);
1538 else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
1540 TRACE("=> %04x\n", ret);
1544 /**************************************************************************
1545 * mciFreeCommandResource [WINMM.@]
1547 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1549 TRACE("(%08x)!\n", uTable);
1551 if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
1554 FreeResource(S_MciCmdTable[uTable].hMem);
1555 S_MciCmdTable[uTable].hMem = NULL;
1556 S_MciCmdTable[uTable].lpTable = NULL;
1557 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
1558 S_MciCmdTable[uTable].aVerbs = 0;
1559 S_MciCmdTable[uTable].nVerbs = 0;
1563 /**************************************************************************
1564 * MCI_Open [internal]
1566 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1568 WCHAR strDevTyp[128];
1570 LPWINE_MCIDRIVER wmd = NULL;
1572 TRACE("(%08X, %p)\n", dwParam, lpParms);
1573 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1575 /* only two low bytes are generic, the other ones are dev type specific */
1576 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1577 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1578 MCI_NOTIFY|MCI_WAIT)
1579 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1580 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1582 #undef WINE_MCIDRIVER_SUPP
1586 if (dwParam & MCI_OPEN_TYPE) {
1587 if (dwParam & MCI_OPEN_TYPE_ID) {
1588 WORD uDevType = LOWORD(lpParms->lpstrDeviceType);
1590 if (uDevType < MCI_DEVTYPE_FIRST ||
1591 uDevType > MCI_DEVTYPE_LAST ||
1592 !LoadStringW(hWinMM32Instance, uDevType,
1593 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1594 dwRet = MCIERR_BAD_INTEGER;
1599 if (lpParms->lpstrDeviceType == NULL) {
1600 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1603 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1604 ptr = strchrW(strDevTyp, '!');
1606 /* this behavior is not documented in windows. However, since, in
1607 * some occasions, MCI_OPEN handling is translated by WinMM into
1608 * a call to mciSendString("open <type>"); this code shall be correct
1610 if (dwParam & MCI_OPEN_ELEMENT) {
1611 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1612 debugstr_w(lpParms->lpstrElementName),
1613 debugstr_w(strDevTyp));
1614 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1617 dwParam |= MCI_OPEN_ELEMENT;
1619 /* FIXME: not a good idea to write in user supplied buffer */
1620 lpParms->lpstrElementName = ptr;
1624 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1627 if (dwParam & MCI_OPEN_ELEMENT) {
1628 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1630 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1631 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1632 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1636 if (!lpParms->lpstrElementName) {
1637 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1641 /* type, if given as a parameter, supersedes file extension */
1642 if (!strDevTyp[0] &&
1643 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1644 strDevTyp, sizeof(strDevTyp))) {
1645 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1646 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1647 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1650 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1651 strcpyW(strDevTyp, wszCdAudio);
1655 if (strDevTyp[0] == 0) {
1656 FIXME("Couldn't load driver\n");
1657 dwRet = MCIERR_INVALID_DEVICE_NAME;
1661 if (dwParam & MCI_OPEN_ALIAS) {
1662 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1663 if (!lpParms->lpstrAlias) {
1664 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1669 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1673 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1674 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1675 /* FIXME: is dwRet the correct ret code ? */
1679 /* only handled devices fall through */
1680 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1684 if (wmd) MCI_UnLoadMciDriver(wmd);
1688 /**************************************************************************
1689 * MCI_Close [internal]
1691 static DWORD MCI_Close(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1694 LPWINE_MCIDRIVER wmd;
1696 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1698 /* Every device must handle MCI_NOTIFY on its own. */
1699 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1700 while (MciDrivers) {
1701 /* Retrieve the device ID under lock, but send the message without,
1702 * the driver might be calling some winmm functions from another
1703 * thread before being fully stopped.
1705 EnterCriticalSection(&WINMM_cs);
1708 LeaveCriticalSection(&WINMM_cs);
1711 wDevID = MciDrivers->wDeviceID;
1712 LeaveCriticalSection(&WINMM_cs);
1713 MCI_Close(wDevID, dwParam, lpParms);
1718 if (!(wmd = MCI_GetDriver(wDevID))) {
1719 return MCIERR_INVALID_DEVICE_ID;
1722 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD_PTR)lpParms);
1724 MCI_UnLoadMciDriver(wmd);
1729 /**************************************************************************
1730 * MCI_WriteString [internal]
1732 static DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1737 if (dstSize <= strlenW(lpSrcStr)) {
1738 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1739 ret = MCIERR_PARAM_OVERFLOW;
1741 strcpyW(lpDstStr, lpSrcStr);
1749 /**************************************************************************
1750 * MCI_Sysinfo [internal]
1752 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1754 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1755 WCHAR buf[2048], *s = buf, *p;
1756 LPWINE_MCIDRIVER wmd;
1759 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1760 if (lpParms->lpstrReturn == NULL) return MCIERR_PARAM_OVERFLOW;
1762 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1763 uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1764 if ((WORD)MCI_ALL_DEVICE_ID == LOWORD(uDevID))
1765 uDevID = MCI_ALL_DEVICE_ID; /* Be compatible with Win9x */
1767 switch (dwFlags & ~(MCI_SYSINFO_OPEN|MCI_NOTIFY|MCI_WAIT)) {
1768 case MCI_SYSINFO_QUANTITY:
1769 if (lpParms->dwRetSize < sizeof(DWORD))
1770 return MCIERR_PARAM_OVERFLOW;
1771 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1772 if (uDevID == MCI_ALL_DEVICE_ID) {
1773 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1774 if (dwFlags & MCI_SYSINFO_OPEN) {
1775 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1776 EnterCriticalSection(&WINMM_cs);
1777 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1780 LeaveCriticalSection(&WINMM_cs);
1782 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1783 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1784 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1785 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1786 RegCloseKey( hKey );
1788 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1789 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1792 if (dwFlags & MCI_SYSINFO_OPEN) {
1793 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms->wDeviceType);
1794 EnterCriticalSection(&WINMM_cs);
1795 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1796 if (wmd->wType == lpParms->wDeviceType) cnt++;
1798 LeaveCriticalSection(&WINMM_cs);
1800 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms->wDeviceType);
1801 FIXME("Don't know how to get # of MCI devices of a given type\n");
1805 *(DWORD*)lpParms->lpstrReturn = cnt;
1806 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1807 ret = MCI_INTEGER_RETURNED;
1808 /* return ret; Only Win9x sends a notification in this case. */
1810 case MCI_SYSINFO_INSTALLNAME:
1811 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1812 if ((wmd = MCI_GetDriver(uDevID))) {
1813 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1814 wmd->lpstrDeviceType);
1816 *lpParms->lpstrReturn = 0;
1817 ret = MCIERR_INVALID_DEVICE_ID;
1819 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1821 case MCI_SYSINFO_NAME:
1823 if (dwFlags & MCI_SYSINFO_OPEN) {
1824 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1825 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1826 uDevID == MCI_ALL_DEVICE_ID ? MCI_ALL_DEVICE_ID : lpParms->wDeviceType);
1827 EnterCriticalSection(&WINMM_cs);
1828 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1829 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1830 if (uDevID == MCI_ALL_DEVICE_ID ||
1831 lpParms->wDeviceType == wmd->wType) {
1833 if (cnt == lpParms->dwNumber) {
1834 s = wmd->lpstrAlias;
1839 LeaveCriticalSection(&WINMM_cs);
1840 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, s) : MCIERR_OUTOFRANGE;
1841 } else if (MCI_ALL_DEVICE_ID == uDevID) {
1842 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms->dwNumber);
1843 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1844 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1845 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1846 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1847 lpParms->dwNumber <= cnt) {
1848 DWORD bufLen = sizeof(buf)/sizeof(buf[0]);
1849 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1850 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1853 RegCloseKey( hKey );
1856 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1857 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1858 TRACE("%d: %s\n", cnt, debugstr_w(p));
1859 if (cnt == lpParms->dwNumber - 1) {
1866 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, s) : MCIERR_OUTOFRANGE;
1868 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms->wDeviceType);
1869 /* Cheating: what is asked for is the nth device from the registry. */
1870 if (1 != lpParms->dwNumber || /* Handle only one of each kind. */
1871 lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST)
1872 ret = MCIERR_OUTOFRANGE;
1874 LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType),
1875 lpParms->lpstrReturn, lpParms->dwRetSize);
1879 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1882 TRACE("Unsupported flag value=%08x\n", dwFlags);
1883 ret = MCIERR_UNRECOGNIZED_KEYWORD;
1885 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1886 mciDriverNotify((HWND)lpParms->dwCallback, uDevID, MCI_NOTIFY_SUCCESSFUL);
1890 /**************************************************************************
1891 * MCI_Break [internal]
1893 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1897 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1898 FIXME("(%04x) vkey %04X stub\n", dwFlags, lpParms->nVirtKey);
1900 if (MMSYSERR_NOERROR==dwRet && (dwFlags & MCI_NOTIFY))
1901 mciDriverNotify((HWND)lpParms->dwCallback, wDevID, MCI_NOTIFY_SUCCESSFUL);
1905 /**************************************************************************
1906 * MCI_Sound [internal]
1908 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1912 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1914 if (dwFlags & MCI_SOUND_NAME)
1915 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1917 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1919 if (MMSYSERR_NOERROR==dwRet && (dwFlags & MCI_NOTIFY))
1920 mciDriverNotify((HWND)lpParms->dwCallback, wDevID, MCI_NOTIFY_SUCCESSFUL);
1924 /**************************************************************************
1925 * MCI_SendCommand [internal]
1927 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1929 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1933 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1936 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1939 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1942 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1945 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
1948 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1949 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1950 dwRet = MCIERR_CANNOT_USE_ALL;
1952 dwRet = MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2);
1959 /**************************************************************************
1960 * MCI_CleanUp [internal]
1962 * Some MCI commands need to be cleaned-up (when not called from
1963 * mciSendString), because MCI drivers return extra information for string
1964 * transformation. This function gets rid of them.
1966 static LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD_PTR dwParam2)
1969 return LOWORD(dwRet);
1972 case MCI_GETDEVCAPS:
1973 switch (dwRet & 0xFFFF0000ul) {
1975 case MCI_COLONIZED3_RETURN:
1976 case MCI_COLONIZED4_RETURN:
1977 case MCI_INTEGER_RETURNED:
1980 case MCI_RESOURCE_RETURNED:
1981 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1983 LPMCI_GETDEVCAPS_PARMS lmgp;
1985 lmgp = (LPMCI_GETDEVCAPS_PARMS)dwParam2;
1986 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
1987 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1991 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1992 HIWORD(dwRet), MCI_MessageToString(wMsg));
1996 switch (dwRet & 0xFFFF0000ul) {
1998 case MCI_COLONIZED3_RETURN:
1999 case MCI_COLONIZED4_RETURN:
2000 case MCI_INTEGER_RETURNED:
2003 case MCI_RESOURCE_RETURNED:
2004 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2006 LPMCI_STATUS_PARMS lsp;
2008 lsp = (LPMCI_STATUS_PARMS)dwParam2;
2009 TRACE("Changing %08lx to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
2010 lsp->dwReturn = LOWORD(lsp->dwReturn);
2014 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2015 HIWORD(dwRet), MCI_MessageToString(wMsg));
2019 switch (dwRet & 0xFFFF0000ul) {
2021 case MCI_INTEGER_RETURNED:
2025 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2029 if (HIWORD(dwRet)) {
2030 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2031 dwRet, MCI_MessageToString(wMsg));
2035 return LOWORD(dwRet);
2038 /**************************************************************************
2039 * mciGetErrorStringW [WINMM.@]
2041 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2045 if (lpstrBuffer != NULL && uLength > 0 &&
2046 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2048 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
2055 /**************************************************************************
2056 * mciGetErrorStringA [WINMM.@]
2058 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2062 if (lpstrBuffer != NULL && uLength > 0 &&
2063 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2065 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2072 /**************************************************************************
2073 * mciDriverNotify [WINMM.@]
2075 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2077 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2079 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2082 /**************************************************************************
2083 * mciGetDriverData [WINMM.@]
2085 DWORD_PTR WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2087 LPWINE_MCIDRIVER wmd;
2089 TRACE("(%04x)\n", uDeviceID);
2091 wmd = MCI_GetDriver(uDeviceID);
2094 WARN("Bad uDeviceID\n");
2098 return wmd->dwPrivate;
2101 /**************************************************************************
2102 * mciSetDriverData [WINMM.@]
2104 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD_PTR data)
2106 LPWINE_MCIDRIVER wmd;
2108 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2110 wmd = MCI_GetDriver(uDeviceID);
2113 WARN("Bad uDeviceID\n");
2117 wmd->dwPrivate = data;
2121 /**************************************************************************
2122 * mciSendCommandW [WINMM.@]
2125 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2129 TRACE("(%08x, %s, %08lx, %08lx)\n",
2130 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2132 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2);
2133 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2134 TRACE("=> %08x\n", dwRet);
2138 /**************************************************************************
2139 * mciSendCommandA [WINMM.@]
2141 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2146 TRACE("(%08x, %s, %08lx, %08lx)\n",
2147 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2149 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2152 FIXME("message %04x mapping failed\n", wMsg);
2153 return MCIERR_OUT_OF_MEMORY;
2155 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2157 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2161 /**************************************************************************
2162 * mciGetDeviceIDA [WINMM.@]
2164 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2166 LPWSTR w = MCI_strdupAtoW(lpstrName);
2167 UINT ret = MCIERR_OUT_OF_MEMORY;
2171 ret = mciGetDeviceIDW(w);
2172 HeapFree(GetProcessHeap(), 0, w);
2177 /**************************************************************************
2178 * mciGetDeviceIDW [WINMM.@]
2180 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2182 return MCI_GetDriverFromString(lpwstrName);
2185 /**************************************************************************
2186 * MCI_DefYieldProc [internal]
2188 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2193 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2195 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2196 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2197 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2200 msg.hwnd = HWND_32(HIWORD(data));
2201 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2207 /**************************************************************************
2208 * mciSetYieldProc [WINMM.@]
2210 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2212 LPWINE_MCIDRIVER wmd;
2214 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2216 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2217 WARN("Bad uDeviceID\n");
2221 wmd->lpfnYieldProc = fpYieldProc;
2222 wmd->dwYieldData = dwYieldData;
2227 /**************************************************************************
2228 * mciGetDeviceIDFromElementIDA [WINMM.@]
2230 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2232 LPWSTR w = MCI_strdupAtoW(lpstrType);
2237 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2238 HeapFree(GetProcessHeap(), 0, w);
2243 /**************************************************************************
2244 * mciGetDeviceIDFromElementIDW [WINMM.@]
2246 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2248 /* FIXME: that's rather strange, there is no
2249 * mciGetDeviceIDFromElementID32A in winmm.spec
2251 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2255 /**************************************************************************
2256 * mciGetYieldProc [WINMM.@]
2258 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2260 LPWINE_MCIDRIVER wmd;
2262 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2264 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2265 WARN("Bad uDeviceID\n");
2268 if (!wmd->lpfnYieldProc) {
2269 WARN("No proc set\n");
2272 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
2273 return wmd->lpfnYieldProc;
2276 /**************************************************************************
2277 * mciGetCreatorTask [WINMM.@]
2279 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2281 LPWINE_MCIDRIVER wmd;
2284 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)(DWORD_PTR)wmd->CreatorThread;
2286 TRACE("(%u) => %p\n", uDeviceID, ret);
2290 /**************************************************************************
2291 * mciDriverYield [WINMM.@]
2293 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2295 LPWINE_MCIDRIVER wmd;
2298 TRACE("(%04x)\n", uDeviceID);
2300 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc) {
2302 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2304 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);