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};
1237 TRACE("(%s, %p, %d, %p)\n",
1238 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1240 /* format is <command> <device> <optargs> */
1241 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1242 return MCIERR_OUT_OF_MEMORY;
1243 strcpyW( verb, lpstrCommand );
1246 memset(data, 0, sizeof(data));
1248 if (!(args = strchrW(verb, ' '))) {
1249 dwRet = MCIERR_MISSING_DEVICE_NAME;
1253 if ((dwRet = MCI_GetString(&dev, &args))) {
1256 uDevID = strcmpiW(dev, wszAll) ? 0 : MCI_ALL_DEVICE_ID;
1258 /* Determine devType from open */
1259 if (!strcmpW(verb, wszOpen)) {
1260 LPWSTR devType, tmp;
1263 /* case dev == 'new' has to be handled */
1264 if (!strcmpW(dev, wszNew)) {
1266 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1268 tmp = strchrW(devType, ' ');
1269 if (tmp) *tmp = '\0';
1270 devType = str_dup_upper(devType);
1271 if (tmp) *tmp = ' ';
1272 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1274 WARN("open new requires device type\n");
1275 dwRet = MCIERR_MISSING_DEVICE_NAME;
1278 } else if ((devType = strchrW(dev, '!')) != NULL) {
1280 tmp = devType; devType = dev; dev = tmp;
1282 dwFlags |= MCI_OPEN_TYPE;
1283 data[2] = (DWORD_PTR)devType;
1284 devType = str_dup_upper(devType);
1285 dwFlags |= MCI_OPEN_ELEMENT;
1286 data[3] = (DWORD_PTR)dev;
1287 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1288 /* this is the name of a mci driver's type */
1289 tmp = strchrW(dev, ' ');
1290 if (tmp) *tmp = '\0';
1291 data[2] = (DWORD_PTR)dev;
1292 devType = str_dup_upper(dev);
1293 if (tmp) *tmp = ' ';
1294 dwFlags |= MCI_OPEN_TYPE;
1296 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1298 tmp = strchrW(devType, ' ');
1299 if (tmp) *tmp = '\0';
1300 devType = str_dup_upper(devType);
1301 if (tmp) *tmp = ' ';
1302 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1304 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1307 devType = str_dup_upper(buf);
1309 dwFlags |= MCI_OPEN_ELEMENT;
1310 data[3] = (DWORD_PTR)dev;
1312 if (MCI_ALL_DEVICE_ID == uDevID) {
1313 dwRet = MCIERR_CANNOT_USE_ALL;
1316 if (!strstrW(args, wszSAliasS) && !dev) {
1317 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1321 dwRet = MCI_LoadMciDriver(devType, &wmd);
1322 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1323 dwRet = MCIERR_INVALID_DEVICE_NAME;
1324 HeapFree(GetProcessHeap(), 0, devType);
1326 MCI_UnLoadMciDriver(wmd);
1329 } else if ((MCI_ALL_DEVICE_ID != uDevID) && !(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1331 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1333 sprintfW(buf, wszOpenWait, dev);
1335 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1338 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1340 /* FIXME: memory leak, MCI driver is not closed */
1341 dwRet = MCIERR_INVALID_DEVICE_ID;
1346 /* get the verb in the different command tables */
1348 /* try the device specific command table */
1349 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1351 /* try the type specific command table */
1352 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1353 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1354 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1355 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1358 /* try core command table */
1359 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1362 TRACE("Command %s not found!\n", debugstr_w(verb));
1363 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1367 /* set return information */
1368 switch (retType = MCI_GetReturnType(lpCmd)) {
1369 case 0: offset = 1; break;
1370 case MCI_INTEGER: offset = 2; break;
1371 case MCI_STRING: data[1] = (DWORD_PTR)lpstrRet; data[2] = uRetLen; offset = 3; break;
1372 case MCI_RECT: offset = 5; break;
1373 default: ERR("oops\n");
1376 TRACE("verb=%s on dev=%s; offset=%d\n",
1377 debugstr_w(verb), debugstr_w(dev), offset);
1379 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1382 /* set up call back */
1383 if (dwFlags & MCI_NOTIFY) {
1384 data[0] = (DWORD_PTR)hwndCallback;
1387 /* FIXME: the command should get it's own notification window set up and
1388 * ask for device closing while processing the notification mechanism
1390 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1392 TRACE("[%d, %s, %08x, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1393 wmd ? wmd->wDeviceID : uDevID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1394 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1395 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1396 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1398 if (strcmpW(verb, wszOpen) == 0) {
1399 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1400 MCI_UnLoadMciDriver(wmd);
1401 /* FIXME: notification is not properly shared across two opens */
1403 dwRet = MCI_SendCommand(wmd ? wmd->wDeviceID : uDevID, MCI_GetMessage(lpCmd), dwFlags, (DWORD_PTR)data);
1405 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1406 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1407 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1410 HeapFree(GetProcessHeap(), 0, verb);
1414 /**************************************************************************
1415 * mciSendStringA [WINMM.@]
1417 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1418 UINT uRetLen, HWND hwndCallback)
1420 LPWSTR lpwstrCommand;
1421 LPWSTR lpwstrRet = NULL;
1425 /* FIXME: is there something to do with lpstrReturnString ? */
1426 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1427 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1428 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1431 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1433 WARN("no memory\n");
1434 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1435 return MCIERR_OUT_OF_MEMORY;
1438 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1439 if (!ret && lpwstrRet)
1440 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1441 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1442 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1446 /**************************************************************************
1447 * mciExecute [WINMM.@]
1449 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1454 TRACE("(%s)!\n", lpstrCommand);
1456 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1458 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1459 sprintf(strRet, "Unknown MCI error (%d)", ret);
1461 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1463 /* FIXME: what shall I return ? */
1467 /**************************************************************************
1468 * mciLoadCommandResource [WINMM.@]
1470 * Strangely, this function only exists as a UNICODE one.
1472 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1474 UINT ret = MCI_NO_COMMAND_TABLE;
1478 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1480 /* if a file named "resname.mci" exits, then load resource "resname" from it
1481 * otherwise directly from driver
1482 * We don't support it (who uses this feature ?), but we check anyway
1486 /* FIXME: we should put this back into order, but I never found a program
1487 * actually using this feature, so we may not need it
1492 strcat(strcpy(buf, resname), ".mci");
1493 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1494 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1498 if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
1499 (hMem = LoadResource(hInst, hRsrc))) {
1500 ret = MCI_SetCommandTable(hMem, type);
1503 else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
1505 TRACE("=> %04x\n", ret);
1509 /**************************************************************************
1510 * mciFreeCommandResource [WINMM.@]
1512 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1514 TRACE("(%08x)!\n", uTable);
1516 if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
1519 FreeResource(S_MciCmdTable[uTable].hMem);
1520 S_MciCmdTable[uTable].hMem = NULL;
1521 S_MciCmdTable[uTable].lpTable = NULL;
1522 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
1523 S_MciCmdTable[uTable].aVerbs = 0;
1524 S_MciCmdTable[uTable].nVerbs = 0;
1528 /**************************************************************************
1529 * MCI_Open [internal]
1531 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1533 WCHAR strDevTyp[128];
1535 LPWINE_MCIDRIVER wmd = NULL;
1537 TRACE("(%08X, %p)\n", dwParam, lpParms);
1538 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1540 /* only two low bytes are generic, the other ones are dev type specific */
1541 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1542 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1543 MCI_NOTIFY|MCI_WAIT)
1544 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1545 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1547 #undef WINE_MCIDRIVER_SUPP
1551 if (dwParam & MCI_OPEN_TYPE) {
1552 if (dwParam & MCI_OPEN_TYPE_ID) {
1553 WORD uDevType = LOWORD(lpParms->lpstrDeviceType);
1555 if (uDevType < MCI_DEVTYPE_FIRST ||
1556 uDevType > MCI_DEVTYPE_LAST ||
1557 !LoadStringW(hWinMM32Instance, uDevType,
1558 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1559 dwRet = MCIERR_BAD_INTEGER;
1564 if (lpParms->lpstrDeviceType == NULL) {
1565 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1568 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1569 ptr = strchrW(strDevTyp, '!');
1571 /* this behavior is not documented in windows. However, since, in
1572 * some occasions, MCI_OPEN handling is translated by WinMM into
1573 * a call to mciSendString("open <type>"); this code shall be correct
1575 if (dwParam & MCI_OPEN_ELEMENT) {
1576 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1577 debugstr_w(lpParms->lpstrElementName),
1578 debugstr_w(strDevTyp));
1579 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1582 dwParam |= MCI_OPEN_ELEMENT;
1584 /* FIXME: not a good idea to write in user supplied buffer */
1585 lpParms->lpstrElementName = ptr;
1589 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1592 if (dwParam & MCI_OPEN_ELEMENT) {
1593 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1595 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1596 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1597 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1601 if (!lpParms->lpstrElementName) {
1602 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1606 /* type, if given as a parameter, supersedes file extension */
1607 if (!strDevTyp[0] &&
1608 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1609 strDevTyp, sizeof(strDevTyp))) {
1610 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1611 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1612 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1615 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1616 strcpyW(strDevTyp, wszCdAudio);
1620 if (strDevTyp[0] == 0) {
1621 FIXME("Couldn't load driver\n");
1622 dwRet = MCIERR_INVALID_DEVICE_NAME;
1626 if (dwParam & MCI_OPEN_ALIAS) {
1627 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1628 if (!lpParms->lpstrAlias) {
1629 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1634 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1638 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1639 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1640 /* FIXME: is dwRet the correct ret code ? */
1644 /* only handled devices fall through */
1645 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1647 if (dwParam & MCI_NOTIFY)
1648 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1652 if (wmd) MCI_UnLoadMciDriver(wmd);
1654 if (dwParam & MCI_NOTIFY)
1655 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1659 /**************************************************************************
1660 * MCI_Close [internal]
1662 static DWORD MCI_Close(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1665 LPWINE_MCIDRIVER wmd;
1667 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1669 /* Every device must handle MCI_NOTIFY on its own. */
1670 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1671 while (MciDrivers) {
1672 /* Retrieve the device ID under lock, but send the message without,
1673 * the driver might be calling some winmm functions from another
1674 * thread before being fully stopped.
1676 EnterCriticalSection(&WINMM_cs);
1679 LeaveCriticalSection(&WINMM_cs);
1682 wDevID = MciDrivers->wDeviceID;
1683 LeaveCriticalSection(&WINMM_cs);
1684 MCI_Close(wDevID, dwParam, lpParms);
1689 if (!(wmd = MCI_GetDriver(wDevID))) {
1690 return MCIERR_INVALID_DEVICE_ID;
1693 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD_PTR)lpParms);
1695 MCI_UnLoadMciDriver(wmd);
1700 /**************************************************************************
1701 * MCI_WriteString [internal]
1703 static DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1708 dstSize /= sizeof(WCHAR);
1709 if (dstSize <= strlenW(lpSrcStr)) {
1710 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1711 ret = MCIERR_PARAM_OVERFLOW;
1713 strcpyW(lpDstStr, lpSrcStr);
1721 /**************************************************************************
1722 * MCI_Sysinfo [internal]
1724 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1726 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1727 WCHAR buf[2048], *s = buf, *p;
1728 LPWINE_MCIDRIVER wmd;
1731 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1732 if (lpParms->lpstrReturn == NULL) return MCIERR_PARAM_OVERFLOW;
1734 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1735 uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1736 if ((WORD)MCI_ALL_DEVICE_ID == LOWORD(uDevID))
1737 uDevID = MCI_ALL_DEVICE_ID; /* Be compatible with Win9x */
1739 switch (dwFlags & ~(MCI_SYSINFO_OPEN|MCI_NOTIFY|MCI_WAIT)) {
1740 case MCI_SYSINFO_QUANTITY:
1741 if (lpParms->dwRetSize < sizeof(DWORD))
1742 return MCIERR_PARAM_OVERFLOW;
1743 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1744 if (uDevID == MCI_ALL_DEVICE_ID) {
1745 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1746 if (dwFlags & MCI_SYSINFO_OPEN) {
1747 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1748 EnterCriticalSection(&WINMM_cs);
1749 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1752 LeaveCriticalSection(&WINMM_cs);
1754 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1755 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1756 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1757 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1758 RegCloseKey( hKey );
1760 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1761 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1764 if (dwFlags & MCI_SYSINFO_OPEN) {
1765 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms->wDeviceType);
1766 EnterCriticalSection(&WINMM_cs);
1767 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1768 if (wmd->wType == lpParms->wDeviceType) cnt++;
1770 LeaveCriticalSection(&WINMM_cs);
1772 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms->wDeviceType);
1773 FIXME("Don't know how to get # of MCI devices of a given type\n");
1777 *(DWORD*)lpParms->lpstrReturn = cnt;
1778 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1779 ret = MCI_INTEGER_RETURNED;
1780 /* return ret; Only Win9x sends a notification in this case. */
1782 case MCI_SYSINFO_INSTALLNAME:
1783 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1784 if ((wmd = MCI_GetDriver(uDevID))) {
1785 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1786 wmd->lpstrDeviceType);
1788 *lpParms->lpstrReturn = 0;
1789 ret = MCIERR_INVALID_DEVICE_ID;
1791 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1793 case MCI_SYSINFO_NAME:
1795 if (dwFlags & MCI_SYSINFO_OPEN) {
1796 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1797 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1798 uDevID == MCI_ALL_DEVICE_ID ? MCI_ALL_DEVICE_ID : lpParms->wDeviceType);
1799 EnterCriticalSection(&WINMM_cs);
1800 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1801 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1802 if (uDevID == MCI_ALL_DEVICE_ID ||
1803 lpParms->wDeviceType == wmd->wType) {
1805 if (cnt == lpParms->dwNumber) {
1806 s = wmd->lpstrAlias;
1811 LeaveCriticalSection(&WINMM_cs);
1812 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1813 } else if (MCI_ALL_DEVICE_ID == uDevID) {
1814 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms->dwNumber);
1815 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1816 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1817 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1818 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1819 lpParms->dwNumber <= cnt) {
1820 DWORD bufLen = sizeof(buf)/sizeof(buf[0]);
1821 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1822 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1825 RegCloseKey( hKey );
1828 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1829 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1830 TRACE("%d: %s\n", cnt, debugstr_w(p));
1831 if (cnt == lpParms->dwNumber - 1) {
1838 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1840 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms->wDeviceType);
1841 /* Cheating: what is asked for is the nth device from the registry. */
1842 if (1 != lpParms->dwNumber || /* Handle only one of each kind. */
1843 lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST)
1844 ret = MCIERR_OUTOFRANGE;
1846 LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType),
1847 lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR));
1851 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1854 TRACE("Unsupported flag value=%08x\n", dwFlags);
1855 ret = MCIERR_UNRECOGNIZED_KEYWORD;
1857 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1858 mciDriverNotify((HWND)lpParms->dwCallback, uDevID, MCI_NOTIFY_SUCCESSFUL);
1862 /**************************************************************************
1863 * MCI_Break [internal]
1865 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1869 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1871 if (dwFlags & MCI_NOTIFY)
1872 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1873 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1878 /**************************************************************************
1879 * MCI_Sound [internal]
1881 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1885 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1887 if (dwFlags & MCI_SOUND_NAME)
1888 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1890 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1891 if (dwFlags & MCI_NOTIFY)
1892 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1893 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1898 /**************************************************************************
1899 * MCI_SendCommand [internal]
1901 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1903 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1907 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1910 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1913 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1916 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1919 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
1922 if ((UINT16)wDevID == (UINT16)MCI_ALL_DEVICE_ID) {
1923 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1924 dwRet = MCIERR_CANNOT_USE_ALL;
1926 dwRet = MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2);
1933 /**************************************************************************
1934 * MCI_CleanUp [internal]
1936 * Some MCI commands need to be cleaned-up (when not called from
1937 * mciSendString), because MCI drivers return extra information for string
1938 * transformation. This function gets rid of them.
1940 static LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD_PTR dwParam2)
1943 return LOWORD(dwRet);
1946 case MCI_GETDEVCAPS:
1947 switch (dwRet & 0xFFFF0000ul) {
1949 case MCI_COLONIZED3_RETURN:
1950 case MCI_COLONIZED4_RETURN:
1951 case MCI_INTEGER_RETURNED:
1954 case MCI_RESOURCE_RETURNED:
1955 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1957 LPMCI_GETDEVCAPS_PARMS lmgp;
1959 lmgp = (LPMCI_GETDEVCAPS_PARMS)dwParam2;
1960 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
1961 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1965 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1966 HIWORD(dwRet), MCI_MessageToString(wMsg));
1970 switch (dwRet & 0xFFFF0000ul) {
1972 case MCI_COLONIZED3_RETURN:
1973 case MCI_COLONIZED4_RETURN:
1974 case MCI_INTEGER_RETURNED:
1977 case MCI_RESOURCE_RETURNED:
1978 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1980 LPMCI_STATUS_PARMS lsp;
1982 lsp = (LPMCI_STATUS_PARMS)dwParam2;
1983 TRACE("Changing %08lx to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
1984 lsp->dwReturn = LOWORD(lsp->dwReturn);
1988 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1989 HIWORD(dwRet), MCI_MessageToString(wMsg));
1993 switch (dwRet & 0xFFFF0000ul) {
1995 case MCI_INTEGER_RETURNED:
1999 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2003 if (HIWORD(dwRet)) {
2004 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2005 dwRet, MCI_MessageToString(wMsg));
2009 return LOWORD(dwRet);
2012 /**************************************************************************
2013 * mciGetErrorStringW [WINMM.@]
2015 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2019 if (lpstrBuffer != NULL && uLength > 0 &&
2020 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2022 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
2029 /**************************************************************************
2030 * mciGetErrorStringA [WINMM.@]
2032 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2036 if (lpstrBuffer != NULL && uLength > 0 &&
2037 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2039 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2046 /**************************************************************************
2047 * mciDriverNotify [WINMM.@]
2049 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2051 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2053 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2056 /**************************************************************************
2057 * mciGetDriverData [WINMM.@]
2059 DWORD_PTR WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2061 LPWINE_MCIDRIVER wmd;
2063 TRACE("(%04x)\n", uDeviceID);
2065 wmd = MCI_GetDriver(uDeviceID);
2068 WARN("Bad uDeviceID\n");
2072 return wmd->dwPrivate;
2075 /**************************************************************************
2076 * mciSetDriverData [WINMM.@]
2078 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD_PTR data)
2080 LPWINE_MCIDRIVER wmd;
2082 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2084 wmd = MCI_GetDriver(uDeviceID);
2087 WARN("Bad uDeviceID\n");
2091 wmd->dwPrivate = data;
2095 /**************************************************************************
2096 * mciSendCommandW [WINMM.@]
2099 DWORD WINAPI mciSendCommandW(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 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2);
2107 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2108 TRACE("=> %08x\n", dwRet);
2112 /**************************************************************************
2113 * mciSendCommandA [WINMM.@]
2115 DWORD WINAPI mciSendCommandA(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 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2126 FIXME("message %04x mapping failed\n", wMsg);
2127 return MMSYSERR_NOMEM;
2129 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2131 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2135 /**************************************************************************
2136 * mciGetDeviceIDA [WINMM.@]
2138 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2140 LPWSTR w = MCI_strdupAtoW(lpstrName);
2141 UINT ret = MCIERR_OUT_OF_MEMORY;
2145 ret = mciGetDeviceIDW(w);
2146 HeapFree(GetProcessHeap(), 0, w);
2151 /**************************************************************************
2152 * mciGetDeviceIDW [WINMM.@]
2154 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2156 return MCI_GetDriverFromString(lpwstrName);
2159 /**************************************************************************
2160 * MCI_DefYieldProc [internal]
2162 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2167 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2169 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2170 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2171 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2174 msg.hwnd = HWND_32(HIWORD(data));
2175 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2181 /**************************************************************************
2182 * mciSetYieldProc [WINMM.@]
2184 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2186 LPWINE_MCIDRIVER wmd;
2188 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2190 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2191 WARN("Bad uDeviceID\n");
2195 wmd->lpfnYieldProc = fpYieldProc;
2196 wmd->dwYieldData = dwYieldData;
2201 /**************************************************************************
2202 * mciGetDeviceIDFromElementIDA [WINMM.@]
2204 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2206 LPWSTR w = MCI_strdupAtoW(lpstrType);
2211 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2212 HeapFree(GetProcessHeap(), 0, w);
2217 /**************************************************************************
2218 * mciGetDeviceIDFromElementIDW [WINMM.@]
2220 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2222 /* FIXME: that's rather strange, there is no
2223 * mciGetDeviceIDFromElementID32A in winmm.spec
2225 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2229 /**************************************************************************
2230 * mciGetYieldProc [WINMM.@]
2232 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2234 LPWINE_MCIDRIVER wmd;
2236 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2238 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2239 WARN("Bad uDeviceID\n");
2242 if (!wmd->lpfnYieldProc) {
2243 WARN("No proc set\n");
2246 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
2247 return wmd->lpfnYieldProc;
2250 /**************************************************************************
2251 * mciGetCreatorTask [WINMM.@]
2253 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2255 LPWINE_MCIDRIVER wmd;
2258 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)(DWORD_PTR)wmd->CreatorThread;
2260 TRACE("(%u) => %p\n", uDeviceID, ret);
2264 /**************************************************************************
2265 * mciDriverYield [WINMM.@]
2267 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2269 LPWINE_MCIDRIVER wmd;
2272 TRACE("(%04x)\n", uDeviceID);
2274 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc) {
2276 PeekMessageW(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
2278 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);