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
40 /* to be cross checked:
41 * - heapalloc for *sizeof(WCHAR) when needed
42 * - size of string in WCHAR or bytes? (#chars for MCI_INFO, #bytes for MCI_SYSINFO)
46 #include "wine/port.h"
66 #include "wine/debug.h"
67 #include "wine/unicode.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(mci);
71 WINMM_MapType (*pFnMciMapMsg16To32W) (WORD,WORD,DWORD,DWORD_PTR*) = NULL;
72 WINMM_MapType (*pFnMciUnMapMsg16To32W)(WORD,WORD,DWORD,DWORD_PTR) = NULL;
73 WINMM_MapType (*pFnMciMapMsg32WTo16) (WORD,WORD,DWORD,DWORD_PTR*) = NULL;
74 WINMM_MapType (*pFnMciUnMapMsg32WTo16)(WORD,WORD,DWORD,DWORD_PTR) = NULL;
76 /* First MCI valid device ID (0 means error) */
77 #define MCI_MAGIC 0x0001
80 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};
81 static const WCHAR wszNull [] = {0};
82 static const WCHAR wszAll [] = {'A','L','L',0};
83 static const WCHAR wszMci [] = {'M','C','I',0};
84 static const WCHAR wszOpen [] = {'o','p','e','n',0};
85 static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
87 /* dup a string and uppercase it */
88 inline static LPWSTR str_dup_upper( LPCWSTR str )
90 INT len = (strlenW(str) + 1) * sizeof(WCHAR);
91 LPWSTR p = HeapAlloc( GetProcessHeap(), 0, len );
94 memcpy( p, str, len );
100 /**************************************************************************
101 * MCI_GetDriver [internal]
103 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
105 LPWINE_MCIDRIVER wmd = 0;
107 EnterCriticalSection(&WINMM_IData.cs);
108 for (wmd = WINMM_IData.lpMciDrvs; wmd; wmd = wmd->lpNext) {
109 if (wmd->wDeviceID == wDevID)
112 LeaveCriticalSection(&WINMM_IData.cs);
116 /**************************************************************************
117 * MCI_GetDriverFromString [internal]
119 UINT MCI_GetDriverFromString(LPCWSTR lpstrName)
121 LPWINE_MCIDRIVER wmd;
127 if (!strcmpiW(lpstrName, wszAll))
128 return MCI_ALL_DEVICE_ID;
130 EnterCriticalSection(&WINMM_IData.cs);
131 for (wmd = WINMM_IData.lpMciDrvs; wmd; wmd = wmd->lpNext) {
132 if (wmd->lpstrElementName && strcmpW(wmd->lpstrElementName, lpstrName) == 0) {
133 ret = wmd->wDeviceID;
136 if (wmd->lpstrDeviceType && strcmpiW(wmd->lpstrDeviceType, lpstrName) == 0) {
137 ret = wmd->wDeviceID;
140 if (wmd->lpstrAlias && strcmpiW(wmd->lpstrAlias, lpstrName) == 0) {
141 ret = wmd->wDeviceID;
145 LeaveCriticalSection(&WINMM_IData.cs);
150 /**************************************************************************
151 * MCI_MessageToString [internal]
153 const char* MCI_MessageToString(UINT wMsg)
155 static char buffer[100];
157 #define CASE(s) case (s): return #s
167 CASE(DRV_QUERYCONFIGURE);
170 CASE(DRV_EXITSESSION);
171 CASE(DRV_EXITAPPLICATION);
175 CASE(MCI_CLOSE_DRIVER);
184 CASE(MCI_GETDEVCAPS);
188 CASE(MCI_OPEN_DRIVER);
206 /* constants for digital video */
220 sprintf(buffer, "MCI_<<%04X>>", wMsg);
225 LPWSTR MCI_strdupAtoW( LPCSTR str )
230 if (!str) return NULL;
231 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
232 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
233 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
237 LPSTR MCI_strdupWtoA( LPCWSTR str )
242 if (!str) return NULL;
243 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
244 ret = HeapAlloc( GetProcessHeap(), 0, len );
245 if (ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
249 static int MCI_MapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
251 if (msg < DRV_RESERVED) return 0;
290 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA*)*dwParam2;
291 MCI_OPEN_PARMSW *mci_openW;
294 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW) + 2 * sizeof(DWORD));
297 *ptr++ = *dwParam2; /* save the previous pointer */
298 *dwParam2 = (DWORD_PTR)ptr;
299 mci_openW = (MCI_OPEN_PARMSW *)ptr;
301 if (dwParam1 & MCI_NOTIFY)
302 mci_openW->dwCallback = mci_openA->dwCallback;
304 if (dwParam1 & MCI_OPEN_TYPE)
306 if (dwParam1 & MCI_OPEN_TYPE_ID)
307 mci_openW->lpstrDeviceType = (LPWSTR)mci_openA->lpstrDeviceType;
309 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
311 if (dwParam1 & MCI_OPEN_ELEMENT)
313 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
314 mci_openW->lpstrElementName = (LPWSTR)mci_openA->lpstrElementName;
316 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
318 if (dwParam1 & MCI_OPEN_ALIAS)
319 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
320 /* FIXME: this is only needed for specific types of MCI devices, and
321 * may cause a segfault if the two DWORD:s don't exist at the end of
324 memcpy(mci_openW + 1, mci_openA + 1, 2 * sizeof(DWORD));
329 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
331 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
332 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
334 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
335 if (!mci_windowW) return -1;
337 *dwParam2 = (DWORD_PTR)mci_windowW;
339 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
341 if (dwParam1 & MCI_NOTIFY)
342 mci_windowW->dwCallback = mci_windowA->dwCallback;
343 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
344 mci_windowW->hWnd = mci_windowA->hWnd;
345 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
346 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
354 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
355 MCI_SYSINFO_PARMSW *mci_sysinfoW;
358 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
361 *ptr++ = *dwParam2; /* save the previous pointer */
362 *dwParam2 = (DWORD_PTR)ptr;
363 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
365 if (dwParam1 & MCI_NOTIFY)
366 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
368 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
369 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize);
370 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
371 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
376 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
377 MCI_INFO_PARMSW *mci_infoW;
380 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
383 *ptr++ = *dwParam2; /* save the previous pointer */
384 *dwParam2 = (DWORD_PTR)ptr;
385 mci_infoW = (MCI_INFO_PARMSW *)ptr;
387 if (dwParam1 & MCI_NOTIFY)
388 mci_infoW->dwCallback = mci_infoA->dwCallback;
390 mci_infoW->dwRetSize = mci_infoA->dwRetSize * sizeof(WCHAR); /* it's not the same as SYSINFO !!! */
391 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize);
396 MCI_SAVE_PARMSA *mci_saveA = (MCI_SAVE_PARMSA *)*dwParam2;
397 MCI_SAVE_PARMSW *mci_saveW;
399 mci_saveW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW));
400 if (!mci_saveW) return -1;
402 *dwParam2 = (DWORD_PTR)mci_saveW;
403 if (dwParam1 & MCI_NOTIFY)
404 mci_saveW->dwCallback = mci_saveA->dwCallback;
405 mci_saveW->lpfilename = MCI_strdupAtoW(mci_saveA->lpfilename);
410 MCI_LOAD_PARMSA *mci_loadA = (MCI_LOAD_PARMSA *)*dwParam2;
411 MCI_LOAD_PARMSW *mci_loadW;
413 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
414 if (!mci_loadW) return -1;
416 *dwParam2 = (DWORD_PTR)mci_loadW;
417 if (dwParam1 & MCI_NOTIFY)
418 mci_loadW->dwCallback = mci_loadA->dwCallback;
419 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
425 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
426 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
428 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
429 if (!mci_vd_escapeW) return -1;
431 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
432 if (dwParam1 & MCI_NOTIFY)
433 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
434 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
438 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
443 static DWORD MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
450 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
451 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
452 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)(ptr + 1);
454 mci_openA->wDeviceID = mci_openW->wDeviceID;
456 if (dwParam1 & MCI_OPEN_TYPE)
458 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
459 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrDeviceType);
461 if (dwParam1 & MCI_OPEN_ELEMENT)
463 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
464 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrElementName);
466 if (dwParam1 & MCI_OPEN_ALIAS)
467 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrAlias);
468 HeapFree(GetProcessHeap(), 0, ptr);
472 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
474 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
476 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
477 HeapFree(GetProcessHeap(), 0, mci_windowW);
483 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
484 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
485 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)(ptr + 1);
489 mci_sysinfoA->dwNumber = mci_sysinfoW->dwNumber;
490 mci_sysinfoA->wDeviceType = mci_sysinfoW->wDeviceType;
491 if (dwParam1 & MCI_SYSINFO_QUANTITY)
492 *(DWORD*)mci_sysinfoA->lpstrReturn = *(DWORD*)mci_sysinfoW->lpstrReturn;
494 WideCharToMultiByte(CP_ACP, 0,
495 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
496 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
500 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
501 HeapFree(GetProcessHeap(), 0, ptr);
506 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
507 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
508 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)(ptr + 1);
512 WideCharToMultiByte(CP_ACP, 0,
513 mci_infoW->lpstrReturn, mci_infoW->dwRetSize / sizeof(WCHAR),
514 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
518 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
519 HeapFree(GetProcessHeap(), 0, ptr);
524 MCI_SAVE_PARMSW *mci_saveW = (MCI_SAVE_PARMSW *)dwParam2;
526 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW->lpfilename);
527 HeapFree(GetProcessHeap(), 0, mci_saveW);
532 MCI_LOAD_PARMSW *mci_loadW = (MCI_LOAD_PARMSW *)dwParam2;
534 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
535 HeapFree(GetProcessHeap(), 0, mci_loadW);
540 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
542 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
543 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
548 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
555 /**************************************************************************
556 * MCI_GetDevTypeFromFileName [internal]
558 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
562 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
563 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
564 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
565 if ((tmp = strrchrW(fileName, '.'))) {
566 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
567 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
569 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
571 if (lRet == ERROR_SUCCESS) return 0;
573 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
575 return MCIERR_EXTENSION_NOT_FOUND;
578 #define MAX_MCICMDTABLE 20
579 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
581 typedef struct tagWINE_MCICMDTABLE {
584 UINT nVerbs; /* number of verbs in command table */
585 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
586 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
588 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
590 /**************************************************************************
591 * MCI_IsCommandTableValid [internal]
593 static BOOL MCI_IsCommandTableValid(UINT uTbl)
602 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
603 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
605 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
608 lmem = S_MciCmdTable[uTbl].lpTable;
611 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
612 flg = *(const DWORD*)lmem;
613 eid = *(const WORD*)(lmem + sizeof(DWORD));
614 lmem += sizeof(DWORD) + sizeof(WORD);
616 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
618 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
619 case MCI_STRING: if (inCst) return FALSE; break;
620 case MCI_INTEGER: if (!*str) return FALSE; break;
621 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
622 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
623 case MCI_FLAG: if (!*str) return FALSE; break;
624 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
625 case MCI_RECT: if (!*str || inCst) return FALSE; break;
626 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
627 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
628 default: return FALSE;
630 } while (eid != MCI_END_COMMAND_LIST);
634 /**************************************************************************
635 * MCI_DumpCommandTable [internal]
637 static BOOL MCI_DumpCommandTable(UINT uTbl)
644 if (!MCI_IsCommandTableValid(uTbl)) {
645 ERR("Ooops: %d is not valid\n", uTbl);
649 lmem = S_MciCmdTable[uTbl].lpTable;
653 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
654 flg = *(const DWORD*)lmem;
655 eid = *(const WORD*)(lmem + sizeof(DWORD));
656 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
657 lmem += sizeof(DWORD) + sizeof(WORD);
658 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
659 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
660 } while (eid != MCI_END_COMMAND_LIST);
665 /**************************************************************************
666 * MCI_GetCommandTable [internal]
668 static UINT MCI_GetCommandTable(UINT uDevType)
674 /* first look up existing for existing devType */
675 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
676 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
680 /* well try to load id */
681 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
682 if (LoadStringW(WINMM_IData.hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
685 } else if (uDevType == 0) {
686 static const WCHAR wszCore[] = {'C','O','R','E',0};
689 uTbl = MCI_NO_COMMAND_TABLE;
691 HRSRC hRsrc = FindResourceW(WINMM_IData.hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
694 if (hRsrc) hMem = LoadResource(WINMM_IData.hWinMM32Instance, hRsrc);
696 uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType);
698 WARN("No command table found in resource %p[%s]\n",
699 WINMM_IData.hWinMM32Instance, debugstr_w(str));
702 TRACE("=> %d\n", uTbl);
706 /**************************************************************************
707 * MCI_SetCommandTable [internal]
709 UINT MCI_SetCommandTable(void *table, UINT uDevType)
712 static BOOL bInitDone = FALSE;
715 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
716 * can be called with 0 as a uDevType to retrieve it.
721 MCI_GetCommandTable(0);
723 TRACE("(%p, %u)\n", table, uDevType);
724 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
725 if (!S_MciCmdTable[uTbl].lpTable) {
731 S_MciCmdTable[uTbl].uDevType = uDevType;
732 S_MciCmdTable[uTbl].lpTable = table;
735 MCI_DumpCommandTable(uTbl);
738 /* create the verbs table */
739 /* get # of entries */
740 lmem = S_MciCmdTable[uTbl].lpTable;
744 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
745 eid = *(const WORD*)(lmem + sizeof(DWORD));
746 lmem += sizeof(DWORD) + sizeof(WORD);
747 if (eid == MCI_COMMAND_HEAD)
749 } while (eid != MCI_END_COMMAND_LIST);
751 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
752 S_MciCmdTable[uTbl].nVerbs = count;
754 lmem = S_MciCmdTable[uTbl].lpTable;
758 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
759 eid = *(const WORD*)(lmem + sizeof(DWORD));
760 lmem += sizeof(DWORD) + sizeof(WORD);
761 if (eid == MCI_COMMAND_HEAD)
762 S_MciCmdTable[uTbl].aVerbs[count++] = str;
763 } while (eid != MCI_END_COMMAND_LIST);
764 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
769 return MCI_NO_COMMAND_TABLE;
772 /**************************************************************************
773 * MCI_DeleteCommandTable [internal]
775 BOOL MCI_DeleteCommandTable(UINT uTbl, BOOL delete)
777 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
780 if (delete) HeapFree(GetProcessHeap(), 0, (void*)S_MciCmdTable[uTbl].lpTable);
781 S_MciCmdTable[uTbl].lpTable = NULL;
782 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
783 S_MciCmdTable[uTbl].aVerbs = 0;
787 /**************************************************************************
788 * MCI_UnLoadMciDriver [internal]
790 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
792 LPWINE_MCIDRIVER* tmp;
797 CloseDriver(wmd->hDriver, 0, 0);
799 if (wmd->dwPrivate != 0)
800 WARN("Unloading mci driver with non nul dwPrivate field\n");
802 EnterCriticalSection(&WINMM_IData.cs);
803 for (tmp = &WINMM_IData.lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
809 LeaveCriticalSection(&WINMM_IData.cs);
811 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
812 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
813 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
815 HeapFree(GetProcessHeap(), 0, wmd);
819 /**************************************************************************
820 * MCI_OpenMciDriver [internal]
822 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
826 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
830 /* First load driver */
831 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
833 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32WTo16) {
836 switch (res = pFnMciMapMsg32WTo16(0, DRV_OPEN, 0, &lp)) {
837 case WINMM_MAP_MSGERROR:
838 TRACE("Not handled yet (DRV_OPEN)\n");
840 case WINMM_MAP_NOMEM:
841 TRACE("Problem mapping msg=DRV_OPEN from 32W to 16\n");
844 case WINMM_MAP_OKMEM:
845 if ((wmd->hDriver = OpenDriver(drvTyp, wszMci, lp)))
847 if (res == WINMM_MAP_OKMEM)
848 pFnMciUnMapMsg32WTo16(0, DRV_OPEN, 0, lp);
852 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
855 /**************************************************************************
856 * MCI_LoadMciDriver [internal]
858 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
860 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
861 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
862 MCI_OPEN_DRIVER_PARMSW modp;
865 if (!wmd || !strDevTyp) {
866 dwRet = MCIERR_OUT_OF_MEMORY;
870 wmd->lpfnYieldProc = MCI_DefYieldProc;
871 wmd->dwYieldData = VK_CANCEL;
872 wmd->CreatorThread = GetCurrentThreadId();
874 EnterCriticalSection(&WINMM_IData.cs);
875 /* wmd must be inserted in list before sending opening the driver, coz' it
876 * may want to lookup at wDevID
878 wmd->lpNext = WINMM_IData.lpMciDrvs;
879 WINMM_IData.lpMciDrvs = wmd;
881 for (modp.wDeviceID = MCI_MAGIC;
882 MCI_GetDriver(modp.wDeviceID) != 0;
885 wmd->wDeviceID = modp.wDeviceID;
887 LeaveCriticalSection(&WINMM_IData.cs);
889 TRACE("wDevID=%04X\n", modp.wDeviceID);
891 modp.lpstrParams = NULL;
893 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
894 /* silence warning if all is used... some bogus program use commands like
897 if (strcmpiW(strDevTyp, wszAll) == 0) {
898 dwRet = MCIERR_CANNOT_USE_ALL;
900 FIXME("Couldn't load driver for type %s.\n"
901 "If you don't have a windows installation accessible from Wine,\n"
902 "you perhaps forgot to create a [mci] section in system.ini\n",
903 debugstr_w(strDevTyp));
904 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
909 /* FIXME: should also check that module's description is of the form
910 * MODULENAME:[MCI] comment
913 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
914 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
915 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
917 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
918 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
920 wmd->lpstrDeviceType = strDevTyp;
921 wmd->wType = modp.wType;
923 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
924 modp.wDeviceID, modp.wType, modp.wDeviceID);
928 MCI_UnLoadMciDriver(wmd);
929 HeapFree(GetProcessHeap(), 0, strDevTyp);
934 /**************************************************************************
935 * MCI_FinishOpen [internal]
937 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
940 if (dwParam & MCI_OPEN_ELEMENT)
942 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms->lpstrElementName)+1) * sizeof(WCHAR));
943 strcpyW( wmd->lpstrElementName, lpParms->lpstrElementName );
945 if (dwParam & MCI_OPEN_ALIAS)
947 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms->lpstrAlias)+1) * sizeof(WCHAR));
948 strcpyW( wmd->lpstrAlias, lpParms->lpstrAlias);
950 lpParms->wDeviceID = wmd->wDeviceID;
952 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
956 /**************************************************************************
957 * MCI_FindCommand [internal]
959 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
963 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
966 /* another improvement would be to have the aVerbs array sorted,
967 * so that we could use a dichotomic search on it, rather than this dumb
970 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
971 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
972 return S_MciCmdTable[uTbl].aVerbs[idx];
978 /**************************************************************************
979 * MCI_GetReturnType [internal]
981 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
983 lpCmd = (LPCWSTR)((BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
984 if (*lpCmd == '\0' && *(const WORD*)((BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
985 return *(const DWORD*)(lpCmd + 1);
990 /**************************************************************************
991 * MCI_GetMessage [internal]
993 static WORD MCI_GetMessage(LPCWSTR lpCmd)
995 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
998 /**************************************************************************
999 * MCI_GetDWord [internal]
1001 static BOOL MCI_GetDWord(LPDWORD data, LPWSTR* ptr)
1006 val = strtoulW(*ptr, &ret, 0);
1010 case ' ': ret++; break;
1011 default: return FALSE;
1019 /**************************************************************************
1020 * MCI_GetString [internal]
1022 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
1026 /* see if we have a quoted string */
1028 ptr = strchrW(*str = ptr + 1, '"');
1029 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
1030 /* FIXME: shall we escape \" from string ?? */
1031 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1032 *ptr++ = '\0'; /* remove trailing " */
1033 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
1035 ptr = strchrW(ptr, ' ');
1040 ptr = *args + strlenW(*args);
1049 #define MCI_DATA_SIZE 16
1051 /**************************************************************************
1052 * MCI_ParseOptArgs [internal]
1054 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCWSTR lpCmd,
1055 LPWSTR args, LPDWORD dwFlags)
1060 DWORD dwRet, flg, cflg = 0;
1064 /* loop on arguments */
1066 lmem = (const char*)lpCmd;
1067 found = inCst = FALSE;
1070 /* skip any leading white space(s) */
1071 while (*args == ' ') args++;
1072 TRACE("args=%s offset=%d\n", debugstr_w(args), offset);
1074 do { /* loop on options for command table for the requested verb */
1075 str = (LPCWSTR)lmem;
1076 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1077 flg = *(const DWORD*)lmem;
1078 eid = *(const WORD*)(lmem + sizeof(DWORD));
1079 lmem += sizeof(DWORD) + sizeof(WORD);
1080 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1084 inCst = TRUE; cflg = flg; break;
1085 case MCI_END_CONSTANT:
1086 /* there may be additional integral values after flag in constant */
1087 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1090 inCst = FALSE; cflg = 0;
1094 if (strncmpiW(args, str, len) == 0 &&
1095 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1096 /* store good values into data[] */
1098 while (*args == ' ') args++;
1102 case MCI_COMMAND_HEAD:
1104 case MCI_END_COMMAND:
1105 case MCI_END_COMMAND_LIST:
1106 case MCI_CONSTANT: /* done above */
1107 case MCI_END_CONSTANT: /* done above */
1114 data[offset] |= flg;
1119 if (!MCI_GetDWord(&(data[offset]), &args)) {
1120 return MCIERR_BAD_INTEGER;
1125 /* store rect in data (offset...offset+3) */
1127 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1128 !MCI_GetDWord(&(data[offset+1]), &args) ||
1129 !MCI_GetDWord(&(data[offset+2]), &args) ||
1130 !MCI_GetDWord(&(data[offset+3]), &args)) {
1131 ERR("Bad rect %s\n", debugstr_w(args));
1132 return MCIERR_BAD_INTEGER;
1137 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1140 default: ERR("oops\n");
1142 /* exit inside while loop, except if just entered in constant area definition */
1143 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1145 /* have offset incremented if needed */
1147 case MCI_COMMAND_HEAD:
1149 case MCI_END_COMMAND:
1150 case MCI_END_COMMAND_LIST:
1152 case MCI_FLAG: break;
1153 case MCI_INTEGER: if (!inCst) offset++; break;
1154 case MCI_END_CONSTANT:
1155 case MCI_STRING: offset++; break;
1156 case MCI_RECT: offset += 4; break;
1157 default: ERR("oops\n");
1160 } while (eid != MCI_END_COMMAND);
1162 WARN("Optarg %s not found\n", debugstr_w(args));
1163 return MCIERR_UNRECOGNIZED_COMMAND;
1165 if (offset == MCI_DATA_SIZE) {
1166 ERR("Internal data[] buffer overflow\n");
1167 return MCIERR_PARSER_INTERNAL;
1173 /**************************************************************************
1174 * MCI_HandleReturnValues [internal]
1176 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1177 LPDWORD data, LPWSTR lpstrRet, UINT uRetLen)
1179 static const WCHAR wszLd [] = {'%','l','d',0};
1180 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1181 static const WCHAR wszCol3[] = {'%','d',':','%','d',':','%','d',0};
1182 static const WCHAR wszCol4[] = {'%','d',':','%','d',':','%','d',':','%','d',0};
1186 case 0: /* nothing to return */
1189 switch (dwRet & 0xFFFF0000ul) {
1191 case MCI_INTEGER_RETURNED:
1192 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1194 case MCI_RESOURCE_RETURNED:
1195 /* return string which ID is HIWORD(data[1]),
1196 * string is loaded from mmsystem.dll */
1197 LoadStringW(WINMM_IData.hWinMM32Instance, HIWORD(data[1]),
1200 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1201 /* return string which ID is HIWORD(data[1]),
1202 * string is loaded from driver */
1203 /* FIXME: this is wrong for a 16 bit handle */
1204 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1205 HIWORD(data[1]), lpstrRet, uRetLen);
1207 case MCI_COLONIZED3_RETURN:
1208 snprintfW(lpstrRet, uRetLen, wszCol3,
1209 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1210 LOBYTE(HIWORD(data[1])));
1212 case MCI_COLONIZED4_RETURN:
1213 snprintfW(lpstrRet, uRetLen, wszCol4,
1214 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1215 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1217 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1221 switch (dwRet & 0xFFFF0000ul) {
1223 /* nothing to do data[1] == lpstrRet */
1225 case MCI_INTEGER_RETURNED:
1226 data[1] = *(LPDWORD)lpstrRet;
1227 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1230 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1235 if (dwRet & 0xFFFF0000ul)
1236 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1237 snprintfW(lpstrRet, uRetLen, wszLd4,
1238 data[1], data[2], data[3], data[4]);
1240 default: ERR("oops\n");
1243 return LOWORD(dwRet);
1246 /**************************************************************************
1247 * mciSendStringW [WINMM.@]
1249 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1250 UINT uRetLen, HWND hwndCallback)
1252 LPWSTR verb, dev, args;
1253 LPWINE_MCIDRIVER wmd = 0;
1254 DWORD dwFlags = 0, dwRet = 0;
1256 DWORD data[MCI_DATA_SIZE];
1259 LPWSTR devAlias = NULL;
1260 BOOL bAutoOpen = FALSE;
1261 static const WCHAR wszNew[] = {'n','e','w',0};
1262 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1264 TRACE("(%s, %p, %d, %p)\n",
1265 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1267 /* format is <command> <device> <optargs> */
1268 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1269 return MCIERR_OUT_OF_MEMORY;
1270 strcpyW( verb, lpstrCommand );
1273 memset(data, 0, sizeof(data));
1275 if (!(args = strchrW(verb, ' '))) {
1276 dwRet = MCIERR_MISSING_DEVICE_NAME;
1280 if ((dwRet = MCI_GetString(&dev, &args))) {
1284 /* case dev == 'new' has to be handled */
1285 if (!strcmpW(dev, wszNew)) {
1286 FIXME("'new': NIY as device name\n");
1287 dwRet = MCIERR_MISSING_DEVICE_NAME;
1291 /* otherwise, try to grab devType from open */
1292 if (!strcmpW(verb, wszOpen)) {
1293 LPWSTR devType, tmp;
1295 if ((devType = strchrW(dev, '!')) != NULL) {
1297 tmp = devType; devType = dev; dev = tmp;
1299 dwFlags |= MCI_OPEN_TYPE;
1300 data[2] = (DWORD)devType;
1301 devType = str_dup_upper(devType);
1302 dwFlags |= MCI_OPEN_ELEMENT;
1303 data[3] = (DWORD)dev;
1304 } else if (strchrW(dev, '.') == NULL) {
1305 tmp = strchrW(dev,' ');
1306 if (tmp) *tmp = '\0';
1307 data[2] = (DWORD)dev;
1308 devType = str_dup_upper(dev);
1309 if (tmp) *tmp = ' ';
1310 dwFlags |= MCI_OPEN_TYPE;
1312 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1313 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1315 tmp = strchrW(devType, ' ');
1316 if (tmp) *tmp = '\0';
1317 devType = str_dup_upper(devType);
1318 if (tmp) *tmp = ' ';
1319 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1322 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1325 devType = str_dup_upper(buf);
1327 dwFlags |= MCI_OPEN_ELEMENT;
1328 data[3] = (DWORD)dev;
1330 if ((devAlias = strstrW(args, wszSAliasS))) {
1333 if (!(tmp = strchrW(devAlias,' '))) tmp = devAlias + strlenW(devAlias);
1334 if (tmp) *tmp = '\0';
1335 tmp2 = HeapAlloc(GetProcessHeap(), 0, (tmp - devAlias + 1) * sizeof(WCHAR) );
1336 memcpy( tmp2, devAlias, (tmp - devAlias) * sizeof(WCHAR) );
1337 tmp2[tmp - devAlias] = 0;
1338 data[4] = (DWORD)tmp2;
1339 /* should be done in regular options parsing */
1340 /* dwFlags |= MCI_OPEN_ALIAS; */
1343 dwRet = MCI_LoadMciDriver(devType, &wmd);
1344 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1345 dwRet = MCIERR_INVALID_DEVICE_NAME;
1346 HeapFree(GetProcessHeap(), 0, devType);
1348 MCI_UnLoadMciDriver(wmd);
1351 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1353 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1355 sprintfW(buf, wszOpenWait, dev);
1357 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1360 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1362 /* FIXME: memory leak, MCI driver is not closed */
1363 dwRet = MCIERR_INVALID_DEVICE_ID;
1368 /* get the verb in the different command tables */
1370 /* try the device specific command table */
1371 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1373 /* try the type specific command table */
1374 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1375 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1376 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1377 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1380 /* try core command table */
1381 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1384 TRACE("Command %s not found!\n", debugstr_w(verb));
1385 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1389 /* set up call back */
1390 if (hwndCallback != 0) {
1391 dwFlags |= MCI_NOTIFY;
1392 data[0] = (DWORD)hwndCallback;
1395 /* set return information */
1396 switch (retType = MCI_GetReturnType(lpCmd)) {
1397 case 0: offset = 1; break;
1398 case MCI_INTEGER: offset = 2; break;
1399 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1400 case MCI_RECT: offset = 5; break;
1401 default: ERR("oops\n");
1404 TRACE("verb=%s on dev=%s; offset=%d\n",
1405 debugstr_w(verb), debugstr_w(dev), offset);
1407 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1410 if (bAutoOpen && (dwFlags & MCI_NOTIFY)) {
1411 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1414 /* FIXME: the command should get it's own notification window set up and
1415 * ask for device closing while processing the notification mechanism
1417 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1419 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1420 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1421 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1422 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1423 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1425 if (strcmpW(verb, wszOpen) == 0) {
1426 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1427 MCI_UnLoadMciDriver(wmd);
1428 /* FIXME: notification is not properly shared across two opens */
1430 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
1432 TRACE("=> 1/ %lx (%s)\n", dwRet, debugstr_w(lpstrRet));
1433 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1434 TRACE("=> 2/ %lx (%s)\n", dwRet, debugstr_w(lpstrRet));
1437 HeapFree(GetProcessHeap(), 0, verb);
1438 HeapFree(GetProcessHeap(), 0, devAlias);
1442 /**************************************************************************
1443 * mciSendStringA [WINMM.@]
1445 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1446 UINT uRetLen, HWND hwndCallback)
1448 LPWSTR lpwstrCommand;
1449 LPWSTR lpwstrRet = NULL;
1453 /* FIXME: is there something to do with lpstrReturnString ? */
1454 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1455 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1456 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1459 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1461 WARN("no memory\n");
1462 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1463 return MCIERR_OUT_OF_MEMORY;
1466 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1468 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1469 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1470 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1474 /**************************************************************************
1475 * mciExecute [WINMM.@]
1476 * mciExecute [MMSYSTEM.712]
1478 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1483 TRACE("(%s)!\n", lpstrCommand);
1485 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1487 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1488 sprintf(strRet, "Unknown MCI error (%ld)", ret);
1490 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1492 /* FIXME: what shall I return ? */
1496 /**************************************************************************
1497 * mciLoadCommandResource [WINMM.@]
1499 * Strangely, this function only exists as an UNICODE one.
1501 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1505 UINT16 ret = MCI_NO_COMMAND_TABLE;
1507 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1509 /* if a file named "resname.mci" exits, then load resource "resname" from it
1510 * otherwise directly from driver
1511 * We don't support it (who uses this feature ?), but we check anyway
1515 /* FIXME: we should put this back into order, but I never found a program
1516 * actually using this feature, so we may not need it
1521 strcat(strcpy(buf, resname), ".mci");
1522 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1523 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1527 if (!(hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA))) {
1528 WARN("No command table found in resource\n");
1529 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1530 ret = MCI_SetCommandTable(LockResource(hMem), type);
1532 WARN("Couldn't load resource.\n");
1534 TRACE("=> %04x\n", ret);
1538 /**************************************************************************
1539 * mciFreeCommandResource [WINMM.@]
1541 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1543 TRACE("(%08x)!\n", uTable);
1545 return MCI_DeleteCommandTable(uTable, FALSE);
1548 /**************************************************************************
1549 * MCI_SendCommandFrom32 [internal]
1551 DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1553 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1554 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1558 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1559 } else if (pFnMciMapMsg32WTo16) {
1562 switch (res = pFnMciMapMsg32WTo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1563 case WINMM_MAP_MSGERROR:
1564 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1565 dwRet = MCIERR_DRIVER_INTERNAL;
1567 case WINMM_MAP_NOMEM:
1568 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1569 dwRet = MCIERR_OUT_OF_MEMORY;
1572 case WINMM_MAP_OKMEM:
1573 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1574 if (res == WINMM_MAP_OKMEM)
1575 pFnMciUnMapMsg32WTo16(wmd->wType, wMsg, dwParam1, dwParam2);
1583 /**************************************************************************
1584 * MCI_SendCommandFrom16 [internal]
1586 DWORD MCI_SendCommandFrom16(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1588 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1589 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1592 dwRet = MCIERR_INVALID_DEVICE_ID;
1594 if (wmd->bIs32 && pFnMciMapMsg16To32W) {
1597 switch (res = pFnMciMapMsg16To32W(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1598 case WINMM_MAP_MSGERROR:
1599 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1600 dwRet = MCIERR_DRIVER_INTERNAL;
1602 case WINMM_MAP_NOMEM:
1603 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1604 dwRet = MCIERR_OUT_OF_MEMORY;
1607 case WINMM_MAP_OKMEM:
1608 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1609 if (res == WINMM_MAP_OKMEM)
1610 pFnMciUnMapMsg16To32W(wmd->wType, wMsg, dwParam1, dwParam2);
1614 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1620 /**************************************************************************
1621 * MCI_Open [internal]
1623 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1625 WCHAR strDevTyp[128];
1627 LPWINE_MCIDRIVER wmd = NULL;
1629 TRACE("(%08lX, %p)\n", dwParam, lpParms);
1630 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1632 /* only two low bytes are generic, the other ones are dev type specific */
1633 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1634 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1635 MCI_NOTIFY|MCI_WAIT)
1636 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1637 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1639 #undef WINE_MCIDRIVER_SUPP
1643 if (dwParam & MCI_OPEN_TYPE) {
1644 if (dwParam & MCI_OPEN_TYPE_ID) {
1645 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
1647 if (uDevType < MCI_DEVTYPE_FIRST ||
1648 uDevType > MCI_DEVTYPE_LAST ||
1649 !LoadStringW(WINMM_IData.hWinMM32Instance, uDevType,
1650 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1651 dwRet = MCIERR_BAD_INTEGER;
1656 if (lpParms->lpstrDeviceType == NULL) {
1657 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1660 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1661 ptr = strchrW(strDevTyp, '!');
1663 /* this behavior is not documented in windows. However, since, in
1664 * some occasions, MCI_OPEN handling is translated by WinMM into
1665 * a call to mciSendString("open <type>"); this code shall be correct
1667 if (dwParam & MCI_OPEN_ELEMENT) {
1668 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1669 debugstr_w(lpParms->lpstrElementName),
1670 debugstr_w(strDevTyp));
1671 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1674 dwParam |= MCI_OPEN_ELEMENT;
1676 /* FIXME: not a good idea to write in user supplied buffer */
1677 lpParms->lpstrElementName = ptr;
1681 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1684 if (dwParam & MCI_OPEN_ELEMENT) {
1685 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1687 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1688 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1689 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1693 if (!lpParms->lpstrElementName) {
1694 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1698 /* type, if given as a parameter, supersedes file extension */
1699 if (!strDevTyp[0] &&
1700 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1701 strDevTyp, sizeof(strDevTyp))) {
1702 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1703 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1704 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1707 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1708 strcpyW(strDevTyp, wszCdAudio);
1712 if (strDevTyp[0] == 0) {
1713 FIXME("Couldn't load driver\n");
1714 dwRet = MCIERR_INVALID_DEVICE_NAME;
1718 if (dwParam & MCI_OPEN_ALIAS) {
1719 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1720 if (!lpParms->lpstrAlias) {
1721 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1726 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1730 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1731 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet);
1732 /* FIXME: is dwRet the correct ret code ? */
1736 /* only handled devices fall through */
1737 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1739 if (dwParam & MCI_NOTIFY)
1740 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1744 if (wmd) MCI_UnLoadMciDriver(wmd);
1746 if (dwParam & MCI_NOTIFY)
1747 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1751 /**************************************************************************
1752 * MCI_Close [internal]
1754 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1757 LPWINE_MCIDRIVER wmd;
1759 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
1761 if (wDevID == MCI_ALL_DEVICE_ID) {
1762 LPWINE_MCIDRIVER next;
1764 EnterCriticalSection(&WINMM_IData.cs);
1765 /* FIXME: shall I notify once after all is done, or for
1766 * each of the open drivers ? if the latest, which notif
1767 * to return when only one fails ?
1769 for (wmd = WINMM_IData.lpMciDrvs; wmd; ) {
1771 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
1774 LeaveCriticalSection(&WINMM_IData.cs);
1778 if (!(wmd = MCI_GetDriver(wDevID))) {
1779 return MCIERR_INVALID_DEVICE_ID;
1782 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
1784 MCI_UnLoadMciDriver(wmd);
1786 if (dwParam & MCI_NOTIFY)
1787 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1788 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1793 /**************************************************************************
1794 * MCI_WriteString [internal]
1796 DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1801 dstSize /= sizeof(WCHAR);
1802 if (dstSize <= strlenW(lpSrcStr)) {
1803 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1804 ret = MCIERR_PARAM_OVERFLOW;
1806 strcpyW(lpDstStr, lpSrcStr);
1814 /**************************************************************************
1815 * MCI_Sysinfo [internal]
1817 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1819 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1820 WCHAR buf[2048], *s = buf, *p;
1821 LPWINE_MCIDRIVER wmd;
1824 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1826 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1827 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1829 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1830 case MCI_SYSINFO_QUANTITY:
1831 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1832 if (dwFlags & MCI_SYSINFO_OPEN) {
1833 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1834 EnterCriticalSection(&WINMM_IData.cs);
1835 for (wmd = WINMM_IData.lpMciDrvs; wmd; wmd = wmd->lpNext) {
1838 LeaveCriticalSection(&WINMM_IData.cs);
1840 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1841 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1842 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1843 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1844 RegCloseKey( hKey );
1846 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1847 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1850 if (dwFlags & MCI_SYSINFO_OPEN) {
1851 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
1852 EnterCriticalSection(&WINMM_IData.cs);
1853 for (wmd = WINMM_IData.lpMciDrvs; wmd; wmd = wmd->lpNext) {
1854 if (wmd->wType == lpParms->wDeviceType) cnt++;
1856 LeaveCriticalSection(&WINMM_IData.cs);
1858 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
1859 FIXME("Don't know how to get # of MCI devices of a given type\n");
1863 *(DWORD*)lpParms->lpstrReturn = cnt;
1864 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1865 ret = MCI_INTEGER_RETURNED;
1867 case MCI_SYSINFO_INSTALLNAME:
1868 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1869 if ((wmd = MCI_GetDriver(uDevID))) {
1870 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1871 wmd->lpstrDeviceType);
1873 *lpParms->lpstrReturn = 0;
1874 ret = MCIERR_INVALID_DEVICE_ID;
1876 TRACE("(%ld) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1878 case MCI_SYSINFO_NAME:
1879 TRACE("MCI_SYSINFO_NAME\n");
1880 if (dwFlags & MCI_SYSINFO_OPEN) {
1881 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1882 ret = MCIERR_UNRECOGNIZED_COMMAND;
1885 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1886 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1887 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1888 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1889 lpParms->dwNumber <= cnt) {
1890 DWORD bufLen = sizeof(buf);
1891 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1892 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1895 RegCloseKey( hKey );
1898 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1899 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1900 TRACE("%ld: %s\n", cnt, debugstr_w(p));
1901 if (cnt == lpParms->dwNumber - 1) {
1908 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1910 TRACE("(%ld) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1913 TRACE("Unsupported flag value=%08lx\n", dwFlags);
1914 ret = MCIERR_UNRECOGNIZED_COMMAND;
1919 /**************************************************************************
1920 * MCI_Break [internal]
1922 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1926 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1928 if (dwFlags & MCI_NOTIFY)
1929 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1930 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1935 /**************************************************************************
1936 * MCI_Sound [internal]
1938 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1942 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1944 if (dwFlags & MCI_SOUND_NAME)
1945 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1947 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1948 if (dwFlags & MCI_NOTIFY)
1949 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1950 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1955 /**************************************************************************
1956 * MCI_SendCommand [internal]
1958 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
1959 DWORD dwParam2, BOOL bFrom32)
1961 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1966 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1967 } else if (pFnMciMapMsg16To32W) {
1968 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
1970 case WINMM_MAP_OKMEM:
1971 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1972 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
1974 default: break; /* so that gcc does not bark */
1980 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1981 } else if (pFnMciMapMsg16To32W) {
1982 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
1984 case WINMM_MAP_OKMEM:
1985 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1986 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
1988 default: break; /* so that gcc does not bark */
1994 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1995 } else if (pFnMciMapMsg16To32W) {
1996 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
1998 case WINMM_MAP_OKMEM:
1999 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
2000 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
2002 default: break; /* so that gcc does not bark */
2008 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2009 } else if (pFnMciMapMsg16To32W) {
2010 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
2012 case WINMM_MAP_OKMEM:
2013 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2014 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
2016 default: break; /* so that gcc does not bark */
2022 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
2023 } else if (pFnMciMapMsg16To32W) {
2024 switch (pFnMciMapMsg16To32W(0, wMsg, dwParam1, &dwParam2)) {
2026 case WINMM_MAP_OKMEM:
2027 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
2028 pFnMciUnMapMsg16To32W(0, wMsg, dwParam1, dwParam2);
2030 default: break; /* so that gcc does not bark */
2035 if (wDevID == MCI_ALL_DEVICE_ID) {
2036 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2037 dwRet = MCIERR_CANNOT_USE_ALL;
2040 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
2041 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
2048 /**************************************************************************
2049 * MCI_CleanUp [internal]
2051 * Some MCI commands need to be cleaned-up (when not called from
2052 * mciSendString), because MCI drivers return extra information for string
2053 * transformation. This function gets rid of them.
2055 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2)
2058 return LOWORD(dwRet);
2061 case MCI_GETDEVCAPS:
2062 switch (dwRet & 0xFFFF0000ul) {
2064 case MCI_COLONIZED3_RETURN:
2065 case MCI_COLONIZED4_RETURN:
2066 case MCI_INTEGER_RETURNED:
2069 case MCI_RESOURCE_RETURNED:
2070 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2072 LPMCI_GETDEVCAPS_PARMS lmgp;
2074 lmgp = (LPMCI_GETDEVCAPS_PARMS)(void*)dwParam2;
2075 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
2076 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
2080 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2081 HIWORD(dwRet), MCI_MessageToString(wMsg));
2085 switch (dwRet & 0xFFFF0000ul) {
2087 case MCI_COLONIZED3_RETURN:
2088 case MCI_COLONIZED4_RETURN:
2089 case MCI_INTEGER_RETURNED:
2092 case MCI_RESOURCE_RETURNED:
2093 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2095 LPMCI_STATUS_PARMS lsp;
2097 lsp = (LPMCI_STATUS_PARMS)(void*)dwParam2;
2098 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
2099 lsp->dwReturn = LOWORD(lsp->dwReturn);
2103 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2104 HIWORD(dwRet), MCI_MessageToString(wMsg));
2108 switch (dwRet & 0xFFFF0000ul) {
2110 case MCI_INTEGER_RETURNED:
2114 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2118 if (HIWORD(dwRet)) {
2119 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2120 dwRet, MCI_MessageToString(wMsg));
2124 return LOWORD(dwRet);
2127 /**************************************************************************
2128 * mciGetErrorStringW [WINMM.@]
2130 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2134 if (lpstrBuffer != NULL && uLength > 0 &&
2135 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2137 if (LoadStringW(WINMM_IData.hWinMM32Instance,
2138 wError, lpstrBuffer, uLength) > 0) {
2145 /**************************************************************************
2146 * mciGetErrorStringA [WINMM.@]
2148 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2152 if (lpstrBuffer != NULL && uLength > 0 &&
2153 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2155 if (LoadStringA(WINMM_IData.hWinMM32Instance,
2156 dwError, lpstrBuffer, uLength) > 0) {
2163 /**************************************************************************
2164 * mciDriverNotify [WINMM.@]
2166 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2168 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2170 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2173 /**************************************************************************
2174 * mciGetDriverData [WINMM.@]
2176 DWORD WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2178 LPWINE_MCIDRIVER wmd;
2180 TRACE("(%04x)\n", uDeviceID);
2182 wmd = MCI_GetDriver(uDeviceID);
2185 WARN("Bad uDeviceID\n");
2189 return wmd->dwPrivate;
2192 /**************************************************************************
2193 * mciSetDriverData [WINMM.@]
2195 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD data)
2197 LPWINE_MCIDRIVER wmd;
2199 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2201 wmd = MCI_GetDriver(uDeviceID);
2204 WARN("Bad uDeviceID\n");
2208 wmd->dwPrivate = data;
2212 /**************************************************************************
2213 * mciSendCommandW [WINMM.@]
2216 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2220 TRACE("(%08x, %s, %08lx, %08lx)\n",
2221 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2223 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, TRUE);
2224 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2225 TRACE("=> %08lx\n", dwRet);
2229 /**************************************************************************
2230 * mciSendCommandA [WINMM.@]
2232 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2237 TRACE("(%08x, %s, %08lx, %08lx)\n",
2238 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2240 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2243 FIXME("message %04x mapping failed\n", wMsg);
2244 return MMSYSERR_NOMEM;
2246 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2248 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2252 /**************************************************************************
2253 * mciGetDeviceIDA [WINMM.@]
2255 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2257 LPWSTR w = MCI_strdupAtoW(lpstrName);
2258 UINT ret = MCIERR_OUT_OF_MEMORY;
2262 ret = mciGetDeviceIDW(w);
2263 HeapFree(GetProcessHeap(), 0, w);
2268 /**************************************************************************
2269 * mciGetDeviceIDW [WINMM.@]
2271 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2273 return MCI_GetDriverFromString(lpwstrName);
2276 /******************************************************************
2279 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
2281 static void MyUserYield(void)
2283 HMODULE mod = GetModuleHandleA( "user32.dll" );
2286 FARPROC proc = GetProcAddress( mod, "UserYield16" );
2291 /**************************************************************************
2292 * MCI_DefYieldProc [internal]
2294 UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2298 TRACE("(0x%04x, 0x%08lx)\n", wDevID, data);
2300 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2301 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2307 msg.hwnd = HWND_32(HIWORD(data));
2308 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2314 /**************************************************************************
2315 * mciSetYieldProc [WINMM.@]
2317 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2319 LPWINE_MCIDRIVER wmd;
2321 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
2323 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2324 WARN("Bad uDeviceID\n");
2328 wmd->lpfnYieldProc = fpYieldProc;
2329 wmd->dwYieldData = dwYieldData;
2335 /**************************************************************************
2336 * mciGetDeviceIDFromElementIDA [WINMM.@]
2338 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2340 LPWSTR w = MCI_strdupAtoW(lpstrType);
2345 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2346 HeapFree(GetProcessHeap(), 0, w);
2351 /**************************************************************************
2352 * mciGetDeviceIDFromElementIDW [WINMM.@]
2354 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2356 /* FIXME: that's rather strange, there is no
2357 * mciGetDeviceIDFromElementID32A in winmm.spec
2359 FIXME("(%lu, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2363 /**************************************************************************
2364 * mciGetYieldProc [WINMM.@]
2366 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2368 LPWINE_MCIDRIVER wmd;
2370 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2372 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2373 WARN("Bad uDeviceID\n");
2376 if (!wmd->lpfnYieldProc) {
2377 WARN("No proc set\n");
2381 WARN("Proc is 32 bit\n");
2384 return wmd->lpfnYieldProc;
2387 /**************************************************************************
2388 * mciGetCreatorTask [WINMM.@]
2390 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2392 LPWINE_MCIDRIVER wmd;
2395 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
2397 TRACE("(%u) => %p\n", uDeviceID, ret);
2401 /**************************************************************************
2402 * mciDriverYield [WINMM.@]
2404 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2406 LPWINE_MCIDRIVER wmd;
2409 TRACE("(%04x)\n", uDeviceID);
2411 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || !wmd->bIs32) {
2414 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);