1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * MCI internal functions
6 * Copyright 1998/1999 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mci);
46 static int MCI_InstalledCount;
47 static LPSTR MCI_lpInstallNames /* = NULL */;
49 WINMM_MapType (*pFnMciMapMsg16To32A) (WORD,WORD,DWORD*) /* = NULL */;
50 WINMM_MapType (*pFnMciUnMapMsg16To32A)(WORD,WORD,DWORD) /* = NULL */;
51 WINMM_MapType (*pFnMciMapMsg32ATo16) (WORD,WORD,DWORD,DWORD*) /* = NULL */;
52 WINMM_MapType (*pFnMciUnMapMsg32ATo16)(WORD,WORD,DWORD,DWORD) /* = NULL */;
54 /* First MCI valid device ID (0 means error) */
55 #define MCI_MAGIC 0x0001
57 /* dup a string and uppercase it */
58 inline static LPSTR str_dup_upper( LPCSTR str )
60 INT len = strlen(str) + 1;
61 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
64 memcpy( p, str, len );
70 /**************************************************************************
71 * MCI_GetDriver [internal]
73 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
75 LPWINE_MCIDRIVER wmd = 0;
77 EnterCriticalSection(&WINMM_IData->cs);
78 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
79 if (wmd->wDeviceID == wDevID)
82 LeaveCriticalSection(&WINMM_IData->cs);
86 /**************************************************************************
87 * MCI_GetDriverFromString [internal]
89 UINT MCI_GetDriverFromString(LPCSTR lpstrName)
97 if (!lstrcmpiA(lpstrName, "ALL"))
98 return MCI_ALL_DEVICE_ID;
100 EnterCriticalSection(&WINMM_IData->cs);
101 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
102 if (wmd->lpstrElementName && strcmp(wmd->lpstrElementName, lpstrName) == 0) {
103 ret = wmd->wDeviceID;
106 if (wmd->lpstrDeviceType && strcasecmp(wmd->lpstrDeviceType, lpstrName) == 0) {
107 ret = wmd->wDeviceID;
110 if (wmd->lpstrAlias && strcasecmp(wmd->lpstrAlias, lpstrName) == 0) {
111 ret = wmd->wDeviceID;
115 LeaveCriticalSection(&WINMM_IData->cs);
120 /**************************************************************************
121 * MCI_MessageToString [internal]
123 const char* MCI_MessageToString(UINT16 wMsg)
125 static char buffer[100];
127 #define CASE(s) case (s): return #s
132 CASE(MCI_CLOSE_DRIVER);
141 CASE(MCI_GETDEVCAPS);
145 CASE(MCI_OPEN_DRIVER);
163 /* constants for digital video */
177 sprintf(buffer, "MCI_<<%04X>>", wMsg);
182 /**************************************************************************
183 * MCI_GetDevTypeFromFileName [internal]
185 static DWORD MCI_GetDevTypeFromFileName(LPCSTR fileName, LPSTR buf, UINT len)
189 if ((tmp = strrchr(fileName, '.'))) {
190 GetProfileStringA("mci extensions", tmp + 1, "*", buf, len);
191 if (strcmp(buf, "*") != 0) {
194 TRACE("No [mci extensions] entry for '%s' found.\n", tmp);
196 return MCIERR_EXTENSION_NOT_FOUND;
199 #define MAX_MCICMDTABLE 20
200 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
202 typedef struct tagWINE_MCICMDTABLE {
205 UINT nVerbs; /* number of verbs in command table */
206 LPCSTR* aVerbs; /* array of verbs to speed up the verb look up process */
207 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
209 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
211 /**************************************************************************
212 * MCI_IsCommandTableValid [internal]
214 static BOOL MCI_IsCommandTableValid(UINT uTbl)
222 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
223 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
225 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
228 lmem = S_MciCmdTable[uTbl].lpTable;
232 lmem += strlen(lmem) + 1;
233 flg = *(LPDWORD)lmem;
234 eid = *(LPWORD)(lmem + sizeof(DWORD));
235 lmem += sizeof(DWORD) + sizeof(WORD);
237 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
239 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
240 case MCI_STRING: if (inCst) return FALSE; break;
241 case MCI_INTEGER: if (!*str) return FALSE; break;
242 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
243 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
244 case MCI_FLAG: if (!*str) return FALSE; break;
245 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
246 case MCI_RECT: if (!*str || inCst) return FALSE; break;
247 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
248 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
249 default: return FALSE;
251 } while (eid != MCI_END_COMMAND_LIST);
252 } while (eid != MCI_END_COMMAND_LIST);
256 /**************************************************************************
257 * MCI_DumpCommandTable [internal]
259 static BOOL MCI_DumpCommandTable(UINT uTbl)
266 if (!MCI_IsCommandTableValid(uTbl)) {
267 ERR("Ooops: %d is not valid\n", uTbl);
271 lmem = S_MciCmdTable[uTbl].lpTable;
275 lmem += strlen(lmem) + 1;
276 flg = *(LPDWORD)lmem;
277 eid = *(LPWORD)(lmem + sizeof(DWORD));
278 TRACE("cmd='%s' %08lx %04x\n", str, flg, eid);
279 lmem += sizeof(DWORD) + sizeof(WORD);
280 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
281 TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : "");
282 } while (eid != MCI_END_COMMAND_LIST);
287 /**************************************************************************
288 * MCI_GetCommandTable [internal]
290 static UINT MCI_GetCommandTable(UINT uDevType)
296 /* first look up existing for existing devType */
297 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
298 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
302 /* well try to load id */
303 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
304 if (LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
307 } else if (uDevType == 0) {
310 uTbl = MCI_NO_COMMAND_TABLE;
312 HRSRC hRsrc = FindResourceA(WINMM_IData->hWinMM32Instance, str, (LPCSTR)RT_RCDATAA);
315 if (hRsrc) hMem = LoadResource(WINMM_IData->hWinMM32Instance, hRsrc);
317 uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType);
319 WARN("No command table found in resource %p[%s]\n",
320 WINMM_IData->hWinMM32Instance, str);
323 TRACE("=> %d\n", uTbl);
327 /**************************************************************************
328 * MCI_SetCommandTable [internal]
330 UINT MCI_SetCommandTable(void *table, UINT uDevType)
333 static BOOL bInitDone = FALSE;
336 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
337 * can be called with 0 as a uDevType to retrieve it.
342 MCI_GetCommandTable(0);
345 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
346 if (!S_MciCmdTable[uTbl].lpTable) {
351 S_MciCmdTable[uTbl].uDevType = uDevType;
352 S_MciCmdTable[uTbl].lpTable = table;
355 MCI_DumpCommandTable(uTbl);
358 /* create the verbs table */
359 /* get # of entries */
360 lmem = S_MciCmdTable[uTbl].lpTable;
363 lmem += strlen(lmem) + 1;
364 eid = *(LPWORD)(lmem + sizeof(DWORD));
365 lmem += sizeof(DWORD) + sizeof(WORD);
366 if (eid == MCI_COMMAND_HEAD)
368 } while (eid != MCI_END_COMMAND_LIST);
370 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCSTR));
371 S_MciCmdTable[uTbl].nVerbs = count;
373 lmem = S_MciCmdTable[uTbl].lpTable;
377 lmem += strlen(lmem) + 1;
378 eid = *(LPWORD)(lmem + sizeof(DWORD));
379 lmem += sizeof(DWORD) + sizeof(WORD);
380 if (eid == MCI_COMMAND_HEAD)
381 S_MciCmdTable[uTbl].aVerbs[count++] = str;
382 } while (eid != MCI_END_COMMAND_LIST);
383 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
388 return MCI_NO_COMMAND_TABLE;
391 /**************************************************************************
392 * MCI_DeleteCommandTable [internal]
394 static BOOL MCI_DeleteCommandTable(UINT uTbl)
396 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
399 S_MciCmdTable[uTbl].lpTable = NULL;
400 if (S_MciCmdTable[uTbl].aVerbs) {
401 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
402 S_MciCmdTable[uTbl].aVerbs = 0;
407 /**************************************************************************
408 * MCI_UnLoadMciDriver [internal]
410 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
412 LPWINE_MCIDRIVER* tmp;
417 CloseDriver(wmd->hDriver, 0, 0);
419 if (wmd->dwPrivate != 0)
420 WARN("Unloading mci driver with non nul dwPrivate field\n");
422 EnterCriticalSection(&WINMM_IData->cs);
423 for (tmp = &WINMM_IData->lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
429 LeaveCriticalSection(&WINMM_IData->cs);
431 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
432 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
433 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
435 HeapFree(GetProcessHeap(), 0, wmd);
439 /**************************************************************************
440 * MCI_OpenMciDriver [internal]
442 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCSTR drvTyp, LPARAM lp)
446 if (!DRIVER_GetLibName(drvTyp, "mci", libName, sizeof(libName)))
450 /* First load driver */
451 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
453 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32ATo16) {
456 switch (res = pFnMciMapMsg32ATo16(0, DRV_OPEN, 0, &lp)) {
457 case WINMM_MAP_MSGERROR:
458 TRACE("Not handled yet (DRV_OPEN)\n");
460 case WINMM_MAP_NOMEM:
461 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
464 case WINMM_MAP_OKMEM:
465 if ((wmd->hDriver = OpenDriverA(drvTyp, "mci", lp)))
467 if (res == WINMM_MAP_OKMEM)
468 pFnMciUnMapMsg32ATo16(0, DRV_OPEN, 0, lp);
472 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
475 /**************************************************************************
476 * MCI_LoadMciDriver [internal]
478 static DWORD MCI_LoadMciDriver(LPCSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
480 LPSTR strDevTyp = str_dup_upper(_strDevTyp);
481 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
482 MCI_OPEN_DRIVER_PARMSA modp;
485 if (!wmd || !strDevTyp) {
486 dwRet = MCIERR_OUT_OF_MEMORY;
490 wmd->lpfnYieldProc = MCI_DefYieldProc;
491 wmd->dwYieldData = VK_CANCEL;
492 wmd->CreatorThread = GetCurrentThreadId();
494 EnterCriticalSection(&WINMM_IData->cs);
495 /* wmd must be inserted in list before sending opening the driver, coz' it
496 * may want to lookup at wDevID
498 wmd->lpNext = WINMM_IData->lpMciDrvs;
499 WINMM_IData->lpMciDrvs = wmd;
501 for (modp.wDeviceID = MCI_MAGIC;
502 MCI_GetDriver(modp.wDeviceID) != 0;
505 wmd->wDeviceID = modp.wDeviceID;
507 LeaveCriticalSection(&WINMM_IData->cs);
509 TRACE("wDevID=%04X \n", modp.wDeviceID);
511 modp.lpstrParams = NULL;
513 if (!MCI_OpenMciDriver(wmd, strDevTyp, (LPARAM)&modp)) {
514 /* silence warning if all is used... some bogus program use commands like
517 if (strcasecmp(strDevTyp, "all") == 0) {
518 dwRet = MCIERR_CANNOT_USE_ALL;
520 FIXME("Couldn't load driver for type %s.\n"
521 "If you don't have a windows installation accessible from Wine,\n"
522 "you perhaps forgot to create a [mci] section in system.ini\n",
524 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
529 /* FIXME: should also check that module's description is of the form
530 * MODULENAME:[MCI] comment
533 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
534 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
535 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
537 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
538 wmd->hDriver, strDevTyp, modp.wType, modp.wCustomCommandTable);
540 wmd->lpstrDeviceType = strDevTyp;
541 wmd->wType = modp.wType;
543 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
544 modp.wDeviceID, modp.wType, modp.wDeviceID);
548 MCI_UnLoadMciDriver(wmd);
549 HeapFree(GetProcessHeap(), 0, strDevTyp);
554 /**************************************************************************
555 * MCI_FinishOpen [internal]
557 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSA lpParms,
560 if (dwParam & MCI_OPEN_ELEMENT)
562 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,strlen(lpParms->lpstrElementName)+1);
563 strcpy( wmd->lpstrElementName, lpParms->lpstrElementName );
565 if (dwParam & MCI_OPEN_ALIAS)
567 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, strlen(lpParms->lpstrAlias)+1);
568 strcpy( wmd->lpstrAlias, lpParms->lpstrAlias);
570 lpParms->wDeviceID = wmd->wDeviceID;
572 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
576 /**************************************************************************
577 * MCI_FindCommand [internal]
579 static LPCSTR MCI_FindCommand(UINT uTbl, LPCSTR verb)
583 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
586 /* another improvement would be to have the aVerbs array sorted,
587 * so that we could use a dichotomic search on it, rather than this dumb
590 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
591 if (strcmp(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
592 return S_MciCmdTable[uTbl].aVerbs[idx];
598 /**************************************************************************
599 * MCI_GetReturnType [internal]
601 static DWORD MCI_GetReturnType(LPCSTR lpCmd)
603 lpCmd += strlen(lpCmd) + 1 + sizeof(DWORD) + sizeof(WORD);
604 if (*lpCmd == '\0' && *(LPWORD)(lpCmd + 1 + sizeof(DWORD)) == MCI_RETURN) {
605 return *(LPDWORD)(lpCmd + 1);
610 /**************************************************************************
611 * MCI_GetMessage [internal]
613 static WORD MCI_GetMessage(LPCSTR lpCmd)
615 return (WORD)*(LPDWORD)(lpCmd + strlen(lpCmd) + 1);
618 /**************************************************************************
619 * MCI_GetDWord [internal]
621 static BOOL MCI_GetDWord(LPDWORD data, LPSTR* ptr)
626 val = strtoul(*ptr, &ret, 0);
630 case ' ': ret++; break;
631 default: return FALSE;
639 /**************************************************************************
640 * MCI_GetString [internal]
642 static DWORD MCI_GetString(LPSTR* str, LPSTR* args)
646 /* see if we have a quoted string */
648 ptr = strchr(*str = ptr + 1, '"');
649 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
650 /* FIXME: shall we escape \" from string ?? */
651 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
652 *ptr++ = '\0'; /* remove trailing " */
653 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
656 ptr = strchr(ptr, ' ');
661 ptr = *args + strlen(*args);
670 #define MCI_DATA_SIZE 16
672 /**************************************************************************
673 * MCI_ParseOptArgs [internal]
675 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCSTR lpCmd,
676 LPSTR args, LPDWORD dwFlags)
680 DWORD dwRet, flg, cflg = 0;
684 /* loop on arguments */
687 found = inCst = FALSE;
690 /* skip any leading white space(s) */
691 while (*args == ' ') args++;
692 TRACE("args='%s' offset=%d\n", args, offset);
694 do { /* loop on options for command table for the requested verb */
696 lmem += (len = strlen(lmem)) + 1;
697 flg = *(LPDWORD)lmem;
698 eid = *(LPWORD)(lmem + sizeof(DWORD));
699 lmem += sizeof(DWORD) + sizeof(WORD);
700 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
704 inCst = TRUE; cflg = flg; break;
705 case MCI_END_CONSTANT:
706 /* there may be additional integral values after flag in constant */
707 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
710 inCst = FALSE; cflg = 0;
714 if (strncasecmp(args, str, len) == 0 &&
715 (args[len] == 0 || args[len] == ' ')) {
716 /* store good values into data[] */
718 while (*args == ' ') args++;
722 case MCI_COMMAND_HEAD:
724 case MCI_END_COMMAND:
725 case MCI_END_COMMAND_LIST:
726 case MCI_CONSTANT: /* done above */
727 case MCI_END_CONSTANT: /* done above */
739 if (!MCI_GetDWord(&(data[offset]), &args)) {
740 return MCIERR_BAD_INTEGER;
745 /* store rect in data (offset...offset+3) */
747 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
748 !MCI_GetDWord(&(data[offset+1]), &args) ||
749 !MCI_GetDWord(&(data[offset+2]), &args) ||
750 !MCI_GetDWord(&(data[offset+3]), &args)) {
751 ERR("Bad rect '%s'\n", args);
752 return MCIERR_BAD_INTEGER;
757 if ((dwRet = MCI_GetString((LPSTR*)&data[offset], &args)))
760 default: ERR("oops\n");
762 /* exit inside while loop, except if just entered in constant area definition */
763 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
765 /* have offset incremented if needed */
767 case MCI_COMMAND_HEAD:
769 case MCI_END_COMMAND:
770 case MCI_END_COMMAND_LIST:
772 case MCI_FLAG: break;
773 case MCI_INTEGER: if (!inCst) offset++; break;
774 case MCI_END_CONSTANT:
775 case MCI_STRING: offset++; break;
776 case MCI_RECT: offset += 4; break;
777 default: ERR("oops\n");
780 } while (eid != MCI_END_COMMAND);
782 WARN("Optarg '%s' not found\n", args);
783 return MCIERR_UNRECOGNIZED_COMMAND;
785 if (offset == MCI_DATA_SIZE) {
786 ERR("Internal data[] buffer overflow\n");
787 return MCIERR_PARSER_INTERNAL;
793 /**************************************************************************
794 * MCI_HandleReturnValues [internal]
796 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
797 LPDWORD data, LPSTR lpstrRet, UINT uRetLen)
801 case 0: /* nothing to return */
804 switch (dwRet & 0xFFFF0000ul) {
806 case MCI_INTEGER_RETURNED:
807 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
809 case MCI_RESOURCE_RETURNED:
810 /* return string which ID is HIWORD(data[1]),
811 * string is loaded from mmsystem.dll */
812 LoadStringA(WINMM_IData->hWinMM32Instance, HIWORD(data[1]),
815 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
816 /* return string which ID is HIWORD(data[1]),
817 * string is loaded from driver */
818 /* FIXME: this is wrong for a 16 bit handle */
819 LoadStringA(GetDriverModuleHandle(wmd->hDriver),
820 HIWORD(data[1]), lpstrRet, uRetLen);
822 case MCI_COLONIZED3_RETURN:
823 snprintf(lpstrRet, uRetLen, "%d:%d:%d",
824 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
825 LOBYTE(HIWORD(data[1])));
827 case MCI_COLONIZED4_RETURN:
828 snprintf(lpstrRet, uRetLen, "%d:%d:%d:%d",
829 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
830 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
832 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
836 switch (dwRet & 0xFFFF0000ul) {
838 /* nothing to do data[1] == lpstrRet */
840 case MCI_INTEGER_RETURNED:
841 data[1] = *(LPDWORD)lpstrRet;
842 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
845 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
850 if (dwRet & 0xFFFF0000ul)
851 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
852 snprintf(lpstrRet, uRetLen, "%ld %ld %ld %ld",
853 data[1], data[2], data[3], data[4]);
855 default: ERR("oops\n");
858 return LOWORD(dwRet);
861 /**************************************************************************
862 * mciSendStringA [WINMM.@]
864 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
865 UINT uRetLen, HWND hwndCallback)
867 LPSTR verb, dev, args;
868 LPWINE_MCIDRIVER wmd = 0;
869 DWORD dwFlags = 0, dwRet = 0;
871 DWORD data[MCI_DATA_SIZE];
874 LPSTR devAlias = NULL;
875 BOOL bAutoOpen = FALSE;
877 TRACE("('%s', %p, %d, %p)\n", lpstrCommand, lpstrRet, uRetLen, hwndCallback);
879 /* format is <command> <device> <optargs> */
880 if (!(verb = HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand)+1)))
881 return MCIERR_OUT_OF_MEMORY;
882 strcpy( verb, lpstrCommand );
884 memset(data, 0, sizeof(data));
886 if (!(args = strchr(verb, ' '))) {
887 dwRet = MCIERR_MISSING_DEVICE_NAME;
891 if ((dwRet = MCI_GetString(&dev, &args))) {
895 /* case dev == 'new' has to be handled */
896 if (!strcasecmp(dev, "new")) {
897 FIXME("'new': NIY as device name\n");
898 dwRet = MCIERR_MISSING_DEVICE_NAME;
902 /* otherwise, try to grab devType from open */
903 if (!strcmp(verb, "open")) {
906 if ((devType = strchr(dev, '!')) != NULL) {
908 tmp = devType; devType = dev; dev = tmp;
910 dwFlags |= MCI_OPEN_TYPE;
911 data[2] = (DWORD)devType;
912 devType = str_dup_upper(devType);
913 dwFlags |= MCI_OPEN_ELEMENT;
914 data[3] = (DWORD)dev;
915 } else if (strchr(dev, '.') == NULL) {
916 tmp = strchr(dev,' ');
917 if (tmp) *tmp = '\0';
918 data[2] = (DWORD)dev;
919 devType = str_dup_upper(dev);
921 dwFlags |= MCI_OPEN_TYPE;
923 if ((devType = strstr(args, "type ")) != NULL) {
925 tmp = strchr(devType, ' ');
926 if (tmp) *tmp = '\0';
927 devType = str_dup_upper(devType);
929 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
932 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
935 devType = str_dup_upper(buf);
937 dwFlags |= MCI_OPEN_ELEMENT;
938 data[3] = (DWORD)dev;
940 if ((devAlias = strstr(args," alias "))) {
943 if (!(tmp = strchr(devAlias,' '))) tmp = devAlias + strlen(devAlias);
944 if (tmp) *tmp = '\0';
945 tmp2 = HeapAlloc(GetProcessHeap(), 0, tmp - devAlias + 1 );
946 memcpy( tmp2, devAlias, tmp - devAlias );
947 tmp2[tmp - devAlias] = 0;
948 data[4] = (DWORD)tmp2;
949 /* should be done in regular options parsing */
950 /* dwFlags |= MCI_OPEN_ALIAS; */
953 dwRet = MCI_LoadMciDriver(devType, &wmd);
954 HeapFree(GetProcessHeap(), 0, devType);
956 MCI_UnLoadMciDriver(wmd);
959 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDA(dev)))) {
962 sprintf(buf, "open %s wait", dev);
964 if ((dwRet = mciSendStringA(buf, NULL, 0, 0)) != 0)
967 wmd = MCI_GetDriver(mciGetDeviceIDA(dev));
969 /* FIXME: memory leak, MCI driver is not closed */
970 dwRet = MCIERR_INVALID_DEVICE_ID;
975 /* get the verb in the different command tables */
977 /* try the device specific command table */
978 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
980 /* try the type specific command table */
981 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
982 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
983 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
984 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
987 /* try core command table */
988 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
991 TRACE("Command '%s' not found!\n", verb);
992 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
996 /* set up call back */
997 if (hwndCallback != 0) {
998 dwFlags |= MCI_NOTIFY;
999 data[0] = (DWORD)hwndCallback;
1002 /* set return information */
1003 switch (retType = MCI_GetReturnType(lpCmd)) {
1004 case 0: offset = 1; break;
1005 case MCI_INTEGER: offset = 2; break;
1006 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1007 case MCI_RECT: offset = 5; break;
1008 default: ERR("oops\n");
1011 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb, dev, offset);
1013 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1016 if (bAutoOpen && (dwFlags & MCI_NOTIFY)) {
1017 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1020 /* FIXME: the command should get it's own notification window set up and
1021 * ask for device closing while processing the notification mechanism
1023 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1025 #define STR_OF(_x) (IsBadReadPtr((char*)_x,1)?"?":(char*)(_x))
1026 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1027 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1028 data[0], STR_OF(data[0]), data[1], STR_OF(data[1]),
1029 data[2], STR_OF(data[2]), data[3], STR_OF(data[3]),
1030 data[4], STR_OF(data[4]), data[5], STR_OF(data[5]));
1033 if (strcmp(verb, "open") == 0) {
1034 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSA)data, dwFlags)))
1035 MCI_UnLoadMciDriver(wmd);
1036 /* FIXME: notification is not properly shared across two opens */
1038 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
1040 TRACE("=> 1/ %lx (%s)\n", dwRet, lpstrRet);
1041 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1042 TRACE("=> 2/ %lx (%s)\n", dwRet, lpstrRet);
1045 HeapFree(GetProcessHeap(), 0, verb);
1046 HeapFree(GetProcessHeap(), 0, devAlias);
1050 /**************************************************************************
1051 * mciSendStringW [WINMM.@]
1053 DWORD WINAPI mciSendStringW(LPCWSTR lpwstrCommand, LPSTR lpstrRet,
1054 UINT uRetLen, HWND hwndCallback)
1060 /* FIXME: is there something to do with lpstrReturnString ? */
1061 len = WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, NULL, 0, NULL, NULL );
1062 lpstrCommand = HeapAlloc( GetProcessHeap(), 0, len );
1063 WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, lpstrCommand, len, NULL, NULL );
1064 ret = mciSendStringA(lpstrCommand, lpstrRet, uRetLen, hwndCallback);
1065 HeapFree(GetProcessHeap(), 0, lpstrCommand);
1069 /**************************************************************************
1070 * mciExecute [WINMM.@]
1071 * mciExecute [MMSYSTEM.712]
1073 DWORD WINAPI mciExecute(LPCSTR lpstrCommand)
1078 TRACE("(%s)!\n", lpstrCommand);
1080 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1082 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1083 sprintf(strRet, "Unknown MCI error (%ld)", ret);
1085 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1087 /* FIXME: what shall I return ? */
1091 /**************************************************************************
1092 * mciLoadCommandResource [WINMM.@]
1094 * Strangely, this function only exists as an UNICODE one.
1096 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1100 UINT16 ret = MCI_NO_COMMAND_TABLE;
1102 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1104 /* if a file named "resname.mci" exits, then load resource "resname" from it
1105 * otherwise directly from driver
1106 * We don't support it (who uses this feature ?), but we check anyway
1110 /* FIXME: we should put this back into order, but I never found a program
1111 * actually using this feature, so we not need it
1116 strcat(strcpy(buf, resname), ".mci");
1117 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1118 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1122 if (!(hRsrc = FindResourceW(hInst, resNameW, RT_RCDATAW))) {
1123 WARN("No command table found in resource\n");
1124 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1125 ret = MCI_SetCommandTable(LockResource(hMem), type);
1127 WARN("Couldn't load resource.\n");
1129 TRACE("=> %04x\n", ret);
1133 /**************************************************************************
1134 * mciFreeCommandResource [WINMM.@]
1136 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1138 TRACE("(%08x)!\n", uTable);
1140 return MCI_DeleteCommandTable(uTable);
1143 /**************************************************************************
1144 * MCI_SendCommandFrom32 [internal]
1146 DWORD MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1148 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1149 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1153 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1154 } else if (pFnMciMapMsg32ATo16) {
1157 switch (res = pFnMciMapMsg32ATo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1158 case WINMM_MAP_MSGERROR:
1159 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1160 dwRet = MCIERR_DRIVER_INTERNAL;
1162 case WINMM_MAP_NOMEM:
1163 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1164 dwRet = MCIERR_OUT_OF_MEMORY;
1167 case WINMM_MAP_OKMEM:
1168 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1169 if (res == WINMM_MAP_OKMEM)
1170 pFnMciUnMapMsg32ATo16(wmd->wType, wMsg, dwParam1, dwParam2);
1178 /**************************************************************************
1179 * MCI_SendCommandFrom16 [internal]
1181 DWORD MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1183 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1184 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1187 dwRet = MCIERR_INVALID_DEVICE_ID;
1189 if (wmd->bIs32 && pFnMciMapMsg16To32A) {
1192 switch (res = pFnMciMapMsg16To32A(wmd->wType, wMsg, &dwParam2)) {
1193 case WINMM_MAP_MSGERROR:
1194 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1195 dwRet = MCIERR_DRIVER_INTERNAL;
1197 case WINMM_MAP_NOMEM:
1198 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1199 dwRet = MCIERR_OUT_OF_MEMORY;
1202 case WINMM_MAP_OKMEM:
1203 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1204 if (res == WINMM_MAP_OKMEM)
1205 pFnMciUnMapMsg16To32A(wmd->wType, wMsg, dwParam2);
1209 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1215 /**************************************************************************
1216 * MCI_Open [internal]
1218 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
1220 char strDevTyp[128];
1222 LPWINE_MCIDRIVER wmd = NULL;
1224 TRACE("(%08lX, %p)\n", dwParam, lpParms);
1225 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1227 /* only two low bytes are generic, the other ones are dev type specific */
1228 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1229 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1230 MCI_NOTIFY|MCI_WAIT)
1231 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1232 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1234 #undef WINE_MCIDRIVER_SUPP
1238 if (dwParam & MCI_OPEN_TYPE) {
1239 if (dwParam & MCI_OPEN_TYPE_ID) {
1240 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
1242 if (uDevType < MCI_DEVTYPE_FIRST ||
1243 uDevType > MCI_DEVTYPE_LAST ||
1244 !LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
1245 dwRet = MCIERR_BAD_INTEGER;
1250 if (lpParms->lpstrDeviceType == NULL) {
1251 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1254 strcpy(strDevTyp, lpParms->lpstrDeviceType);
1255 ptr = strchr(strDevTyp, '!');
1257 /* this behavior is not documented in windows. However, since, in
1258 * some occasions, MCI_OPEN handling is translated by WinMM into
1259 * a call to mciSendString("open <type>"); this code shall be correct
1261 if (dwParam & MCI_OPEN_ELEMENT) {
1262 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1263 lpParms->lpstrElementName, strDevTyp);
1264 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1267 dwParam |= MCI_OPEN_ELEMENT;
1269 /* FIXME: not a good idea to write in user supplied buffer */
1270 lpParms->lpstrElementName = ptr;
1274 TRACE("devType='%s' !\n", strDevTyp);
1277 if (dwParam & MCI_OPEN_ELEMENT) {
1278 TRACE("lpstrElementName='%s'\n", lpParms->lpstrElementName);
1280 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1281 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1282 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1286 if (!lpParms->lpstrElementName) {
1287 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1291 /* type, if given as a parameter, supersedes file extension */
1292 if (!strDevTyp[0] &&
1293 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1294 strDevTyp, sizeof(strDevTyp))) {
1295 if (GetDriveTypeA(lpParms->lpstrElementName) != DRIVE_CDROM) {
1296 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1299 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1300 strcpy(strDevTyp, "CDAUDIO");
1304 if (strDevTyp[0] == 0) {
1305 FIXME("Couldn't load driver\n");
1306 dwRet = MCIERR_INVALID_DEVICE_NAME;
1310 if (dwParam & MCI_OPEN_ALIAS) {
1311 TRACE("Alias='%s' !\n", lpParms->lpstrAlias);
1312 if (!lpParms->lpstrAlias) {
1313 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1318 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1322 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1323 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet);
1324 /* FIXME: is dwRet the correct ret code ? */
1328 /* only handled devices fall through */
1329 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1331 if (dwParam & MCI_NOTIFY)
1332 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1336 if (wmd) MCI_UnLoadMciDriver(wmd);
1338 if (dwParam & MCI_NOTIFY)
1339 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1343 /**************************************************************************
1344 * MCI_Close [internal]
1346 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1349 LPWINE_MCIDRIVER wmd;
1351 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
1353 if (wDevID == MCI_ALL_DEVICE_ID) {
1354 LPWINE_MCIDRIVER next;
1356 EnterCriticalSection(&WINMM_IData->cs);
1357 /* FIXME: shall I notify once after all is done, or for
1358 * each of the open drivers ? if the latest, which notif
1359 * to return when only one fails ?
1361 for (wmd = WINMM_IData->lpMciDrvs; wmd; ) {
1363 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
1366 LeaveCriticalSection(&WINMM_IData->cs);
1370 if (!(wmd = MCI_GetDriver(wDevID))) {
1371 return MCIERR_INVALID_DEVICE_ID;
1374 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
1376 MCI_UnLoadMciDriver(wmd);
1378 if (dwParam & MCI_NOTIFY)
1379 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1380 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1385 /**************************************************************************
1386 * MCI_WriteString [internal]
1388 DWORD MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr)
1393 if (dstSize <= strlen(lpSrcStr)) {
1394 lstrcpynA(lpDstStr, lpSrcStr, dstSize - 1);
1395 ret = MCIERR_PARAM_OVERFLOW;
1397 strcpy(lpDstStr, lpSrcStr);
1405 /**************************************************************************
1406 * MCI_Sysinfo [internal]
1408 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParms)
1410 DWORD ret = MCIERR_INVALID_DEVICE_ID;
1411 LPWINE_MCIDRIVER wmd;
1413 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1415 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1416 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1418 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1419 case MCI_SYSINFO_QUANTITY:
1423 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST ||
1424 lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1425 if (dwFlags & MCI_SYSINFO_OPEN) {
1426 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1427 EnterCriticalSection(&WINMM_IData->cs);
1428 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1431 LeaveCriticalSection(&WINMM_IData->cs);
1433 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1434 cnt = MCI_InstalledCount;
1437 if (dwFlags & MCI_SYSINFO_OPEN) {
1438 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
1439 lpParms->wDeviceType);
1440 EnterCriticalSection(&WINMM_IData->cs);
1441 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1442 if (wmd->wType == lpParms->wDeviceType)
1445 LeaveCriticalSection(&WINMM_IData->cs);
1447 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
1448 lpParms->wDeviceType);
1449 FIXME("Don't know how to get # of MCI devices of a given type\n");
1453 *(DWORD*)lpParms->lpstrReturn = cnt;
1455 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1456 ret = MCI_INTEGER_RETURNED;
1458 case MCI_SYSINFO_INSTALLNAME:
1459 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1460 if ((wmd = MCI_GetDriver(uDevID))) {
1461 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1462 wmd->lpstrDeviceType);
1464 *lpParms->lpstrReturn = 0;
1465 ret = MCIERR_INVALID_DEVICE_ID;
1467 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1469 case MCI_SYSINFO_NAME:
1470 TRACE("MCI_SYSINFO_NAME\n");
1471 if (dwFlags & MCI_SYSINFO_OPEN) {
1472 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1473 ret = MCIERR_UNRECOGNIZED_COMMAND;
1474 } else if (lpParms->dwNumber > MCI_InstalledCount) {
1475 ret = MCIERR_OUTOFRANGE;
1477 DWORD count = lpParms->dwNumber;
1478 LPSTR ptr = MCI_lpInstallNames;
1480 while (--count > 0) ptr += strlen(ptr) + 1;
1481 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, ptr);
1483 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1486 TRACE("Unsupported flag value=%08lx\n", dwFlags);
1487 ret = MCIERR_UNRECOGNIZED_COMMAND;
1492 /**************************************************************************
1493 * MCI_Break [internal]
1495 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1499 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1501 if (dwFlags & MCI_NOTIFY)
1502 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1503 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1508 /**************************************************************************
1509 * MCI_SendCommand [internal]
1511 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
1512 DWORD dwParam2, BOOL bFrom32)
1514 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1519 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1520 } else if (pFnMciMapMsg16To32A) {
1521 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1523 case WINMM_MAP_OKMEM:
1524 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1525 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1527 default: break; /* so that gcc does not bark */
1533 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1534 } else if (pFnMciMapMsg16To32A) {
1535 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1537 case WINMM_MAP_OKMEM:
1538 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1539 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1541 default: break; /* so that gcc does not bark */
1547 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1548 } else if (pFnMciMapMsg16To32A) {
1549 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1551 case WINMM_MAP_OKMEM:
1552 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1553 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1555 default: break; /* so that gcc doesnot bark */
1561 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1562 } else if (pFnMciMapMsg16To32A) {
1563 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1565 case WINMM_MAP_OKMEM:
1566 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1567 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1569 default: break; /* so that gcc does not bark */
1574 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
1575 * but I couldn't get any doc on this MCI message
1579 if (wDevID == MCI_ALL_DEVICE_ID) {
1580 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1581 dwRet = MCIERR_CANNOT_USE_ALL;
1584 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
1585 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
1592 /**************************************************************************
1593 * MCI_CleanUp [internal]
1595 * Some MCI commands need to be cleaned-up (when not called from
1596 * mciSendString), because MCI drivers return extra information for string
1597 * transformation. This function gets rid of them.
1599 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2)
1602 return LOWORD(dwRet);
1605 case MCI_GETDEVCAPS:
1606 switch (dwRet & 0xFFFF0000ul) {
1608 case MCI_COLONIZED3_RETURN:
1609 case MCI_COLONIZED4_RETURN:
1610 case MCI_INTEGER_RETURNED:
1613 case MCI_RESOURCE_RETURNED:
1614 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1616 LPMCI_GETDEVCAPS_PARMS lmgp;
1618 lmgp = (LPMCI_GETDEVCAPS_PARMS)(void*)dwParam2;
1619 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
1620 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1624 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1625 HIWORD(dwRet), MCI_MessageToString(wMsg));
1629 switch (dwRet & 0xFFFF0000ul) {
1631 case MCI_COLONIZED3_RETURN:
1632 case MCI_COLONIZED4_RETURN:
1633 case MCI_INTEGER_RETURNED:
1636 case MCI_RESOURCE_RETURNED:
1637 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1639 LPMCI_STATUS_PARMS lsp;
1641 lsp = (LPMCI_STATUS_PARMS)(void*)dwParam2;
1642 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
1643 lsp->dwReturn = LOWORD(lsp->dwReturn);
1647 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1648 HIWORD(dwRet), MCI_MessageToString(wMsg));
1652 switch (dwRet & 0xFFFF0000ul) {
1654 case MCI_INTEGER_RETURNED:
1658 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
1662 if (HIWORD(dwRet)) {
1663 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1664 dwRet, MCI_MessageToString(wMsg));
1668 return LOWORD(dwRet);
1671 /**************************************************************************
1672 * MCI_Init [internal]
1674 * Initializes the MCI internal variables.
1686 MCI_InstalledCount = 0;
1687 ptr1 = MCI_lpInstallNames = HeapAlloc(GetProcessHeap(), 0, count);
1689 if (!MCI_lpInstallNames)
1692 /* FIXME: should do also some registry diving here ? */
1693 if (!(err = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", &hWineConf)) &&
1694 !(err = RegOpenKeyA(hWineConf, "options", &hkey))) {
1695 err = RegQueryValueExA(hkey, "mci", 0, &type, MCI_lpInstallNames, &count);
1700 TRACE("Wine => '%s' \n", ptr1);
1701 while ((ptr2 = strchr(ptr1, ':')) != 0) {
1703 TRACE("---> '%s' \n", ptr1);
1704 MCI_InstalledCount++;
1707 MCI_InstalledCount++;
1708 TRACE("---> '%s' \n", ptr1);
1709 ptr1 += strlen(ptr1) + 1;
1711 GetPrivateProfileStringA("mci", NULL, "", MCI_lpInstallNames, count, "SYSTEM.INI");
1712 while (strlen(ptr1) > 0) {
1713 TRACE("---> '%s' \n", ptr1);
1714 ptr1 += strlen(ptr1) + 1;
1715 MCI_InstalledCount++;
1718 RegCloseKey(hWineConf);