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"
65 #include "wine/debug.h"
66 #include "wine/unicode.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(mci);
70 /* First MCI valid device ID (0 means error) */
71 #define MCI_MAGIC 0x0001
74 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};
75 static const WCHAR wszNull [] = {0};
76 static const WCHAR wszAll [] = {'A','L','L',0};
77 static const WCHAR wszMci [] = {'M','C','I',0};
78 static const WCHAR wszOpen [] = {'o','p','e','n',0};
79 static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
81 static WINE_MCIDRIVER *MciDrivers;
83 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
84 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType);
86 /* dup a string and uppercase it */
87 static inline LPWSTR str_dup_upper( LPCWSTR str )
89 INT len = (strlenW(str) + 1) * sizeof(WCHAR);
90 LPWSTR p = HeapAlloc( GetProcessHeap(), 0, len );
93 memcpy( p, str, len );
99 /**************************************************************************
100 * MCI_GetDriver [internal]
102 static LPWINE_MCIDRIVER MCI_GetDriver(UINT wDevID)
104 LPWINE_MCIDRIVER wmd = 0;
106 EnterCriticalSection(&WINMM_cs);
107 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
108 if (wmd->wDeviceID == wDevID)
111 LeaveCriticalSection(&WINMM_cs);
115 /**************************************************************************
116 * MCI_GetDriverFromString [internal]
118 static UINT MCI_GetDriverFromString(LPCWSTR lpstrName)
120 LPWINE_MCIDRIVER wmd;
126 if (!strcmpiW(lpstrName, wszAll))
127 return MCI_ALL_DEVICE_ID;
129 EnterCriticalSection(&WINMM_cs);
130 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
131 if (wmd->lpstrElementName && strcmpW(wmd->lpstrElementName, lpstrName) == 0) {
132 ret = wmd->wDeviceID;
135 if (wmd->lpstrDeviceType && strcmpiW(wmd->lpstrDeviceType, lpstrName) == 0) {
136 ret = wmd->wDeviceID;
139 if (wmd->lpstrAlias && strcmpiW(wmd->lpstrAlias, lpstrName) == 0) {
140 ret = wmd->wDeviceID;
144 LeaveCriticalSection(&WINMM_cs);
149 /**************************************************************************
150 * MCI_MessageToString [internal]
152 const char* MCI_MessageToString(UINT wMsg)
154 #define CASE(s) case (s): return #s
164 CASE(DRV_QUERYCONFIGURE);
167 CASE(DRV_EXITSESSION);
168 CASE(DRV_EXITAPPLICATION);
172 CASE(MCI_CLOSE_DRIVER);
181 CASE(MCI_GETDEVCAPS);
185 CASE(MCI_OPEN_DRIVER);
203 /* constants for digital video */
217 return wine_dbg_sprintf("MCI_<<%04X>>", wMsg);
221 LPWSTR MCI_strdupAtoW( LPCSTR str )
226 if (!str) return NULL;
227 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
228 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
229 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
233 LPSTR MCI_strdupWtoA( LPCWSTR str )
238 if (!str) return NULL;
239 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
240 ret = HeapAlloc( GetProcessHeap(), 0, len );
241 if (ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
245 static int MCI_MapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
247 if (msg < DRV_RESERVED) return 0;
286 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA*)*dwParam2;
287 MCI_OPEN_PARMSW *mci_openW;
290 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW) + 2 * sizeof(DWORD));
293 *ptr++ = *dwParam2; /* save the previous pointer */
294 *dwParam2 = (DWORD_PTR)ptr;
295 mci_openW = (MCI_OPEN_PARMSW *)ptr;
297 if (dwParam1 & MCI_NOTIFY)
298 mci_openW->dwCallback = mci_openA->dwCallback;
300 if (dwParam1 & MCI_OPEN_TYPE)
302 if (dwParam1 & MCI_OPEN_TYPE_ID)
303 mci_openW->lpstrDeviceType = (LPCWSTR)mci_openA->lpstrDeviceType;
305 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
307 if (dwParam1 & MCI_OPEN_ELEMENT)
309 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
310 mci_openW->lpstrElementName = (LPCWSTR)mci_openA->lpstrElementName;
312 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
314 if (dwParam1 & MCI_OPEN_ALIAS)
315 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
316 /* FIXME: this is only needed for specific types of MCI devices, and
317 * may cause a segfault if the two DWORD:s don't exist at the end of
320 memcpy(mci_openW + 1, mci_openA + 1, 2 * sizeof(DWORD));
325 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
327 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
328 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
330 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
331 if (!mci_windowW) return -1;
333 *dwParam2 = (DWORD_PTR)mci_windowW;
335 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
337 if (dwParam1 & MCI_NOTIFY)
338 mci_windowW->dwCallback = mci_windowA->dwCallback;
339 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
340 mci_windowW->hWnd = mci_windowA->hWnd;
341 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
342 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
350 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
351 MCI_SYSINFO_PARMSW *mci_sysinfoW;
354 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
357 *ptr++ = *dwParam2; /* save the previous pointer */
358 *dwParam2 = (DWORD_PTR)ptr;
359 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
361 if (dwParam1 & MCI_NOTIFY)
362 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
364 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
365 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize);
366 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
367 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
372 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
373 MCI_INFO_PARMSW *mci_infoW;
376 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
379 *ptr++ = *dwParam2; /* save the previous pointer */
380 *dwParam2 = (DWORD_PTR)ptr;
381 mci_infoW = (MCI_INFO_PARMSW *)ptr;
383 if (dwParam1 & MCI_NOTIFY)
384 mci_infoW->dwCallback = mci_infoA->dwCallback;
386 mci_infoW->dwRetSize = mci_infoA->dwRetSize * sizeof(WCHAR); /* it's not the same as SYSINFO !!! */
387 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize);
392 MCI_SAVE_PARMSA *mci_saveA = (MCI_SAVE_PARMSA *)*dwParam2;
393 MCI_SAVE_PARMSW *mci_saveW;
395 mci_saveW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW));
396 if (!mci_saveW) return -1;
398 *dwParam2 = (DWORD_PTR)mci_saveW;
399 if (dwParam1 & MCI_NOTIFY)
400 mci_saveW->dwCallback = mci_saveA->dwCallback;
401 mci_saveW->lpfilename = MCI_strdupAtoW(mci_saveA->lpfilename);
406 MCI_LOAD_PARMSA *mci_loadA = (MCI_LOAD_PARMSA *)*dwParam2;
407 MCI_LOAD_PARMSW *mci_loadW;
409 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
410 if (!mci_loadW) return -1;
412 *dwParam2 = (DWORD_PTR)mci_loadW;
413 if (dwParam1 & MCI_NOTIFY)
414 mci_loadW->dwCallback = mci_loadA->dwCallback;
415 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
421 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
422 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
424 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
425 if (!mci_vd_escapeW) return -1;
427 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
428 if (dwParam1 & MCI_NOTIFY)
429 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
430 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
434 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
439 static DWORD MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
446 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
447 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
448 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)(ptr + 1);
450 mci_openA->wDeviceID = mci_openW->wDeviceID;
452 if (dwParam1 & MCI_OPEN_TYPE)
454 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
455 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrDeviceType);
457 if (dwParam1 & MCI_OPEN_ELEMENT)
459 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
460 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrElementName);
462 if (dwParam1 & MCI_OPEN_ALIAS)
463 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrAlias);
464 HeapFree(GetProcessHeap(), 0, ptr);
468 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
470 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
472 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
473 HeapFree(GetProcessHeap(), 0, mci_windowW);
479 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
480 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
481 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)(ptr + 1);
485 mci_sysinfoA->dwNumber = mci_sysinfoW->dwNumber;
486 mci_sysinfoA->wDeviceType = mci_sysinfoW->wDeviceType;
487 if (dwParam1 & MCI_SYSINFO_QUANTITY)
488 *(DWORD*)mci_sysinfoA->lpstrReturn = *(DWORD*)mci_sysinfoW->lpstrReturn;
490 WideCharToMultiByte(CP_ACP, 0,
491 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
492 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
496 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
497 HeapFree(GetProcessHeap(), 0, ptr);
502 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
503 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
504 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)(ptr + 1);
508 WideCharToMultiByte(CP_ACP, 0,
509 mci_infoW->lpstrReturn, mci_infoW->dwRetSize / sizeof(WCHAR),
510 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
514 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
515 HeapFree(GetProcessHeap(), 0, ptr);
520 MCI_SAVE_PARMSW *mci_saveW = (MCI_SAVE_PARMSW *)dwParam2;
522 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW->lpfilename);
523 HeapFree(GetProcessHeap(), 0, mci_saveW);
528 MCI_LOAD_PARMSW *mci_loadW = (MCI_LOAD_PARMSW *)dwParam2;
530 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
531 HeapFree(GetProcessHeap(), 0, mci_loadW);
536 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
538 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
539 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
544 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
551 /**************************************************************************
552 * MCI_GetDevTypeFromFileName [internal]
554 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
558 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
559 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
560 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
561 if ((tmp = strrchrW(fileName, '.'))) {
562 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
563 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
565 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
567 if (lRet == ERROR_SUCCESS) return 0;
569 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
571 return MCIERR_EXTENSION_NOT_FOUND;
574 #define MAX_MCICMDTABLE 20
575 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
577 typedef struct tagWINE_MCICMDTABLE {
581 UINT nVerbs; /* number of verbs in command table */
582 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
583 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
585 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
587 /**************************************************************************
588 * MCI_IsCommandTableValid [internal]
590 static BOOL MCI_IsCommandTableValid(UINT uTbl)
599 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
600 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
602 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
605 lmem = S_MciCmdTable[uTbl].lpTable;
608 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
609 flg = *(const DWORD*)lmem;
610 eid = *(const WORD*)(lmem + sizeof(DWORD));
611 lmem += sizeof(DWORD) + sizeof(WORD);
613 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
615 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
616 case MCI_STRING: if (inCst) return FALSE; break;
617 case MCI_INTEGER: if (!*str) return FALSE; break;
618 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
619 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
620 case MCI_FLAG: if (!*str) return FALSE; break;
621 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
622 case MCI_RECT: if (!*str || inCst) return FALSE; break;
623 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
624 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
625 default: return FALSE;
627 } while (eid != MCI_END_COMMAND_LIST);
631 /**************************************************************************
632 * MCI_DumpCommandTable [internal]
634 static BOOL MCI_DumpCommandTable(UINT uTbl)
641 if (!MCI_IsCommandTableValid(uTbl)) {
642 ERR("Ooops: %d is not valid\n", uTbl);
646 lmem = S_MciCmdTable[uTbl].lpTable;
650 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
651 flg = *(const DWORD*)lmem;
652 eid = *(const WORD*)(lmem + sizeof(DWORD));
653 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
654 lmem += sizeof(DWORD) + sizeof(WORD);
655 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
656 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
657 } while (eid != MCI_END_COMMAND_LIST);
662 /**************************************************************************
663 * MCI_GetCommandTable [internal]
665 static UINT MCI_GetCommandTable(UINT uDevType)
671 /* first look up existing for existing devType */
672 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
673 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
677 /* well try to load id */
678 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
679 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
682 } else if (uDevType == 0) {
683 static const WCHAR wszCore[] = {'C','O','R','E',0};
686 uTbl = MCI_NO_COMMAND_TABLE;
688 HRSRC hRsrc = FindResourceW(hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
691 if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
693 uTbl = MCI_SetCommandTable(hMem, uDevType);
695 WARN("No command table found in resource %p[%s]\n",
696 hWinMM32Instance, debugstr_w(str));
699 TRACE("=> %d\n", uTbl);
703 /**************************************************************************
704 * MCI_SetCommandTable [internal]
706 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType)
709 static BOOL bInitDone = FALSE;
712 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
713 * can be called with 0 as a uDevType to retrieve it.
718 MCI_GetCommandTable(0);
720 TRACE("(%p, %u)\n", hMem, uDevType);
721 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
722 if (!S_MciCmdTable[uTbl].lpTable) {
728 S_MciCmdTable[uTbl].uDevType = uDevType;
729 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
730 S_MciCmdTable[uTbl].hMem = hMem;
733 MCI_DumpCommandTable(uTbl);
736 /* create the verbs table */
737 /* get # of entries */
738 lmem = S_MciCmdTable[uTbl].lpTable;
742 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
743 eid = *(const WORD*)(lmem + sizeof(DWORD));
744 lmem += sizeof(DWORD) + sizeof(WORD);
745 if (eid == MCI_COMMAND_HEAD)
747 } while (eid != MCI_END_COMMAND_LIST);
749 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
750 S_MciCmdTable[uTbl].nVerbs = count;
752 lmem = S_MciCmdTable[uTbl].lpTable;
756 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
757 eid = *(const WORD*)(lmem + sizeof(DWORD));
758 lmem += sizeof(DWORD) + sizeof(WORD);
759 if (eid == MCI_COMMAND_HEAD)
760 S_MciCmdTable[uTbl].aVerbs[count++] = str;
761 } while (eid != MCI_END_COMMAND_LIST);
762 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
767 return MCI_NO_COMMAND_TABLE;
770 /**************************************************************************
771 * MCI_UnLoadMciDriver [internal]
773 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
775 LPWINE_MCIDRIVER* tmp;
780 CloseDriver(wmd->hDriver, 0, 0);
782 if (wmd->dwPrivate != 0)
783 WARN("Unloading mci driver with non nul dwPrivate field\n");
785 EnterCriticalSection(&WINMM_cs);
786 for (tmp = &MciDrivers; *tmp; tmp = &(*tmp)->lpNext) {
792 LeaveCriticalSection(&WINMM_cs);
794 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
795 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
796 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
798 HeapFree(GetProcessHeap(), 0, wmd);
802 /**************************************************************************
803 * MCI_OpenMciDriver [internal]
805 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
809 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
812 /* First load driver */
813 wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp);
814 return wmd->hDriver != NULL;
817 /**************************************************************************
818 * MCI_LoadMciDriver [internal]
820 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
822 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
823 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
824 MCI_OPEN_DRIVER_PARMSW modp;
827 if (!wmd || !strDevTyp) {
828 dwRet = MCIERR_OUT_OF_MEMORY;
832 wmd->lpfnYieldProc = MCI_DefYieldProc;
833 wmd->dwYieldData = VK_CANCEL;
834 wmd->CreatorThread = GetCurrentThreadId();
836 EnterCriticalSection(&WINMM_cs);
837 /* wmd must be inserted in list before sending opening the driver, because it
838 * may want to lookup at wDevID
840 wmd->lpNext = MciDrivers;
843 for (modp.wDeviceID = MCI_MAGIC;
844 MCI_GetDriver(modp.wDeviceID) != 0;
847 wmd->wDeviceID = modp.wDeviceID;
849 LeaveCriticalSection(&WINMM_cs);
851 TRACE("wDevID=%04X\n", modp.wDeviceID);
853 modp.lpstrParams = NULL;
855 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
856 /* silence warning if all is used... some bogus program use commands like
859 if (strcmpiW(strDevTyp, wszAll) == 0) {
860 dwRet = MCIERR_CANNOT_USE_ALL;
862 FIXME("Couldn't load driver for type %s.\n",
863 debugstr_w(strDevTyp));
864 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
869 /* FIXME: should also check that module's description is of the form
870 * MODULENAME:[MCI] comment
873 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
874 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
875 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
877 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
878 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
880 wmd->lpstrDeviceType = strDevTyp;
881 wmd->wType = modp.wType;
883 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
884 modp.wDeviceID, modp.wType, modp.wDeviceID);
888 MCI_UnLoadMciDriver(wmd);
889 HeapFree(GetProcessHeap(), 0, strDevTyp);
894 /**************************************************************************
895 * MCI_SendCommandFrom32 [internal]
897 static DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
899 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
900 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
903 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
908 /**************************************************************************
909 * MCI_FinishOpen [internal]
911 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
914 if (dwParam & MCI_OPEN_ELEMENT)
916 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms->lpstrElementName)+1) * sizeof(WCHAR));
917 strcpyW( wmd->lpstrElementName, lpParms->lpstrElementName );
919 if (dwParam & MCI_OPEN_ALIAS)
921 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms->lpstrAlias)+1) * sizeof(WCHAR));
922 strcpyW( wmd->lpstrAlias, lpParms->lpstrAlias);
924 lpParms->wDeviceID = wmd->wDeviceID;
926 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
930 /**************************************************************************
931 * MCI_FindCommand [internal]
933 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
937 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
940 /* another improvement would be to have the aVerbs array sorted,
941 * so that we could use a dichotomic search on it, rather than this dumb
944 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
945 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
946 return S_MciCmdTable[uTbl].aVerbs[idx];
952 /**************************************************************************
953 * MCI_GetReturnType [internal]
955 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
957 lpCmd = (LPCWSTR)((const BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
958 if (*lpCmd == '\0' && *(const WORD*)((const BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
959 return *(const DWORD*)(lpCmd + 1);
964 /**************************************************************************
965 * MCI_GetMessage [internal]
967 static WORD MCI_GetMessage(LPCWSTR lpCmd)
969 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
972 /**************************************************************************
973 * MCI_GetDWord [internal]
975 static BOOL MCI_GetDWord(DWORD_PTR* data, LPWSTR* ptr)
980 val = strtoulW(*ptr, &ret, 0);
984 case ' ': ret++; break;
985 default: return FALSE;
993 /**************************************************************************
994 * MCI_GetString [internal]
996 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
1000 /* see if we have a quoted string */
1002 ptr = strchrW(*str = ptr + 1, '"');
1003 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
1004 /* FIXME: shall we escape \" from string ?? */
1005 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1006 *ptr++ = '\0'; /* remove trailing " */
1007 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
1009 ptr = strchrW(ptr, ' ');
1014 ptr = *args + strlenW(*args);
1023 #define MCI_DATA_SIZE 16
1025 /**************************************************************************
1026 * MCI_ParseOptArgs [internal]
1028 static DWORD MCI_ParseOptArgs(DWORD_PTR* data, int _offset, LPCWSTR lpCmd,
1029 LPWSTR args, LPDWORD dwFlags)
1034 DWORD dwRet, flg, cflg = 0;
1038 /* loop on arguments */
1040 lmem = (const char*)lpCmd;
1041 found = inCst = FALSE;
1044 /* skip any leading white space(s) */
1045 while (*args == ' ') args++;
1046 TRACE("args=%s offset=%d\n", debugstr_w(args), offset);
1048 do { /* loop on options for command table for the requested verb */
1049 str = (LPCWSTR)lmem;
1050 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1051 flg = *(const DWORD*)lmem;
1052 eid = *(const WORD*)(lmem + sizeof(DWORD));
1053 lmem += sizeof(DWORD) + sizeof(WORD);
1054 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1058 inCst = TRUE; cflg = flg; break;
1059 case MCI_END_CONSTANT:
1060 /* there may be additional integral values after flag in constant */
1061 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1064 inCst = FALSE; cflg = 0;
1068 if (strncmpiW(args, str, len) == 0 &&
1069 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1070 /* store good values into data[] */
1072 while (*args == ' ') args++;
1076 case MCI_COMMAND_HEAD:
1078 case MCI_END_COMMAND:
1079 case MCI_END_COMMAND_LIST:
1080 case MCI_CONSTANT: /* done above */
1081 case MCI_END_CONSTANT: /* done above */
1088 data[offset] |= flg;
1093 if (!MCI_GetDWord(&(data[offset]), &args)) {
1094 return MCIERR_BAD_INTEGER;
1099 /* store rect in data (offset..offset+3) */
1101 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1102 !MCI_GetDWord(&(data[offset+1]), &args) ||
1103 !MCI_GetDWord(&(data[offset+2]), &args) ||
1104 !MCI_GetDWord(&(data[offset+3]), &args)) {
1105 ERR("Bad rect %s\n", debugstr_w(args));
1106 return MCIERR_BAD_INTEGER;
1111 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1114 default: ERR("oops\n");
1116 /* exit inside while loop, except if just entered in constant area definition */
1117 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1119 /* have offset incremented if needed */
1121 case MCI_COMMAND_HEAD:
1123 case MCI_END_COMMAND:
1124 case MCI_END_COMMAND_LIST:
1126 case MCI_FLAG: break;
1127 case MCI_INTEGER: if (!inCst) offset++; break;
1128 case MCI_END_CONSTANT:
1129 case MCI_STRING: offset++; break;
1130 case MCI_RECT: offset += 4; break;
1131 default: ERR("oops\n");
1134 } while (eid != MCI_END_COMMAND);
1136 WARN("Optarg %s not found\n", debugstr_w(args));
1137 return MCIERR_UNRECOGNIZED_COMMAND;
1139 if (offset == MCI_DATA_SIZE) {
1140 ERR("Internal data[] buffer overflow\n");
1141 return MCIERR_PARSER_INTERNAL;
1147 /**************************************************************************
1148 * MCI_HandleReturnValues [internal]
1150 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1151 DWORD_PTR* data, LPWSTR lpstrRet, UINT uRetLen)
1153 static const WCHAR wszLd [] = {'%','l','d',0};
1154 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1155 static const WCHAR wszCol3[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1156 static const WCHAR wszCol4[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1160 case 0: /* nothing to return */
1163 switch (dwRet & 0xFFFF0000ul) {
1165 case MCI_INTEGER_RETURNED:
1166 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1168 case MCI_RESOURCE_RETURNED:
1169 /* return string which ID is HIWORD(data[1]),
1170 * string is loaded from mmsystem.dll */
1171 LoadStringW(hWinMM32Instance, HIWORD(data[1]), lpstrRet, uRetLen);
1173 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1174 /* return string which ID is HIWORD(data[1]),
1175 * string is loaded from driver */
1176 /* FIXME: this is wrong for a 16 bit handle */
1177 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1178 HIWORD(data[1]), lpstrRet, uRetLen);
1180 case MCI_COLONIZED3_RETURN:
1181 snprintfW(lpstrRet, uRetLen, wszCol3,
1182 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1183 LOBYTE(HIWORD(data[1])));
1185 case MCI_COLONIZED4_RETURN:
1186 snprintfW(lpstrRet, uRetLen, wszCol4,
1187 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1188 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1190 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1194 switch (dwRet & 0xFFFF0000ul) {
1196 /* nothing to do data[1] == lpstrRet */
1198 case MCI_INTEGER_RETURNED:
1199 data[1] = *(LPDWORD)lpstrRet;
1200 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1203 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1208 if (dwRet & 0xFFFF0000ul)
1209 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1210 snprintfW(lpstrRet, uRetLen, wszLd4,
1211 data[1], data[2], data[3], data[4]);
1213 default: ERR("oops\n");
1216 return LOWORD(dwRet);
1219 /**************************************************************************
1220 * mciSendStringW [WINMM.@]
1222 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1223 UINT uRetLen, HWND hwndCallback)
1225 LPWSTR verb, dev, args;
1226 LPWINE_MCIDRIVER wmd = 0;
1228 DWORD dwFlags = 0, dwRet = 0;
1230 DWORD_PTR data[MCI_DATA_SIZE];
1233 static const WCHAR wszNew[] = {'n','e','w',0};
1234 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1235 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1236 static const WCHAR wszSysinfo[] = {'s','y','s','i','n','f','o',0};
1237 static const WCHAR wszSound[] = {'s','o','u','n','d',0};
1238 static const WCHAR wszBreak[] = {'b','r','e','a','k',0};
1240 TRACE("(%s, %p, %d, %p)\n",
1241 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1243 /* format is <command> <device> <optargs> */
1244 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1245 return MCIERR_OUT_OF_MEMORY;
1246 strcpyW( verb, lpstrCommand );
1249 memset(data, 0, sizeof(data));
1251 if (!(args = strchrW(verb, ' '))) {
1252 dwRet = MCIERR_MISSING_DEVICE_NAME;
1256 if ((dwRet = MCI_GetString(&dev, &args))) {
1259 uDevID = strcmpiW(dev, wszAll) ? 0 : MCI_ALL_DEVICE_ID;
1261 /* Determine devType from open */
1262 if (!strcmpW(verb, wszOpen)) {
1263 LPWSTR devType, tmp;
1266 /* case dev == 'new' has to be handled */
1267 if (!strcmpW(dev, wszNew)) {
1269 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1271 tmp = strchrW(devType, ' ');
1272 if (tmp) *tmp = '\0';
1273 devType = str_dup_upper(devType);
1274 if (tmp) *tmp = ' ';
1275 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1277 WARN("open new requires device type\n");
1278 dwRet = MCIERR_MISSING_DEVICE_NAME;
1281 } else if ((devType = strchrW(dev, '!')) != NULL) {
1283 tmp = devType; devType = dev; dev = tmp;
1285 dwFlags |= MCI_OPEN_TYPE;
1286 data[2] = (DWORD_PTR)devType;
1287 devType = str_dup_upper(devType);
1288 dwFlags |= MCI_OPEN_ELEMENT;
1289 data[3] = (DWORD_PTR)dev;
1290 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1291 /* this is the name of a mci driver's type */
1292 tmp = strchrW(dev, ' ');
1293 if (tmp) *tmp = '\0';
1294 data[2] = (DWORD_PTR)dev;
1295 devType = str_dup_upper(dev);
1296 if (tmp) *tmp = ' ';
1297 dwFlags |= MCI_OPEN_TYPE;
1299 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1301 tmp = strchrW(devType, ' ');
1302 if (tmp) *tmp = '\0';
1303 devType = str_dup_upper(devType);
1304 if (tmp) *tmp = ' ';
1305 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1307 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1310 devType = str_dup_upper(buf);
1312 dwFlags |= MCI_OPEN_ELEMENT;
1313 data[3] = (DWORD_PTR)dev;
1315 if (MCI_ALL_DEVICE_ID == uDevID) {
1316 dwRet = MCIERR_CANNOT_USE_ALL;
1319 if (!strstrW(args, wszSAliasS) && !dev) {
1320 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1324 dwRet = MCI_LoadMciDriver(devType, &wmd);
1325 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1326 dwRet = MCIERR_INVALID_DEVICE_NAME;
1327 HeapFree(GetProcessHeap(), 0, devType);
1329 MCI_UnLoadMciDriver(wmd);
1332 } else if (!strcmpW(verb, wszSysinfo)) {
1333 /* System commands are not subject to auto-open. */
1334 /* It's too early to handle Sysinfo here because the
1335 * requirements on dev depend on the flags:
1336 * alias with INSTALLNAME, name like "waveaudio"
1337 * with QUANTITY and NAME. */
1338 data[4] = MCI_ALL_DEVICE_ID;
1339 if (MCI_ALL_DEVICE_ID != uDevID) {
1340 /* FIXME: Map device name like waveaudio to MCI_DEVTYPE_xyz */
1341 uDevID = mciGetDeviceIDW(dev);
1342 wmd = MCI_GetDriver(uDevID);
1344 data[4] = wmd->wType;
1346 } else if (!strcmpW(verb, wszSound) || !strcmpW(verb, wszBreak)) {
1347 /* Prevent auto-open for system commands. */
1348 } else if ((MCI_ALL_DEVICE_ID != uDevID) && !(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1350 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1352 sprintfW(buf, wszOpenWait, dev);
1354 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1357 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1359 /* FIXME: memory leak, MCI driver is not closed */
1360 dwRet = MCIERR_INVALID_DEVICE_ID;
1365 /* get the verb in the different command tables */
1367 /* try the device specific command table */
1368 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1370 /* try the type specific command table */
1371 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1372 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1373 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1374 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1377 /* try core command table */
1378 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1381 TRACE("Command %s not found!\n", debugstr_w(verb));
1382 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1386 /* set return information */
1387 switch (retType = MCI_GetReturnType(lpCmd)) {
1388 case 0: offset = 1; break;
1389 case MCI_INTEGER: offset = 2; break;
1390 case MCI_STRING: data[1] = (DWORD_PTR)lpstrRet; data[2] = uRetLen; offset = 3; break;
1391 case MCI_RECT: offset = 5; break;
1392 default: ERR("oops\n");
1395 TRACE("verb=%s on dev=%s; offset=%d\n",
1396 debugstr_w(verb), debugstr_w(dev), offset);
1398 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1401 /* set up call back */
1402 if (dwFlags & MCI_NOTIFY) {
1403 data[0] = (DWORD_PTR)hwndCallback;
1406 /* FIXME: the command should get it's own notification window set up and
1407 * ask for device closing while processing the notification mechanism
1409 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1411 TRACE("[%d, %s, %08x, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1412 wmd ? wmd->wDeviceID : uDevID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1413 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1414 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1415 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1417 if (strcmpW(verb, wszOpen) == 0) {
1418 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1419 MCI_UnLoadMciDriver(wmd);
1420 /* FIXME: notification is not properly shared across two opens */
1422 dwRet = MCI_SendCommand(wmd ? wmd->wDeviceID : uDevID, MCI_GetMessage(lpCmd), dwFlags, (DWORD_PTR)data);
1424 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1425 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1426 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1429 HeapFree(GetProcessHeap(), 0, verb);
1433 /**************************************************************************
1434 * mciSendStringA [WINMM.@]
1436 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1437 UINT uRetLen, HWND hwndCallback)
1439 LPWSTR lpwstrCommand;
1440 LPWSTR lpwstrRet = NULL;
1444 /* FIXME: is there something to do with lpstrReturnString ? */
1445 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1446 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1447 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1450 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1452 WARN("no memory\n");
1453 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1454 return MCIERR_OUT_OF_MEMORY;
1457 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1458 if (!ret && lpwstrRet)
1459 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1460 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1461 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1465 /**************************************************************************
1466 * mciExecute [WINMM.@]
1468 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1473 TRACE("(%s)!\n", lpstrCommand);
1475 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1477 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1478 sprintf(strRet, "Unknown MCI error (%d)", ret);
1480 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1482 /* FIXME: what shall I return ? */
1486 /**************************************************************************
1487 * mciLoadCommandResource [WINMM.@]
1489 * Strangely, this function only exists as a UNICODE one.
1491 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1493 UINT ret = MCI_NO_COMMAND_TABLE;
1497 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1499 /* if a file named "resname.mci" exits, then load resource "resname" from it
1500 * otherwise directly from driver
1501 * We don't support it (who uses this feature ?), but we check anyway
1505 /* FIXME: we should put this back into order, but I never found a program
1506 * actually using this feature, so we may not need it
1511 strcat(strcpy(buf, resname), ".mci");
1512 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1513 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1517 if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
1518 (hMem = LoadResource(hInst, hRsrc))) {
1519 ret = MCI_SetCommandTable(hMem, type);
1522 else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
1524 TRACE("=> %04x\n", ret);
1528 /**************************************************************************
1529 * mciFreeCommandResource [WINMM.@]
1531 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1533 TRACE("(%08x)!\n", uTable);
1535 if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
1538 FreeResource(S_MciCmdTable[uTable].hMem);
1539 S_MciCmdTable[uTable].hMem = NULL;
1540 S_MciCmdTable[uTable].lpTable = NULL;
1541 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
1542 S_MciCmdTable[uTable].aVerbs = 0;
1543 S_MciCmdTable[uTable].nVerbs = 0;
1547 /**************************************************************************
1548 * MCI_Open [internal]
1550 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1552 WCHAR strDevTyp[128];
1554 LPWINE_MCIDRIVER wmd = NULL;
1556 TRACE("(%08X, %p)\n", dwParam, lpParms);
1557 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1559 /* only two low bytes are generic, the other ones are dev type specific */
1560 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1561 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1562 MCI_NOTIFY|MCI_WAIT)
1563 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1564 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1566 #undef WINE_MCIDRIVER_SUPP
1570 if (dwParam & MCI_OPEN_TYPE) {
1571 if (dwParam & MCI_OPEN_TYPE_ID) {
1572 WORD uDevType = LOWORD(lpParms->lpstrDeviceType);
1574 if (uDevType < MCI_DEVTYPE_FIRST ||
1575 uDevType > MCI_DEVTYPE_LAST ||
1576 !LoadStringW(hWinMM32Instance, uDevType,
1577 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1578 dwRet = MCIERR_BAD_INTEGER;
1583 if (lpParms->lpstrDeviceType == NULL) {
1584 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1587 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1588 ptr = strchrW(strDevTyp, '!');
1590 /* this behavior is not documented in windows. However, since, in
1591 * some occasions, MCI_OPEN handling is translated by WinMM into
1592 * a call to mciSendString("open <type>"); this code shall be correct
1594 if (dwParam & MCI_OPEN_ELEMENT) {
1595 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1596 debugstr_w(lpParms->lpstrElementName),
1597 debugstr_w(strDevTyp));
1598 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1601 dwParam |= MCI_OPEN_ELEMENT;
1603 /* FIXME: not a good idea to write in user supplied buffer */
1604 lpParms->lpstrElementName = ptr;
1608 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1611 if (dwParam & MCI_OPEN_ELEMENT) {
1612 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1614 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1615 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1616 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1620 if (!lpParms->lpstrElementName) {
1621 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1625 /* type, if given as a parameter, supersedes file extension */
1626 if (!strDevTyp[0] &&
1627 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1628 strDevTyp, sizeof(strDevTyp))) {
1629 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1630 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1631 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1634 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1635 strcpyW(strDevTyp, wszCdAudio);
1639 if (strDevTyp[0] == 0) {
1640 FIXME("Couldn't load driver\n");
1641 dwRet = MCIERR_INVALID_DEVICE_NAME;
1645 if (dwParam & MCI_OPEN_ALIAS) {
1646 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1647 if (!lpParms->lpstrAlias) {
1648 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1653 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1657 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1658 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1659 /* FIXME: is dwRet the correct ret code ? */
1663 /* only handled devices fall through */
1664 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1666 if (dwParam & MCI_NOTIFY)
1667 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1671 if (wmd) MCI_UnLoadMciDriver(wmd);
1673 if (dwParam & MCI_NOTIFY)
1674 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1678 /**************************************************************************
1679 * MCI_Close [internal]
1681 static DWORD MCI_Close(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1684 LPWINE_MCIDRIVER wmd;
1686 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1688 /* Every device must handle MCI_NOTIFY on its own. */
1689 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1690 while (MciDrivers) {
1691 /* Retrieve the device ID under lock, but send the message without,
1692 * the driver might be calling some winmm functions from another
1693 * thread before being fully stopped.
1695 EnterCriticalSection(&WINMM_cs);
1698 LeaveCriticalSection(&WINMM_cs);
1701 wDevID = MciDrivers->wDeviceID;
1702 LeaveCriticalSection(&WINMM_cs);
1703 MCI_Close(wDevID, dwParam, lpParms);
1708 if (!(wmd = MCI_GetDriver(wDevID))) {
1709 return MCIERR_INVALID_DEVICE_ID;
1712 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD_PTR)lpParms);
1714 MCI_UnLoadMciDriver(wmd);
1719 /**************************************************************************
1720 * MCI_WriteString [internal]
1722 static DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1727 dstSize /= sizeof(WCHAR);
1728 if (dstSize <= strlenW(lpSrcStr)) {
1729 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1730 ret = MCIERR_PARAM_OVERFLOW;
1732 strcpyW(lpDstStr, lpSrcStr);
1740 /**************************************************************************
1741 * MCI_Sysinfo [internal]
1743 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1745 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1746 WCHAR buf[2048], *s = buf, *p;
1747 LPWINE_MCIDRIVER wmd;
1750 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1751 if (lpParms->lpstrReturn == NULL) return MCIERR_PARAM_OVERFLOW;
1753 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1754 uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1755 if ((WORD)MCI_ALL_DEVICE_ID == LOWORD(uDevID))
1756 uDevID = MCI_ALL_DEVICE_ID; /* Be compatible with Win9x */
1758 switch (dwFlags & ~(MCI_SYSINFO_OPEN|MCI_NOTIFY|MCI_WAIT)) {
1759 case MCI_SYSINFO_QUANTITY:
1760 if (lpParms->dwRetSize < sizeof(DWORD))
1761 return MCIERR_PARAM_OVERFLOW;
1762 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1763 if (uDevID == MCI_ALL_DEVICE_ID) {
1764 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1765 if (dwFlags & MCI_SYSINFO_OPEN) {
1766 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1767 EnterCriticalSection(&WINMM_cs);
1768 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1771 LeaveCriticalSection(&WINMM_cs);
1773 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1774 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1775 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1776 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1777 RegCloseKey( hKey );
1779 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1780 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1783 if (dwFlags & MCI_SYSINFO_OPEN) {
1784 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms->wDeviceType);
1785 EnterCriticalSection(&WINMM_cs);
1786 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1787 if (wmd->wType == lpParms->wDeviceType) cnt++;
1789 LeaveCriticalSection(&WINMM_cs);
1791 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms->wDeviceType);
1792 FIXME("Don't know how to get # of MCI devices of a given type\n");
1796 *(DWORD*)lpParms->lpstrReturn = cnt;
1797 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1798 ret = MCI_INTEGER_RETURNED;
1799 /* return ret; Only Win9x sends a notification in this case. */
1801 case MCI_SYSINFO_INSTALLNAME:
1802 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1803 if ((wmd = MCI_GetDriver(uDevID))) {
1804 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1805 wmd->lpstrDeviceType);
1807 *lpParms->lpstrReturn = 0;
1808 ret = MCIERR_INVALID_DEVICE_ID;
1810 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1812 case MCI_SYSINFO_NAME:
1814 if (dwFlags & MCI_SYSINFO_OPEN) {
1815 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1816 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1817 uDevID == MCI_ALL_DEVICE_ID ? MCI_ALL_DEVICE_ID : lpParms->wDeviceType);
1818 EnterCriticalSection(&WINMM_cs);
1819 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1820 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1821 if (uDevID == MCI_ALL_DEVICE_ID ||
1822 lpParms->wDeviceType == wmd->wType) {
1824 if (cnt == lpParms->dwNumber) {
1825 s = wmd->lpstrAlias;
1830 LeaveCriticalSection(&WINMM_cs);
1831 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1832 } else if (MCI_ALL_DEVICE_ID == uDevID) {
1833 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms->dwNumber);
1834 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1835 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1836 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1837 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1838 lpParms->dwNumber <= cnt) {
1839 DWORD bufLen = sizeof(buf)/sizeof(buf[0]);
1840 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1841 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1844 RegCloseKey( hKey );
1847 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1848 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1849 TRACE("%d: %s\n", cnt, debugstr_w(p));
1850 if (cnt == lpParms->dwNumber - 1) {
1857 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1859 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms->wDeviceType);
1860 /* Cheating: what is asked for is the nth device from the registry. */
1861 if (1 != lpParms->dwNumber || /* Handle only one of each kind. */
1862 lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST)
1863 ret = MCIERR_OUTOFRANGE;
1865 LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType),
1866 lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR));
1870 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1873 TRACE("Unsupported flag value=%08x\n", dwFlags);
1874 ret = MCIERR_UNRECOGNIZED_KEYWORD;
1876 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1877 mciDriverNotify((HWND)lpParms->dwCallback, uDevID, MCI_NOTIFY_SUCCESSFUL);
1881 /**************************************************************************
1882 * MCI_Break [internal]
1884 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1888 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1889 FIXME("(%04x) vkey %04X stub\n", dwFlags, lpParms->nVirtKey);
1891 if (MMSYSERR_NOERROR==dwRet && (dwFlags & MCI_NOTIFY))
1892 mciDriverNotify((HWND)lpParms->dwCallback, wDevID, MCI_NOTIFY_SUCCESSFUL);
1896 /**************************************************************************
1897 * MCI_Sound [internal]
1899 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1903 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1905 if (dwFlags & MCI_SOUND_NAME)
1906 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1908 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1910 if (MMSYSERR_NOERROR==dwRet && (dwFlags & MCI_NOTIFY))
1911 mciDriverNotify((HWND)lpParms->dwCallback, wDevID, MCI_NOTIFY_SUCCESSFUL);
1915 /**************************************************************************
1916 * MCI_SendCommand [internal]
1918 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1920 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1924 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1927 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1930 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1933 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1936 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
1939 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1940 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1941 dwRet = MCIERR_CANNOT_USE_ALL;
1943 dwRet = MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2);
1950 /**************************************************************************
1951 * MCI_CleanUp [internal]
1953 * Some MCI commands need to be cleaned-up (when not called from
1954 * mciSendString), because MCI drivers return extra information for string
1955 * transformation. This function gets rid of them.
1957 static LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD_PTR dwParam2)
1960 return LOWORD(dwRet);
1963 case MCI_GETDEVCAPS:
1964 switch (dwRet & 0xFFFF0000ul) {
1966 case MCI_COLONIZED3_RETURN:
1967 case MCI_COLONIZED4_RETURN:
1968 case MCI_INTEGER_RETURNED:
1971 case MCI_RESOURCE_RETURNED:
1972 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1974 LPMCI_GETDEVCAPS_PARMS lmgp;
1976 lmgp = (LPMCI_GETDEVCAPS_PARMS)dwParam2;
1977 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
1978 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1982 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1983 HIWORD(dwRet), MCI_MessageToString(wMsg));
1987 switch (dwRet & 0xFFFF0000ul) {
1989 case MCI_COLONIZED3_RETURN:
1990 case MCI_COLONIZED4_RETURN:
1991 case MCI_INTEGER_RETURNED:
1994 case MCI_RESOURCE_RETURNED:
1995 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1997 LPMCI_STATUS_PARMS lsp;
1999 lsp = (LPMCI_STATUS_PARMS)dwParam2;
2000 TRACE("Changing %08lx to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
2001 lsp->dwReturn = LOWORD(lsp->dwReturn);
2005 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2006 HIWORD(dwRet), MCI_MessageToString(wMsg));
2010 switch (dwRet & 0xFFFF0000ul) {
2012 case MCI_INTEGER_RETURNED:
2016 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2020 if (HIWORD(dwRet)) {
2021 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2022 dwRet, MCI_MessageToString(wMsg));
2026 return LOWORD(dwRet);
2029 /**************************************************************************
2030 * mciGetErrorStringW [WINMM.@]
2032 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2036 if (lpstrBuffer != NULL && uLength > 0 &&
2037 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2039 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
2046 /**************************************************************************
2047 * mciGetErrorStringA [WINMM.@]
2049 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2053 if (lpstrBuffer != NULL && uLength > 0 &&
2054 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2056 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2063 /**************************************************************************
2064 * mciDriverNotify [WINMM.@]
2066 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2068 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2070 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2073 /**************************************************************************
2074 * mciGetDriverData [WINMM.@]
2076 DWORD_PTR WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2078 LPWINE_MCIDRIVER wmd;
2080 TRACE("(%04x)\n", uDeviceID);
2082 wmd = MCI_GetDriver(uDeviceID);
2085 WARN("Bad uDeviceID\n");
2089 return wmd->dwPrivate;
2092 /**************************************************************************
2093 * mciSetDriverData [WINMM.@]
2095 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD_PTR data)
2097 LPWINE_MCIDRIVER wmd;
2099 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2101 wmd = MCI_GetDriver(uDeviceID);
2104 WARN("Bad uDeviceID\n");
2108 wmd->dwPrivate = data;
2112 /**************************************************************************
2113 * mciSendCommandW [WINMM.@]
2116 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2120 TRACE("(%08x, %s, %08lx, %08lx)\n",
2121 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2123 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2);
2124 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2125 TRACE("=> %08x\n", dwRet);
2129 /**************************************************************************
2130 * mciSendCommandA [WINMM.@]
2132 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2137 TRACE("(%08x, %s, %08lx, %08lx)\n",
2138 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2140 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2143 FIXME("message %04x mapping failed\n", wMsg);
2144 return MMSYSERR_NOMEM;
2146 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2148 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2152 /**************************************************************************
2153 * mciGetDeviceIDA [WINMM.@]
2155 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2157 LPWSTR w = MCI_strdupAtoW(lpstrName);
2158 UINT ret = MCIERR_OUT_OF_MEMORY;
2162 ret = mciGetDeviceIDW(w);
2163 HeapFree(GetProcessHeap(), 0, w);
2168 /**************************************************************************
2169 * mciGetDeviceIDW [WINMM.@]
2171 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2173 return MCI_GetDriverFromString(lpwstrName);
2176 /**************************************************************************
2177 * MCI_DefYieldProc [internal]
2179 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2184 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2186 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2187 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2188 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2191 msg.hwnd = HWND_32(HIWORD(data));
2192 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2198 /**************************************************************************
2199 * mciSetYieldProc [WINMM.@]
2201 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2203 LPWINE_MCIDRIVER wmd;
2205 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2207 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2208 WARN("Bad uDeviceID\n");
2212 wmd->lpfnYieldProc = fpYieldProc;
2213 wmd->dwYieldData = dwYieldData;
2218 /**************************************************************************
2219 * mciGetDeviceIDFromElementIDA [WINMM.@]
2221 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2223 LPWSTR w = MCI_strdupAtoW(lpstrType);
2228 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2229 HeapFree(GetProcessHeap(), 0, w);
2234 /**************************************************************************
2235 * mciGetDeviceIDFromElementIDW [WINMM.@]
2237 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2239 /* FIXME: that's rather strange, there is no
2240 * mciGetDeviceIDFromElementID32A in winmm.spec
2242 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2246 /**************************************************************************
2247 * mciGetYieldProc [WINMM.@]
2249 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2251 LPWINE_MCIDRIVER wmd;
2253 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2255 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2256 WARN("Bad uDeviceID\n");
2259 if (!wmd->lpfnYieldProc) {
2260 WARN("No proc set\n");
2263 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
2264 return wmd->lpfnYieldProc;
2267 /**************************************************************************
2268 * mciGetCreatorTask [WINMM.@]
2270 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2272 LPWINE_MCIDRIVER wmd;
2275 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)(DWORD_PTR)wmd->CreatorThread;
2277 TRACE("(%u) => %p\n", uDeviceID, ret);
2281 /**************************************************************************
2282 * mciDriverYield [WINMM.@]
2284 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2286 LPWINE_MCIDRIVER wmd;
2289 TRACE("(%04x)\n", uDeviceID);
2291 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc) {
2293 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2295 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);