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(UINT16 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 static char buffer[100];
156 #define CASE(s) case (s): return #s
166 CASE(DRV_QUERYCONFIGURE);
169 CASE(DRV_EXITSESSION);
170 CASE(DRV_EXITAPPLICATION);
174 CASE(MCI_CLOSE_DRIVER);
183 CASE(MCI_GETDEVCAPS);
187 CASE(MCI_OPEN_DRIVER);
205 /* constants for digital video */
219 sprintf(buffer, "MCI_<<%04X>>", wMsg);
224 LPWSTR MCI_strdupAtoW( LPCSTR str )
229 if (!str) return NULL;
230 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
231 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
232 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
236 LPSTR MCI_strdupWtoA( LPCWSTR str )
241 if (!str) return NULL;
242 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
243 ret = HeapAlloc( GetProcessHeap(), 0, len );
244 if (ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
248 static int MCI_MapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
250 if (msg < DRV_RESERVED) return 0;
289 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA*)*dwParam2;
290 MCI_OPEN_PARMSW *mci_openW;
293 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW) + 2 * sizeof(DWORD));
296 *ptr++ = *dwParam2; /* save the previous pointer */
297 *dwParam2 = (DWORD_PTR)ptr;
298 mci_openW = (MCI_OPEN_PARMSW *)ptr;
300 if (dwParam1 & MCI_NOTIFY)
301 mci_openW->dwCallback = mci_openA->dwCallback;
303 if (dwParam1 & MCI_OPEN_TYPE)
305 if (dwParam1 & MCI_OPEN_TYPE_ID)
306 mci_openW->lpstrDeviceType = (LPCWSTR)mci_openA->lpstrDeviceType;
308 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
310 if (dwParam1 & MCI_OPEN_ELEMENT)
312 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
313 mci_openW->lpstrElementName = (LPCWSTR)mci_openA->lpstrElementName;
315 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
317 if (dwParam1 & MCI_OPEN_ALIAS)
318 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
319 /* FIXME: this is only needed for specific types of MCI devices, and
320 * may cause a segfault if the two DWORD:s don't exist at the end of
323 memcpy(mci_openW + 1, mci_openA + 1, 2 * sizeof(DWORD));
328 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
330 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
331 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
333 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
334 if (!mci_windowW) return -1;
336 *dwParam2 = (DWORD_PTR)mci_windowW;
338 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
340 if (dwParam1 & MCI_NOTIFY)
341 mci_windowW->dwCallback = mci_windowA->dwCallback;
342 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
343 mci_windowW->hWnd = mci_windowA->hWnd;
344 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
345 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
353 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
354 MCI_SYSINFO_PARMSW *mci_sysinfoW;
357 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
360 *ptr++ = *dwParam2; /* save the previous pointer */
361 *dwParam2 = (DWORD_PTR)ptr;
362 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
364 if (dwParam1 & MCI_NOTIFY)
365 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
367 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
368 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize);
369 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
370 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
375 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
376 MCI_INFO_PARMSW *mci_infoW;
379 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
382 *ptr++ = *dwParam2; /* save the previous pointer */
383 *dwParam2 = (DWORD_PTR)ptr;
384 mci_infoW = (MCI_INFO_PARMSW *)ptr;
386 if (dwParam1 & MCI_NOTIFY)
387 mci_infoW->dwCallback = mci_infoA->dwCallback;
389 mci_infoW->dwRetSize = mci_infoA->dwRetSize * sizeof(WCHAR); /* it's not the same as SYSINFO !!! */
390 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize);
395 MCI_SAVE_PARMSA *mci_saveA = (MCI_SAVE_PARMSA *)*dwParam2;
396 MCI_SAVE_PARMSW *mci_saveW;
398 mci_saveW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW));
399 if (!mci_saveW) return -1;
401 *dwParam2 = (DWORD_PTR)mci_saveW;
402 if (dwParam1 & MCI_NOTIFY)
403 mci_saveW->dwCallback = mci_saveA->dwCallback;
404 mci_saveW->lpfilename = MCI_strdupAtoW(mci_saveA->lpfilename);
409 MCI_LOAD_PARMSA *mci_loadA = (MCI_LOAD_PARMSA *)*dwParam2;
410 MCI_LOAD_PARMSW *mci_loadW;
412 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
413 if (!mci_loadW) return -1;
415 *dwParam2 = (DWORD_PTR)mci_loadW;
416 if (dwParam1 & MCI_NOTIFY)
417 mci_loadW->dwCallback = mci_loadA->dwCallback;
418 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
424 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
425 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
427 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
428 if (!mci_vd_escapeW) return -1;
430 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
431 if (dwParam1 & MCI_NOTIFY)
432 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
433 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
437 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
442 static DWORD MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
449 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
450 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
451 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)(ptr + 1);
453 mci_openA->wDeviceID = mci_openW->wDeviceID;
455 if (dwParam1 & MCI_OPEN_TYPE)
457 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
458 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrDeviceType);
460 if (dwParam1 & MCI_OPEN_ELEMENT)
462 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
463 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrElementName);
465 if (dwParam1 & MCI_OPEN_ALIAS)
466 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrAlias);
467 HeapFree(GetProcessHeap(), 0, ptr);
471 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
473 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
475 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
476 HeapFree(GetProcessHeap(), 0, mci_windowW);
482 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
483 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
484 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)(ptr + 1);
488 mci_sysinfoA->dwNumber = mci_sysinfoW->dwNumber;
489 mci_sysinfoA->wDeviceType = mci_sysinfoW->wDeviceType;
490 if (dwParam1 & MCI_SYSINFO_QUANTITY)
491 *(DWORD*)mci_sysinfoA->lpstrReturn = *(DWORD*)mci_sysinfoW->lpstrReturn;
493 WideCharToMultiByte(CP_ACP, 0,
494 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
495 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
499 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
500 HeapFree(GetProcessHeap(), 0, ptr);
505 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
506 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
507 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)(ptr + 1);
511 WideCharToMultiByte(CP_ACP, 0,
512 mci_infoW->lpstrReturn, mci_infoW->dwRetSize / sizeof(WCHAR),
513 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
517 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
518 HeapFree(GetProcessHeap(), 0, ptr);
523 MCI_SAVE_PARMSW *mci_saveW = (MCI_SAVE_PARMSW *)dwParam2;
525 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW->lpfilename);
526 HeapFree(GetProcessHeap(), 0, mci_saveW);
531 MCI_LOAD_PARMSW *mci_loadW = (MCI_LOAD_PARMSW *)dwParam2;
533 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
534 HeapFree(GetProcessHeap(), 0, mci_loadW);
539 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
541 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
542 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
547 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
554 /**************************************************************************
555 * MCI_GetDevTypeFromFileName [internal]
557 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
561 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
562 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
563 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
564 if ((tmp = strrchrW(fileName, '.'))) {
565 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
566 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
568 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
570 if (lRet == ERROR_SUCCESS) return 0;
572 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
574 return MCIERR_EXTENSION_NOT_FOUND;
577 #define MAX_MCICMDTABLE 20
578 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
580 typedef struct tagWINE_MCICMDTABLE {
584 UINT nVerbs; /* number of verbs in command table */
585 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
586 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
588 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
590 /**************************************************************************
591 * MCI_IsCommandTableValid [internal]
593 static BOOL MCI_IsCommandTableValid(UINT uTbl)
602 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
603 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
605 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
608 lmem = S_MciCmdTable[uTbl].lpTable;
611 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
612 flg = *(const DWORD*)lmem;
613 eid = *(const WORD*)(lmem + sizeof(DWORD));
614 lmem += sizeof(DWORD) + sizeof(WORD);
616 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
618 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
619 case MCI_STRING: if (inCst) return FALSE; break;
620 case MCI_INTEGER: if (!*str) return FALSE; break;
621 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
622 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
623 case MCI_FLAG: if (!*str) return FALSE; break;
624 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
625 case MCI_RECT: if (!*str || inCst) return FALSE; break;
626 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
627 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
628 default: return FALSE;
630 } while (eid != MCI_END_COMMAND_LIST);
634 /**************************************************************************
635 * MCI_DumpCommandTable [internal]
637 static BOOL MCI_DumpCommandTable(UINT uTbl)
644 if (!MCI_IsCommandTableValid(uTbl)) {
645 ERR("Ooops: %d is not valid\n", uTbl);
649 lmem = S_MciCmdTable[uTbl].lpTable;
653 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
654 flg = *(const DWORD*)lmem;
655 eid = *(const WORD*)(lmem + sizeof(DWORD));
656 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
657 lmem += sizeof(DWORD) + sizeof(WORD);
658 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
659 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
660 } while (eid != MCI_END_COMMAND_LIST);
665 /**************************************************************************
666 * MCI_GetCommandTable [internal]
668 static UINT MCI_GetCommandTable(UINT uDevType)
674 /* first look up existing for existing devType */
675 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
676 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
680 /* well try to load id */
681 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
682 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
685 } else if (uDevType == 0) {
686 static const WCHAR wszCore[] = {'C','O','R','E',0};
689 uTbl = MCI_NO_COMMAND_TABLE;
691 HRSRC hRsrc = FindResourceW(hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
694 if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
696 uTbl = MCI_SetCommandTable(hMem, uDevType);
698 WARN("No command table found in resource %p[%s]\n",
699 hWinMM32Instance, debugstr_w(str));
702 TRACE("=> %d\n", uTbl);
706 /**************************************************************************
707 * MCI_SetCommandTable [internal]
709 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType)
712 static BOOL bInitDone = FALSE;
715 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
716 * can be called with 0 as a uDevType to retrieve it.
721 MCI_GetCommandTable(0);
723 TRACE("(%p, %u)\n", hMem, uDevType);
724 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
725 if (!S_MciCmdTable[uTbl].lpTable) {
731 S_MciCmdTable[uTbl].uDevType = uDevType;
732 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
733 S_MciCmdTable[uTbl].hMem = hMem;
736 MCI_DumpCommandTable(uTbl);
739 /* create the verbs table */
740 /* get # of entries */
741 lmem = S_MciCmdTable[uTbl].lpTable;
745 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
746 eid = *(const WORD*)(lmem + sizeof(DWORD));
747 lmem += sizeof(DWORD) + sizeof(WORD);
748 if (eid == MCI_COMMAND_HEAD)
750 } while (eid != MCI_END_COMMAND_LIST);
752 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
753 S_MciCmdTable[uTbl].nVerbs = count;
755 lmem = S_MciCmdTable[uTbl].lpTable;
759 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
760 eid = *(const WORD*)(lmem + sizeof(DWORD));
761 lmem += sizeof(DWORD) + sizeof(WORD);
762 if (eid == MCI_COMMAND_HEAD)
763 S_MciCmdTable[uTbl].aVerbs[count++] = str;
764 } while (eid != MCI_END_COMMAND_LIST);
765 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
770 return MCI_NO_COMMAND_TABLE;
773 /**************************************************************************
774 * MCI_UnLoadMciDriver [internal]
776 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
778 LPWINE_MCIDRIVER* tmp;
783 CloseDriver(wmd->hDriver, 0, 0);
785 if (wmd->dwPrivate != 0)
786 WARN("Unloading mci driver with non nul dwPrivate field\n");
788 EnterCriticalSection(&WINMM_cs);
789 for (tmp = &MciDrivers; *tmp; tmp = &(*tmp)->lpNext) {
795 LeaveCriticalSection(&WINMM_cs);
797 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
798 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
799 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
801 HeapFree(GetProcessHeap(), 0, wmd);
805 /**************************************************************************
806 * MCI_OpenMciDriver [internal]
808 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
812 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
815 /* First load driver */
816 wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp);
817 return wmd->hDriver != NULL;
820 /**************************************************************************
821 * MCI_LoadMciDriver [internal]
823 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
825 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
826 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
827 MCI_OPEN_DRIVER_PARMSW modp;
830 if (!wmd || !strDevTyp) {
831 dwRet = MCIERR_OUT_OF_MEMORY;
835 wmd->lpfnYieldProc = MCI_DefYieldProc;
836 wmd->dwYieldData = VK_CANCEL;
837 wmd->CreatorThread = GetCurrentThreadId();
839 EnterCriticalSection(&WINMM_cs);
840 /* wmd must be inserted in list before sending opening the driver, because it
841 * may want to lookup at wDevID
843 wmd->lpNext = MciDrivers;
846 for (modp.wDeviceID = MCI_MAGIC;
847 MCI_GetDriver(modp.wDeviceID) != 0;
850 wmd->wDeviceID = modp.wDeviceID;
852 LeaveCriticalSection(&WINMM_cs);
854 TRACE("wDevID=%04X\n", modp.wDeviceID);
856 modp.lpstrParams = NULL;
858 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
859 /* silence warning if all is used... some bogus program use commands like
862 if (strcmpiW(strDevTyp, wszAll) == 0) {
863 dwRet = MCIERR_CANNOT_USE_ALL;
865 FIXME("Couldn't load driver for type %s.\n",
866 debugstr_w(strDevTyp));
867 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
872 /* FIXME: should also check that module's description is of the form
873 * MODULENAME:[MCI] comment
876 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
877 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
878 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
880 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
881 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
883 wmd->lpstrDeviceType = strDevTyp;
884 wmd->wType = modp.wType;
886 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
887 modp.wDeviceID, modp.wType, modp.wDeviceID);
891 MCI_UnLoadMciDriver(wmd);
892 HeapFree(GetProcessHeap(), 0, strDevTyp);
897 /**************************************************************************
898 * MCI_SendCommandFrom32 [internal]
900 static DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
902 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
903 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
906 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
911 /**************************************************************************
912 * MCI_FinishOpen [internal]
914 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
917 if (dwParam & MCI_OPEN_ELEMENT)
919 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms->lpstrElementName)+1) * sizeof(WCHAR));
920 strcpyW( wmd->lpstrElementName, lpParms->lpstrElementName );
922 if (dwParam & MCI_OPEN_ALIAS)
924 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms->lpstrAlias)+1) * sizeof(WCHAR));
925 strcpyW( wmd->lpstrAlias, lpParms->lpstrAlias);
927 lpParms->wDeviceID = wmd->wDeviceID;
929 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
933 /**************************************************************************
934 * MCI_FindCommand [internal]
936 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
940 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
943 /* another improvement would be to have the aVerbs array sorted,
944 * so that we could use a dichotomic search on it, rather than this dumb
947 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
948 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
949 return S_MciCmdTable[uTbl].aVerbs[idx];
955 /**************************************************************************
956 * MCI_GetReturnType [internal]
958 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
960 lpCmd = (LPCWSTR)((const BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
961 if (*lpCmd == '\0' && *(const WORD*)((const BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
962 return *(const DWORD*)(lpCmd + 1);
967 /**************************************************************************
968 * MCI_GetMessage [internal]
970 static WORD MCI_GetMessage(LPCWSTR lpCmd)
972 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
975 /**************************************************************************
976 * MCI_GetDWord [internal]
978 static BOOL MCI_GetDWord(LPDWORD data, LPWSTR* ptr)
983 val = strtoulW(*ptr, &ret, 0);
987 case ' ': ret++; break;
988 default: return FALSE;
996 /**************************************************************************
997 * MCI_GetString [internal]
999 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
1003 /* see if we have a quoted string */
1005 ptr = strchrW(*str = ptr + 1, '"');
1006 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
1007 /* FIXME: shall we escape \" from string ?? */
1008 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1009 *ptr++ = '\0'; /* remove trailing " */
1010 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
1012 ptr = strchrW(ptr, ' ');
1017 ptr = *args + strlenW(*args);
1026 #define MCI_DATA_SIZE 16
1028 /**************************************************************************
1029 * MCI_ParseOptArgs [internal]
1031 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCWSTR lpCmd,
1032 LPWSTR args, LPDWORD dwFlags)
1037 DWORD dwRet, flg, cflg = 0;
1041 /* loop on arguments */
1043 lmem = (const char*)lpCmd;
1044 found = inCst = FALSE;
1047 /* skip any leading white space(s) */
1048 while (*args == ' ') args++;
1049 TRACE("args=%s offset=%d\n", debugstr_w(args), offset);
1051 do { /* loop on options for command table for the requested verb */
1052 str = (LPCWSTR)lmem;
1053 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1054 flg = *(const DWORD*)lmem;
1055 eid = *(const WORD*)(lmem + sizeof(DWORD));
1056 lmem += sizeof(DWORD) + sizeof(WORD);
1057 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1061 inCst = TRUE; cflg = flg; break;
1062 case MCI_END_CONSTANT:
1063 /* there may be additional integral values after flag in constant */
1064 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1067 inCst = FALSE; cflg = 0;
1071 if (strncmpiW(args, str, len) == 0 &&
1072 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1073 /* store good values into data[] */
1075 while (*args == ' ') args++;
1079 case MCI_COMMAND_HEAD:
1081 case MCI_END_COMMAND:
1082 case MCI_END_COMMAND_LIST:
1083 case MCI_CONSTANT: /* done above */
1084 case MCI_END_CONSTANT: /* done above */
1091 data[offset] |= flg;
1096 if (!MCI_GetDWord(&(data[offset]), &args)) {
1097 return MCIERR_BAD_INTEGER;
1102 /* store rect in data (offset..offset+3) */
1104 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1105 !MCI_GetDWord(&(data[offset+1]), &args) ||
1106 !MCI_GetDWord(&(data[offset+2]), &args) ||
1107 !MCI_GetDWord(&(data[offset+3]), &args)) {
1108 ERR("Bad rect %s\n", debugstr_w(args));
1109 return MCIERR_BAD_INTEGER;
1114 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1117 default: ERR("oops\n");
1119 /* exit inside while loop, except if just entered in constant area definition */
1120 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1122 /* have offset incremented if needed */
1124 case MCI_COMMAND_HEAD:
1126 case MCI_END_COMMAND:
1127 case MCI_END_COMMAND_LIST:
1129 case MCI_FLAG: break;
1130 case MCI_INTEGER: if (!inCst) offset++; break;
1131 case MCI_END_CONSTANT:
1132 case MCI_STRING: offset++; break;
1133 case MCI_RECT: offset += 4; break;
1134 default: ERR("oops\n");
1137 } while (eid != MCI_END_COMMAND);
1139 WARN("Optarg %s not found\n", debugstr_w(args));
1140 return MCIERR_UNRECOGNIZED_COMMAND;
1142 if (offset == MCI_DATA_SIZE) {
1143 ERR("Internal data[] buffer overflow\n");
1144 return MCIERR_PARSER_INTERNAL;
1150 /**************************************************************************
1151 * MCI_HandleReturnValues [internal]
1153 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1154 LPDWORD data, LPWSTR lpstrRet, UINT uRetLen)
1156 static const WCHAR wszLd [] = {'%','l','d',0};
1157 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1158 static const WCHAR wszCol3[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1159 static const WCHAR wszCol4[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1163 case 0: /* nothing to return */
1166 switch (dwRet & 0xFFFF0000ul) {
1168 case MCI_INTEGER_RETURNED:
1169 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1171 case MCI_RESOURCE_RETURNED:
1172 /* return string which ID is HIWORD(data[1]),
1173 * string is loaded from mmsystem.dll */
1174 LoadStringW(hWinMM32Instance, HIWORD(data[1]), lpstrRet, uRetLen);
1176 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1177 /* return string which ID is HIWORD(data[1]),
1178 * string is loaded from driver */
1179 /* FIXME: this is wrong for a 16 bit handle */
1180 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1181 HIWORD(data[1]), lpstrRet, uRetLen);
1183 case MCI_COLONIZED3_RETURN:
1184 snprintfW(lpstrRet, uRetLen, wszCol3,
1185 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1186 LOBYTE(HIWORD(data[1])));
1188 case MCI_COLONIZED4_RETURN:
1189 snprintfW(lpstrRet, uRetLen, wszCol4,
1190 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1191 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1193 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1197 switch (dwRet & 0xFFFF0000ul) {
1199 /* nothing to do data[1] == lpstrRet */
1201 case MCI_INTEGER_RETURNED:
1202 data[1] = *(LPDWORD)lpstrRet;
1203 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1206 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1211 if (dwRet & 0xFFFF0000ul)
1212 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1213 snprintfW(lpstrRet, uRetLen, wszLd4,
1214 data[1], data[2], data[3], data[4]);
1216 default: ERR("oops\n");
1219 return LOWORD(dwRet);
1222 /**************************************************************************
1223 * mciSendStringW [WINMM.@]
1225 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1226 UINT uRetLen, HWND hwndCallback)
1228 LPWSTR verb, dev, args;
1229 LPWINE_MCIDRIVER wmd = 0;
1230 DWORD dwFlags = 0, dwRet = 0;
1232 DWORD data[MCI_DATA_SIZE];
1235 LPWSTR devAlias = NULL;
1236 static const WCHAR wszNew[] = {'n','e','w',0};
1237 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1238 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',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))) {
1260 /* Determine devType from open */
1261 if (!strcmpW(verb, wszOpen)) {
1262 LPWSTR devType, tmp;
1265 /* case dev == 'new' has to be handled */
1266 if (!strcmpW(dev, wszNew)) {
1268 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1270 tmp = strchrW(devType, ' ');
1271 if (tmp) *tmp = '\0';
1272 devType = str_dup_upper(devType);
1273 if (tmp) *tmp = ' ';
1274 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1276 WARN("open new requires device type\n");
1277 dwRet = MCIERR_MISSING_DEVICE_NAME;
1280 } else if ((devType = strchrW(dev, '!')) != NULL) {
1282 tmp = devType; devType = dev; dev = tmp;
1284 dwFlags |= MCI_OPEN_TYPE;
1285 data[2] = (DWORD)devType;
1286 devType = str_dup_upper(devType);
1287 dwFlags |= MCI_OPEN_ELEMENT;
1288 data[3] = (DWORD)dev;
1289 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1290 /* this is the name of a mci driver's type */
1291 tmp = strchrW(dev, ' ');
1292 if (tmp) *tmp = '\0';
1293 data[2] = (DWORD)dev;
1294 devType = str_dup_upper(dev);
1295 if (tmp) *tmp = ' ';
1296 dwFlags |= MCI_OPEN_TYPE;
1298 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1300 tmp = strchrW(devType, ' ');
1301 if (tmp) *tmp = '\0';
1302 devType = str_dup_upper(devType);
1303 if (tmp) *tmp = ' ';
1304 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1306 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1309 devType = str_dup_upper(buf);
1311 dwFlags |= MCI_OPEN_ELEMENT;
1312 data[3] = (DWORD)dev;
1314 if ((devAlias = strstrW(args, wszSAliasS))) {
1317 if (!(tmp = strchrW(devAlias,' '))) tmp = devAlias + strlenW(devAlias);
1318 if (tmp) *tmp = '\0';
1319 tmp2 = HeapAlloc(GetProcessHeap(), 0, (tmp - devAlias + 1) * sizeof(WCHAR) );
1320 memcpy( tmp2, devAlias, (tmp - devAlias) * sizeof(WCHAR) );
1321 tmp2[tmp - devAlias] = 0;
1322 data[4] = (DWORD)tmp2;
1323 /* should be done in regular options parsing */
1324 /* dwFlags |= MCI_OPEN_ALIAS; */
1325 } else if (dev == 0) {
1326 /* "open new" requires alias */
1327 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1331 dwRet = MCI_LoadMciDriver(devType, &wmd);
1332 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1333 dwRet = MCIERR_INVALID_DEVICE_NAME;
1334 HeapFree(GetProcessHeap(), 0, devType);
1336 MCI_UnLoadMciDriver(wmd);
1339 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1341 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1343 sprintfW(buf, wszOpenWait, dev);
1345 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1348 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1350 /* FIXME: memory leak, MCI driver is not closed */
1351 dwRet = MCIERR_INVALID_DEVICE_ID;
1356 /* get the verb in the different command tables */
1358 /* try the device specific command table */
1359 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1361 /* try the type specific command table */
1362 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1363 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1364 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1365 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1368 /* try core command table */
1369 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1372 TRACE("Command %s not found!\n", debugstr_w(verb));
1373 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1377 /* set return information */
1378 switch (retType = MCI_GetReturnType(lpCmd)) {
1379 case 0: offset = 1; break;
1380 case MCI_INTEGER: offset = 2; break;
1381 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1382 case MCI_RECT: offset = 5; break;
1383 default: ERR("oops\n");
1386 TRACE("verb=%s on dev=%s; offset=%d\n",
1387 debugstr_w(verb), debugstr_w(dev), offset);
1389 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1392 /* set up call back */
1393 if (dwFlags & MCI_NOTIFY) {
1394 data[0] = (DWORD)hwndCallback;
1397 /* FIXME: the command should get it's own notification window set up and
1398 * ask for device closing while processing the notification mechanism
1400 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1402 TRACE("[%d, %s, %08x, %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s]\n",
1403 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1404 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1405 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1406 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1408 if (strcmpW(verb, wszOpen) == 0) {
1409 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1410 MCI_UnLoadMciDriver(wmd);
1411 /* FIXME: notification is not properly shared across two opens */
1413 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD_PTR)data);
1415 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1416 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1417 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1420 HeapFree(GetProcessHeap(), 0, verb);
1424 /**************************************************************************
1425 * mciSendStringA [WINMM.@]
1427 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1428 UINT uRetLen, HWND hwndCallback)
1430 LPWSTR lpwstrCommand;
1431 LPWSTR lpwstrRet = NULL;
1435 /* FIXME: is there something to do with lpstrReturnString ? */
1436 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1437 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1438 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1441 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1443 WARN("no memory\n");
1444 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1445 return MCIERR_OUT_OF_MEMORY;
1448 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1449 if (!ret && lpwstrRet)
1450 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1451 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1452 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1456 /**************************************************************************
1457 * mciExecute [WINMM.@]
1459 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1464 TRACE("(%s)!\n", lpstrCommand);
1466 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1468 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1469 sprintf(strRet, "Unknown MCI error (%d)", ret);
1471 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1473 /* FIXME: what shall I return ? */
1477 /**************************************************************************
1478 * mciLoadCommandResource [WINMM.@]
1480 * Strangely, this function only exists as a UNICODE one.
1482 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1484 UINT ret = MCI_NO_COMMAND_TABLE;
1488 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1490 /* if a file named "resname.mci" exits, then load resource "resname" from it
1491 * otherwise directly from driver
1492 * We don't support it (who uses this feature ?), but we check anyway
1496 /* FIXME: we should put this back into order, but I never found a program
1497 * actually using this feature, so we may not need it
1502 strcat(strcpy(buf, resname), ".mci");
1503 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1504 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1508 if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
1509 (hMem = LoadResource(hInst, hRsrc))) {
1510 ret = MCI_SetCommandTable(hMem, type);
1513 else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
1515 TRACE("=> %04x\n", ret);
1519 /**************************************************************************
1520 * mciFreeCommandResource [WINMM.@]
1522 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1524 TRACE("(%08x)!\n", uTable);
1526 if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
1529 FreeResource(S_MciCmdTable[uTable].hMem);
1530 S_MciCmdTable[uTable].hMem = NULL;
1531 S_MciCmdTable[uTable].lpTable = NULL;
1532 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
1533 S_MciCmdTable[uTable].aVerbs = 0;
1534 S_MciCmdTable[uTable].nVerbs = 0;
1538 /**************************************************************************
1539 * MCI_Open [internal]
1541 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1543 WCHAR strDevTyp[128];
1545 LPWINE_MCIDRIVER wmd = NULL;
1547 TRACE("(%08X, %p)\n", dwParam, lpParms);
1548 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1550 /* only two low bytes are generic, the other ones are dev type specific */
1551 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1552 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1553 MCI_NOTIFY|MCI_WAIT)
1554 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1555 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1557 #undef WINE_MCIDRIVER_SUPP
1561 if (dwParam & MCI_OPEN_TYPE) {
1562 if (dwParam & MCI_OPEN_TYPE_ID) {
1563 WORD uDevType = LOWORD(lpParms->lpstrDeviceType);
1565 if (uDevType < MCI_DEVTYPE_FIRST ||
1566 uDevType > MCI_DEVTYPE_LAST ||
1567 !LoadStringW(hWinMM32Instance, uDevType,
1568 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1569 dwRet = MCIERR_BAD_INTEGER;
1574 if (lpParms->lpstrDeviceType == NULL) {
1575 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1578 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1579 ptr = strchrW(strDevTyp, '!');
1581 /* this behavior is not documented in windows. However, since, in
1582 * some occasions, MCI_OPEN handling is translated by WinMM into
1583 * a call to mciSendString("open <type>"); this code shall be correct
1585 if (dwParam & MCI_OPEN_ELEMENT) {
1586 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1587 debugstr_w(lpParms->lpstrElementName),
1588 debugstr_w(strDevTyp));
1589 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1592 dwParam |= MCI_OPEN_ELEMENT;
1594 /* FIXME: not a good idea to write in user supplied buffer */
1595 lpParms->lpstrElementName = ptr;
1599 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1602 if (dwParam & MCI_OPEN_ELEMENT) {
1603 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1605 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1606 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1607 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1611 if (!lpParms->lpstrElementName) {
1612 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1616 /* type, if given as a parameter, supersedes file extension */
1617 if (!strDevTyp[0] &&
1618 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1619 strDevTyp, sizeof(strDevTyp))) {
1620 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1621 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1622 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1625 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1626 strcpyW(strDevTyp, wszCdAudio);
1630 if (strDevTyp[0] == 0) {
1631 FIXME("Couldn't load driver\n");
1632 dwRet = MCIERR_INVALID_DEVICE_NAME;
1636 if (dwParam & MCI_OPEN_ALIAS) {
1637 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1638 if (!lpParms->lpstrAlias) {
1639 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1644 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1648 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1649 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1650 /* FIXME: is dwRet the correct ret code ? */
1654 /* only handled devices fall through */
1655 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1657 if (dwParam & MCI_NOTIFY)
1658 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1662 if (wmd) MCI_UnLoadMciDriver(wmd);
1664 if (dwParam & MCI_NOTIFY)
1665 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1669 /**************************************************************************
1670 * MCI_Close [internal]
1672 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1675 LPWINE_MCIDRIVER wmd;
1677 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1679 if (wDevID == MCI_ALL_DEVICE_ID) {
1680 /* FIXME: shall I notify once after all is done, or for
1681 * each of the open drivers ? if the latest, which notif
1682 * to return when only one fails ?
1684 while (MciDrivers) {
1685 /* Retrieve the device ID under lock, but send the message without,
1686 * the driver might be calling some winmm functions from another
1687 * thread before being fully stopped.
1689 EnterCriticalSection(&WINMM_cs);
1692 LeaveCriticalSection(&WINMM_cs);
1695 wDevID = MciDrivers->wDeviceID;
1696 LeaveCriticalSection(&WINMM_cs);
1697 MCI_Close(wDevID, dwParam, lpParms);
1702 if (!(wmd = MCI_GetDriver(wDevID))) {
1703 return MCIERR_INVALID_DEVICE_ID;
1706 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD_PTR)lpParms);
1708 MCI_UnLoadMciDriver(wmd);
1710 if (dwParam & MCI_NOTIFY)
1711 mciDriverNotify(lpParms ? (HWND)lpParms->dwCallback : 0,
1713 dwRet ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
1718 /**************************************************************************
1719 * MCI_WriteString [internal]
1721 static DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1726 dstSize /= sizeof(WCHAR);
1727 if (dstSize <= strlenW(lpSrcStr)) {
1728 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1729 ret = MCIERR_PARAM_OVERFLOW;
1731 strcpyW(lpDstStr, lpSrcStr);
1739 /**************************************************************************
1740 * MCI_Sysinfo [internal]
1742 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1744 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1745 WCHAR buf[2048], *s = buf, *p;
1746 LPWINE_MCIDRIVER wmd;
1749 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1750 if (lpParms->lpstrReturn == NULL) return MCIERR_PARAM_OVERFLOW;
1752 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1753 uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1755 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1756 case MCI_SYSINFO_QUANTITY:
1757 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1758 if (dwFlags & MCI_SYSINFO_OPEN) {
1759 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1760 EnterCriticalSection(&WINMM_cs);
1761 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1764 LeaveCriticalSection(&WINMM_cs);
1766 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1767 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1768 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1769 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1770 RegCloseKey( hKey );
1772 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1773 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1776 if (dwFlags & MCI_SYSINFO_OPEN) {
1777 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
1778 EnterCriticalSection(&WINMM_cs);
1779 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1780 if (wmd->wType == lpParms->wDeviceType) cnt++;
1782 LeaveCriticalSection(&WINMM_cs);
1784 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
1785 FIXME("Don't know how to get # of MCI devices of a given type\n");
1789 *(DWORD*)lpParms->lpstrReturn = cnt;
1790 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1791 ret = MCI_INTEGER_RETURNED;
1793 case MCI_SYSINFO_INSTALLNAME:
1794 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1795 if ((wmd = MCI_GetDriver(uDevID))) {
1796 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1797 wmd->lpstrDeviceType);
1799 *lpParms->lpstrReturn = 0;
1800 ret = MCIERR_INVALID_DEVICE_ID;
1802 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1804 case MCI_SYSINFO_NAME:
1805 TRACE("MCI_SYSINFO_NAME\n");
1806 if (dwFlags & MCI_SYSINFO_OPEN) {
1807 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1808 ret = MCIERR_UNRECOGNIZED_COMMAND;
1811 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1812 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1813 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1814 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1815 lpParms->dwNumber <= cnt) {
1816 DWORD bufLen = sizeof(buf)/sizeof(buf[0]);
1817 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1818 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1821 RegCloseKey( hKey );
1824 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1825 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1826 TRACE("%d: %s\n", cnt, debugstr_w(p));
1827 if (cnt == lpParms->dwNumber - 1) {
1834 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1836 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1839 TRACE("Unsupported flag value=%08x\n", dwFlags);
1840 ret = MCIERR_UNRECOGNIZED_COMMAND;
1845 /**************************************************************************
1846 * MCI_Break [internal]
1848 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1852 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1854 if (dwFlags & MCI_NOTIFY)
1855 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1856 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1861 /**************************************************************************
1862 * MCI_Sound [internal]
1864 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1868 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1870 if (dwFlags & MCI_SOUND_NAME)
1871 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1873 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1874 if (dwFlags & MCI_NOTIFY)
1875 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1876 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1881 /**************************************************************************
1882 * MCI_SendCommand [internal]
1884 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1886 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1890 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1893 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1896 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1899 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1902 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
1905 if (wDevID == MCI_ALL_DEVICE_ID) {
1906 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1907 dwRet = MCIERR_CANNOT_USE_ALL;
1909 dwRet = MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2);
1916 /**************************************************************************
1917 * MCI_CleanUp [internal]
1919 * Some MCI commands need to be cleaned-up (when not called from
1920 * mciSendString), because MCI drivers return extra information for string
1921 * transformation. This function gets rid of them.
1923 static LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD_PTR dwParam2)
1926 return LOWORD(dwRet);
1929 case MCI_GETDEVCAPS:
1930 switch (dwRet & 0xFFFF0000ul) {
1932 case MCI_COLONIZED3_RETURN:
1933 case MCI_COLONIZED4_RETURN:
1934 case MCI_INTEGER_RETURNED:
1937 case MCI_RESOURCE_RETURNED:
1938 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1940 LPMCI_GETDEVCAPS_PARMS lmgp;
1942 lmgp = (LPMCI_GETDEVCAPS_PARMS)dwParam2;
1943 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
1944 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1948 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1949 HIWORD(dwRet), MCI_MessageToString(wMsg));
1953 switch (dwRet & 0xFFFF0000ul) {
1955 case MCI_COLONIZED3_RETURN:
1956 case MCI_COLONIZED4_RETURN:
1957 case MCI_INTEGER_RETURNED:
1960 case MCI_RESOURCE_RETURNED:
1961 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1963 LPMCI_STATUS_PARMS lsp;
1965 lsp = (LPMCI_STATUS_PARMS)dwParam2;
1966 TRACE("Changing %08lx to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
1967 lsp->dwReturn = LOWORD(lsp->dwReturn);
1971 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1972 HIWORD(dwRet), MCI_MessageToString(wMsg));
1976 switch (dwRet & 0xFFFF0000ul) {
1978 case MCI_INTEGER_RETURNED:
1982 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
1986 if (HIWORD(dwRet)) {
1987 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1988 dwRet, MCI_MessageToString(wMsg));
1992 return LOWORD(dwRet);
1995 /**************************************************************************
1996 * mciGetErrorStringW [WINMM.@]
1998 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2002 if (lpstrBuffer != NULL && uLength > 0 &&
2003 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2005 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
2012 /**************************************************************************
2013 * mciGetErrorStringA [WINMM.@]
2015 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2019 if (lpstrBuffer != NULL && uLength > 0 &&
2020 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2022 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2029 /**************************************************************************
2030 * mciDriverNotify [WINMM.@]
2032 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2034 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2036 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2039 /**************************************************************************
2040 * mciGetDriverData [WINMM.@]
2042 DWORD_PTR WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2044 LPWINE_MCIDRIVER wmd;
2046 TRACE("(%04x)\n", uDeviceID);
2048 wmd = MCI_GetDriver(uDeviceID);
2051 WARN("Bad uDeviceID\n");
2055 return wmd->dwPrivate;
2058 /**************************************************************************
2059 * mciSetDriverData [WINMM.@]
2061 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD_PTR data)
2063 LPWINE_MCIDRIVER wmd;
2065 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2067 wmd = MCI_GetDriver(uDeviceID);
2070 WARN("Bad uDeviceID\n");
2074 wmd->dwPrivate = data;
2078 /**************************************************************************
2079 * mciSendCommandW [WINMM.@]
2082 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2086 TRACE("(%08x, %s, %08lx, %08lx)\n",
2087 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2089 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2);
2090 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2091 TRACE("=> %08x\n", dwRet);
2095 /**************************************************************************
2096 * mciSendCommandA [WINMM.@]
2098 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2103 TRACE("(%08x, %s, %08lx, %08lx)\n",
2104 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2106 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2109 FIXME("message %04x mapping failed\n", wMsg);
2110 return MMSYSERR_NOMEM;
2112 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2114 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2118 /**************************************************************************
2119 * mciGetDeviceIDA [WINMM.@]
2121 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2123 LPWSTR w = MCI_strdupAtoW(lpstrName);
2124 UINT ret = MCIERR_OUT_OF_MEMORY;
2128 ret = mciGetDeviceIDW(w);
2129 HeapFree(GetProcessHeap(), 0, w);
2134 /**************************************************************************
2135 * mciGetDeviceIDW [WINMM.@]
2137 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2139 return MCI_GetDriverFromString(lpwstrName);
2142 /******************************************************************
2145 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
2147 static void MyUserYield(void)
2149 HMODULE mod = GetModuleHandleA( "user32.dll" );
2152 FARPROC proc = GetProcAddress( mod, "UserYield16" );
2157 /**************************************************************************
2158 * MCI_DefYieldProc [internal]
2160 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2164 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2166 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2167 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2173 msg.hwnd = HWND_32(HIWORD(data));
2174 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2180 /**************************************************************************
2181 * mciSetYieldProc [WINMM.@]
2183 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2185 LPWINE_MCIDRIVER wmd;
2187 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2189 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2190 WARN("Bad uDeviceID\n");
2194 wmd->lpfnYieldProc = fpYieldProc;
2195 wmd->dwYieldData = dwYieldData;
2200 /**************************************************************************
2201 * mciGetDeviceIDFromElementIDA [WINMM.@]
2203 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2205 LPWSTR w = MCI_strdupAtoW(lpstrType);
2210 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2211 HeapFree(GetProcessHeap(), 0, w);
2216 /**************************************************************************
2217 * mciGetDeviceIDFromElementIDW [WINMM.@]
2219 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2221 /* FIXME: that's rather strange, there is no
2222 * mciGetDeviceIDFromElementID32A in winmm.spec
2224 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2228 /**************************************************************************
2229 * mciGetYieldProc [WINMM.@]
2231 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2233 LPWINE_MCIDRIVER wmd;
2235 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2237 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2238 WARN("Bad uDeviceID\n");
2241 if (!wmd->lpfnYieldProc) {
2242 WARN("No proc set\n");
2245 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
2246 return wmd->lpfnYieldProc;
2249 /**************************************************************************
2250 * mciGetCreatorTask [WINMM.@]
2252 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2254 LPWINE_MCIDRIVER wmd;
2257 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
2259 TRACE("(%u) => %p\n", uDeviceID, ret);
2263 /**************************************************************************
2264 * mciDriverYield [WINMM.@]
2266 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2268 LPWINE_MCIDRIVER wmd;
2271 TRACE("(%04x)\n", uDeviceID);
2273 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc) {
2276 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);