2 * MCI internal functions
4 * Copyright 1998/1999 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - implement WINMM (32bit) multitasking and use it in all MCI drivers
23 * instead of the home grown one
24 * - 16bit mmTaskXXX functions are currently broken because the 16
25 * loader does not support binary command lines => provide Wine's
26 * own mmtask.tsk not using binary command line.
27 * - correctly handle the MCI_ALL_DEVICE_ID in functions.
28 * - finish mapping 16 <=> 32 of MCI structures and commands
29 * - implement auto-open feature (ie, when a string command is issued
30 * for a not yet opened device, MCI automatically opens it)
31 * - use a default registry setting to replace the [mci] section in
32 * configuration file (layout of info in registry should be compatible
33 * with all Windows' version - which use different layouts of course)
37 #include "wine/port.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(mci);
60 WINMM_MapType (*pFnMciMapMsg16To32A) (WORD,WORD,DWORD*) /* = NULL */;
61 WINMM_MapType (*pFnMciUnMapMsg16To32A)(WORD,WORD,DWORD) /* = NULL */;
62 WINMM_MapType (*pFnMciMapMsg32ATo16) (WORD,WORD,DWORD,DWORD*) /* = NULL */;
63 WINMM_MapType (*pFnMciUnMapMsg32ATo16)(WORD,WORD,DWORD,DWORD) /* = NULL */;
65 /* First MCI valid device ID (0 means error) */
66 #define MCI_MAGIC 0x0001
69 #define HKLM_MCI "Software\\Microsoft\\Windows NT\\CurrentVersion\\MCI"
71 /* dup a string and uppercase it */
72 inline static LPSTR str_dup_upper( LPCSTR str )
74 INT len = strlen(str) + 1;
75 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
78 memcpy( p, str, len );
84 /**************************************************************************
85 * MCI_GetDriver [internal]
87 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
89 LPWINE_MCIDRIVER wmd = 0;
91 EnterCriticalSection(&WINMM_IData->cs);
92 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
93 if (wmd->wDeviceID == wDevID)
96 LeaveCriticalSection(&WINMM_IData->cs);
100 /**************************************************************************
101 * MCI_GetDriverFromString [internal]
103 UINT MCI_GetDriverFromString(LPCSTR lpstrName)
105 LPWINE_MCIDRIVER wmd;
111 if (!lstrcmpiA(lpstrName, "ALL"))
112 return MCI_ALL_DEVICE_ID;
114 EnterCriticalSection(&WINMM_IData->cs);
115 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
116 if (wmd->lpstrElementName && strcmp(wmd->lpstrElementName, lpstrName) == 0) {
117 ret = wmd->wDeviceID;
120 if (wmd->lpstrDeviceType && strcasecmp(wmd->lpstrDeviceType, lpstrName) == 0) {
121 ret = wmd->wDeviceID;
124 if (wmd->lpstrAlias && strcasecmp(wmd->lpstrAlias, lpstrName) == 0) {
125 ret = wmd->wDeviceID;
129 LeaveCriticalSection(&WINMM_IData->cs);
134 /**************************************************************************
135 * MCI_MessageToString [internal]
137 const char* MCI_MessageToString(UINT16 wMsg)
139 static char buffer[100];
141 #define CASE(s) case (s): return #s
146 CASE(MCI_CLOSE_DRIVER);
155 CASE(MCI_GETDEVCAPS);
159 CASE(MCI_OPEN_DRIVER);
177 /* constants for digital video */
191 sprintf(buffer, "MCI_<<%04X>>", wMsg);
196 /**************************************************************************
197 * MCI_GetDevTypeFromFileName [internal]
199 static DWORD MCI_GetDevTypeFromFileName(LPCSTR fileName, LPSTR buf, UINT len)
204 if ((tmp = strrchr(fileName, '.'))) {
205 if (RegOpenKeyExA( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions",
206 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
208 LONG lRet = RegQueryValueExA( hKey, tmp + 1, 0, 0, buf, &dwLen );
210 if (lRet == ERROR_SUCCESS) return 0;
212 TRACE("No ...\\MCI Extensions entry for '%s' found.\n", tmp);
214 return MCIERR_EXTENSION_NOT_FOUND;
217 #define MAX_MCICMDTABLE 20
218 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
220 typedef struct tagWINE_MCICMDTABLE {
223 UINT nVerbs; /* number of verbs in command table */
224 LPCSTR* aVerbs; /* array of verbs to speed up the verb look up process */
225 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
227 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
229 /**************************************************************************
230 * MCI_IsCommandTableValid [internal]
232 static BOOL MCI_IsCommandTableValid(UINT uTbl)
240 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
241 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
243 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
246 lmem = S_MciCmdTable[uTbl].lpTable;
250 lmem += strlen(lmem) + 1;
251 flg = *(LPDWORD)lmem;
252 eid = *(LPWORD)(lmem + sizeof(DWORD));
253 lmem += sizeof(DWORD) + sizeof(WORD);
255 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
257 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
258 case MCI_STRING: if (inCst) return FALSE; break;
259 case MCI_INTEGER: if (!*str) return FALSE; break;
260 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
261 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
262 case MCI_FLAG: if (!*str) return FALSE; break;
263 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
264 case MCI_RECT: if (!*str || inCst) return FALSE; break;
265 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
266 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
267 default: return FALSE;
269 } while (eid != MCI_END_COMMAND_LIST);
270 } while (eid != MCI_END_COMMAND_LIST);
274 /**************************************************************************
275 * MCI_DumpCommandTable [internal]
277 static BOOL MCI_DumpCommandTable(UINT uTbl)
284 if (!MCI_IsCommandTableValid(uTbl)) {
285 ERR("Ooops: %d is not valid\n", uTbl);
289 lmem = S_MciCmdTable[uTbl].lpTable;
293 lmem += strlen(lmem) + 1;
294 flg = *(LPDWORD)lmem;
295 eid = *(LPWORD)(lmem + sizeof(DWORD));
296 TRACE("cmd='%s' %08lx %04x\n", str, flg, eid);
297 lmem += sizeof(DWORD) + sizeof(WORD);
298 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
299 TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : "");
300 } while (eid != MCI_END_COMMAND_LIST);
305 /**************************************************************************
306 * MCI_GetCommandTable [internal]
308 static UINT MCI_GetCommandTable(UINT uDevType)
314 /* first look up existing for existing devType */
315 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
316 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
320 /* well try to load id */
321 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
322 if (LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
325 } else if (uDevType == 0) {
328 uTbl = MCI_NO_COMMAND_TABLE;
330 HRSRC hRsrc = FindResourceA(WINMM_IData->hWinMM32Instance, str, (LPCSTR)RT_RCDATA);
333 if (hRsrc) hMem = LoadResource(WINMM_IData->hWinMM32Instance, hRsrc);
335 uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType);
337 WARN("No command table found in resource %p[%s]\n",
338 WINMM_IData->hWinMM32Instance, str);
341 TRACE("=> %d\n", uTbl);
345 /**************************************************************************
346 * MCI_SetCommandTable [internal]
348 UINT MCI_SetCommandTable(void *table, UINT uDevType)
351 static BOOL bInitDone = FALSE;
354 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
355 * can be called with 0 as a uDevType to retrieve it.
360 MCI_GetCommandTable(0);
363 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
364 if (!S_MciCmdTable[uTbl].lpTable) {
369 S_MciCmdTable[uTbl].uDevType = uDevType;
370 S_MciCmdTable[uTbl].lpTable = table;
373 MCI_DumpCommandTable(uTbl);
376 /* create the verbs table */
377 /* get # of entries */
378 lmem = S_MciCmdTable[uTbl].lpTable;
381 lmem += strlen(lmem) + 1;
382 eid = *(LPWORD)(lmem + sizeof(DWORD));
383 lmem += sizeof(DWORD) + sizeof(WORD);
384 if (eid == MCI_COMMAND_HEAD)
386 } while (eid != MCI_END_COMMAND_LIST);
388 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCSTR));
389 S_MciCmdTable[uTbl].nVerbs = count;
391 lmem = S_MciCmdTable[uTbl].lpTable;
395 lmem += strlen(lmem) + 1;
396 eid = *(LPWORD)(lmem + sizeof(DWORD));
397 lmem += sizeof(DWORD) + sizeof(WORD);
398 if (eid == MCI_COMMAND_HEAD)
399 S_MciCmdTable[uTbl].aVerbs[count++] = str;
400 } while (eid != MCI_END_COMMAND_LIST);
401 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
406 return MCI_NO_COMMAND_TABLE;
409 /**************************************************************************
410 * MCI_DeleteCommandTable [internal]
412 static BOOL MCI_DeleteCommandTable(UINT uTbl)
414 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
417 S_MciCmdTable[uTbl].lpTable = NULL;
418 if (S_MciCmdTable[uTbl].aVerbs) {
419 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
420 S_MciCmdTable[uTbl].aVerbs = 0;
425 /**************************************************************************
426 * MCI_UnLoadMciDriver [internal]
428 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
430 LPWINE_MCIDRIVER* tmp;
435 CloseDriver(wmd->hDriver, 0, 0);
437 if (wmd->dwPrivate != 0)
438 WARN("Unloading mci driver with non nul dwPrivate field\n");
440 EnterCriticalSection(&WINMM_IData->cs);
441 for (tmp = &WINMM_IData->lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
447 LeaveCriticalSection(&WINMM_IData->cs);
449 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
450 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
451 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
453 HeapFree(GetProcessHeap(), 0, wmd);
457 /**************************************************************************
458 * MCI_OpenMciDriver [internal]
460 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCSTR drvTyp, LPARAM lp)
464 if (!DRIVER_GetLibName(drvTyp, "mci", libName, sizeof(libName)))
468 /* First load driver */
469 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
471 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32ATo16) {
474 switch (res = pFnMciMapMsg32ATo16(0, DRV_OPEN, 0, &lp)) {
475 case WINMM_MAP_MSGERROR:
476 TRACE("Not handled yet (DRV_OPEN)\n");
478 case WINMM_MAP_NOMEM:
479 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
482 case WINMM_MAP_OKMEM:
483 if ((wmd->hDriver = OpenDriverA(drvTyp, "mci", lp)))
485 if (res == WINMM_MAP_OKMEM)
486 pFnMciUnMapMsg32ATo16(0, DRV_OPEN, 0, lp);
490 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
493 /**************************************************************************
494 * MCI_LoadMciDriver [internal]
496 static DWORD MCI_LoadMciDriver(LPCSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
498 LPSTR strDevTyp = str_dup_upper(_strDevTyp);
499 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
500 MCI_OPEN_DRIVER_PARMSA modp;
503 if (!wmd || !strDevTyp) {
504 dwRet = MCIERR_OUT_OF_MEMORY;
508 wmd->lpfnYieldProc = MCI_DefYieldProc;
509 wmd->dwYieldData = VK_CANCEL;
510 wmd->CreatorThread = GetCurrentThreadId();
512 EnterCriticalSection(&WINMM_IData->cs);
513 /* wmd must be inserted in list before sending opening the driver, coz' it
514 * may want to lookup at wDevID
516 wmd->lpNext = WINMM_IData->lpMciDrvs;
517 WINMM_IData->lpMciDrvs = wmd;
519 for (modp.wDeviceID = MCI_MAGIC;
520 MCI_GetDriver(modp.wDeviceID) != 0;
523 wmd->wDeviceID = modp.wDeviceID;
525 LeaveCriticalSection(&WINMM_IData->cs);
527 TRACE("wDevID=%04X \n", modp.wDeviceID);
529 modp.lpstrParams = NULL;
531 if (!MCI_OpenMciDriver(wmd, strDevTyp, (LPARAM)&modp)) {
532 /* silence warning if all is used... some bogus program use commands like
535 if (strcasecmp(strDevTyp, "all") == 0) {
536 dwRet = MCIERR_CANNOT_USE_ALL;
538 FIXME("Couldn't load driver for type %s.\n"
539 "If you don't have a windows installation accessible from Wine,\n"
540 "you perhaps forgot to create a [mci] section in system.ini\n",
542 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
547 /* FIXME: should also check that module's description is of the form
548 * MODULENAME:[MCI] comment
551 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
552 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
553 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
555 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
556 wmd->hDriver, strDevTyp, modp.wType, modp.wCustomCommandTable);
558 wmd->lpstrDeviceType = strDevTyp;
559 wmd->wType = modp.wType;
561 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
562 modp.wDeviceID, modp.wType, modp.wDeviceID);
566 MCI_UnLoadMciDriver(wmd);
567 HeapFree(GetProcessHeap(), 0, strDevTyp);
572 /**************************************************************************
573 * MCI_FinishOpen [internal]
575 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSA lpParms,
578 if (dwParam & MCI_OPEN_ELEMENT)
580 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,strlen(lpParms->lpstrElementName)+1);
581 strcpy( wmd->lpstrElementName, lpParms->lpstrElementName );
583 if (dwParam & MCI_OPEN_ALIAS)
585 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, strlen(lpParms->lpstrAlias)+1);
586 strcpy( wmd->lpstrAlias, lpParms->lpstrAlias);
588 lpParms->wDeviceID = wmd->wDeviceID;
590 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
594 /**************************************************************************
595 * MCI_FindCommand [internal]
597 static LPCSTR MCI_FindCommand(UINT uTbl, LPCSTR verb)
601 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
604 /* another improvement would be to have the aVerbs array sorted,
605 * so that we could use a dichotomic search on it, rather than this dumb
608 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
609 if (strcasecmp(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
610 return S_MciCmdTable[uTbl].aVerbs[idx];
616 /**************************************************************************
617 * MCI_GetReturnType [internal]
619 static DWORD MCI_GetReturnType(LPCSTR lpCmd)
621 lpCmd += strlen(lpCmd) + 1 + sizeof(DWORD) + sizeof(WORD);
622 if (*lpCmd == '\0' && *(LPWORD)(lpCmd + 1 + sizeof(DWORD)) == MCI_RETURN) {
623 return *(LPDWORD)(lpCmd + 1);
628 /**************************************************************************
629 * MCI_GetMessage [internal]
631 static WORD MCI_GetMessage(LPCSTR lpCmd)
633 return (WORD)*(LPDWORD)(lpCmd + strlen(lpCmd) + 1);
636 /**************************************************************************
637 * MCI_GetDWord [internal]
639 static BOOL MCI_GetDWord(LPDWORD data, LPSTR* ptr)
644 val = strtoul(*ptr, &ret, 0);
648 case ' ': ret++; break;
649 default: return FALSE;
657 /**************************************************************************
658 * MCI_GetString [internal]
660 static DWORD MCI_GetString(LPSTR* str, LPSTR* args)
664 /* see if we have a quoted string */
666 ptr = strchr(*str = ptr + 1, '"');
667 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
668 /* FIXME: shall we escape \" from string ?? */
669 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
670 *ptr++ = '\0'; /* remove trailing " */
671 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
674 ptr = strchr(ptr, ' ');
679 ptr = *args + strlen(*args);
688 #define MCI_DATA_SIZE 16
690 /**************************************************************************
691 * MCI_ParseOptArgs [internal]
693 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCSTR lpCmd,
694 LPSTR args, LPDWORD dwFlags)
698 DWORD dwRet, flg, cflg = 0;
702 /* loop on arguments */
705 found = inCst = FALSE;
708 /* skip any leading white space(s) */
709 while (*args == ' ') args++;
710 TRACE("args='%s' offset=%d\n", args, offset);
712 do { /* loop on options for command table for the requested verb */
714 lmem += (len = strlen(lmem)) + 1;
715 flg = *(LPDWORD)lmem;
716 eid = *(LPWORD)(lmem + sizeof(DWORD));
717 lmem += sizeof(DWORD) + sizeof(WORD);
718 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
722 inCst = TRUE; cflg = flg; break;
723 case MCI_END_CONSTANT:
724 /* there may be additional integral values after flag in constant */
725 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
728 inCst = FALSE; cflg = 0;
732 if (strncasecmp(args, str, len) == 0 &&
733 (args[len] == 0 || args[len] == ' ')) {
734 /* store good values into data[] */
736 while (*args == ' ') args++;
740 case MCI_COMMAND_HEAD:
742 case MCI_END_COMMAND:
743 case MCI_END_COMMAND_LIST:
744 case MCI_CONSTANT: /* done above */
745 case MCI_END_CONSTANT: /* done above */
757 if (!MCI_GetDWord(&(data[offset]), &args)) {
758 return MCIERR_BAD_INTEGER;
763 /* store rect in data (offset...offset+3) */
765 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
766 !MCI_GetDWord(&(data[offset+1]), &args) ||
767 !MCI_GetDWord(&(data[offset+2]), &args) ||
768 !MCI_GetDWord(&(data[offset+3]), &args)) {
769 ERR("Bad rect '%s'\n", args);
770 return MCIERR_BAD_INTEGER;
775 if ((dwRet = MCI_GetString((LPSTR*)&data[offset], &args)))
778 default: ERR("oops\n");
780 /* exit inside while loop, except if just entered in constant area definition */
781 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
783 /* have offset incremented if needed */
785 case MCI_COMMAND_HEAD:
787 case MCI_END_COMMAND:
788 case MCI_END_COMMAND_LIST:
790 case MCI_FLAG: break;
791 case MCI_INTEGER: if (!inCst) offset++; break;
792 case MCI_END_CONSTANT:
793 case MCI_STRING: offset++; break;
794 case MCI_RECT: offset += 4; break;
795 default: ERR("oops\n");
798 } while (eid != MCI_END_COMMAND);
800 WARN("Optarg '%s' not found\n", args);
801 return MCIERR_UNRECOGNIZED_COMMAND;
803 if (offset == MCI_DATA_SIZE) {
804 ERR("Internal data[] buffer overflow\n");
805 return MCIERR_PARSER_INTERNAL;
811 /**************************************************************************
812 * MCI_HandleReturnValues [internal]
814 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
815 LPDWORD data, LPSTR lpstrRet, UINT uRetLen)
819 case 0: /* nothing to return */
822 switch (dwRet & 0xFFFF0000ul) {
824 case MCI_INTEGER_RETURNED:
825 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
827 case MCI_RESOURCE_RETURNED:
828 /* return string which ID is HIWORD(data[1]),
829 * string is loaded from mmsystem.dll */
830 LoadStringA(WINMM_IData->hWinMM32Instance, HIWORD(data[1]),
833 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
834 /* return string which ID is HIWORD(data[1]),
835 * string is loaded from driver */
836 /* FIXME: this is wrong for a 16 bit handle */
837 LoadStringA(GetDriverModuleHandle(wmd->hDriver),
838 HIWORD(data[1]), lpstrRet, uRetLen);
840 case MCI_COLONIZED3_RETURN:
841 snprintf(lpstrRet, uRetLen, "%d:%d:%d",
842 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
843 LOBYTE(HIWORD(data[1])));
845 case MCI_COLONIZED4_RETURN:
846 snprintf(lpstrRet, uRetLen, "%d:%d:%d:%d",
847 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
848 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
850 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
854 switch (dwRet & 0xFFFF0000ul) {
856 /* nothing to do data[1] == lpstrRet */
858 case MCI_INTEGER_RETURNED:
859 data[1] = *(LPDWORD)lpstrRet;
860 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
863 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
868 if (dwRet & 0xFFFF0000ul)
869 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
870 snprintf(lpstrRet, uRetLen, "%ld %ld %ld %ld",
871 data[1], data[2], data[3], data[4]);
873 default: ERR("oops\n");
876 return LOWORD(dwRet);
879 /**************************************************************************
880 * mciSendStringA [WINMM.@]
882 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
883 UINT uRetLen, HWND hwndCallback)
885 LPSTR verb, dev, args;
886 LPWINE_MCIDRIVER wmd = 0;
887 DWORD dwFlags = 0, dwRet = 0;
889 DWORD data[MCI_DATA_SIZE];
892 LPSTR devAlias = NULL;
893 BOOL bAutoOpen = FALSE;
895 TRACE("('%s', %p, %d, %p)\n", lpstrCommand, lpstrRet, uRetLen, hwndCallback);
897 /* format is <command> <device> <optargs> */
898 if (!(verb = HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand)+1)))
899 return MCIERR_OUT_OF_MEMORY;
900 strcpy( verb, lpstrCommand );
903 memset(data, 0, sizeof(data));
905 if (!(args = strchr(verb, ' '))) {
906 dwRet = MCIERR_MISSING_DEVICE_NAME;
910 if ((dwRet = MCI_GetString(&dev, &args))) {
914 /* case dev == 'new' has to be handled */
915 if (!strcmp(dev, "new")) {
916 FIXME("'new': NIY as device name\n");
917 dwRet = MCIERR_MISSING_DEVICE_NAME;
921 /* otherwise, try to grab devType from open */
922 if (!strcmp(verb, "open")) {
925 if ((devType = strchr(dev, '!')) != NULL) {
927 tmp = devType; devType = dev; dev = tmp;
929 dwFlags |= MCI_OPEN_TYPE;
930 data[2] = (DWORD)devType;
931 devType = str_dup_upper(devType);
932 dwFlags |= MCI_OPEN_ELEMENT;
933 data[3] = (DWORD)dev;
934 } else if (strchr(dev, '.') == NULL) {
935 tmp = strchr(dev,' ');
936 if (tmp) *tmp = '\0';
937 data[2] = (DWORD)dev;
938 devType = str_dup_upper(dev);
940 dwFlags |= MCI_OPEN_TYPE;
942 if ((devType = strstr(args, "type ")) != NULL) {
944 tmp = strchr(devType, ' ');
945 if (tmp) *tmp = '\0';
946 devType = str_dup_upper(devType);
948 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
951 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
954 devType = str_dup_upper(buf);
956 dwFlags |= MCI_OPEN_ELEMENT;
957 data[3] = (DWORD)dev;
959 if ((devAlias = strstr(args," alias "))) {
962 if (!(tmp = strchr(devAlias,' '))) tmp = devAlias + strlen(devAlias);
963 if (tmp) *tmp = '\0';
964 tmp2 = HeapAlloc(GetProcessHeap(), 0, tmp - devAlias + 1 );
965 memcpy( tmp2, devAlias, tmp - devAlias );
966 tmp2[tmp - devAlias] = 0;
967 data[4] = (DWORD)tmp2;
968 /* should be done in regular options parsing */
969 /* dwFlags |= MCI_OPEN_ALIAS; */
972 dwRet = MCI_LoadMciDriver(devType, &wmd);
973 if (dwRet == MCIERR_DEVICE_NOT_INSTALLED)
974 dwRet = MCIERR_INVALID_DEVICE_NAME;
975 HeapFree(GetProcessHeap(), 0, devType);
977 MCI_UnLoadMciDriver(wmd);
980 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDA(dev)))) {
983 sprintf(buf, "open %s wait", dev);
985 if ((dwRet = mciSendStringA(buf, NULL, 0, 0)) != 0)
988 wmd = MCI_GetDriver(mciGetDeviceIDA(dev));
990 /* FIXME: memory leak, MCI driver is not closed */
991 dwRet = MCIERR_INVALID_DEVICE_ID;
996 /* get the verb in the different command tables */
998 /* try the device specific command table */
999 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
1001 /* try the type specific command table */
1002 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
1003 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
1004 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
1005 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
1008 /* try core command table */
1009 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
1012 TRACE("Command '%s' not found!\n", verb);
1013 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1017 /* set up call back */
1018 if (hwndCallback != 0) {
1019 dwFlags |= MCI_NOTIFY;
1020 data[0] = (DWORD)hwndCallback;
1023 /* set return information */
1024 switch (retType = MCI_GetReturnType(lpCmd)) {
1025 case 0: offset = 1; break;
1026 case MCI_INTEGER: offset = 2; break;
1027 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1028 case MCI_RECT: offset = 5; break;
1029 default: ERR("oops\n");
1032 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb, dev, offset);
1034 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1037 if (bAutoOpen && (dwFlags & MCI_NOTIFY)) {
1038 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1041 /* FIXME: the command should get it's own notification window set up and
1042 * ask for device closing while processing the notification mechanism
1044 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1046 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1047 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1048 data[0], debugstr_a((char *)data[0]), data[1], debugstr_a((char *)data[1]),
1049 data[2], debugstr_a((char *)data[2]), data[3], debugstr_a((char *)data[3]),
1050 data[4], debugstr_a((char *)data[4]), data[5], debugstr_a((char *)data[5]));
1052 if (strcmp(verb, "open") == 0) {
1053 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSA)data, dwFlags)))
1054 MCI_UnLoadMciDriver(wmd);
1055 /* FIXME: notification is not properly shared across two opens */
1057 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
1059 TRACE("=> 1/ %lx (%s)\n", dwRet, lpstrRet);
1060 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1061 TRACE("=> 2/ %lx (%s)\n", dwRet, lpstrRet);
1064 HeapFree(GetProcessHeap(), 0, verb);
1065 HeapFree(GetProcessHeap(), 0, devAlias);
1069 /**************************************************************************
1070 * mciSendStringW [WINMM.@]
1072 DWORD WINAPI mciSendStringW(LPCWSTR lpwstrCommand, LPWSTR lpwstrRet,
1073 UINT uRetLen, HWND hwndCallback)
1076 LPSTR lpstrRet = NULL;
1080 /* FIXME: is there something to do with lpstrReturnString ? */
1081 len = WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, NULL, 0, NULL, NULL );
1082 lpstrCommand = HeapAlloc( GetProcessHeap(), 0, len );
1083 WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, lpstrCommand, len, NULL, NULL );
1086 lpstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1087 if (!lpstrRet) return MMSYSERR_NOMEM;
1089 ret = mciSendStringA(lpstrCommand, lpstrRet, uRetLen, hwndCallback);
1091 MultiByteToWideChar( CP_ACP, 0, lpstrRet, -1, lpwstrRet, uRetLen );
1092 HeapFree(GetProcessHeap(), 0, lpstrCommand);
1093 if (lpstrRet) HeapFree(GetProcessHeap(), 0, lpstrRet);
1097 /**************************************************************************
1098 * mciExecute [WINMM.@]
1099 * mciExecute [MMSYSTEM.712]
1101 DWORD WINAPI mciExecute(LPCSTR lpstrCommand)
1106 TRACE("(%s)!\n", lpstrCommand);
1108 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1110 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1111 sprintf(strRet, "Unknown MCI error (%ld)", ret);
1113 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1115 /* FIXME: what shall I return ? */
1119 /**************************************************************************
1120 * mciLoadCommandResource [WINMM.@]
1122 * Strangely, this function only exists as an UNICODE one.
1124 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1128 UINT16 ret = MCI_NO_COMMAND_TABLE;
1130 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1132 /* if a file named "resname.mci" exits, then load resource "resname" from it
1133 * otherwise directly from driver
1134 * We don't support it (who uses this feature ?), but we check anyway
1138 /* FIXME: we should put this back into order, but I never found a program
1139 * actually using this feature, so we not need it
1144 strcat(strcpy(buf, resname), ".mci");
1145 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1146 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1150 if (!(hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA))) {
1151 WARN("No command table found in resource\n");
1152 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1153 ret = MCI_SetCommandTable(LockResource(hMem), type);
1155 WARN("Couldn't load resource.\n");
1157 TRACE("=> %04x\n", ret);
1161 /**************************************************************************
1162 * mciFreeCommandResource [WINMM.@]
1164 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1166 TRACE("(%08x)!\n", uTable);
1168 return MCI_DeleteCommandTable(uTable);
1171 /**************************************************************************
1172 * MCI_SendCommandFrom32 [internal]
1174 DWORD MCI_SendCommandFrom32(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1176 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1177 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1181 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1182 } else if (pFnMciMapMsg32ATo16) {
1185 switch (res = pFnMciMapMsg32ATo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1186 case WINMM_MAP_MSGERROR:
1187 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1188 dwRet = MCIERR_DRIVER_INTERNAL;
1190 case WINMM_MAP_NOMEM:
1191 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1192 dwRet = MCIERR_OUT_OF_MEMORY;
1195 case WINMM_MAP_OKMEM:
1196 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1197 if (res == WINMM_MAP_OKMEM)
1198 pFnMciUnMapMsg32ATo16(wmd->wType, wMsg, dwParam1, dwParam2);
1206 /**************************************************************************
1207 * MCI_SendCommandFrom16 [internal]
1209 DWORD MCI_SendCommandFrom16(MCIDEVICEID wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1211 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1212 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1215 dwRet = MCIERR_INVALID_DEVICE_ID;
1217 if (wmd->bIs32 && pFnMciMapMsg16To32A) {
1220 switch (res = pFnMciMapMsg16To32A(wmd->wType, wMsg, &dwParam2)) {
1221 case WINMM_MAP_MSGERROR:
1222 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1223 dwRet = MCIERR_DRIVER_INTERNAL;
1225 case WINMM_MAP_NOMEM:
1226 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1227 dwRet = MCIERR_OUT_OF_MEMORY;
1230 case WINMM_MAP_OKMEM:
1231 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1232 if (res == WINMM_MAP_OKMEM)
1233 pFnMciUnMapMsg16To32A(wmd->wType, wMsg, dwParam2);
1237 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1243 /**************************************************************************
1244 * MCI_Open [internal]
1246 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
1248 char strDevTyp[128];
1250 LPWINE_MCIDRIVER wmd = NULL;
1252 TRACE("(%08lX, %p)\n", dwParam, lpParms);
1253 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1255 /* only two low bytes are generic, the other ones are dev type specific */
1256 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1257 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1258 MCI_NOTIFY|MCI_WAIT)
1259 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1260 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1262 #undef WINE_MCIDRIVER_SUPP
1266 if (dwParam & MCI_OPEN_TYPE) {
1267 if (dwParam & MCI_OPEN_TYPE_ID) {
1268 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
1270 if (uDevType < MCI_DEVTYPE_FIRST ||
1271 uDevType > MCI_DEVTYPE_LAST ||
1272 !LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
1273 dwRet = MCIERR_BAD_INTEGER;
1278 if (lpParms->lpstrDeviceType == NULL) {
1279 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1282 strcpy(strDevTyp, lpParms->lpstrDeviceType);
1283 ptr = strchr(strDevTyp, '!');
1285 /* this behavior is not documented in windows. However, since, in
1286 * some occasions, MCI_OPEN handling is translated by WinMM into
1287 * a call to mciSendString("open <type>"); this code shall be correct
1289 if (dwParam & MCI_OPEN_ELEMENT) {
1290 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1291 lpParms->lpstrElementName, strDevTyp);
1292 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1295 dwParam |= MCI_OPEN_ELEMENT;
1297 /* FIXME: not a good idea to write in user supplied buffer */
1298 lpParms->lpstrElementName = ptr;
1302 TRACE("devType='%s' !\n", strDevTyp);
1305 if (dwParam & MCI_OPEN_ELEMENT) {
1306 TRACE("lpstrElementName='%s'\n", lpParms->lpstrElementName);
1308 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1309 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1310 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1314 if (!lpParms->lpstrElementName) {
1315 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1319 /* type, if given as a parameter, supersedes file extension */
1320 if (!strDevTyp[0] &&
1321 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1322 strDevTyp, sizeof(strDevTyp))) {
1323 if (GetDriveTypeA(lpParms->lpstrElementName) != DRIVE_CDROM) {
1324 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1327 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1328 strcpy(strDevTyp, "CDAUDIO");
1332 if (strDevTyp[0] == 0) {
1333 FIXME("Couldn't load driver\n");
1334 dwRet = MCIERR_INVALID_DEVICE_NAME;
1338 if (dwParam & MCI_OPEN_ALIAS) {
1339 TRACE("Alias='%s' !\n", lpParms->lpstrAlias);
1340 if (!lpParms->lpstrAlias) {
1341 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1346 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1350 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1351 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet);
1352 /* FIXME: is dwRet the correct ret code ? */
1356 /* only handled devices fall through */
1357 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1359 if (dwParam & MCI_NOTIFY)
1360 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1364 if (wmd) MCI_UnLoadMciDriver(wmd);
1366 if (dwParam & MCI_NOTIFY)
1367 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1371 /**************************************************************************
1372 * MCI_Close [internal]
1374 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1377 LPWINE_MCIDRIVER wmd;
1379 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
1381 if (wDevID == MCI_ALL_DEVICE_ID) {
1382 LPWINE_MCIDRIVER next;
1384 EnterCriticalSection(&WINMM_IData->cs);
1385 /* FIXME: shall I notify once after all is done, or for
1386 * each of the open drivers ? if the latest, which notif
1387 * to return when only one fails ?
1389 for (wmd = WINMM_IData->lpMciDrvs; wmd; ) {
1391 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
1394 LeaveCriticalSection(&WINMM_IData->cs);
1398 if (!(wmd = MCI_GetDriver(wDevID))) {
1399 return MCIERR_INVALID_DEVICE_ID;
1402 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
1404 MCI_UnLoadMciDriver(wmd);
1406 if (dwParam & MCI_NOTIFY)
1407 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1408 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1413 /**************************************************************************
1414 * MCI_WriteString [internal]
1416 DWORD MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr)
1421 if (dstSize <= strlen(lpSrcStr)) {
1422 lstrcpynA(lpDstStr, lpSrcStr, dstSize - 1);
1423 ret = MCIERR_PARAM_OVERFLOW;
1425 strcpy(lpDstStr, lpSrcStr);
1433 /**************************************************************************
1434 * MCI_Sysinfo [internal]
1436 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParms)
1438 DWORD ret = MCIERR_INVALID_DEVICE_ID, cnt = 0;
1439 CHAR buf[2048], *s = buf, *p;
1440 LPWINE_MCIDRIVER wmd;
1443 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1445 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1446 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1448 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1449 case MCI_SYSINFO_QUANTITY:
1450 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1451 if (dwFlags & MCI_SYSINFO_OPEN) {
1452 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1453 EnterCriticalSection(&WINMM_IData->cs);
1454 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1457 LeaveCriticalSection(&WINMM_IData->cs);
1459 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1460 if (RegOpenKeyExA( HKEY_LOCAL_MACHINE, HKLM_MCI,
1461 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
1462 RegQueryInfoKeyA( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1463 RegCloseKey( hKey );
1465 if (GetPrivateProfileStringA("mci", 0, "", buf, sizeof(buf), "system.ini"))
1466 for(s = buf; *s; s += strlen(s) + 1) cnt++;
1469 if (dwFlags & MCI_SYSINFO_OPEN) {
1470 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType);
1471 EnterCriticalSection(&WINMM_IData->cs);
1472 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1473 if (wmd->wType == lpParms->wDeviceType) cnt++;
1475 LeaveCriticalSection(&WINMM_IData->cs);
1477 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType);
1478 FIXME("Don't know how to get # of MCI devices of a given type\n");
1482 *(DWORD*)lpParms->lpstrReturn = cnt;
1483 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1484 ret = MCI_INTEGER_RETURNED;
1486 case MCI_SYSINFO_INSTALLNAME:
1487 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1488 if ((wmd = MCI_GetDriver(uDevID))) {
1489 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1490 wmd->lpstrDeviceType);
1492 *lpParms->lpstrReturn = 0;
1493 ret = MCIERR_INVALID_DEVICE_ID;
1495 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1497 case MCI_SYSINFO_NAME:
1498 TRACE("MCI_SYSINFO_NAME\n");
1499 if (dwFlags & MCI_SYSINFO_OPEN) {
1500 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1501 ret = MCIERR_UNRECOGNIZED_COMMAND;
1505 lRet = RegOpenKeyExA( HKEY_LOCAL_MACHINE, HKLM_MCI, 0, KEY_QUERY_VALUE, &hKey );
1506 if (lRet == ERROR_SUCCESS) {
1507 lRet = RegQueryInfoKeyA( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
1508 if (lRet == ERROR_SUCCESS && lpParms->dwNumber <= cnt) {
1509 DWORD bufLen = sizeof(buf);
1510 lRet = RegEnumKeyExA(hKey, lpParms->dwNumber - 1, buf, &bufLen, 0, 0, 0, 0);
1511 if (lRet == ERROR_SUCCESS) s = buf;
1513 RegCloseKey( hKey );
1516 if (GetPrivateProfileStringA("mci", 0, "", buf, sizeof(buf), "system.ini")) {
1517 for(p = buf; *p; p += strlen(p) + 1, cnt++) {
1518 TRACE("%ld: %s\n", cnt, p);
1519 if (cnt == lpParms->dwNumber - 1) {
1526 ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, s) : MCIERR_OUTOFRANGE;
1528 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1531 TRACE("Unsupported flag value=%08lx\n", dwFlags);
1532 ret = MCIERR_UNRECOGNIZED_COMMAND;
1537 /**************************************************************************
1538 * MCI_Break [internal]
1540 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1544 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1546 if (dwFlags & MCI_NOTIFY)
1547 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1548 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1553 /**************************************************************************
1554 * MCI_Sound [internal]
1556 static DWORD MCI_Sound(UINT wDevID, DWORD dwFlags, LPMCI_SOUND_PARMS lpParms)
1560 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1562 if (dwFlags & MCI_SOUND_NAME)
1563 dwRet = sndPlaySoundA(lpParms->lpstrSoundName, SND_SYNC) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
1565 dwRet = MMSYSERR_ERROR; /* what should be done ??? */
1566 if (dwFlags & MCI_NOTIFY)
1567 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1568 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1573 /**************************************************************************
1574 * MCI_SendCommand [internal]
1576 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
1577 DWORD dwParam2, BOOL bFrom32)
1579 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1584 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1585 } else if (pFnMciMapMsg16To32A) {
1586 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1588 case WINMM_MAP_OKMEM:
1589 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1590 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1592 default: break; /* so that gcc does not bark */
1598 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1599 } else if (pFnMciMapMsg16To32A) {
1600 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1602 case WINMM_MAP_OKMEM:
1603 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1604 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1606 default: break; /* so that gcc does not bark */
1612 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1613 } else if (pFnMciMapMsg16To32A) {
1614 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1616 case WINMM_MAP_OKMEM:
1617 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1618 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1620 default: break; /* so that gcc does not bark */
1626 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1627 } else if (pFnMciMapMsg16To32A) {
1628 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1630 case WINMM_MAP_OKMEM:
1631 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1632 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1634 default: break; /* so that gcc does not bark */
1640 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMS)dwParam2);
1641 } else if (pFnMciMapMsg16To32A) {
1642 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1644 case WINMM_MAP_OKMEM:
1645 dwRet = MCI_Sound(wDevID, dwParam1, (LPMCI_SOUND_PARMS)dwParam2);
1646 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1648 default: break; /* so that gcc does not bark */
1653 if (wDevID == MCI_ALL_DEVICE_ID) {
1654 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1655 dwRet = MCIERR_CANNOT_USE_ALL;
1658 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
1659 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
1666 /**************************************************************************
1667 * MCI_CleanUp [internal]
1669 * Some MCI commands need to be cleaned-up (when not called from
1670 * mciSendString), because MCI drivers return extra information for string
1671 * transformation. This function gets rid of them.
1673 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2)
1676 return LOWORD(dwRet);
1679 case MCI_GETDEVCAPS:
1680 switch (dwRet & 0xFFFF0000ul) {
1682 case MCI_COLONIZED3_RETURN:
1683 case MCI_COLONIZED4_RETURN:
1684 case MCI_INTEGER_RETURNED:
1687 case MCI_RESOURCE_RETURNED:
1688 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1690 LPMCI_GETDEVCAPS_PARMS lmgp;
1692 lmgp = (LPMCI_GETDEVCAPS_PARMS)(void*)dwParam2;
1693 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
1694 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1698 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1699 HIWORD(dwRet), MCI_MessageToString(wMsg));
1703 switch (dwRet & 0xFFFF0000ul) {
1705 case MCI_COLONIZED3_RETURN:
1706 case MCI_COLONIZED4_RETURN:
1707 case MCI_INTEGER_RETURNED:
1710 case MCI_RESOURCE_RETURNED:
1711 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1713 LPMCI_STATUS_PARMS lsp;
1715 lsp = (LPMCI_STATUS_PARMS)(void*)dwParam2;
1716 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
1717 lsp->dwReturn = LOWORD(lsp->dwReturn);
1721 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1722 HIWORD(dwRet), MCI_MessageToString(wMsg));
1726 switch (dwRet & 0xFFFF0000ul) {
1728 case MCI_INTEGER_RETURNED:
1732 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
1736 if (HIWORD(dwRet)) {
1737 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1738 dwRet, MCI_MessageToString(wMsg));
1742 return LOWORD(dwRet);