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 WINMM_MapType (*pFnMciMapMsg32WTo16) (WORD,WORD,DWORD,DWORD_PTR*) = NULL;
71 WINMM_MapType (*pFnMciUnMapMsg32WTo16)(WORD,WORD,DWORD,DWORD_PTR) = NULL;
73 /* First MCI valid device ID (0 means error) */
74 #define MCI_MAGIC 0x0001
77 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};
78 static const WCHAR wszNull [] = {0};
79 static const WCHAR wszAll [] = {'A','L','L',0};
80 static const WCHAR wszMci [] = {'M','C','I',0};
81 static const WCHAR wszOpen [] = {'o','p','e','n',0};
82 static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
84 static WINE_MCIDRIVER *MciDrivers;
86 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
87 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType);
89 /* dup a string and uppercase it */
90 static inline LPWSTR str_dup_upper( LPCWSTR str )
92 INT len = (strlenW(str) + 1) * sizeof(WCHAR);
93 LPWSTR p = HeapAlloc( GetProcessHeap(), 0, len );
96 memcpy( p, str, len );
102 /**************************************************************************
103 * MCI_GetDriver [internal]
105 static LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
107 LPWINE_MCIDRIVER wmd = 0;
109 EnterCriticalSection(&WINMM_cs);
110 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
111 if (wmd->wDeviceID == wDevID)
114 LeaveCriticalSection(&WINMM_cs);
118 /**************************************************************************
119 * MCI_GetDriverFromString [internal]
121 static UINT MCI_GetDriverFromString(LPCWSTR lpstrName)
123 LPWINE_MCIDRIVER wmd;
129 if (!strcmpiW(lpstrName, wszAll))
130 return MCI_ALL_DEVICE_ID;
132 EnterCriticalSection(&WINMM_cs);
133 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
134 if (wmd->lpstrElementName && strcmpW(wmd->lpstrElementName, lpstrName) == 0) {
135 ret = wmd->wDeviceID;
138 if (wmd->lpstrDeviceType && strcmpiW(wmd->lpstrDeviceType, lpstrName) == 0) {
139 ret = wmd->wDeviceID;
142 if (wmd->lpstrAlias && strcmpiW(wmd->lpstrAlias, lpstrName) == 0) {
143 ret = wmd->wDeviceID;
147 LeaveCriticalSection(&WINMM_cs);
152 /**************************************************************************
153 * MCI_MessageToString [internal]
155 const char* MCI_MessageToString(UINT wMsg)
157 static char buffer[100];
159 #define CASE(s) case (s): return #s
169 CASE(DRV_QUERYCONFIGURE);
172 CASE(DRV_EXITSESSION);
173 CASE(DRV_EXITAPPLICATION);
177 CASE(MCI_CLOSE_DRIVER);
186 CASE(MCI_GETDEVCAPS);
190 CASE(MCI_OPEN_DRIVER);
208 /* constants for digital video */
222 sprintf(buffer, "MCI_<<%04X>>", wMsg);
227 LPWSTR MCI_strdupAtoW( LPCSTR str )
232 if (!str) return NULL;
233 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
234 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
235 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
239 LPSTR MCI_strdupWtoA( LPCWSTR str )
244 if (!str) return NULL;
245 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
246 ret = HeapAlloc( GetProcessHeap(), 0, len );
247 if (ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
251 static int MCI_MapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
253 if (msg < DRV_RESERVED) return 0;
292 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA*)*dwParam2;
293 MCI_OPEN_PARMSW *mci_openW;
296 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR) + sizeof(*mci_openW) + 2 * sizeof(DWORD));
299 *ptr++ = *dwParam2; /* save the previous pointer */
300 *dwParam2 = (DWORD_PTR)ptr;
301 mci_openW = (MCI_OPEN_PARMSW *)ptr;
303 if (dwParam1 & MCI_NOTIFY)
304 mci_openW->dwCallback = mci_openA->dwCallback;
306 if (dwParam1 & MCI_OPEN_TYPE)
308 if (dwParam1 & MCI_OPEN_TYPE_ID)
309 mci_openW->lpstrDeviceType = (LPCWSTR)mci_openA->lpstrDeviceType;
311 mci_openW->lpstrDeviceType = MCI_strdupAtoW(mci_openA->lpstrDeviceType);
313 if (dwParam1 & MCI_OPEN_ELEMENT)
315 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
316 mci_openW->lpstrElementName = (LPCWSTR)mci_openA->lpstrElementName;
318 mci_openW->lpstrElementName = MCI_strdupAtoW(mci_openA->lpstrElementName);
320 if (dwParam1 & MCI_OPEN_ALIAS)
321 mci_openW->lpstrAlias = MCI_strdupAtoW(mci_openA->lpstrAlias);
322 /* FIXME: this is only needed for specific types of MCI devices, and
323 * may cause a segfault if the two DWORD:s don't exist at the end of
326 memcpy(mci_openW + 1, mci_openA + 1, 2 * sizeof(DWORD));
331 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
333 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)*dwParam2;
334 MCI_ANIM_WINDOW_PARMSW *mci_windowW;
336 mci_windowW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW));
337 if (!mci_windowW) return -1;
339 *dwParam2 = (DWORD_PTR)mci_windowW;
341 mci_windowW->lpstrText = MCI_strdupAtoW(mci_windowA->lpstrText);
343 if (dwParam1 & MCI_NOTIFY)
344 mci_windowW->dwCallback = mci_windowA->dwCallback;
345 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
346 mci_windowW->hWnd = mci_windowA->hWnd;
347 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
348 mci_windowW->nCmdShow = mci_windowA->nCmdShow;
356 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*dwParam2;
357 MCI_SYSINFO_PARMSW *mci_sysinfoW;
360 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW) + sizeof(DWORD_PTR));
363 *ptr++ = *dwParam2; /* save the previous pointer */
364 *dwParam2 = (DWORD_PTR)ptr;
365 mci_sysinfoW = (MCI_SYSINFO_PARMSW *)ptr;
367 if (dwParam1 & MCI_NOTIFY)
368 mci_sysinfoW->dwCallback = mci_sysinfoA->dwCallback;
370 mci_sysinfoW->dwRetSize = mci_sysinfoA->dwRetSize;
371 mci_sysinfoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW->dwRetSize);
372 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
373 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
378 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*dwParam2;
379 MCI_INFO_PARMSW *mci_infoW;
382 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW) + sizeof(DWORD_PTR));
385 *ptr++ = *dwParam2; /* save the previous pointer */
386 *dwParam2 = (DWORD_PTR)ptr;
387 mci_infoW = (MCI_INFO_PARMSW *)ptr;
389 if (dwParam1 & MCI_NOTIFY)
390 mci_infoW->dwCallback = mci_infoA->dwCallback;
392 mci_infoW->dwRetSize = mci_infoA->dwRetSize * sizeof(WCHAR); /* it's not the same as SYSINFO !!! */
393 mci_infoW->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_infoW->dwRetSize);
398 MCI_SAVE_PARMSA *mci_saveA = (MCI_SAVE_PARMSA *)*dwParam2;
399 MCI_SAVE_PARMSW *mci_saveW;
401 mci_saveW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW));
402 if (!mci_saveW) return -1;
404 *dwParam2 = (DWORD_PTR)mci_saveW;
405 if (dwParam1 & MCI_NOTIFY)
406 mci_saveW->dwCallback = mci_saveA->dwCallback;
407 mci_saveW->lpfilename = MCI_strdupAtoW(mci_saveA->lpfilename);
412 MCI_LOAD_PARMSA *mci_loadA = (MCI_LOAD_PARMSA *)*dwParam2;
413 MCI_LOAD_PARMSW *mci_loadW;
415 mci_loadW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW));
416 if (!mci_loadW) return -1;
418 *dwParam2 = (DWORD_PTR)mci_loadW;
419 if (dwParam1 & MCI_NOTIFY)
420 mci_loadW->dwCallback = mci_loadA->dwCallback;
421 mci_loadW->lpfilename = MCI_strdupAtoW(mci_loadA->lpfilename);
427 MCI_VD_ESCAPE_PARMSA *mci_vd_escapeA = (MCI_VD_ESCAPE_PARMSA *)*dwParam2;
428 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW;
430 mci_vd_escapeW = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW));
431 if (!mci_vd_escapeW) return -1;
433 *dwParam2 = (DWORD_PTR)mci_vd_escapeW;
434 if (dwParam1 & MCI_NOTIFY)
435 mci_vd_escapeW->dwCallback = mci_vd_escapeA->dwCallback;
436 mci_vd_escapeW->lpstrCommand = MCI_strdupAtoW(mci_vd_escapeA->lpstrCommand);
440 FIXME("Message %s needs translation\n", MCI_MessageToString(msg));
445 static DWORD MCI_UnmapMsgAtoW(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
452 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
453 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)*ptr;
454 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)(ptr + 1);
456 mci_openA->wDeviceID = mci_openW->wDeviceID;
458 if (dwParam1 & MCI_OPEN_TYPE)
460 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
461 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrDeviceType);
463 if (dwParam1 & MCI_OPEN_ELEMENT)
465 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
466 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrElementName);
468 if (dwParam1 & MCI_OPEN_ALIAS)
469 HeapFree(GetProcessHeap(), 0, (LPWSTR)mci_openW->lpstrAlias);
470 HeapFree(GetProcessHeap(), 0, ptr);
474 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
476 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)dwParam2;
478 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW->lpstrText);
479 HeapFree(GetProcessHeap(), 0, mci_windowW);
485 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
486 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)*ptr;
487 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)(ptr + 1);
491 mci_sysinfoA->dwNumber = mci_sysinfoW->dwNumber;
492 mci_sysinfoA->wDeviceType = mci_sysinfoW->wDeviceType;
493 if (dwParam1 & MCI_SYSINFO_QUANTITY)
494 *(DWORD*)mci_sysinfoA->lpstrReturn = *(DWORD*)mci_sysinfoW->lpstrReturn;
496 WideCharToMultiByte(CP_ACP, 0,
497 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize,
498 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
502 HeapFree(GetProcessHeap(), 0, mci_sysinfoW->lpstrReturn);
503 HeapFree(GetProcessHeap(), 0, ptr);
508 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
509 MCI_INFO_PARMSA *mci_infoA = (MCI_INFO_PARMSA *)*ptr;
510 MCI_INFO_PARMSW *mci_infoW = (MCI_INFO_PARMSW *)(ptr + 1);
514 WideCharToMultiByte(CP_ACP, 0,
515 mci_infoW->lpstrReturn, mci_infoW->dwRetSize / sizeof(WCHAR),
516 mci_infoA->lpstrReturn, mci_infoA->dwRetSize,
520 HeapFree(GetProcessHeap(), 0, mci_infoW->lpstrReturn);
521 HeapFree(GetProcessHeap(), 0, ptr);
526 MCI_SAVE_PARMSW *mci_saveW = (MCI_SAVE_PARMSW *)dwParam2;
528 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW->lpfilename);
529 HeapFree(GetProcessHeap(), 0, mci_saveW);
534 MCI_LOAD_PARMSW *mci_loadW = (MCI_LOAD_PARMSW *)dwParam2;
536 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW->lpfilename);
537 HeapFree(GetProcessHeap(), 0, mci_loadW);
542 MCI_VD_ESCAPE_PARMSW *mci_vd_escapeW = (MCI_VD_ESCAPE_PARMSW *)dwParam2;
544 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW->lpstrCommand);
545 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW);
550 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg));
557 /**************************************************************************
558 * MCI_GetDevTypeFromFileName [internal]
560 static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
564 static const WCHAR keyW[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
565 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
566 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
567 if ((tmp = strrchrW(fileName, '.'))) {
568 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, keyW,
569 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
571 LONG lRet = RegQueryValueExW( hKey, tmp + 1, 0, 0, (void*)buf, &dwLen );
573 if (lRet == ERROR_SUCCESS) return 0;
575 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp));
577 return MCIERR_EXTENSION_NOT_FOUND;
580 #define MAX_MCICMDTABLE 20
581 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
583 typedef struct tagWINE_MCICMDTABLE {
587 UINT nVerbs; /* number of verbs in command table */
588 LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
589 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
591 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
593 /**************************************************************************
594 * MCI_IsCommandTableValid [internal]
596 static BOOL MCI_IsCommandTableValid(UINT uTbl)
605 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
606 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
608 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
611 lmem = S_MciCmdTable[uTbl].lpTable;
614 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
615 flg = *(const DWORD*)lmem;
616 eid = *(const WORD*)(lmem + sizeof(DWORD));
617 lmem += sizeof(DWORD) + sizeof(WORD);
619 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
621 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
622 case MCI_STRING: if (inCst) return FALSE; break;
623 case MCI_INTEGER: if (!*str) return FALSE; break;
624 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
625 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
626 case MCI_FLAG: if (!*str) return FALSE; break;
627 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
628 case MCI_RECT: if (!*str || inCst) return FALSE; break;
629 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
630 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
631 default: return FALSE;
633 } while (eid != MCI_END_COMMAND_LIST);
637 /**************************************************************************
638 * MCI_DumpCommandTable [internal]
640 static BOOL MCI_DumpCommandTable(UINT uTbl)
647 if (!MCI_IsCommandTableValid(uTbl)) {
648 ERR("Ooops: %d is not valid\n", uTbl);
652 lmem = S_MciCmdTable[uTbl].lpTable;
656 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
657 flg = *(const DWORD*)lmem;
658 eid = *(const WORD*)(lmem + sizeof(DWORD));
659 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
660 lmem += sizeof(DWORD) + sizeof(WORD);
661 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
662 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
663 } while (eid != MCI_END_COMMAND_LIST);
668 /**************************************************************************
669 * MCI_GetCommandTable [internal]
671 static UINT MCI_GetCommandTable(UINT uDevType)
677 /* first look up existing for existing devType */
678 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
679 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
683 /* well try to load id */
684 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
685 if (LoadStringW(hWinMM32Instance, uDevType, buf, sizeof(buf) / sizeof(WCHAR))) {
688 } else if (uDevType == 0) {
689 static const WCHAR wszCore[] = {'C','O','R','E',0};
692 uTbl = MCI_NO_COMMAND_TABLE;
694 HRSRC hRsrc = FindResourceW(hWinMM32Instance, str, (LPCWSTR)RT_RCDATA);
697 if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
699 uTbl = MCI_SetCommandTable(hMem, uDevType);
701 WARN("No command table found in resource %p[%s]\n",
702 hWinMM32Instance, debugstr_w(str));
705 TRACE("=> %d\n", uTbl);
709 /**************************************************************************
710 * MCI_SetCommandTable [internal]
712 static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType)
715 static BOOL bInitDone = FALSE;
718 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
719 * can be called with 0 as a uDevType to retrieve it.
724 MCI_GetCommandTable(0);
726 TRACE("(%p, %u)\n", hMem, uDevType);
727 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
728 if (!S_MciCmdTable[uTbl].lpTable) {
734 S_MciCmdTable[uTbl].uDevType = uDevType;
735 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
736 S_MciCmdTable[uTbl].hMem = hMem;
739 MCI_DumpCommandTable(uTbl);
742 /* create the verbs table */
743 /* get # of entries */
744 lmem = S_MciCmdTable[uTbl].lpTable;
748 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
749 eid = *(const WORD*)(lmem + sizeof(DWORD));
750 lmem += sizeof(DWORD) + sizeof(WORD);
751 if (eid == MCI_COMMAND_HEAD)
753 } while (eid != MCI_END_COMMAND_LIST);
755 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCWSTR));
756 S_MciCmdTable[uTbl].nVerbs = count;
758 lmem = S_MciCmdTable[uTbl].lpTable;
762 lmem += (strlenW(str) + 1) * sizeof(WCHAR);
763 eid = *(const WORD*)(lmem + sizeof(DWORD));
764 lmem += sizeof(DWORD) + sizeof(WORD);
765 if (eid == MCI_COMMAND_HEAD)
766 S_MciCmdTable[uTbl].aVerbs[count++] = str;
767 } while (eid != MCI_END_COMMAND_LIST);
768 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
773 return MCI_NO_COMMAND_TABLE;
776 /**************************************************************************
777 * MCI_UnLoadMciDriver [internal]
779 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
781 LPWINE_MCIDRIVER* tmp;
786 CloseDriver(wmd->hDriver, 0, 0);
788 if (wmd->dwPrivate != 0)
789 WARN("Unloading mci driver with non nul dwPrivate field\n");
791 EnterCriticalSection(&WINMM_cs);
792 for (tmp = &MciDrivers; *tmp; tmp = &(*tmp)->lpNext) {
798 LeaveCriticalSection(&WINMM_cs);
800 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
801 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
802 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
804 HeapFree(GetProcessHeap(), 0, wmd);
808 /**************************************************************************
809 * MCI_OpenMciDriver [internal]
811 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCWSTR drvTyp, DWORD_PTR lp)
815 if (!DRIVER_GetLibName(drvTyp, wszMci, libName, sizeof(libName)))
819 /* First load driver */
820 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
822 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32WTo16) {
825 switch (res = pFnMciMapMsg32WTo16(0, DRV_OPEN, 0, &lp)) {
826 case WINMM_MAP_MSGERROR:
827 TRACE("Not handled yet (DRV_OPEN)\n");
829 case WINMM_MAP_NOMEM:
830 TRACE("Problem mapping msg=DRV_OPEN from 32W to 16\n");
833 case WINMM_MAP_OKMEM:
834 if ((wmd->hDriver = OpenDriver(drvTyp, wszMci, lp)))
836 if (res == WINMM_MAP_OKMEM)
837 pFnMciUnMapMsg32WTo16(0, DRV_OPEN, 0, lp);
841 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
844 /**************************************************************************
845 * MCI_LoadMciDriver [internal]
847 static DWORD MCI_LoadMciDriver(LPCWSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
849 LPWSTR strDevTyp = str_dup_upper(_strDevTyp);
850 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
851 MCI_OPEN_DRIVER_PARMSW modp;
854 if (!wmd || !strDevTyp) {
855 dwRet = MCIERR_OUT_OF_MEMORY;
859 wmd->lpfnYieldProc = MCI_DefYieldProc;
860 wmd->dwYieldData = VK_CANCEL;
861 wmd->CreatorThread = GetCurrentThreadId();
863 EnterCriticalSection(&WINMM_cs);
864 /* wmd must be inserted in list before sending opening the driver, because it
865 * may want to lookup at wDevID
867 wmd->lpNext = MciDrivers;
870 for (modp.wDeviceID = MCI_MAGIC;
871 MCI_GetDriver(modp.wDeviceID) != 0;
874 wmd->wDeviceID = modp.wDeviceID;
876 LeaveCriticalSection(&WINMM_cs);
878 TRACE("wDevID=%04X\n", modp.wDeviceID);
880 modp.lpstrParams = NULL;
882 if (!MCI_OpenMciDriver(wmd, strDevTyp, (DWORD_PTR)&modp)) {
883 /* silence warning if all is used... some bogus program use commands like
886 if (strcmpiW(strDevTyp, wszAll) == 0) {
887 dwRet = MCIERR_CANNOT_USE_ALL;
889 FIXME("Couldn't load driver for type %s.\n",
890 debugstr_w(strDevTyp));
891 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
896 /* FIXME: should also check that module's description is of the form
897 * MODULENAME:[MCI] comment
900 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
901 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
902 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
904 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
905 wmd->hDriver, debugstr_w(strDevTyp), modp.wType, modp.wCustomCommandTable);
907 wmd->lpstrDeviceType = strDevTyp;
908 wmd->wType = modp.wType;
910 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
911 modp.wDeviceID, modp.wType, modp.wDeviceID);
915 MCI_UnLoadMciDriver(wmd);
916 HeapFree(GetProcessHeap(), 0, strDevTyp);
921 /**************************************************************************
922 * MCI_SendCommandFrom32 [internal]
924 static DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
926 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
927 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
931 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
932 } else if (pFnMciMapMsg32WTo16) {
935 switch (res = pFnMciMapMsg32WTo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
936 case WINMM_MAP_MSGERROR:
937 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
938 dwRet = MCIERR_DRIVER_INTERNAL;
940 case WINMM_MAP_NOMEM:
941 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
942 dwRet = MCIERR_OUT_OF_MEMORY;
945 case WINMM_MAP_OKMEM:
946 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
947 if (res == WINMM_MAP_OKMEM)
948 pFnMciUnMapMsg32WTo16(wmd->wType, wMsg, dwParam1, dwParam2);
956 /**************************************************************************
957 * MCI_FinishOpen [internal]
959 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSW lpParms,
962 if (dwParam & MCI_OPEN_ELEMENT)
964 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms->lpstrElementName)+1) * sizeof(WCHAR));
965 strcpyW( wmd->lpstrElementName, lpParms->lpstrElementName );
967 if (dwParam & MCI_OPEN_ALIAS)
969 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms->lpstrAlias)+1) * sizeof(WCHAR));
970 strcpyW( wmd->lpstrAlias, lpParms->lpstrAlias);
972 lpParms->wDeviceID = wmd->wDeviceID;
974 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
978 /**************************************************************************
979 * MCI_FindCommand [internal]
981 static LPCWSTR MCI_FindCommand(UINT uTbl, LPCWSTR verb)
985 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
988 /* another improvement would be to have the aVerbs array sorted,
989 * so that we could use a dichotomic search on it, rather than this dumb
992 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
993 if (strcmpiW(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
994 return S_MciCmdTable[uTbl].aVerbs[idx];
1000 /**************************************************************************
1001 * MCI_GetReturnType [internal]
1003 static DWORD MCI_GetReturnType(LPCWSTR lpCmd)
1005 lpCmd = (LPCWSTR)((const BYTE*)(lpCmd + strlenW(lpCmd) + 1) + sizeof(DWORD) + sizeof(WORD));
1006 if (*lpCmd == '\0' && *(const WORD*)((const BYTE*)(lpCmd + 1) + sizeof(DWORD)) == MCI_RETURN) {
1007 return *(const DWORD*)(lpCmd + 1);
1012 /**************************************************************************
1013 * MCI_GetMessage [internal]
1015 static WORD MCI_GetMessage(LPCWSTR lpCmd)
1017 return (WORD)*(const DWORD*)(lpCmd + strlenW(lpCmd) + 1);
1020 /**************************************************************************
1021 * MCI_GetDWord [internal]
1023 static BOOL MCI_GetDWord(LPDWORD data, LPWSTR* ptr)
1028 val = strtoulW(*ptr, &ret, 0);
1032 case ' ': ret++; break;
1033 default: return FALSE;
1041 /**************************************************************************
1042 * MCI_GetString [internal]
1044 static DWORD MCI_GetString(LPWSTR* str, LPWSTR* args)
1048 /* see if we have a quoted string */
1050 ptr = strchrW(*str = ptr + 1, '"');
1051 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
1052 /* FIXME: shall we escape \" from string ?? */
1053 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1054 *ptr++ = '\0'; /* remove trailing " */
1055 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
1057 ptr = strchrW(ptr, ' ');
1062 ptr = *args + strlenW(*args);
1071 #define MCI_DATA_SIZE 16
1073 /**************************************************************************
1074 * MCI_ParseOptArgs [internal]
1076 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCWSTR lpCmd,
1077 LPWSTR args, LPDWORD dwFlags)
1082 DWORD dwRet, flg, cflg = 0;
1086 /* loop on arguments */
1088 lmem = (const char*)lpCmd;
1089 found = inCst = FALSE;
1092 /* skip any leading white space(s) */
1093 while (*args == ' ') args++;
1094 TRACE("args=%s offset=%d\n", debugstr_w(args), offset);
1096 do { /* loop on options for command table for the requested verb */
1097 str = (LPCWSTR)lmem;
1098 lmem += ((len = strlenW(str)) + 1) * sizeof(WCHAR);
1099 flg = *(const DWORD*)lmem;
1100 eid = *(const WORD*)(lmem + sizeof(DWORD));
1101 lmem += sizeof(DWORD) + sizeof(WORD);
1102 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1106 inCst = TRUE; cflg = flg; break;
1107 case MCI_END_CONSTANT:
1108 /* there may be additional integral values after flag in constant */
1109 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
1112 inCst = FALSE; cflg = 0;
1116 if (strncmpiW(args, str, len) == 0 &&
1117 ((eid == MCI_STRING && len == 0) || args[len] == 0 || args[len] == ' ')) {
1118 /* store good values into data[] */
1120 while (*args == ' ') args++;
1124 case MCI_COMMAND_HEAD:
1126 case MCI_END_COMMAND:
1127 case MCI_END_COMMAND_LIST:
1128 case MCI_CONSTANT: /* done above */
1129 case MCI_END_CONSTANT: /* done above */
1136 data[offset] |= flg;
1141 if (!MCI_GetDWord(&(data[offset]), &args)) {
1142 return MCIERR_BAD_INTEGER;
1147 /* store rect in data (offset..offset+3) */
1149 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
1150 !MCI_GetDWord(&(data[offset+1]), &args) ||
1151 !MCI_GetDWord(&(data[offset+2]), &args) ||
1152 !MCI_GetDWord(&(data[offset+3]), &args)) {
1153 ERR("Bad rect %s\n", debugstr_w(args));
1154 return MCIERR_BAD_INTEGER;
1159 if ((dwRet = MCI_GetString((LPWSTR*)&data[offset], &args)))
1162 default: ERR("oops\n");
1164 /* exit inside while loop, except if just entered in constant area definition */
1165 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
1167 /* have offset incremented if needed */
1169 case MCI_COMMAND_HEAD:
1171 case MCI_END_COMMAND:
1172 case MCI_END_COMMAND_LIST:
1174 case MCI_FLAG: break;
1175 case MCI_INTEGER: if (!inCst) offset++; break;
1176 case MCI_END_CONSTANT:
1177 case MCI_STRING: offset++; break;
1178 case MCI_RECT: offset += 4; break;
1179 default: ERR("oops\n");
1182 } while (eid != MCI_END_COMMAND);
1184 WARN("Optarg %s not found\n", debugstr_w(args));
1185 return MCIERR_UNRECOGNIZED_COMMAND;
1187 if (offset == MCI_DATA_SIZE) {
1188 ERR("Internal data[] buffer overflow\n");
1189 return MCIERR_PARSER_INTERNAL;
1195 /**************************************************************************
1196 * MCI_HandleReturnValues [internal]
1198 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
1199 LPDWORD data, LPWSTR lpstrRet, UINT uRetLen)
1201 static const WCHAR wszLd [] = {'%','l','d',0};
1202 static const WCHAR wszLd4 [] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1203 static const WCHAR wszCol3[] = {'%','d',':','%','d',':','%','d',0};
1204 static const WCHAR wszCol4[] = {'%','d',':','%','d',':','%','d',':','%','d',0};
1208 case 0: /* nothing to return */
1211 switch (dwRet & 0xFFFF0000ul) {
1213 case MCI_INTEGER_RETURNED:
1214 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1216 case MCI_RESOURCE_RETURNED:
1217 /* return string which ID is HIWORD(data[1]),
1218 * string is loaded from mmsystem.dll */
1219 LoadStringW(hWinMM32Instance, HIWORD(data[1]), lpstrRet, uRetLen);
1221 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1222 /* return string which ID is HIWORD(data[1]),
1223 * string is loaded from driver */
1224 /* FIXME: this is wrong for a 16 bit handle */
1225 LoadStringW(GetDriverModuleHandle(wmd->hDriver),
1226 HIWORD(data[1]), lpstrRet, uRetLen);
1228 case MCI_COLONIZED3_RETURN:
1229 snprintfW(lpstrRet, uRetLen, wszCol3,
1230 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1231 LOBYTE(HIWORD(data[1])));
1233 case MCI_COLONIZED4_RETURN:
1234 snprintfW(lpstrRet, uRetLen, wszCol4,
1235 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
1236 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
1238 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
1242 switch (dwRet & 0xFFFF0000ul) {
1244 /* nothing to do data[1] == lpstrRet */
1246 case MCI_INTEGER_RETURNED:
1247 data[1] = *(LPDWORD)lpstrRet;
1248 snprintfW(lpstrRet, uRetLen, wszLd, data[1]);
1251 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1256 if (dwRet & 0xFFFF0000ul)
1257 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
1258 snprintfW(lpstrRet, uRetLen, wszLd4,
1259 data[1], data[2], data[3], data[4]);
1261 default: ERR("oops\n");
1264 return LOWORD(dwRet);
1267 /**************************************************************************
1268 * mciSendStringW [WINMM.@]
1270 DWORD WINAPI mciSendStringW(LPCWSTR lpstrCommand, LPWSTR lpstrRet,
1271 UINT uRetLen, HWND hwndCallback)
1273 LPWSTR verb, dev, args;
1274 LPWINE_MCIDRIVER wmd = 0;
1275 DWORD dwFlags = 0, dwRet = 0;
1277 DWORD data[MCI_DATA_SIZE];
1280 LPWSTR devAlias = NULL;
1281 static const WCHAR wszNew[] = {'n','e','w',0};
1282 static const WCHAR wszSAliasS[] = {' ','a','l','i','a','s',' ',0};
1283 static const WCHAR wszTypeS[] = {'t','y','p','e',' ',0};
1285 TRACE("(%s, %p, %d, %p)\n",
1286 debugstr_w(lpstrCommand), lpstrRet, uRetLen, hwndCallback);
1288 /* format is <command> <device> <optargs> */
1289 if (!(verb = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand)+1) * sizeof(WCHAR))))
1290 return MCIERR_OUT_OF_MEMORY;
1291 strcpyW( verb, lpstrCommand );
1294 memset(data, 0, sizeof(data));
1296 if (!(args = strchrW(verb, ' '))) {
1297 dwRet = MCIERR_MISSING_DEVICE_NAME;
1301 if ((dwRet = MCI_GetString(&dev, &args))) {
1305 /* Determine devType from open */
1306 if (!strcmpW(verb, wszOpen)) {
1307 LPWSTR devType, tmp;
1310 /* case dev == 'new' has to be handled */
1311 if (!strcmpW(dev, wszNew)) {
1313 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1315 tmp = strchrW(devType, ' ');
1316 if (tmp) *tmp = '\0';
1317 devType = str_dup_upper(devType);
1318 if (tmp) *tmp = ' ';
1319 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1321 WARN("open new requires device type\n");
1322 dwRet = MCIERR_MISSING_DEVICE_NAME;
1325 } else if ((devType = strchrW(dev, '!')) != NULL) {
1327 tmp = devType; devType = dev; dev = tmp;
1329 dwFlags |= MCI_OPEN_TYPE;
1330 data[2] = (DWORD)devType;
1331 devType = str_dup_upper(devType);
1332 dwFlags |= MCI_OPEN_ELEMENT;
1333 data[3] = (DWORD)dev;
1334 } else if (DRIVER_GetLibName(dev, wszMci, buf, sizeof(buf))) {
1335 /* this is the name of a mci driver's type */
1336 tmp = strchrW(dev, ' ');
1337 if (tmp) *tmp = '\0';
1338 data[2] = (DWORD)dev;
1339 devType = str_dup_upper(dev);
1340 if (tmp) *tmp = ' ';
1341 dwFlags |= MCI_OPEN_TYPE;
1343 if ((devType = strstrW(args, wszTypeS)) != NULL) {
1345 tmp = strchrW(devType, ' ');
1346 if (tmp) *tmp = '\0';
1347 devType = str_dup_upper(devType);
1348 if (tmp) *tmp = ' ';
1349 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1351 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
1354 devType = str_dup_upper(buf);
1356 dwFlags |= MCI_OPEN_ELEMENT;
1357 data[3] = (DWORD)dev;
1359 if ((devAlias = strstrW(args, wszSAliasS))) {
1362 if (!(tmp = strchrW(devAlias,' '))) tmp = devAlias + strlenW(devAlias);
1363 if (tmp) *tmp = '\0';
1364 tmp2 = HeapAlloc(GetProcessHeap(), 0, (tmp - devAlias + 1) * sizeof(WCHAR) );
1365 memcpy( tmp2, devAlias, (tmp - devAlias) * sizeof(WCHAR) );
1366 tmp2[tmp - devAlias] = 0;
1367 data[4] = (DWORD)tmp2;
1368 /* should be done in regular options parsing */
1369 /* dwFlags |= MCI_OPEN_ALIAS; */
1370 } else if (dev == 0) {
1371 /* "open new" requires alias */
1372 dwRet = MCIERR_NEW_REQUIRES_ALIAS;
1376 dwRet = MCI_LoadMciDriver(devType, &wmd);
1377 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
1378 dwRet = MCIERR_INVALID_DEVICE_NAME;
1379 HeapFree(GetProcessHeap(), 0, devType);
1381 MCI_UnLoadMciDriver(wmd);
1384 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDW(dev)))) {
1386 static const WCHAR wszOpenWait[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1388 sprintfW(buf, wszOpenWait, dev);
1390 if ((dwRet = mciSendStringW(buf, NULL, 0, 0)) != 0)
1393 wmd = MCI_GetDriver(mciGetDeviceIDW(dev));
1395 /* FIXME: memory leak, MCI driver is not closed */
1396 dwRet = MCIERR_INVALID_DEVICE_ID;
1401 /* get the verb in the different command tables */
1403 /* try the device specific command table */
1404 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1406 /* try the type specific command table */
1407 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1408 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1409 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1410 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1413 /* try core command table */
1414 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1417 TRACE("Command %s not found!\n", debugstr_w(verb));
1418 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1422 /* set return information */
1423 switch (retType = MCI_GetReturnType(lpCmd)) {
1424 case 0: offset = 1; break;
1425 case MCI_INTEGER: offset = 2; break;
1426 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1427 case MCI_RECT: offset = 5; break;
1428 default: ERR("oops\n");
1431 TRACE("verb=%s on dev=%s; offset=%d\n",
1432 debugstr_w(verb), debugstr_w(dev), offset);
1434 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1437 /* set up call back */
1438 if (dwFlags & MCI_NOTIFY) {
1439 data[0] = (DWORD)hwndCallback;
1442 /* FIXME: the command should get it's own notification window set up and
1443 * ask for device closing while processing the notification mechanism
1445 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1447 TRACE("[%d, %s, %08x, %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s]\n",
1448 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1449 data[0], debugstr_w((WCHAR *)data[0]), data[1], debugstr_w((WCHAR *)data[1]),
1450 data[2], debugstr_w((WCHAR *)data[2]), data[3], debugstr_w((WCHAR *)data[3]),
1451 data[4], debugstr_w((WCHAR *)data[4]), data[5], debugstr_w((WCHAR *)data[5]));
1453 if (strcmpW(verb, wszOpen) == 0) {
1454 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSW)data, dwFlags)))
1455 MCI_UnLoadMciDriver(wmd);
1456 /* FIXME: notification is not properly shared across two opens */
1458 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD_PTR)data);
1460 TRACE("=> 1/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1461 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1462 TRACE("=> 2/ %x (%s)\n", dwRet, debugstr_w(lpstrRet));
1465 HeapFree(GetProcessHeap(), 0, verb);
1469 /**************************************************************************
1470 * mciSendStringA [WINMM.@]
1472 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
1473 UINT uRetLen, HWND hwndCallback)
1475 LPWSTR lpwstrCommand;
1476 LPWSTR lpwstrRet = NULL;
1480 /* FIXME: is there something to do with lpstrReturnString ? */
1481 len = MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, NULL, 0 );
1482 lpwstrCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1483 MultiByteToWideChar( CP_ACP, 0, lpstrCommand, -1, lpwstrCommand, len );
1486 lpwstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1488 WARN("no memory\n");
1489 HeapFree( GetProcessHeap(), 0, lpwstrCommand );
1490 return MCIERR_OUT_OF_MEMORY;
1493 ret = mciSendStringW(lpwstrCommand, lpwstrRet, uRetLen, hwndCallback);
1494 if (!ret && lpwstrRet)
1495 WideCharToMultiByte( CP_ACP, 0, lpwstrRet, -1, lpstrRet, uRetLen, NULL, NULL );
1496 HeapFree(GetProcessHeap(), 0, lpwstrCommand);
1497 HeapFree(GetProcessHeap(), 0, lpwstrRet);
1501 /**************************************************************************
1502 * mciExecute [WINMM.@]
1504 BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
1509 TRACE("(%s)!\n", lpstrCommand);
1511 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1513 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1514 sprintf(strRet, "Unknown MCI error (%d)", ret);
1516 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1518 /* FIXME: what shall I return ? */
1522 /**************************************************************************
1523 * mciLoadCommandResource [WINMM.@]
1525 * Strangely, this function only exists as a UNICODE one.
1527 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1529 UINT ret = MCI_NO_COMMAND_TABLE;
1533 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1535 /* if a file named "resname.mci" exits, then load resource "resname" from it
1536 * otherwise directly from driver
1537 * We don't support it (who uses this feature ?), but we check anyway
1541 /* FIXME: we should put this back into order, but I never found a program
1542 * actually using this feature, so we may not need it
1547 strcat(strcpy(buf, resname), ".mci");
1548 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1549 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1553 if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
1554 (hMem = LoadResource(hInst, hRsrc))) {
1555 ret = MCI_SetCommandTable(hMem, type);
1558 else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
1560 TRACE("=> %04x\n", ret);
1564 /**************************************************************************
1565 * mciFreeCommandResource [WINMM.@]
1567 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1569 TRACE("(%08x)!\n", uTable);
1571 if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
1574 FreeResource(S_MciCmdTable[uTable].hMem);
1575 S_MciCmdTable[uTable].hMem = NULL;
1576 S_MciCmdTable[uTable].lpTable = NULL;
1577 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
1578 S_MciCmdTable[uTable].aVerbs = 0;
1579 S_MciCmdTable[uTable].nVerbs = 0;
1583 /**************************************************************************
1584 * MCI_Open [internal]
1586 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSW lpParms)
1588 WCHAR strDevTyp[128];
1590 LPWINE_MCIDRIVER wmd = NULL;
1592 TRACE("(%08X, %p)\n", dwParam, lpParms);
1593 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1595 /* only two low bytes are generic, the other ones are dev type specific */
1596 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1597 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1598 MCI_NOTIFY|MCI_WAIT)
1599 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1600 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1602 #undef WINE_MCIDRIVER_SUPP
1606 if (dwParam & MCI_OPEN_TYPE) {
1607 if (dwParam & MCI_OPEN_TYPE_ID) {
1608 WORD uDevType = LOWORD(lpParms->lpstrDeviceType);
1610 if (uDevType < MCI_DEVTYPE_FIRST ||
1611 uDevType > MCI_DEVTYPE_LAST ||
1612 !LoadStringW(hWinMM32Instance, uDevType,
1613 strDevTyp, sizeof(strDevTyp) / sizeof(WCHAR))) {
1614 dwRet = MCIERR_BAD_INTEGER;
1619 if (lpParms->lpstrDeviceType == NULL) {
1620 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1623 strcpyW(strDevTyp, lpParms->lpstrDeviceType);
1624 ptr = strchrW(strDevTyp, '!');
1626 /* this behavior is not documented in windows. However, since, in
1627 * some occasions, MCI_OPEN handling is translated by WinMM into
1628 * a call to mciSendString("open <type>"); this code shall be correct
1630 if (dwParam & MCI_OPEN_ELEMENT) {
1631 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1632 debugstr_w(lpParms->lpstrElementName),
1633 debugstr_w(strDevTyp));
1634 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1637 dwParam |= MCI_OPEN_ELEMENT;
1639 /* FIXME: not a good idea to write in user supplied buffer */
1640 lpParms->lpstrElementName = ptr;
1644 TRACE("devType=%s !\n", debugstr_w(strDevTyp));
1647 if (dwParam & MCI_OPEN_ELEMENT) {
1648 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms->lpstrElementName));
1650 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1651 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1652 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1656 if (!lpParms->lpstrElementName) {
1657 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1661 /* type, if given as a parameter, supersedes file extension */
1662 if (!strDevTyp[0] &&
1663 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1664 strDevTyp, sizeof(strDevTyp))) {
1665 static const WCHAR wszCdAudio[] = {'C','D','A','U','D','I','O',0};
1666 if (GetDriveTypeW(lpParms->lpstrElementName) != DRIVE_CDROM) {
1667 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1670 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1671 strcpyW(strDevTyp, wszCdAudio);
1675 if (strDevTyp[0] == 0) {
1676 FIXME("Couldn't load driver\n");
1677 dwRet = MCIERR_INVALID_DEVICE_NAME;
1681 if (dwParam & MCI_OPEN_ALIAS) {
1682 TRACE("Alias=%s !\n", debugstr_w(lpParms->lpstrAlias));
1683 if (!lpParms->lpstrAlias) {
1684 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1689 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1693 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1694 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet);
1695 /* FIXME: is dwRet the correct ret code ? */
1699 /* only handled devices fall through */
1700 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1702 if (dwParam & MCI_NOTIFY)
1703 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1707 if (wmd) MCI_UnLoadMciDriver(wmd);
1709 if (dwParam & MCI_NOTIFY)
1710 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1714 /**************************************************************************
1715 * MCI_Close [internal]
1717 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1720 LPWINE_MCIDRIVER wmd;
1722 TRACE("(%04x, %08X, %p)\n", wDevID, dwParam, lpParms);
1724 if (wDevID == MCI_ALL_DEVICE_ID) {
1725 /* FIXME: shall I notify once after all is done, or for
1726 * each of the open drivers ? if the latest, which notif
1727 * to return when only one fails ?
1729 while (MciDrivers) {
1730 /* Retrieve the device ID under lock, but send the message without,
1731 * the driver might be calling some winmm functions from another
1732 * thread before being fully stopped.
1734 EnterCriticalSection(&WINMM_cs);
1737 LeaveCriticalSection(&WINMM_cs);
1740 wDevID = MciDrivers->wDeviceID;
1741 LeaveCriticalSection(&WINMM_cs);
1742 MCI_Close(wDevID, dwParam, lpParms);
1747 if (!(wmd = MCI_GetDriver(wDevID))) {
1748 return MCIERR_INVALID_DEVICE_ID;
1751 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD_PTR)lpParms);
1753 MCI_UnLoadMciDriver(wmd);
1755 if (dwParam & MCI_NOTIFY)
1756 mciDriverNotify(lpParms ? (HWND)lpParms->dwCallback : 0,
1758 dwRet ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
1763 /**************************************************************************
1764 * MCI_WriteString [internal]
1766 static DWORD MCI_WriteString(LPWSTR lpDstStr, DWORD dstSize, LPCWSTR lpSrcStr)
1771 dstSize /= sizeof(WCHAR);
1772 if (dstSize <= strlenW(lpSrcStr)) {
1773 lstrcpynW(lpDstStr, lpSrcStr, dstSize - 1);
1774 ret = MCIERR_PARAM_OVERFLOW;
1776 strcpyW(lpDstStr, lpSrcStr);
1784 /**************************************************************************
1785 * MCI_Sysinfo [internal]
1787 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParms)
1789 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1790 WCHAR buf[2048], *s = buf, *p;
1791 LPWINE_MCIDRIVER wmd;
1794 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1795 return MCIERR_NULL_PARAMETER_BLOCK;
1797 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1798 uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1800 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1801 case MCI_SYSINFO_QUANTITY:
1802 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1803 if (dwFlags & MCI_SYSINFO_OPEN) {
1804 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1805 EnterCriticalSection(&WINMM_cs);
1806 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1809 LeaveCriticalSection(&WINMM_cs);
1811 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1812 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci,
1813 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1814 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1815 RegCloseKey( hKey );
1817 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni))
1818 for (s = buf; *s; s += strlenW(s) + 1) cnt++;
1821 if (dwFlags & MCI_SYSINFO_OPEN) {
1822 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
1823 EnterCriticalSection(&WINMM_cs);
1824 for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
1825 if (wmd->wType == lpParms->wDeviceType) cnt++;
1827 LeaveCriticalSection(&WINMM_cs);
1829 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
1830 FIXME("Don't know how to get # of MCI devices of a given type\n");
1834 *(DWORD*)lpParms->lpstrReturn = cnt;
1835 TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1836 ret = MCI_INTEGER_RETURNED;
1838 case MCI_SYSINFO_INSTALLNAME:
1839 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1840 if ((wmd = MCI_GetDriver(uDevID))) {
1841 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1842 wmd->lpstrDeviceType);
1844 *lpParms->lpstrReturn = 0;
1845 ret = MCIERR_INVALID_DEVICE_ID;
1847 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1849 case MCI_SYSINFO_NAME:
1850 TRACE("MCI_SYSINFO_NAME\n");
1851 if (dwFlags & MCI_SYSINFO_OPEN) {
1852 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1853 ret = MCIERR_UNRECOGNIZED_COMMAND;
1856 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
1857 KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1858 if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
1859 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS &&
1860 lpParms->dwNumber <= cnt) {
1861 DWORD bufLen = sizeof(buf)/sizeof(buf[0]);
1862 if (RegEnumKeyExW(hKey, lpParms->dwNumber - 1,
1863 buf, &bufLen, 0, 0, 0, 0) == ERROR_SUCCESS)
1866 RegCloseKey( hKey );
1869 if (GetPrivateProfileStringW(wszMci, 0, wszNull, buf, sizeof(buf) / sizeof(buf[0]), wszSystemIni)) {
1870 for (p = buf; *p; p += strlenW(p) + 1, cnt++) {
1871 TRACE("%d: %s\n", cnt, debugstr_w(p));
1872 if (cnt == lpParms->dwNumber - 1) {
1879 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
1881 TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
1884 TRACE("Unsupported flag value=%08x\n", dwFlags);
1885 ret = MCIERR_UNRECOGNIZED_COMMAND;
1890 /**************************************************************************
1891 * MCI_Break [internal]
1893 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1897 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1899 if (dwFlags & MCI_NOTIFY)
1900 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1901 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1906 /**************************************************************************
1907 * MCI_Sound [internal]
1909 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMSW lpParms)
1913 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1915 if (dwFlags & MCI_SOUND_NAME)
1916 dwRet = sndPlaySoundW(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1918 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1919 if (dwFlags & MCI_NOTIFY)
1920 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1921 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1926 /**************************************************************************
1927 * MCI_SendCommand [internal]
1929 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1931 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1935 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1938 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1941 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSW)dwParam2);
1944 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1947 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMSW)dwParam2);
1950 if (wDevID == MCI_ALL_DEVICE_ID) {
1951 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1952 dwRet = MCIERR_CANNOT_USE_ALL;
1954 dwRet = MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2);
1961 /**************************************************************************
1962 * MCI_CleanUp [internal]
1964 * Some MCI commands need to be cleaned-up (when not called from
1965 * mciSendString), because MCI drivers return extra information for string
1966 * transformation. This function gets rid of them.
1968 static LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD_PTR dwParam2)
1971 return LOWORD(dwRet);
1974 case MCI_GETDEVCAPS:
1975 switch (dwRet & 0xFFFF0000ul) {
1977 case MCI_COLONIZED3_RETURN:
1978 case MCI_COLONIZED4_RETURN:
1979 case MCI_INTEGER_RETURNED:
1982 case MCI_RESOURCE_RETURNED:
1983 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1985 LPMCI_GETDEVCAPS_PARMS lmgp;
1987 lmgp = (LPMCI_GETDEVCAPS_PARMS)dwParam2;
1988 TRACE("Changing %08x to %08x\n", lmgp->dwReturn, LOWORD(lmgp->dwReturn));
1989 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1993 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1994 HIWORD(dwRet), MCI_MessageToString(wMsg));
1998 switch (dwRet & 0xFFFF0000ul) {
2000 case MCI_COLONIZED3_RETURN:
2001 case MCI_COLONIZED4_RETURN:
2002 case MCI_INTEGER_RETURNED:
2005 case MCI_RESOURCE_RETURNED:
2006 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2008 LPMCI_STATUS_PARMS lsp;
2010 lsp = (LPMCI_STATUS_PARMS)dwParam2;
2011 TRACE("Changing %08lx to %08x\n", lsp->dwReturn, LOWORD(lsp->dwReturn));
2012 lsp->dwReturn = LOWORD(lsp->dwReturn);
2016 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2017 HIWORD(dwRet), MCI_MessageToString(wMsg));
2021 switch (dwRet & 0xFFFF0000ul) {
2023 case MCI_INTEGER_RETURNED:
2027 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2031 if (HIWORD(dwRet)) {
2032 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2033 dwRet, MCI_MessageToString(wMsg));
2037 return LOWORD(dwRet);
2040 /**************************************************************************
2041 * mciGetErrorStringW [WINMM.@]
2043 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
2047 if (lpstrBuffer != NULL && uLength > 0 &&
2048 wError >= MCIERR_BASE && wError <= MCIERR_CUSTOM_DRIVER_BASE) {
2050 if (LoadStringW(hWinMM32Instance, wError, lpstrBuffer, uLength) > 0) {
2057 /**************************************************************************
2058 * mciGetErrorStringA [WINMM.@]
2060 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
2064 if (lpstrBuffer != NULL && uLength > 0 &&
2065 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
2067 if (LoadStringA(hWinMM32Instance, dwError, lpstrBuffer, uLength) > 0) {
2074 /**************************************************************************
2075 * mciDriverNotify [WINMM.@]
2077 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
2079 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
2081 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
2084 /**************************************************************************
2085 * mciGetDriverData [WINMM.@]
2087 DWORD_PTR WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
2089 LPWINE_MCIDRIVER wmd;
2091 TRACE("(%04x)\n", uDeviceID);
2093 wmd = MCI_GetDriver(uDeviceID);
2096 WARN("Bad uDeviceID\n");
2100 return wmd->dwPrivate;
2103 /**************************************************************************
2104 * mciSetDriverData [WINMM.@]
2106 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD_PTR data)
2108 LPWINE_MCIDRIVER wmd;
2110 TRACE("(%04x, %08lx)\n", uDeviceID, data);
2112 wmd = MCI_GetDriver(uDeviceID);
2115 WARN("Bad uDeviceID\n");
2119 wmd->dwPrivate = data;
2123 /**************************************************************************
2124 * mciSendCommandW [WINMM.@]
2127 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2131 TRACE("(%08x, %s, %08lx, %08lx)\n",
2132 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2134 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2);
2135 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
2136 TRACE("=> %08x\n", dwRet);
2140 /**************************************************************************
2141 * mciSendCommandA [WINMM.@]
2143 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2148 TRACE("(%08x, %s, %08lx, %08lx)\n",
2149 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
2151 mapped = MCI_MapMsgAtoW(wMsg, dwParam1, &dwParam2);
2154 FIXME("message %04x mapping failed\n", wMsg);
2155 return MMSYSERR_NOMEM;
2157 ret = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
2159 MCI_UnmapMsgAtoW(wMsg, dwParam1, dwParam2, ret);
2163 /**************************************************************************
2164 * mciGetDeviceIDA [WINMM.@]
2166 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
2168 LPWSTR w = MCI_strdupAtoW(lpstrName);
2169 UINT ret = MCIERR_OUT_OF_MEMORY;
2173 ret = mciGetDeviceIDW(w);
2174 HeapFree(GetProcessHeap(), 0, w);
2179 /**************************************************************************
2180 * mciGetDeviceIDW [WINMM.@]
2182 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
2184 return MCI_GetDriverFromString(lpwstrName);
2187 /******************************************************************
2190 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
2192 static void MyUserYield(void)
2194 HMODULE mod = GetModuleHandleA( "user32.dll" );
2197 FARPROC proc = GetProcAddress( mod, "UserYield16" );
2202 /**************************************************************************
2203 * MCI_DefYieldProc [internal]
2205 static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
2209 TRACE("(0x%04x, 0x%08x)\n", wDevID, data);
2211 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
2212 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
2218 msg.hwnd = HWND_32(HIWORD(data));
2219 while (!PeekMessageW(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
2225 /**************************************************************************
2226 * mciSetYieldProc [WINMM.@]
2228 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
2230 LPWINE_MCIDRIVER wmd;
2232 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
2234 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2235 WARN("Bad uDeviceID\n");
2239 wmd->lpfnYieldProc = fpYieldProc;
2240 wmd->dwYieldData = dwYieldData;
2245 /**************************************************************************
2246 * mciGetDeviceIDFromElementIDA [WINMM.@]
2248 UINT WINAPI mciGetDeviceIDFromElementIDA(DWORD dwElementID, LPCSTR lpstrType)
2250 LPWSTR w = MCI_strdupAtoW(lpstrType);
2255 ret = mciGetDeviceIDFromElementIDW(dwElementID, w);
2256 HeapFree(GetProcessHeap(), 0, w);
2261 /**************************************************************************
2262 * mciGetDeviceIDFromElementIDW [WINMM.@]
2264 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
2266 /* FIXME: that's rather strange, there is no
2267 * mciGetDeviceIDFromElementID32A in winmm.spec
2269 FIXME("(%u, %s) stub\n", dwElementID, debugstr_w(lpstrType));
2273 /**************************************************************************
2274 * mciGetYieldProc [WINMM.@]
2276 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
2278 LPWINE_MCIDRIVER wmd;
2280 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
2282 if (!(wmd = MCI_GetDriver(uDeviceID))) {
2283 WARN("Bad uDeviceID\n");
2286 if (!wmd->lpfnYieldProc) {
2287 WARN("No proc set\n");
2290 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
2291 return wmd->lpfnYieldProc;
2294 /**************************************************************************
2295 * mciGetCreatorTask [WINMM.@]
2297 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
2299 LPWINE_MCIDRIVER wmd;
2302 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
2304 TRACE("(%u) => %p\n", uDeviceID, ret);
2308 /**************************************************************************
2309 * mciDriverYield [WINMM.@]
2311 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
2313 LPWINE_MCIDRIVER wmd;
2316 TRACE("(%04x)\n", uDeviceID);
2318 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc) {
2321 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);