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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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*) /* = NULL */;
72 WINMM_MapType (*pFnMciUnMapMsg16To32W)(WORD,WORD,DWORD) /* = NULL */;
73 WINMM_MapType (*pFnMciMapMsg32WTo16) (WORD,WORD,DWORD,DWORD*) /* = NULL */;
74 WINMM_MapType (*pFnMciUnMapMsg32WTo16)(WORD,WORD,DWORD,DWORD) /* = 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;
285 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA*)*dwParam2;
286 MCI_OPEN_PARMSW *mci_openW;
289 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW) + 2 * sizeof(DWORD));
292 *ptr++ = *dwParam2; /* save the previous pointer */
293 *dwParam2 = (DWORD_PTR)ptr;
294 mci_openW = (MCI_OPEN_PARMSW *)ptr;
296 if (dwParam1 & MCI_NOTIFY)
297 mci_openW->dwCallback = mci_openA->dwCallback;
299 if (dwParam1 & MCI_OPEN_TYPE)
301 if (dwParam1 & MCI_OPEN_TYPE_ID)
302 mci_openW->lpstrDeviceType = (LPWSTR)mci_openA->lpstrDeviceType;
304 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
306 if (dwParam1 & MCI_OPEN_ELEMENT)
308 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
309 mci_openW->lpstrElementName = (LPWSTR)mci_openA->lpstrElementName;
311 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
313 if (dwParam1 & MCI_OPEN_ALIAS)
314 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
315 /* FIXME: this is only needed for specific types of MCI devices, and
316 * may cause a segfault if the two DWORD:s don't exist at the end of
319 memcpy(mci_openW + 1, mci_openA + 1, 2 * sizeof(DWORD));
324 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
326 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
327 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
329 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
330 if (!mci_windowW) return -1;
332 *dwParam2 = (DWORD_PTR)mci_windowW;
334 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
336 if (dwParam1 & MCI_NOTIFY)
337 mci_windowW->dwCallback = mci_windowA->dwCallback;
338 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
339 mci_windowW->hWnd = mci_windowA->hWnd;
340 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
341 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
349 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
350 MCI_SYSINFO_PARMSW *mci_sysinfoW;
353 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
356 *ptr++ = *dwParam2; /* save the previous pointer */
357 *dwParam2 = (DWORD_PTR)ptr;
358 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
360 if (dwParam1 & MCI_NOTIFY)
361 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
363 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
364 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize);
365 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
366 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
371 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
372 MCI_INFO_PARMSW *mci_infoW;
375 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
378 *ptr++ = *dwParam2; /* save the previous pointer */
379 *dwParam2 = (DWORD_PTR)ptr;
380 mci_infoW = (MCI_INFO_PARMSW *)ptr;
382 if (dwParam1 & MCI_NOTIFY)
383 mci_infoW->dwCallback = mci_infoA->dwCallback;
385 mci_infoW->dwRetSize = mci_infoA->dwRetSize * sizeof(WCHAR); /* it's not the same as SYSINFO !!! */
386 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize);
391 MCI_SAVE_PARMSA *mci_saveA = (MCI_SAVE_PARMSA *)*dwParam2;
392 MCI_SAVE_PARMSW *mci_saveW;
394 mci_saveW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW));
395 if (!mci_saveW) return -1;
397 *dwParam2 = (DWORD_PTR)mci_saveW;
398 if (dwParam1 & MCI_NOTIFY)
399 mci_saveW->dwCallback = mci_saveA->dwCallback;
400 mci_saveW->lpfilename = MCI_strdupAtoW(mci_saveA->lpfilename);
405 MCI_LOAD_PARMSA *mci_loadA = (MCI_LOAD_PARMSA *)*dwParam2;
406 MCI_LOAD_PARMSW *mci_loadW;
408 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
409 if (!mci_loadW) return -1;
411 *dwParam2 = (DWORD_PTR)mci_loadW;
412 if (dwParam1 & MCI_NOTIFY)
413 mci_loadW->dwCallback = mci_loadA->dwCallback;
414 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
420 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
421 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
423 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
424 if (!mci_vd_escapeW) return -1;
426 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
427 if (dwParam1 & MCI_NOTIFY)
428 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
429 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
433 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
438 static DWORD MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
445 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
446 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
447 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)(ptr + 1);
449 mci_openA->wDeviceID = mci_openW->wDeviceID;
451 if (dwParam1 & MCI_OPEN_TYPE)
453 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
454 HeapFree(GetProcessHeap(), 0, mci_openW->lpstrDeviceType);
456 if (dwParam1 & MCI_OPEN_ELEMENT)
458 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
459 HeapFree(GetProcessHeap(), 0, mci_openW->lpstrElementName);
461 if (dwParam1 & MCI_OPEN_ALIAS)
462 HeapFree(GetProcessHeap(), 0, mci_openW->lpstrAlias);
463 HeapFree(GetProcessHeap(), 0, ptr);
467 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
469 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
471 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
472 HeapFree(GetProcessHeap(), 0, mci_windowW);
478 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
479 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
480 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)(ptr + 1);
484 mci_sysinfoA->dwNumber = mci_sysinfoW->dwNumber;
485 mci_sysinfoA->wDeviceType = mci_sysinfoW->wDeviceType;
486 if (dwParam1 & MCI_SYSINFO_QUANTITY)
487 *(DWORD*)mci_sysinfoA->lpstrReturn = *(DWORD*)mci_sysinfoW->lpstrReturn;
489 WideCharToMultiByte(CP_ACP, 0,
490 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
491 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
495 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
496 HeapFree(GetProcessHeap(), 0, ptr);
501 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
502 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
503 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)(ptr + 1);
507 WideCharToMultiByte(CP_ACP, 0,
508 mci_infoW->lpstrReturn, mci_infoW->dwRetSize / sizeof(WCHAR),
509 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
513 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
514 HeapFree(GetProcessHeap(), 0, ptr);
519 MCI_SAVE_PARMSW *mci_saveW = (MCI_SAVE_PARMSW *)dwParam2;
521 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW->lpfilename);
522 HeapFree(GetProcessHeap(), 0, mci_saveW);
527 MCI_LOAD_PARMSW *mci_loadW = (MCI_LOAD_PARMSW *)dwParam2;
529 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
530 HeapFree(GetProcessHeap(), 0, mci_loadW);
535 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
537 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
538 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
543 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
550 /**************************************************************************
551 * MCI_GetDevTypeFromFileName [internal]
553 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPCWSTR buf, UINT len)
557 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
558 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
559 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
560 if ((tmp = strrchrW(fileName, '.'))) {
561 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
562 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
564 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
566 if (lRet == ERROR_SUCCESS) return 0;
568 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
570 return MCIERR_EXTENSION_NOT_FOUND;
573 #define MAX_MCICMDTABLE 20
574 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
576 typedef struct tagWINE_MCICMDTABLE {
579 UINT nVerbs; /* number of verbs in command table */
580 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
581 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
583 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
585 /**************************************************************************
586 * MCI_IsCommandTableValid [internal]
588 static BOOL MCI_IsCommandTableValid(UINT uTbl)
597 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
598 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
600 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
603 lmem = S_MciCmdTable[uTbl].lpTable;
606 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
607 flg = *(const DWORD*)lmem;
608 eid = *(const WORD*)(lmem + sizeof(DWORD));
609 lmem += sizeof(DWORD) + sizeof(WORD);
611 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
613 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
614 case MCI_STRING: if (inCst) return FALSE; break;
615 case MCI_INTEGER: if (!*str) return FALSE; break;
616 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
617 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
618 case MCI_FLAG: if (!*str) return FALSE; break;
619 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
620 case MCI_RECT: if (!*str || inCst) return FALSE; break;
621 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
622 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
623 default: return FALSE;
625 } while (eid != MCI_END_COMMAND_LIST);
629 /**************************************************************************
630 * MCI_DumpCommandTable [internal]
632 static BOOL MCI_DumpCommandTable(UINT uTbl)
639 if (!MCI_IsCommandTableValid(uTbl)) {
640 ERR("Ooops: %d is not valid\n", uTbl);
644 lmem = S_MciCmdTable[uTbl].lpTable;
648 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
649 flg = *(const DWORD*)lmem;
650 eid = *(const WORD*)(lmem + sizeof(DWORD));
651 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
652 lmem += sizeof(DWORD) + sizeof(WORD);
653 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
654 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
655 } while (eid != MCI_END_COMMAND_LIST);
660 /**************************************************************************
661 * MCI_GetCommandTable [internal]
663 static UINT MCI_GetCommandTable(UINT uDevType)
669 /* first look up existing for existing devType */
670 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
671 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
675 /* well try to load id */
676 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
677 if (LoadStringW(WINMM_IData->hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
680 } else if (uDevType == 0) {
681 static const WCHAR wszCore[] = {'C','O','R','E',0};
684 uTbl = MCI_NO_COMMAND_TABLE;
686 HRSRC hRsrc = FindResourceW(WINMM_IData->hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
689 if (hRsrc) hMem = LoadResource(WINMM_IData->hWinMM32Instance, hRsrc);
691 uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType);
693 WARN("No command table found in resource %p[%s]\n",
694 WINMM_IData->hWinMM32Instance, debugstr_w(str));
697 TRACE("=> %d\n", uTbl);
701 /**************************************************************************
702 * MCI_SetCommandTable [internal]
704 UINT MCI_SetCommandTable(void *table, UINT uDevType)
707 static BOOL bInitDone = FALSE;
710 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
711 * can be called with 0 as a uDevType to retrieve it.
716 MCI_GetCommandTable(0);
718 TRACE("(%p, %u)\n", table, uDevType);
719 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
720 if (!S_MciCmdTable[uTbl].lpTable) {
726 S_MciCmdTable[uTbl].uDevType = uDevType;
727 S_MciCmdTable[uTbl].lpTable = table;
730 MCI_DumpCommandTable(uTbl);
733 /* create the verbs table */
734 /* get # of entries */
735 lmem = S_MciCmdTable[uTbl].lpTable;
739 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
740 eid = *(const WORD*)(lmem + sizeof(DWORD));
741 lmem += sizeof(DWORD) + sizeof(WORD);
742 if (eid == MCI_COMMAND_HEAD)
744 } while (eid != MCI_END_COMMAND_LIST);
746 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
747 S_MciCmdTable[uTbl].nVerbs = count;
749 lmem = S_MciCmdTable[uTbl].lpTable;
753 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
754 eid = *(const WORD*)(lmem + sizeof(DWORD));
755 lmem += sizeof(DWORD) + sizeof(WORD);
756 if (eid == MCI_COMMAND_HEAD)
757 S_MciCmdTable[uTbl].aVerbs[count++] = str;
758 } while (eid != MCI_END_COMMAND_LIST);
759 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
764 return MCI_NO_COMMAND_TABLE;
767 /**************************************************************************
768 * MCI_DeleteCommandTable [internal]
770 BOOL MCI_DeleteCommandTable(UINT uTbl, BOOL delete)
772 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
775 if (delete) HeapFree(GetProcessHeap(), 0, (void*)S_MciCmdTable[uTbl].lpTable);
776 S_MciCmdTable[uTbl].lpTable = NULL;
777 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
778 S_MciCmdTable[uTbl].aVerbs = 0;
782 /**************************************************************************
783 * MCI_UnLoadMciDriver [internal]
785 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
787 LPWINE_MCIDRIVER* tmp;
792 CloseDriver(wmd->hDriver, 0, 0);
794 if (wmd->dwPrivate != 0)
795 WARN("Unloading mci driver with non nul dwPrivate field\n");
797 EnterCriticalSection(&WINMM_IData->cs);
798 for (tmp = &WINMM_IData->lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
804 LeaveCriticalSection(&WINMM_IData->cs);
806 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
807 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
808 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
810 HeapFree(GetProcessHeap(), 0, wmd);
814 /**************************************************************************
815 * MCI_OpenMciDriver [internal]
817 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, LPARAM lp)
821 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
825 /* First load driver */
826 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
828 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32WTo16) {
831 switch (res = pFnMciMapMsg32WTo16(0, DRV_OPEN, 0, &lp)) {
832 case WINMM_MAP_MSGERROR:
833 TRACE("Not handled yet (DRV_OPEN)\n");
835 case WINMM_MAP_NOMEM:
836 TRACE("Problem mapping msg=DRV_OPEN from 32W to 16\n");
839 case WINMM_MAP_OKMEM:
840 if ((wmd->hDriver = OpenDriver(drvTyp, wszMci, lp)))
842 if (res == WINMM_MAP_OKMEM)
843 pFnMciUnMapMsg32WTo16(0, DRV_OPEN, 0, lp);
847 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
850 /**************************************************************************
851 * MCI_LoadMciDriver [internal]
853 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
855 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
856 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
857 MCI_OPEN_DRIVER_PARMSW modp;
860 if (!wmd || !strDevTyp) {
861 dwRet = MCIERR_OUT_OF_MEMORY;
865 wmd->lpfnYieldProc = MCI_DefYieldProc;
866 wmd->dwYieldData = VK_CANCEL;
867 wmd->CreatorThread = GetCurrentThreadId();
869 EnterCriticalSection(&WINMM_IData->cs);
870 /* wmd must be inserted in list before sending opening the driver, coz' it
871 * may want to lookup at wDevID
873 wmd->lpNext = WINMM_IData->lpMciDrvs;
874 WINMM_IData->lpMciDrvs = wmd;
876 for (modp.wDeviceID = MCI_MAGIC;
877 MCI_GetDriver(modp.wDeviceID) != 0;
880 wmd->wDeviceID = modp.wDeviceID;
882 LeaveCriticalSection(&WINMM_IData->cs);
884 TRACE("wDevID=%04X \n", modp.wDeviceID);
886 modp.lpstrParams = NULL;
888 if (!MCI_OpenMciDriver(wmd, strDevTyp, (LPARAM)&modp)) {
889 /* silence warning if all is used... some bogus program use commands like
892 if (strcmpiW(strDevTyp, wszAll) == 0) {
893 dwRet = MCIERR_CANNOT_USE_ALL;
895 FIXME("Couldn't load driver for type %s.\n"
896 "If you don't have a windows installation accessible from Wine,\n"
897 "you perhaps forgot to create a [mci] section in system.ini\n",
898 debugstr_w(strDevTyp));
899 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
904 /* FIXME: should also check that module's description is of the form
905 * MODULENAME:[MCI] comment
908 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
909 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
910 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
912 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
913 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
915 wmd->lpstrDeviceType = strDevTyp;
916 wmd->wType = modp.wType;
918 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
919 modp.wDeviceID, modp.wType, modp.wDeviceID);
923 MCI_UnLoadMciDriver(wmd);
924 HeapFree(GetProcessHeap(), 0, strDevTyp);
929 /**************************************************************************
930 * MCI_FinishOpen [internal]
932 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
935 if (dwParam & MCI_OPEN_ELEMENT)
937 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms->lpstrElementName)+1) * sizeof(WCHAR));
938 strcpyW( wmd->lpstrElementName, lpParms->lpstrElementName );
940 if (dwParam & MCI_OPEN_ALIAS)
942 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms->lpstrAlias)+1) * sizeof(WCHAR));
943 strcpyW( wmd->lpstrAlias, lpParms->lpstrAlias);
945 lpParms->wDeviceID = wmd->wDeviceID;
947 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
951 /**************************************************************************
952 * MCI_FindCommand [internal]
954 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
958 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
961 /* another improvement would be to have the aVerbs array sorted,
962 * so that we could use a dichotomic search on it, rather than this dumb
965 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
966 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
967 return S_MciCmdTable[uTbl].aVerbs[idx];
973 /**************************************************************************
974 * MCI_GetReturnType [internal]
976 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
978 lpCmd = (LPCWSTR)((BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
979 if (*lpCmd == '\0' && *(const WORD*)((BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
980 return *(const DWORD*)(lpCmd + 1);
985 /**************************************************************************
986 * MCI_GetMessage [internal]
988 static WORD MCI_GetMessage(LPCWSTR lpCmd)
990 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
993 /**************************************************************************
994 * MCI_GetDWord [internal]
996 static BOOL MCI_GetDWord(LPDWORD data, LPWSTR* ptr)
1001 val = strtoulW(*ptr, &ret, 0);
1005 case ' ': ret++; break;
1006 default: return FALSE;
1014 /**************************************************************************
1015 * MCI_GetString [internal]
1017 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
1021 /* see if we have a quoted string */
1023 ptr = strchrW(*str = ptr + 1, '"');
1024 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
1025 /* FIXME: shall we escape \" from string ?? */
1026 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1027 *ptr++ = '\0'; /* remove trailing " */
1028 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
1031 ptr = strchrW(ptr, ' ');
1036 ptr = *args + strlenW(*args);
1045 #define MCI_DATA_SIZE 16
1047 /**************************************************************************
1048 * MCI_ParseOptArgs [internal]
1050 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCWSTR lpCmd,
1051 LPWSTR args, LPDWORD dwFlags)
1056 DWORD dwRet, flg, cflg = 0;
1060 /* loop on arguments */
1062 lmem = (const char*)lpCmd;
1063 found = inCst = FALSE;
1066 /* skip any leading white space(s) */
1067 while (*args == ' ') args++;
1068 TRACE("args=%s offset=%d\n", debugstr_w(args), offset);
1070 do { /* loop on options for command table for the requested verb */
1071 str = (LPCWSTR)lmem;
1072 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1073 flg = *(const DWORD*)lmem;
1074 eid = *(const WORD*)(lmem + sizeof(DWORD));
1075 lmem += sizeof(DWORD) + sizeof(WORD);
1076 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1080 inCst = TRUE; cflg = flg; break;
1081 case MCI_END_CONSTANT:
1082 /* there may be additional integral values after flag in constant */
1083 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1086 inCst = FALSE; cflg = 0;
1090 if (strncmpiW(args, str, len) == 0 &&
1091 (args[len] == 0 || args[len] == ' ')) {
1092 /* store good values into data[] */
1094 while (*args == ' ') args++;
1098 case MCI_COMMAND_HEAD:
1100 case MCI_END_COMMAND:
1101 case MCI_END_COMMAND_LIST:
1102 case MCI_CONSTANT: /* done above */
1103 case MCI_END_CONSTANT: /* done above */
1110 data[offset] |= flg;
1115 if (!MCI_GetDWord(&(data[offset]), &args)) {
1116 return MCIERR_BAD_INTEGER;
1121 /* store rect in data (offset...offset+3) */
1123 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1124 !MCI_GetDWord(&(data[offset+1]), &args) ||
1125 !MCI_GetDWord(&(data[offset+2]), &args) ||
1126 !MCI_GetDWord(&(data[offset+3]), &args)) {
1127 ERR("Bad rect %s\n", debugstr_w(args));
1128 return MCIERR_BAD_INTEGER;
1133 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1136 default: ERR("oops\n");
1138 /* exit inside while loop, except if just entered in constant area definition */
1139 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1141 /* have offset incremented if needed */
1143 case MCI_COMMAND_HEAD:
1145 case MCI_END_COMMAND:
1146 case MCI_END_COMMAND_LIST:
1148 case MCI_FLAG: break;
1149 case MCI_INTEGER: if (!inCst) offset++; break;
1150 case MCI_END_CONSTANT:
1151 case MCI_STRING: offset++; break;
1152 case MCI_RECT: offset += 4; break;
1153 default: ERR("oops\n");
1156 } while (eid != MCI_END_COMMAND);
1158 WARN("Optarg %s not found\n", debugstr_w(args));
1159 return MCIERR_UNRECOGNIZED_COMMAND;
1161 if (offset == MCI_DATA_SIZE) {
1162 ERR("Internal data[] buffer overflow\n");
1163 return MCIERR_PARSER_INTERNAL;
1169 /**************************************************************************
1170 * MCI_HandleReturnValues [internal]
1172 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1173 LPDWORD data, LPWSTR lpstrRet, UINT uRetLen)
1175 static const WCHAR wszLd [] = {'%','l','d',0};
1176 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1177 static const WCHAR wszCol3[] = {'%','d',':','%','d',':','%','d',0};
1178 static const WCHAR wszCol4[] = {'%','d',':','%','d',':','%','d',':','%','d',0};
1182 case 0: /* nothing to return */
1185 switch (dwRet & 0xFFFF0000ul) {
1187 case MCI_INTEGER_RETURNED:
1188 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1190 case MCI_RESOURCE_RETURNED:
1191 /* return string which ID is HIWORD(data[1]),
1192 * string is loaded from mmsystem.dll */
1193 LoadStringW(WINMM_IData->hWinMM32Instance, HIWORD(data[1]),
1196 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1197 /* return string which ID is HIWORD(data[1]),
1198 * string is loaded from driver */
1199 /* FIXME: this is wrong for a 16 bit handle */
1200 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1201 HIWORD(data[1]), lpstrRet, uRetLen);
1203 case MCI_COLONIZED3_RETURN:
1204 snprintfW(lpstrRet, uRetLen, wszCol3,
1205 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1206 LOBYTE(HIWORD(data[1])));
1208 case MCI_COLONIZED4_RETURN:
1209 snprintfW(lpstrRet, uRetLen, wszCol4,
1210 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1211 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1213 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1217 switch (dwRet & 0xFFFF0000ul) {
1219 /* nothing to do data[1] == lpstrRet */
1221 case MCI_INTEGER_RETURNED:
1222 data[1] = *(LPDWORD)lpstrRet;
1223 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1226 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1231 if (dwRet & 0xFFFF0000ul)
1232 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1233 snprintfW(lpstrRet, uRetLen, wszLd4,
1234 data[1], data[2], data[3], data[4]);
1236 default: ERR("oops\n");
1239 return LOWORD(dwRet);
1242 /**************************************************************************
1243 * mciSendStringW [WINMM.@]
1245 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1246 UINT uRetLen, HWND hwndCallback)
1248 LPWSTR verb, dev, args;
1249 LPWINE_MCIDRIVER wmd = 0;
1250 DWORD dwFlags = 0, dwRet = 0;
1252 DWORD data[MCI_DATA_SIZE];
1255 LPWSTR devAlias = NULL;
1256 BOOL bAutoOpen = FALSE;
1257 static const WCHAR wszNew[] = {'n','e','w',0};
1258 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1260 TRACE("(%s, %p, %d, %p)\n",
1261 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1263 /* format is <command> <device> <optargs> */
1264 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1265 return MCIERR_OUT_OF_MEMORY;
1266 strcpyW( verb, lpstrCommand );
1269 memset(data, 0, sizeof(data));
1271 if (!(args = strchrW(verb, ' '))) {
1272 dwRet = MCIERR_MISSING_DEVICE_NAME;
1276 if ((dwRet = MCI_GetString(&dev, &args))) {
1280 /* case dev == 'new' has to be handled */
1281 if (!strcmpW(dev, wszNew)) {
1282 FIXME("'new': NIY as device name\n");
1283 dwRet = MCIERR_MISSING_DEVICE_NAME;
1287 /* otherwise, try to grab devType from open */
1288 if (!strcmpW(verb, wszOpen)) {
1289 LPWSTR devType, tmp;
1291 if ((devType = strchrW(dev, '!')) != NULL) {
1293 tmp = devType; devType = dev; dev = tmp;
1295 dwFlags |= MCI_OPEN_TYPE;
1296 data[2] = (DWORD)devType;
1297 devType = str_dup_upper(devType);
1298 dwFlags |= MCI_OPEN_ELEMENT;
1299 data[3] = (DWORD)dev;
1300 } else if (strchrW(dev, '.') == NULL) {
1301 tmp = strchrW(dev,' ');
1302 if (tmp) *tmp = '\0';
1303 data[2] = (DWORD)dev;
1304 devType = str_dup_upper(dev);
1305 if (tmp) *tmp = ' ';
1306 dwFlags |= MCI_OPEN_TYPE;
1308 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1309 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1311 tmp = strchrW(devType, ' ');
1312 if (tmp) *tmp = '\0';
1313 devType = str_dup_upper(devType);
1314 if (tmp) *tmp = ' ';
1315 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1318 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1321 devType = str_dup_upper(buf);
1323 dwFlags |= MCI_OPEN_ELEMENT;
1324 data[3] = (DWORD)dev;
1326 if ((devAlias = strstrW(args, wszSAliasS))) {
1329 if (!(tmp = strchrW(devAlias,' '))) tmp = devAlias + strlenW(devAlias);
1330 if (tmp) *tmp = '\0';
1331 tmp2 = HeapAlloc(GetProcessHeap(), 0, (tmp - devAlias + 1) * sizeof(WCHAR) );
1332 memcpy( tmp2, devAlias, (tmp - devAlias) * sizeof(WCHAR) );
1333 tmp2[tmp - devAlias] = 0;
1334 data[4] = (DWORD)tmp2;
1335 /* should be done in regular options parsing */
1336 /* dwFlags |= MCI_OPEN_ALIAS; */
1339 dwRet = MCI_LoadMciDriver(devType, &wmd);
1340 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1341 dwRet = MCIERR_INVALID_DEVICE_NAME;
1342 HeapFree(GetProcessHeap(), 0, devType);
1344 MCI_UnLoadMciDriver(wmd);
1347 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1349 static WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1351 sprintfW(buf, wszOpenWait, dev);
1353 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1356 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1358 /* FIXME: memory leak, MCI driver is not closed */
1359 dwRet = MCIERR_INVALID_DEVICE_ID;
1364 /* get the verb in the different command tables */
1366 /* try the device specific command table */
1367 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1369 /* try the type specific command table */
1370 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1371 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1372 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1373 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1376 /* try core command table */
1377 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1380 TRACE("Command %s not found!\n", debugstr_w(verb));
1381 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1385 /* set up call back */
1386 if (hwndCallback != 0) {
1387 dwFlags |= MCI_NOTIFY;
1388 data[0] = (DWORD)hwndCallback;
1391 /* set return information */
1392 switch (retType = MCI_GetReturnType(lpCmd)) {
1393 case 0: offset = 1; break;
1394 case MCI_INTEGER: offset = 2; break;
1395 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1396 case MCI_RECT: offset = 5; break;
1397 default: ERR("oops\n");
1400 TRACE("verb=%s on dev=%s; offset=%d\n",
1401 debugstr_w(verb), debugstr_w(dev), offset);
1403 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1406 if (bAutoOpen && (dwFlags & MCI_NOTIFY)) {
1407 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1410 /* FIXME: the command should get it's own notification window set up and
1411 * ask for device closing while processing the notification mechanism
1413 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1415 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1416 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1417 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1418 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1419 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1421 if (strcmpW(verb, wszOpen) == 0) {
1422 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1423 MCI_UnLoadMciDriver(wmd);
1424 /* FIXME: notification is not properly shared across two opens */
1426 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
1428 TRACE("=> 1/ %lx (%s)\n", dwRet, debugstr_w(lpstrRet));
1429 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1430 TRACE("=> 2/ %lx (%s)\n", dwRet, debugstr_w(lpstrRet));
1433 HeapFree(GetProcessHeap(), 0, verb);
1434 HeapFree(GetProcessHeap(), 0, devAlias);
1438 /**************************************************************************
1439 * mciSendStringA [WINMM.@]
1441 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1442 UINT uRetLen, HWND hwndCallback)
1444 LPWSTR lpwstrCommand;
1445 LPWSTR lpwstrRet = NULL;
1449 /* FIXME: is there something to do with lpstrReturnString ? */
1450 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1451 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1452 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1455 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1456 if (!lpwstrRet) return MCIERR_OUT_OF_MEMORY;
1458 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1460 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1461 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1462 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1466 /**************************************************************************
1467 * mciExecute [WINMM.@]
1468 * mciExecute [MMSYSTEM.712]
1470 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1475 TRACE("(%s)!\n", lpstrCommand);
1477 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1479 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1480 sprintf(strRet, "Unknown MCI error (%ld)", ret);
1482 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1484 /* FIXME: what shall I return ? */
1488 /**************************************************************************
1489 * mciLoadCommandResource [WINMM.@]
1491 * Strangely, this function only exists as an UNICODE one.
1493 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1497 UINT16 ret = MCI_NO_COMMAND_TABLE;
1499 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1501 /* if a file named "resname.mci" exits, then load resource "resname" from it
1502 * otherwise directly from driver
1503 * We don't support it (who uses this feature ?), but we check anyway
1507 /* FIXME: we should put this back into order, but I never found a program
1508 * actually using this feature, so we may not need it
1513 strcat(strcpy(buf, resname), ".mci");
1514 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1515 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1519 if (!(hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA))) {
1520 WARN("No command table found in resource\n");
1521 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1522 ret = MCI_SetCommandTable(LockResource(hMem), type);
1524 WARN("Couldn't load resource.\n");
1526 TRACE("=> %04x\n", ret);
1530 /**************************************************************************
1531 * mciFreeCommandResource [WINMM.@]
1533 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1535 TRACE("(%08x)!\n", uTable);
1537 return MCI_DeleteCommandTable(uTable, FALSE);
1540 /**************************************************************************
1541 * MCI_SendCommandFrom32 [internal]
1543 DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1545 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1546 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1550 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1551 } else if (pFnMciMapMsg32WTo16) {
1554 switch (res = pFnMciMapMsg32WTo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1555 case WINMM_MAP_MSGERROR:
1556 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1557 dwRet = MCIERR_DRIVER_INTERNAL;
1559 case WINMM_MAP_NOMEM:
1560 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1561 dwRet = MCIERR_OUT_OF_MEMORY;
1564 case WINMM_MAP_OKMEM:
1565 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1566 if (res == WINMM_MAP_OKMEM)
1567 pFnMciUnMapMsg32WTo16(wmd->wType, wMsg, dwParam1, dwParam2);
1575 /**************************************************************************
1576 * MCI_SendCommandFrom16 [internal]
1578 DWORD MCI_SendCommandFrom16(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1580 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1581 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1584 dwRet = MCIERR_INVALID_DEVICE_ID;
1586 if (wmd->bIs32 && pFnMciMapMsg16To32W) {
1589 switch (res = pFnMciMapMsg16To32W(wmd->wType, wMsg, &dwParam2)) {
1590 case WINMM_MAP_MSGERROR:
1591 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1592 dwRet = MCIERR_DRIVER_INTERNAL;
1594 case WINMM_MAP_NOMEM:
1595 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1596 dwRet = MCIERR_OUT_OF_MEMORY;
1599 case WINMM_MAP_OKMEM:
1600 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1601 if (res == WINMM_MAP_OKMEM)
1602 pFnMciUnMapMsg16To32W(wmd->wType, wMsg, dwParam2);
1606 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1612 /**************************************************************************
1613 * MCI_Open [internal]
1615 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1617 WCHAR strDevTyp[128];
1619 LPWINE_MCIDRIVER wmd = NULL;
1621 TRACE("(%08lX, %p)\n", dwParam, lpParms);
1622 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1624 /* only two low bytes are generic, the other ones are dev type specific */
1625 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1626 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1627 MCI_NOTIFY|MCI_WAIT)
1628 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1629 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1631 #undef WINE_MCIDRIVER_SUPP
1635 if (dwParam & MCI_OPEN_TYPE) {
1636 if (dwParam & MCI_OPEN_TYPE_ID) {
1637 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
1639 if (uDevType < MCI_DEVTYPE_FIRST ||
1640 uDevType > MCI_DEVTYPE_LAST ||
1641 !LoadStringW(WINMM_IData->hWinMM32Instance, uDevType,
1642 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1643 dwRet = MCIERR_BAD_INTEGER;
1648 if (lpParms->lpstrDeviceType == NULL) {
1649 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1652 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1653 ptr = strchrW(strDevTyp, '!');
1655 /* this behavior is not documented in windows. However, since, in
1656 * some occasions, MCI_OPEN handling is translated by WinMM into
1657 * a call to mciSendString("open <type>"); this code shall be correct
1659 if (dwParam & MCI_OPEN_ELEMENT) {
1660 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1661 debugstr_w(lpParms->lpstrElementName),
1662 debugstr_w(strDevTyp));
1663 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1666 dwParam |= MCI_OPEN_ELEMENT;
1668 /* FIXME: not a good idea to write in user supplied buffer */
1669 lpParms->lpstrElementName = ptr;
1673 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1676 if (dwParam & MCI_OPEN_ELEMENT) {
1677 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1679 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1680 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1681 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1685 if (!lpParms->lpstrElementName) {
1686 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1690 /* type, if given as a parameter, supersedes file extension */
1691 if (!strDevTyp[0] &&
1692 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1693 strDevTyp, sizeof(strDevTyp))) {
1694 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1695 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1696 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1699 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1700 strcpyW(strDevTyp, wszCdAudio);
1704 if (strDevTyp[0] == 0) {
1705 FIXME("Couldn't load driver\n");
1706 dwRet = MCIERR_INVALID_DEVICE_NAME;
1710 if (dwParam & MCI_OPEN_ALIAS) {
1711 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1712 if (!lpParms->lpstrAlias) {
1713 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1718 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1722 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1723 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet);
1724 /* FIXME: is dwRet the correct ret code ? */
1728 /* only handled devices fall through */
1729 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1731 if (dwParam & MCI_NOTIFY)
1732 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1736 if (wmd) MCI_UnLoadMciDriver(wmd);
1738 if (dwParam & MCI_NOTIFY)
1739 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1743 /**************************************************************************
1744 * MCI_Close [internal]
1746 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1749 LPWINE_MCIDRIVER wmd;
1751 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
1753 if (wDevID == MCI_ALL_DEVICE_ID) {
1754 LPWINE_MCIDRIVER next;
1756 EnterCriticalSection(&WINMM_IData->cs);
1757 /* FIXME: shall I notify once after all is done, or for
1758 * each of the open drivers ? if the latest, which notif
1759 * to return when only one fails ?
1761 for (wmd = WINMM_IData->lpMciDrvs; wmd; ) {
1763 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
1766 LeaveCriticalSection(&WINMM_IData->cs);
1770 if (!(wmd = MCI_GetDriver(wDevID))) {
1771 return MCIERR_INVALID_DEVICE_ID;
1774 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
1776 MCI_UnLoadMciDriver(wmd);
1778 if (dwParam & MCI_NOTIFY)
1779 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1780 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1785 /**************************************************************************
1786 * MCI_WriteString [internal]
1788 DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1793 dstSize /= sizeof(WCHAR);
1794 if (dstSize <= strlenW(lpSrcStr)) {
1795 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1796 ret = MCIERR_PARAM_OVERFLOW;
1798 strcpyW(lpDstStr, lpSrcStr);
1806 /**************************************************************************
1807 * MCI_Sysinfo [internal]
1809 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1811 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1812 WCHAR buf[2048], *s = buf, *p;
1813 LPWINE_MCIDRIVER wmd;
1816 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1818 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1819 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1821 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1822 case MCI_SYSINFO_QUANTITY:
1823 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1824 if (dwFlags & MCI_SYSINFO_OPEN) {
1825 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1826 EnterCriticalSection(&WINMM_IData->cs);
1827 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1830 LeaveCriticalSection(&WINMM_IData->cs);
1832 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1833 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1834 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1835 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1836 RegCloseKey( hKey );
1838 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf), wszSystemIni))
1839 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1842 if (dwFlags & MCI_SYSINFO_OPEN) {
1843 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
1844 EnterCriticalSection(&WINMM_IData->cs);
1845 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1846 if (wmd->wType == lpParms->wDeviceType) cnt++;
1848 LeaveCriticalSection(&WINMM_IData->cs);
1850 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
1851 FIXME("Don't know how to get # of MCI devices of a given type\n");
1855 *(DWORD*)lpParms->lpstrReturn = cnt;
1856 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1857 ret = MCI_INTEGER_RETURNED;
1859 case MCI_SYSINFO_INSTALLNAME:
1860 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1861 if ((wmd = MCI_GetDriver(uDevID))) {
1862 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1863 wmd->lpstrDeviceType);
1865 *lpParms->lpstrReturn = 0;
1866 ret = MCIERR_INVALID_DEVICE_ID;
1868 TRACE("(%ld) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1870 case MCI_SYSINFO_NAME:
1871 TRACE("MCI_SYSINFO_NAME\n");
1872 if (dwFlags & MCI_SYSINFO_OPEN) {
1873 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1874 ret = MCIERR_UNRECOGNIZED_COMMAND;
1877 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1878 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1879 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1880 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1881 lpParms->dwNumber <= cnt) {
1882 DWORD bufLen = sizeof(buf);
1883 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1884 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1887 RegCloseKey( hKey );
1890 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf), wszSystemIni)) {
1891 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1892 TRACE("%ld: %s\n", cnt, debugstr_w(p));
1893 if (cnt == lpParms->dwNumber - 1) {
1900 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1902 TRACE("(%ld) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1905 TRACE("Unsupported flag value=%08lx\n", dwFlags);
1906 ret = MCIERR_UNRECOGNIZED_COMMAND;
1911 /**************************************************************************
1912 * MCI_Break [internal]
1914 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1918 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1920 if (dwFlags & MCI_NOTIFY)
1921 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1922 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1927 /**************************************************************************
1928 * MCI_Sound [internal]
1930 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1934 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1936 if (dwFlags & MCI_SOUND_NAME)
1937 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1939 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1940 if (dwFlags & MCI_NOTIFY)
1941 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1942 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1947 /**************************************************************************
1948 * MCI_SendCommand [internal]
1950 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
1951 DWORD dwParam2, BOOL bFrom32)
1953 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1958 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1959 } else if (pFnMciMapMsg16To32W) {
1960 switch (pFnMciMapMsg16To32W(0, wMsg, &dwParam2)) {
1962 case WINMM_MAP_OKMEM:
1963 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1964 pFnMciUnMapMsg16To32W(0, wMsg, dwParam2);
1966 default: break; /* so that gcc does not bark */
1972 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1973 } else if (pFnMciMapMsg16To32W) {
1974 switch (pFnMciMapMsg16To32W(0, wMsg, &dwParam2)) {
1976 case WINMM_MAP_OKMEM:
1977 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1978 pFnMciUnMapMsg16To32W(0, wMsg, dwParam2);
1980 default: break; /* so that gcc does not bark */
1986 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1987 } else if (pFnMciMapMsg16To32W) {
1988 switch (pFnMciMapMsg16To32W(0, wMsg, &dwParam2)) {
1990 case WINMM_MAP_OKMEM:
1991 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1992 pFnMciUnMapMsg16To32W(0, wMsg, dwParam2);
1994 default: break; /* so that gcc does not bark */
2000 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2001 } else if (pFnMciMapMsg16To32W) {
2002 switch (pFnMciMapMsg16To32W(0, wMsg, &dwParam2)) {
2004 case WINMM_MAP_OKMEM:
2005 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2006 pFnMciUnMapMsg16To32W(0, wMsg, dwParam2);
2008 default: break; /* so that gcc does not bark */
2014 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
2015 } else if (pFnMciMapMsg16To32W) {
2016 switch (pFnMciMapMsg16To32W(0, wMsg, &dwParam2)) {
2018 case WINMM_MAP_OKMEM:
2019 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
2020 pFnMciUnMapMsg16To32W(0, wMsg, dwParam2);
2022 default: break; /* so that gcc does not bark */
2027 if (wDevID == MCI_ALL_DEVICE_ID) {
2028 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2029 dwRet = MCIERR_CANNOT_USE_ALL;
2032 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
2033 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
2040 /**************************************************************************
2041 * MCI_CleanUp [internal]
2043 * Some MCI commands need to be cleaned-up (when not called from
2044 * mciSendString), because MCI drivers return extra information for string
2045 * transformation. This function gets rid of them.
2047 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2)
2050 return LOWORD(dwRet);
2053 case MCI_GETDEVCAPS:
2054 switch (dwRet & 0xFFFF0000ul) {
2056 case MCI_COLONIZED3_RETURN:
2057 case MCI_COLONIZED4_RETURN:
2058 case MCI_INTEGER_RETURNED:
2061 case MCI_RESOURCE_RETURNED:
2062 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2064 LPMCI_GETDEVCAPS_PARMS lmgp;
2066 lmgp = (LPMCI_GETDEVCAPS_PARMS)(void*)dwParam2;
2067 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
2068 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
2072 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2073 HIWORD(dwRet), MCI_MessageToString(wMsg));
2077 switch (dwRet & 0xFFFF0000ul) {
2079 case MCI_COLONIZED3_RETURN:
2080 case MCI_COLONIZED4_RETURN:
2081 case MCI_INTEGER_RETURNED:
2084 case MCI_RESOURCE_RETURNED:
2085 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2087 LPMCI_STATUS_PARMS lsp;
2089 lsp = (LPMCI_STATUS_PARMS)(void*)dwParam2;
2090 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
2091 lsp->dwReturn = LOWORD(lsp->dwReturn);
2095 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2096 HIWORD(dwRet), MCI_MessageToString(wMsg));
2100 switch (dwRet & 0xFFFF0000ul) {
2102 case MCI_INTEGER_RETURNED:
2106 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2110 if (HIWORD(dwRet)) {
2111 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2112 dwRet, MCI_MessageToString(wMsg));
2116 return LOWORD(dwRet);
2119 /**************************************************************************
2120 * mciGetErrorStringW [WINMM.@]
2122 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2126 if (lpstrBuffer != NULL && uLength > 0 &&
2127 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2129 if (LoadStringW(WINMM_IData->hWinMM32Instance,
2130 wError, lpstrBuffer, uLength) > 0) {
2137 /**************************************************************************
2138 * mciGetErrorStringA [WINMM.@]
2140 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2144 if (lpstrBuffer != NULL && uLength > 0 &&
2145 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2147 if (LoadStringA(WINMM_IData->hWinMM32Instance,
2148 dwError, lpstrBuffer, uLength) > 0) {
2155 /**************************************************************************
2156 * mciDriverNotify [WINMM.@]
2158 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2160 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2162 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2165 /**************************************************************************
2166 * mciGetDriverData [WINMM.@]
2168 DWORD WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2170 LPWINE_MCIDRIVER wmd;
2172 TRACE("(%04x)\n", uDeviceID);
2174 wmd = MCI_GetDriver(uDeviceID);
2177 WARN("Bad uDeviceID\n");
2181 return wmd->dwPrivate;
2184 /**************************************************************************
2185 * mciSetDriverData [WINMM.@]
2187 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD data)
2189 LPWINE_MCIDRIVER wmd;
2191 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2193 wmd = MCI_GetDriver(uDeviceID);
2196 WARN("Bad uDeviceID\n");
2200 wmd->dwPrivate = data;
2204 /**************************************************************************
2205 * mciSendCommandW [WINMM.@]
2208 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2212 TRACE("(%08x, %s, %08lx, %08lx)\n",
2213 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2215 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, TRUE);
2216 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2217 TRACE("=> %08lx\n", dwRet);
2221 /**************************************************************************
2222 * mciSendCommandA [WINMM.@]
2224 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2229 TRACE("(%08x, %s, %08lx, %08lx)\n",
2230 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2232 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2235 FIXME("message %04x mapping failed\n", wMsg);
2236 return MMSYSERR_NOMEM;
2238 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2240 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2244 /**************************************************************************
2245 * mciGetDeviceIDA [WINMM.@]
2247 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2249 LPWSTR w = MCI_strdupAtoW(lpstrName);
2250 UINT ret = MCIERR_OUT_OF_MEMORY;
2254 ret = mciGetDeviceIDW(w);
2255 HeapFree(GetProcessHeap(), 0, w);
2260 /**************************************************************************
2261 * mciGetDeviceIDW [WINMM.@]
2263 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2265 return MCI_GetDriverFromString(lpwstrName);
2268 /******************************************************************
2271 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
2273 static void MyUserYield(void)
2275 HMODULE mod = GetModuleHandleA( "user32.dll" );
2278 FARPROC proc = GetProcAddress( mod, "UserYield16" );
2283 /**************************************************************************
2284 * MCI_DefYieldProc [internal]
2286 UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2290 TRACE("(0x%04x, 0x%08lx)\n", wDevID, data);
2292 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2293 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2299 msg.hwnd = HWND_32(HIWORD(data));
2300 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2306 /**************************************************************************
2307 * mciSetYieldProc [WINMM.@]
2309 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2311 LPWINE_MCIDRIVER wmd;
2313 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
2315 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2316 WARN("Bad uDeviceID\n");
2320 wmd->lpfnYieldProc = fpYieldProc;
2321 wmd->dwYieldData = dwYieldData;
2327 /**************************************************************************
2328 * mciGetDeviceIDFromElementIDA [WINMM.@]
2330 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2332 LPWSTR w = MCI_strdupAtoW(lpstrType);
2337 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2338 HeapFree(GetProcessHeap(), 0, w);
2343 /**************************************************************************
2344 * mciGetDeviceIDFromElementIDW [WINMM.@]
2346 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2348 /* FIXME: that's rather strange, there is no
2349 * mciGetDeviceIDFromElementID32A in winmm.spec
2351 FIXME("(%lu, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2355 /**************************************************************************
2356 * mciGetYieldProc [WINMM.@]
2358 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2360 LPWINE_MCIDRIVER wmd;
2362 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2364 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2365 WARN("Bad uDeviceID\n");
2368 if (!wmd->lpfnYieldProc) {
2369 WARN("No proc set\n");
2373 WARN("Proc is 32 bit\n");
2376 return wmd->lpfnYieldProc;
2379 /**************************************************************************
2380 * mciGetCreatorTask [WINMM.@]
2382 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2384 LPWINE_MCIDRIVER wmd;
2387 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
2389 TRACE("(%u) => %p\n", uDeviceID, ret);
2393 /**************************************************************************
2394 * mciDriverYield [WINMM.@]
2396 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2398 LPWINE_MCIDRIVER wmd;
2401 TRACE("(%04x)\n", uDeviceID);
2403 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || !wmd->bIs32) {
2406 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);