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 /**************************************************************************
548 * MCI_GetDevTypeFromResource [internal]
550 static UINT MCI_GetDevTypeFromResource(LPCWSTR lpstrName)
554 for (uDevType = MCI_DEVTYPE_FIRST; uDevType <= MCI_DEVTYPE_LAST; uDevType++) {
555 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
556 /* FIXME: ignore digits suffix */
557 if (!strcmpiW(buf, lpstrName))
564 #define MAX_MCICMDTABLE 20
565 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
567 typedef struct tagWINE_MCICMDTABLE {
571 UINT nVerbs; /* number of verbs in command table */
572 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
573 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
575 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
577 /**************************************************************************
578 * MCI_IsCommandTableValid [internal]
580 static BOOL MCI_IsCommandTableValid(UINT uTbl)
589 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
590 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
592 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
595 lmem = S_MciCmdTable[uTbl].lpTable;
598 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
599 flg = *(const DWORD*)lmem;
600 eid = *(const WORD*)(lmem + sizeof(DWORD));
601 lmem += sizeof(DWORD) + sizeof(WORD);
603 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
605 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
606 case MCI_STRING: if (inCst) return FALSE; break;
607 case MCI_INTEGER: if (!*str) return FALSE; break;
608 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
609 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
610 case MCI_FLAG: if (!*str) return FALSE; break;
611 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
612 case MCI_RECT: if (!*str || inCst) return FALSE; break;
613 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
614 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
615 default: return FALSE;
617 } while (eid != MCI_END_COMMAND_LIST);
621 /**************************************************************************
622 * MCI_DumpCommandTable [internal]
624 static BOOL MCI_DumpCommandTable(UINT uTbl)
631 if (!MCI_IsCommandTableValid(uTbl)) {
632 ERR("Ooops: %d is not valid\n", uTbl);
636 lmem = S_MciCmdTable[uTbl].lpTable;
640 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
641 flg = *(const DWORD*)lmem;
642 eid = *(const WORD*)(lmem + sizeof(DWORD));
643 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
644 lmem += sizeof(DWORD) + sizeof(WORD);
645 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
646 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
647 } while (eid != MCI_END_COMMAND_LIST);
652 /**************************************************************************
653 * MCI_GetCommandTable [internal]
655 static UINT MCI_GetCommandTable(UINT uDevType)
661 /* first look up existing for existing devType */
662 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
663 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
667 /* well try to load id */
668 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
669 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
672 } else if (uDevType == 0) {
673 static const WCHAR wszCore[] = {'C','O','R','E',0};
676 uTbl = MCI_NO_COMMAND_TABLE;
678 HRSRC hRsrc = FindResourceW(hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
681 if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
683 uTbl = MCI_SetCommandTable(hMem, uDevType);
685 WARN("No command table found in resource %p[%s]\n",
686 hWinMM32Instance, debugstr_w(str));
689 TRACE("=> %d\n", uTbl);
693 /**************************************************************************
694 * MCI_SetCommandTable [internal]
696 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType)
699 static BOOL bInitDone = FALSE;
702 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
703 * can be called with 0 as a uDevType to retrieve it.
708 MCI_GetCommandTable(0);
710 TRACE("(%p, %u)\n", hMem, uDevType);
711 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
712 if (!S_MciCmdTable[uTbl].lpTable) {
718 S_MciCmdTable[uTbl].uDevType = uDevType;
719 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
720 S_MciCmdTable[uTbl].hMem = hMem;
723 MCI_DumpCommandTable(uTbl);
726 /* create the verbs table */
727 /* get # of entries */
728 lmem = S_MciCmdTable[uTbl].lpTable;
732 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
733 eid = *(const WORD*)(lmem + sizeof(DWORD));
734 lmem += sizeof(DWORD) + sizeof(WORD);
735 if (eid == MCI_COMMAND_HEAD)
737 } while (eid != MCI_END_COMMAND_LIST);
739 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
740 S_MciCmdTable[uTbl].nVerbs = count;
742 lmem = S_MciCmdTable[uTbl].lpTable;
746 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
747 eid = *(const WORD*)(lmem + sizeof(DWORD));
748 lmem += sizeof(DWORD) + sizeof(WORD);
749 if (eid == MCI_COMMAND_HEAD)
750 S_MciCmdTable[uTbl].aVerbs[count++] = str;
751 } while (eid != MCI_END_COMMAND_LIST);
752 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
757 return MCI_NO_COMMAND_TABLE;
760 /**************************************************************************
761 * MCI_UnLoadMciDriver [internal]
763 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
765 LPWINE_MCIDRIVER* tmp;
770 CloseDriver(wmd->hDriver, 0, 0);
772 if (wmd->dwPrivate != 0)
773 WARN("Unloading mci driver with non nul dwPrivate field\n");
775 EnterCriticalSection(&WINMM_cs);
776 for (tmp = &MciDrivers; *tmp; tmp = &(*tmp)->lpNext) {
782 LeaveCriticalSection(&WINMM_cs);
784 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
785 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
787 HeapFree(GetProcessHeap(), 0, wmd);
791 /**************************************************************************
792 * MCI_OpenMciDriver [internal]
794 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
798 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
801 /* First load driver */
802 wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp);
803 return wmd->hDriver != NULL;
806 /**************************************************************************
807 * MCI_LoadMciDriver [internal]
809 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
811 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
812 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
813 MCI_OPEN_DRIVER_PARMSW modp;
816 if (!wmd || !strDevTyp) {
817 dwRet = MCIERR_OUT_OF_MEMORY;
821 wmd->lpfnYieldProc = MCI_DefYieldProc;
822 wmd->dwYieldData = VK_CANCEL;
823 wmd->CreatorThread = GetCurrentThreadId();
825 EnterCriticalSection(&WINMM_cs);
826 /* wmd must be inserted in list before sending opening the driver, because it
827 * may want to lookup at wDevID
829 wmd->lpNext = MciDrivers;
832 for (modp.wDeviceID = MCI_MAGIC;
833 MCI_GetDriver(modp.wDeviceID) != 0;
836 wmd->wDeviceID = modp.wDeviceID;
838 LeaveCriticalSection(&WINMM_cs);
840 TRACE("wDevID=%04X\n", modp.wDeviceID);
842 modp.lpstrParams = NULL;
844 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
845 /* silence warning if all is used... some bogus program use commands like
848 if (strcmpiW(strDevTyp, wszAll) == 0) {
849 dwRet = MCIERR_CANNOT_USE_ALL;
851 FIXME("Couldn't load driver for type %s.\n",
852 debugstr_w(strDevTyp));
853 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
858 /* FIXME: should also check that module's description is of the form
859 * MODULENAME:[MCI] comment
862 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
863 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
864 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
866 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
867 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
869 wmd->lpstrDeviceType = strDevTyp;
870 wmd->wType = modp.wType;
872 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
873 modp.wDeviceID, modp.wType, modp.wDeviceID);
877 MCI_UnLoadMciDriver(wmd);
878 HeapFree(GetProcessHeap(), 0, strDevTyp);
883 /**************************************************************************
884 * MCI_SendCommandFrom32 [internal]
886 static DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
888 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
889 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
892 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
897 /**************************************************************************
898 * MCI_FinishOpen [internal]
900 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
903 LPCWSTR alias = NULL;
904 /* Open always defines an alias for further reference */
905 if (dwParam & MCI_OPEN_ALIAS) /* open ... alias */
906 alias = lpParms->lpstrAlias;
908 if ((dwParam & MCI_OPEN_ELEMENT) /* open file.wav */
909 && !(dwParam & MCI_OPEN_ELEMENT_ID))
910 alias = lpParms->lpstrElementName;
911 else if (dwParam & MCI_OPEN_TYPE ) /* open cdaudio */
912 alias = wmd->lpstrDeviceType;
915 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(alias)+1) * sizeof(WCHAR));
916 if (!wmd->lpstrAlias) return MCIERR_OUT_OF_MEMORY;
917 strcpyW( wmd->lpstrAlias, alias);
918 /* In most cases, natives adds MCI_OPEN_ALIAS to the flags passed to the driver.
919 * Don't. The drivers don't care about the winmm alias. */
921 lpParms->wDeviceID = wmd->wDeviceID;
923 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
927 /**************************************************************************
928 * MCI_FindCommand [internal]
930 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
934 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
937 /* another improvement would be to have the aVerbs array sorted,
938 * so that we could use a dichotomic search on it, rather than this dumb
941 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
942 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
943 return S_MciCmdTable[uTbl].aVerbs[idx];
949 /**************************************************************************
950 * MCI_GetReturnType [internal]
952 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
954 lpCmd = (LPCWSTR)((const BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
955 if (*lpCmd == '\0' && *(const WORD*)((const BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
956 return *(const DWORD*)(lpCmd + 1);
961 /**************************************************************************
962 * MCI_GetMessage [internal]
964 static WORD MCI_GetMessage(LPCWSTR lpCmd)
966 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
969 /**************************************************************************
970 * MCI_GetDWord [internal]
972 static BOOL MCI_GetDWord(DWORD_PTR* data, LPWSTR* ptr)
977 val = strtoulW(*ptr, &ret, 0);
981 case ' ': ret++; break;
982 default: return FALSE;
990 /**************************************************************************
991 * MCI_GetString [internal]
993 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
997 /* see if we have a quoted string */
999 ptr = strchrW(*str = ptr + 1, '"');
1000 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
1001 /* FIXME: shall we escape \" from string ?? */
1002 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1003 *ptr++ = '\0'; /* remove trailing " */
1004 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
1006 ptr = strchrW(ptr, ' ');
1011 ptr = *args + strlenW(*args);
1020 #define MCI_DATA_SIZE 16
1022 /**************************************************************************
1023 * MCI_ParseOptArgs [internal]
1025 static DWORD MCI_ParseOptArgs(DWORD_PTR* data, int _offset, LPCWSTR lpCmd,
1026 LPWSTR args, LPDWORD dwFlags)
1031 DWORD dwRet, flg, cflg = 0;
1035 /* loop on arguments */
1037 lmem = (const char*)lpCmd;
1038 found = inCst = FALSE;
1041 /* skip any leading white space(s) */
1042 while (*args == ' ') args++;
1043 TRACE("args=%s\n", debugstr_w(args));
1045 do { /* loop on options for command table for the requested verb */
1046 str = (LPCWSTR)lmem;
1047 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1048 flg = *(const DWORD*)lmem;
1049 eid = *(const WORD*)(lmem + sizeof(DWORD));
1050 lmem += sizeof(DWORD) + sizeof(WORD);
1051 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1055 inCst = TRUE; cflg = flg; break;
1056 case MCI_END_CONSTANT:
1057 /* there may be additional integral values after flag in constant */
1058 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1061 inCst = FALSE; cflg = 0;
1064 if (offset != _offset) {
1065 ERR("MCI_RETURN not in first position\n");
1066 return MCIERR_PARSER_INTERNAL;
1070 if (strncmpiW(args, str, len) == 0 &&
1071 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1072 /* store good values into data[] */
1074 while (*args == ' ') args++;
1078 case MCI_COMMAND_HEAD:
1080 case MCI_END_COMMAND:
1081 case MCI_END_COMMAND_LIST:
1082 case MCI_CONSTANT: /* done above */
1083 case MCI_END_CONSTANT: /* done above */
1087 TRACE("flag=%08x\n", flg);
1091 data[offset] |= flg;
1094 TRACE("flag=%08x constant=%08x\n", cflg, flg);
1097 if (!MCI_GetDWord(&(data[offset]), &args)) {
1098 return MCIERR_BAD_INTEGER;
1100 TRACE("flag=%08x int=%ld\n", flg, data[offset]);
1104 /* store rect in data (offset..offset+3) */
1106 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1107 !MCI_GetDWord(&(data[offset+1]), &args) ||
1108 !MCI_GetDWord(&(data[offset+2]), &args) ||
1109 !MCI_GetDWord(&(data[offset+3]), &args)) {
1110 ERR("Bad rect %s\n", debugstr_w(args));
1111 return MCIERR_BAD_INTEGER;
1113 TRACE("flag=%08x for rectangle\n", flg);
1117 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1119 TRACE("flag=%08x string=%s\n", flg, debugstr_w((LPWSTR)data[offset]));
1121 default: ERR("oops\n");
1123 /* exit inside while loop, except if just entered in constant area definition */
1124 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1126 /* have offset incremented if needed */
1128 case MCI_COMMAND_HEAD:
1130 case MCI_END_COMMAND:
1131 case MCI_END_COMMAND_LIST:
1133 case MCI_FLAG: break;
1134 case MCI_INTEGER: if (!inCst) offset++; break;
1135 case MCI_END_CONSTANT:
1136 case MCI_STRING: offset++; break;
1137 case MCI_RECT: offset += 4; break;
1138 default: ERR("oops\n");
1141 } while (eid != MCI_END_COMMAND);
1143 WARN("Optarg %s not found\n", debugstr_w(args));
1144 return MCIERR_UNRECOGNIZED_COMMAND;
1146 if (offset == MCI_DATA_SIZE) {
1147 ERR("Internal data[] buffer overflow\n");
1148 return MCIERR_PARSER_INTERNAL;
1154 /**************************************************************************
1155 * MCI_HandleReturnValues [internal]
1157 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1158 DWORD_PTR* data, LPWSTR lpstrRet, UINT uRetLen)
1160 static const WCHAR wszLd [] = {'%','l','d',0};
1161 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1162 static const WCHAR wszCol3[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1163 static const WCHAR wszCol4[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1167 case 0: /* nothing to return */
1170 switch (dwRet & 0xFFFF0000ul) {
1172 case MCI_INTEGER_RETURNED:
1173 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1175 case MCI_RESOURCE_RETURNED:
1176 /* return string which ID is HIWORD(data[1]),
1177 * string is loaded from mmsystem.dll */
1178 LoadStringW(hWinMM32Instance, HIWORD(data[1]), lpstrRet, uRetLen);
1180 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1181 /* return string which ID is HIWORD(data[1]),
1182 * string is loaded from driver */
1183 /* FIXME: this is wrong for a 16 bit handle */
1184 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1185 HIWORD(data[1]), lpstrRet, uRetLen);
1187 case MCI_COLONIZED3_RETURN:
1188 snprintfW(lpstrRet, uRetLen, wszCol3,
1189 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1190 LOBYTE(HIWORD(data[1])));
1192 case MCI_COLONIZED4_RETURN:
1193 snprintfW(lpstrRet, uRetLen, wszCol4,
1194 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1195 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1197 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1201 switch (dwRet & 0xFFFF0000ul) {
1203 /* nothing to do data[1] == lpstrRet */
1205 case MCI_INTEGER_RETURNED:
1206 data[1] = *(LPDWORD)lpstrRet;
1207 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1210 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1215 if (dwRet & 0xFFFF0000ul)
1216 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1217 snprintfW(lpstrRet, uRetLen, wszLd4,
1218 data[1], data[2], data[3], data[4]);
1220 default: ERR("oops\n");
1223 return LOWORD(dwRet);
1226 /**************************************************************************
1227 * mciSendStringW [WINMM.@]
1229 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1230 UINT uRetLen, HWND hwndCallback)
1232 LPWSTR verb, dev, args;
1233 LPWINE_MCIDRIVER wmd = 0;
1234 MCIDEVICEID uDevID, auto_open = 0;
1235 DWORD dwFlags = 0, dwRet = 0;
1237 DWORD_PTR data[MCI_DATA_SIZE];
1241 static const WCHAR wszNew[] = {'n','e','w',0};
1242 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1243 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1244 static const WCHAR wszSysinfo[] = {'s','y','s','i','n','f','o',0};
1245 static const WCHAR wszSound[] = {'s','o','u','n','d',0};
1246 static const WCHAR wszBreak[] = {'b','r','e','a','k',0};
1248 TRACE("(%s, %p, %d, %p)\n",
1249 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1250 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1252 /* format is <command> <device> <optargs> */
1253 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1254 return MCIERR_OUT_OF_MEMORY;
1255 strcpyW( verb, lpstrCommand );
1258 memset(data, 0, sizeof(data));
1260 if (!(args = strchrW(verb, ' '))) {
1261 dwRet = MCIERR_MISSING_DEVICE_NAME;
1265 if ((dwRet = MCI_GetString(&dev, &args))) {
1268 uDevID = strcmpiW(dev, wszAll) ? 0 : MCI_ALL_DEVICE_ID;
1270 /* Determine devType from open */
1271 if (!strcmpW(verb, wszOpen)) {
1272 LPWSTR devType, tmp;
1275 /* case dev == 'new' has to be handled */
1276 if (!strcmpW(dev, wszNew)) {
1278 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1280 tmp = strchrW(devType, ' ');
1281 if (tmp) *tmp = '\0';
1282 devType = str_dup_upper(devType);
1283 if (tmp) *tmp = ' ';
1284 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1286 WARN("open new requires device type\n");
1287 dwRet = MCIERR_MISSING_DEVICE_NAME;
1290 } else if ((devType = strchrW(dev, '!')) != NULL) {
1292 tmp = devType; devType = dev; dev = tmp;
1294 dwFlags |= MCI_OPEN_TYPE;
1295 data[2] = (DWORD_PTR)devType;
1296 devType = str_dup_upper(devType);
1297 dwFlags |= MCI_OPEN_ELEMENT;
1298 data[3] = (DWORD_PTR)dev;
1299 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1300 /* this is the name of a mci driver's type */
1301 tmp = strchrW(dev, ' ');
1302 if (tmp) *tmp = '\0';
1303 data[2] = (DWORD_PTR)dev;
1304 devType = str_dup_upper(dev);
1305 if (tmp) *tmp = ' ';
1306 dwFlags |= MCI_OPEN_TYPE;
1308 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1310 tmp = strchrW(devType, ' ');
1311 if (tmp) *tmp = '\0';
1312 devType = str_dup_upper(devType);
1313 if (tmp) *tmp = ' ';
1314 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1316 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1319 devType = str_dup_upper(buf);
1321 dwFlags |= MCI_OPEN_ELEMENT;
1322 data[3] = (DWORD_PTR)dev;
1324 if (MCI_ALL_DEVICE_ID == uDevID) {
1325 dwRet = MCIERR_CANNOT_USE_ALL;
1328 if (!strstrW(args, wszSAliasS) && !dev) {
1329 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1333 dwRet = MCI_LoadMciDriver(devType, &wmd);
1334 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1335 dwRet = MCIERR_INVALID_DEVICE_NAME;
1336 HeapFree(GetProcessHeap(), 0, devType);
1339 } else if (!strcmpW(verb, wszSysinfo) || !strcmpW(verb, wszSound) || !strcmpW(verb, wszBreak)) {
1340 /* Prevent auto-open for system commands. */
1341 } else if ((MCI_ALL_DEVICE_ID != uDevID) && !(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1343 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1344 WCHAR buf[138], retbuf[6];
1345 snprintfW(buf, sizeof(buf)/sizeof(WCHAR), wszOpenWait, dev);
1346 /* open via mciSendString handles quoting, dev!file syntax and alias creation */
1347 if ((dwRet = mciSendStringW(buf, retbuf, sizeof(retbuf)/sizeof(WCHAR), 0)) != 0)
1349 auto_open = strtoulW(retbuf, NULL, 10);
1350 TRACE("auto-opened %u\n", auto_open);
1352 /* FIXME: test for notify flag (how to preparse?) before opening */
1353 /* FIXME: Accept only core commands yet parse them with the specific table */
1354 wmd = MCI_GetDriver(auto_open);
1356 ERR("No auto-open device %d for %s\n", auto_open, debugstr_w(dev));
1357 dwRet = MCIERR_INVALID_DEVICE_ID;
1362 /* get the verb in the different command tables */
1364 /* try the device specific command table */
1365 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1367 /* try the type specific command table */
1368 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1369 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1370 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1371 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1374 /* try core command table */
1375 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1378 TRACE("Command %s not found!\n", debugstr_w(verb));
1379 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1382 wMsg = MCI_GetMessage(lpCmd);
1384 /* set return information */
1385 switch (retType = MCI_GetReturnType(lpCmd)) {
1386 case 0: offset = 1; break;
1387 case MCI_INTEGER: offset = 2; break;
1388 case MCI_STRING: data[1] = (DWORD_PTR)lpstrRet; data[2] = uRetLen; offset = 3; break;
1389 case MCI_RECT: offset = 5; break;
1390 default: ERR("oops\n");
1393 TRACE("verb=%s on dev=%s; offset=%d\n",
1394 debugstr_w(verb), debugstr_w(dev), offset);
1396 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1399 /* set up call back */
1401 if (dwFlags & MCI_NOTIFY) {
1402 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1405 /* FIXME: the command should get its own notification window set up and
1406 * ask for device closing while processing the notification mechanism.
1407 * hwndCallback = ...
1408 * dwFlags |= MCI_NOTIFY;
1409 * In the meantime special-case all commands but PLAY and RECORD below. */
1411 if (dwFlags & MCI_NOTIFY) {
1412 data[0] = (DWORD_PTR)hwndCallback;
1417 if (strcmpW(verb, wszOpen)) {
1418 FIXME("Cannot open with command %s\n", debugstr_w(verb));
1419 dwRet = MCIERR_INTERNAL;
1425 /* Requirements on dev depend on the flags:
1426 * alias with INSTALLNAME, name like "digitalvideo"
1427 * with QUANTITY and NAME. */
1429 LPMCI_SYSINFO_PARMSW lpParms = (LPMCI_SYSINFO_PARMSW)data;
1430 lpParms->wDeviceType = MCI_ALL_DEVICE_ID;
1431 if (uDevID != MCI_ALL_DEVICE_ID) {
1432 if (dwFlags & MCI_SYSINFO_INSTALLNAME)
1433 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1434 else if (!(lpParms->wDeviceType = MCI_GetDevTypeFromResource(dev))) {
1435 dwRet = MCIERR_DEVICE_TYPE_REQUIRED;
1443 TRACE("[%d, %s, %08x, %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx]\n",
1444 wmd ? wmd->wDeviceID : uDevID, MCI_MessageToString(wMsg), dwFlags,
1445 data[0], data[1], data[2], data[3], data[4],
1446 data[5], data[6], data[7], data[8], data[9]);
1448 if (wMsg == MCI_OPEN) {
1449 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1451 /* FIXME: notification is not properly shared across two opens */
1453 dwRet = MCI_SendCommand(wmd ? wmd->wDeviceID : uDevID, wMsg, dwFlags, (DWORD_PTR)data);
1455 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1456 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1457 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1461 /* PLAY and RECORD are the only known non-immediate commands */
1462 if (LOWORD(dwRet) || !(wMsg == MCI_PLAY || wMsg == MCI_RECORD))
1463 MCI_SendCommand(auto_open, MCI_CLOSE, 0, 0);
1465 FIXME("leaking auto-open device %u\n", auto_open);
1467 if (wMsg == MCI_OPEN && LOWORD(dwRet) && wmd)
1468 MCI_UnLoadMciDriver(wmd);
1469 HeapFree(GetProcessHeap(), 0, verb);
1473 /**************************************************************************
1474 * mciSendStringA [WINMM.@]
1476 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1477 UINT uRetLen, HWND hwndCallback)
1479 LPWSTR lpwstrCommand;
1480 LPWSTR lpwstrRet = NULL;
1484 /* FIXME: is there something to do with lpstrReturnString ? */
1485 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1486 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1487 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1490 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1492 WARN("no memory\n");
1493 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1494 return MCIERR_OUT_OF_MEMORY;
1497 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1498 if (!ret && lpwstrRet)
1499 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1500 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1501 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1505 /**************************************************************************
1506 * mciExecute [WINMM.@]
1508 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1513 TRACE("(%s)!\n", lpstrCommand);
1515 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1517 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1518 sprintf(strRet, "Unknown MCI error (%d)", ret);
1520 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1522 /* FIXME: what shall I return ? */
1526 /**************************************************************************
1527 * mciLoadCommandResource [WINMM.@]
1529 * Strangely, this function only exists as a UNICODE one.
1531 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1533 UINT ret = MCI_NO_COMMAND_TABLE;
1537 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1539 /* if a file named "resname.mci" exits, then load resource "resname" from it
1540 * otherwise directly from driver
1541 * We don't support it (who uses this feature ?), but we check anyway
1545 /* FIXME: we should put this back into order, but I never found a program
1546 * actually using this feature, so we may not need it
1551 strcat(strcpy(buf, resname), ".mci");
1552 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1553 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1557 if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
1558 (hMem = LoadResource(hInst, hRsrc))) {
1559 ret = MCI_SetCommandTable(hMem, type);
1562 else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
1564 TRACE("=> %04x\n", ret);
1568 /**************************************************************************
1569 * mciFreeCommandResource [WINMM.@]
1571 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1573 TRACE("(%08x)!\n", uTable);
1575 if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
1578 FreeResource(S_MciCmdTable[uTable].hMem);
1579 S_MciCmdTable[uTable].hMem = NULL;
1580 S_MciCmdTable[uTable].lpTable = NULL;
1581 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
1582 S_MciCmdTable[uTable].aVerbs = 0;
1583 S_MciCmdTable[uTable].nVerbs = 0;
1587 /**************************************************************************
1588 * MCI_Open [internal]
1590 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1592 WCHAR strDevTyp[128];
1594 LPWINE_MCIDRIVER wmd = NULL;
1596 TRACE("(%08X, %p)\n", dwParam, lpParms);
1597 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1599 /* only two low bytes are generic, the other ones are dev type specific */
1600 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1601 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1602 MCI_NOTIFY|MCI_WAIT)
1603 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1604 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1606 #undef WINE_MCIDRIVER_SUPP
1610 if (dwParam & MCI_OPEN_TYPE) {
1611 if (dwParam & MCI_OPEN_TYPE_ID) {
1612 WORD uDevType = LOWORD(lpParms->lpstrDeviceType);
1614 if (uDevType < MCI_DEVTYPE_FIRST ||
1615 uDevType > MCI_DEVTYPE_LAST ||
1616 !LoadStringW(hWinMM32Instance, uDevType,
1617 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1618 dwRet = MCIERR_BAD_INTEGER;
1623 if (lpParms->lpstrDeviceType == NULL) {
1624 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1627 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1628 ptr = strchrW(strDevTyp, '!');
1630 /* this behavior is not documented in windows. However, since, in
1631 * some occasions, MCI_OPEN handling is translated by WinMM into
1632 * a call to mciSendString("open <type>"); this code shall be correct
1634 if (dwParam & MCI_OPEN_ELEMENT) {
1635 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1636 debugstr_w(lpParms->lpstrElementName),
1637 debugstr_w(strDevTyp));
1638 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1641 dwParam |= MCI_OPEN_ELEMENT;
1643 /* FIXME: not a good idea to write in user supplied buffer */
1644 lpParms->lpstrElementName = ptr;
1648 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1651 if (dwParam & MCI_OPEN_ELEMENT) {
1652 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1654 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1655 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1656 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1660 if (!lpParms->lpstrElementName) {
1661 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1665 /* type, if given as a parameter, supersedes file extension */
1666 if (!strDevTyp[0] &&
1667 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1668 strDevTyp, sizeof(strDevTyp))) {
1669 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1670 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1671 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1674 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1675 strcpyW(strDevTyp, wszCdAudio);
1679 if (strDevTyp[0] == 0) {
1680 FIXME("Couldn't load driver\n");
1681 dwRet = MCIERR_INVALID_DEVICE_NAME;
1685 if (dwParam & MCI_OPEN_ALIAS) {
1686 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1687 if (!lpParms->lpstrAlias) {
1688 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1693 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1697 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1698 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1699 /* FIXME: is dwRet the correct ret code ? */
1703 /* only handled devices fall through */
1704 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1708 if (wmd) MCI_UnLoadMciDriver(wmd);
1712 /**************************************************************************
1713 * MCI_Close [internal]
1715 static DWORD MCI_Close(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1718 LPWINE_MCIDRIVER wmd;
1720 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1722 /* Every device must handle MCI_NOTIFY on its own. */
1723 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1724 while (MciDrivers) {
1725 /* Retrieve the device ID under lock, but send the message without,
1726 * the driver might be calling some winmm functions from another
1727 * thread before being fully stopped.
1729 EnterCriticalSection(&WINMM_cs);
1732 LeaveCriticalSection(&WINMM_cs);
1735 wDevID = MciDrivers->wDeviceID;
1736 LeaveCriticalSection(&WINMM_cs);
1737 MCI_Close(wDevID, dwParam, lpParms);
1742 if (!(wmd = MCI_GetDriver(wDevID))) {
1743 return MCIERR_INVALID_DEVICE_ID;
1746 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD_PTR)lpParms);
1748 MCI_UnLoadMciDriver(wmd);
1753 /**************************************************************************
1754 * MCI_WriteString [internal]
1756 static DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1761 if (dstSize <= strlenW(lpSrcStr)) {
1762 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1763 ret = MCIERR_PARAM_OVERFLOW;
1765 strcpyW(lpDstStr, lpSrcStr);
1773 /**************************************************************************
1774 * MCI_Sysinfo [internal]
1776 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1778 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1779 WCHAR buf[2048], *s = buf, *p;
1780 LPWINE_MCIDRIVER wmd;
1783 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1784 if (lpParms->lpstrReturn == NULL) return MCIERR_PARAM_OVERFLOW;
1786 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1787 uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1788 if ((WORD)MCI_ALL_DEVICE_ID == LOWORD(uDevID))
1789 uDevID = MCI_ALL_DEVICE_ID; /* Be compatible with Win9x */
1791 switch (dwFlags & ~(MCI_SYSINFO_OPEN|MCI_NOTIFY|MCI_WAIT)) {
1792 case MCI_SYSINFO_QUANTITY:
1793 if (lpParms->dwRetSize < sizeof(DWORD))
1794 return MCIERR_PARAM_OVERFLOW;
1795 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1796 if (uDevID == MCI_ALL_DEVICE_ID) {
1797 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1798 if (dwFlags & MCI_SYSINFO_OPEN) {
1799 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1800 EnterCriticalSection(&WINMM_cs);
1801 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1804 LeaveCriticalSection(&WINMM_cs);
1806 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1807 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1808 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1809 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1810 RegCloseKey( hKey );
1812 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1813 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1816 if (dwFlags & MCI_SYSINFO_OPEN) {
1817 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms->wDeviceType);
1818 EnterCriticalSection(&WINMM_cs);
1819 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1820 if (wmd->wType == lpParms->wDeviceType) cnt++;
1822 LeaveCriticalSection(&WINMM_cs);
1824 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms->wDeviceType);
1825 FIXME("Don't know how to get # of MCI devices of a given type\n");
1826 /* name = LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType))
1827 * then lookup registry and/or system.ini for name, ignoring digits suffix */
1828 switch (LOWORD(lpParms->wDeviceType)) {
1829 case MCI_DEVTYPE_CD_AUDIO:
1830 case MCI_DEVTYPE_WAVEFORM_AUDIO:
1831 case MCI_DEVTYPE_SEQUENCER:
1834 default: /* "digitalvideo" gets 0 because it's not in the registry */
1839 *(DWORD*)lpParms->lpstrReturn = cnt;
1840 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1841 ret = MCI_INTEGER_RETURNED;
1842 /* return ret; Only Win9x sends a notification in this case. */
1844 case MCI_SYSINFO_INSTALLNAME:
1845 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1846 if ((wmd = MCI_GetDriver(uDevID))) {
1847 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1848 wmd->lpstrDeviceType);
1850 *lpParms->lpstrReturn = 0;
1851 ret = (uDevID == MCI_ALL_DEVICE_ID)
1852 ? MCIERR_CANNOT_USE_ALL : MCIERR_INVALID_DEVICE_NAME;
1854 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1856 case MCI_SYSINFO_NAME:
1858 if (dwFlags & MCI_SYSINFO_OPEN) {
1859 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1860 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1861 uDevID == MCI_ALL_DEVICE_ID ? MCI_ALL_DEVICE_ID : lpParms->wDeviceType);
1862 EnterCriticalSection(&WINMM_cs);
1863 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1864 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1865 if (uDevID == MCI_ALL_DEVICE_ID ||
1866 lpParms->wDeviceType == wmd->wType) {
1868 if (cnt == lpParms->dwNumber) {
1869 s = wmd->lpstrAlias;
1874 LeaveCriticalSection(&WINMM_cs);
1875 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, s) : MCIERR_OUTOFRANGE;
1876 } else if (MCI_ALL_DEVICE_ID == uDevID) {
1877 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms->dwNumber);
1878 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1879 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1880 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1881 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1882 lpParms->dwNumber <= cnt) {
1883 DWORD bufLen = sizeof(buf)/sizeof(buf[0]);
1884 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1885 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1888 RegCloseKey( hKey );
1891 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1892 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1893 TRACE("%d: %s\n", cnt, debugstr_w(p));
1894 if (cnt == lpParms->dwNumber - 1) {
1901 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, s) : MCIERR_OUTOFRANGE;
1903 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms->wDeviceType);
1904 /* Cheating: what is asked for is the nth device from the registry. */
1905 if (1 != lpParms->dwNumber || /* Handle only one of each kind. */
1906 lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST)
1907 ret = MCIERR_OUTOFRANGE;
1909 LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType),
1910 lpParms->lpstrReturn, lpParms->dwRetSize);
1914 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1917 TRACE("Unsupported flag value=%08x\n", dwFlags);
1918 ret = MCIERR_UNRECOGNIZED_KEYWORD;
1920 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1921 mciDriverNotify((HWND)lpParms->dwCallback, uDevID, MCI_NOTIFY_SUCCESSFUL);
1925 /**************************************************************************
1926 * MCI_Break [internal]
1928 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1932 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1933 FIXME("(%04x) vkey %04X stub\n", dwFlags, lpParms->nVirtKey);
1935 if (MMSYSERR_NOERROR==dwRet && (dwFlags & MCI_NOTIFY))
1936 mciDriverNotify((HWND)lpParms->dwCallback, wDevID, MCI_NOTIFY_SUCCESSFUL);
1940 /**************************************************************************
1941 * MCI_Sound [internal]
1943 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1947 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1949 if (dwFlags & MCI_SOUND_NAME)
1950 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1952 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1954 if (MMSYSERR_NOERROR==dwRet && (dwFlags & MCI_NOTIFY))
1955 mciDriverNotify((HWND)lpParms->dwCallback, wDevID, MCI_NOTIFY_SUCCESSFUL);
1959 /**************************************************************************
1960 * MCI_SendCommand [internal]
1962 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1964 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1968 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1971 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1974 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1977 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1980 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
1983 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1984 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1985 dwRet = MCIERR_CANNOT_USE_ALL;
1987 dwRet = MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2);
1994 /**************************************************************************
1995 * MCI_CleanUp [internal]
1997 * Some MCI commands need to be cleaned-up (when not called from
1998 * mciSendString), because MCI drivers return extra information for string
1999 * transformation. This function gets rid of them.
2001 static LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD_PTR dwParam2)
2004 return LOWORD(dwRet);
2007 case MCI_GETDEVCAPS:
2008 switch (dwRet & 0xFFFF0000ul) {
2010 case MCI_COLONIZED3_RETURN:
2011 case MCI_COLONIZED4_RETURN:
2012 case MCI_INTEGER_RETURNED:
2015 case MCI_RESOURCE_RETURNED:
2016 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2018 LPMCI_GETDEVCAPS_PARMS lmgp;
2020 lmgp = (LPMCI_GETDEVCAPS_PARMS)dwParam2;
2021 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
2022 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
2026 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2027 HIWORD(dwRet), MCI_MessageToString(wMsg));
2031 switch (dwRet & 0xFFFF0000ul) {
2033 case MCI_COLONIZED3_RETURN:
2034 case MCI_COLONIZED4_RETURN:
2035 case MCI_INTEGER_RETURNED:
2038 case MCI_RESOURCE_RETURNED:
2039 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2041 LPMCI_STATUS_PARMS lsp;
2043 lsp = (LPMCI_STATUS_PARMS)dwParam2;
2044 TRACE("Changing %08lx to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
2045 lsp->dwReturn = LOWORD(lsp->dwReturn);
2049 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2050 HIWORD(dwRet), MCI_MessageToString(wMsg));
2054 switch (dwRet & 0xFFFF0000ul) {
2056 case MCI_INTEGER_RETURNED:
2060 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2064 if (HIWORD(dwRet)) {
2065 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2066 dwRet, MCI_MessageToString(wMsg));
2070 return LOWORD(dwRet);
2073 /**************************************************************************
2074 * mciGetErrorStringW [WINMM.@]
2076 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2080 if (lpstrBuffer != NULL && uLength > 0 &&
2081 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2083 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
2090 /**************************************************************************
2091 * mciGetErrorStringA [WINMM.@]
2093 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2097 if (lpstrBuffer != NULL && uLength > 0 &&
2098 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2100 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2107 /**************************************************************************
2108 * mciDriverNotify [WINMM.@]
2110 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2112 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2114 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2117 /**************************************************************************
2118 * mciGetDriverData [WINMM.@]
2120 DWORD_PTR WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2122 LPWINE_MCIDRIVER wmd;
2124 TRACE("(%04x)\n", uDeviceID);
2126 wmd = MCI_GetDriver(uDeviceID);
2129 WARN("Bad uDeviceID\n");
2133 return wmd->dwPrivate;
2136 /**************************************************************************
2137 * mciSetDriverData [WINMM.@]
2139 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD_PTR data)
2141 LPWINE_MCIDRIVER wmd;
2143 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2145 wmd = MCI_GetDriver(uDeviceID);
2148 WARN("Bad uDeviceID\n");
2152 wmd->dwPrivate = data;
2156 /**************************************************************************
2157 * mciSendCommandW [WINMM.@]
2160 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2164 TRACE("(%08x, %s, %08lx, %08lx)\n",
2165 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2167 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2);
2168 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2169 TRACE("=> %08x\n", dwRet);
2173 /**************************************************************************
2174 * mciSendCommandA [WINMM.@]
2176 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2181 TRACE("(%08x, %s, %08lx, %08lx)\n",
2182 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2184 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2187 FIXME("message %04x mapping failed\n", wMsg);
2188 return MCIERR_OUT_OF_MEMORY;
2190 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2192 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2196 /**************************************************************************
2197 * mciGetDeviceIDA [WINMM.@]
2199 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2201 LPWSTR w = MCI_strdupAtoW(lpstrName);
2202 UINT ret = MCIERR_OUT_OF_MEMORY;
2206 ret = mciGetDeviceIDW(w);
2207 HeapFree(GetProcessHeap(), 0, w);
2212 /**************************************************************************
2213 * mciGetDeviceIDW [WINMM.@]
2215 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2217 return MCI_GetDriverFromString(lpwstrName);
2220 /**************************************************************************
2221 * MCI_DefYieldProc [internal]
2223 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2228 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2230 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2231 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2232 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2235 msg.hwnd = HWND_32(HIWORD(data));
2236 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2242 /**************************************************************************
2243 * mciSetYieldProc [WINMM.@]
2245 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2247 LPWINE_MCIDRIVER wmd;
2249 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2251 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2252 WARN("Bad uDeviceID\n");
2256 wmd->lpfnYieldProc = fpYieldProc;
2257 wmd->dwYieldData = dwYieldData;
2262 /**************************************************************************
2263 * mciGetDeviceIDFromElementIDA [WINMM.@]
2265 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2267 LPWSTR w = MCI_strdupAtoW(lpstrType);
2272 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2273 HeapFree(GetProcessHeap(), 0, w);
2278 /**************************************************************************
2279 * mciGetDeviceIDFromElementIDW [WINMM.@]
2281 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2283 /* FIXME: that's rather strange, there is no
2284 * mciGetDeviceIDFromElementID32A in winmm.spec
2286 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2290 /**************************************************************************
2291 * mciGetYieldProc [WINMM.@]
2293 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2295 LPWINE_MCIDRIVER wmd;
2297 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2299 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2300 WARN("Bad uDeviceID\n");
2303 if (!wmd->lpfnYieldProc) {
2304 WARN("No proc set\n");
2307 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
2308 return wmd->lpfnYieldProc;
2311 /**************************************************************************
2312 * mciGetCreatorTask [WINMM.@]
2314 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2316 LPWINE_MCIDRIVER wmd;
2319 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)(DWORD_PTR)wmd->CreatorThread;
2321 TRACE("(%u) => %p\n", uDeviceID, ret);
2325 /**************************************************************************
2326 * mciDriverYield [WINMM.@]
2328 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2330 LPWINE_MCIDRIVER wmd;
2333 TRACE("(%04x)\n", uDeviceID);
2335 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc) {
2337 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2339 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);