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"
36 #include "wine/mmsystem16.h"
37 #include "wine/winbase16.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mci);
45 static int MCI_InstalledCount;
46 static LPSTR MCI_lpInstallNames = NULL;
48 /* First MCI valid device ID (0 means error) */
49 #define MCI_MAGIC 0x0001
51 /* dup a string and uppercase it */
52 inline static LPSTR str_dup_upper( LPCSTR str )
54 INT len = strlen(str) + 1;
55 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
58 memcpy( p, str, len );
64 /**************************************************************************
65 * MCI_GetDriver [internal]
67 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
69 LPWINE_MCIDRIVER wmd = 0;
71 EnterCriticalSection(&WINMM_IData->cs);
72 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
73 if (wmd->wDeviceID == wDevID)
76 LeaveCriticalSection(&WINMM_IData->cs);
80 /**************************************************************************
81 * MCI_GetDriverFromString [internal]
83 UINT MCI_GetDriverFromString(LPCSTR lpstrName)
91 if (!lstrcmpiA(lpstrName, "ALL"))
92 return MCI_ALL_DEVICE_ID;
94 EnterCriticalSection(&WINMM_IData->cs);
95 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
96 if (wmd->lpstrElementName && strcmp(wmd->lpstrElementName, lpstrName) == 0) {
100 if (wmd->lpstrDeviceType && strcasecmp(wmd->lpstrDeviceType, lpstrName) == 0) {
101 ret = wmd->wDeviceID;
104 if (wmd->lpstrAlias && strcasecmp(wmd->lpstrAlias, lpstrName) == 0) {
105 ret = wmd->wDeviceID;
109 LeaveCriticalSection(&WINMM_IData->cs);
114 /**************************************************************************
115 * MCI_MessageToString [internal]
117 const char* MCI_MessageToString(UINT16 wMsg)
119 static char buffer[100];
121 #define CASE(s) case (s): return #s
126 CASE(MCI_CLOSE_DRIVER);
135 CASE(MCI_GETDEVCAPS);
139 CASE(MCI_OPEN_DRIVER);
157 /* constants for digital video */
171 sprintf(buffer, "MCI_<<%04X>>", wMsg);
176 /**************************************************************************
177 * MCI_GetDevTypeFromFileName [internal]
179 static DWORD MCI_GetDevTypeFromFileName(LPCSTR fileName, LPSTR buf, UINT len)
183 if ((tmp = strrchr(fileName, '.'))) {
184 GetProfileStringA("mci extensions", tmp + 1, "*", buf, len);
185 if (strcmp(buf, "*") != 0) {
188 TRACE("No [mci extensions] entry for '%s' found.\n", tmp);
190 return MCIERR_EXTENSION_NOT_FOUND;
193 #define MAX_MCICMDTABLE 20
194 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
196 typedef struct tagWINE_MCICMDTABLE {
200 UINT nVerbs; /* number of verbs in command table */
201 LPCSTR* aVerbs; /* array of verbs to speed up the verb look up process */
202 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
203 WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
205 /**************************************************************************
206 * MCI_IsCommandTableValid [internal]
208 static BOOL MCI_IsCommandTableValid(UINT uTbl)
216 TRACE("Dumping cmdTbl=%d [hMem=%08x devType=%d]\n",
217 uTbl, S_MciCmdTable[uTbl].hMem, S_MciCmdTable[uTbl].uDevType);
219 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].hMem || !S_MciCmdTable[uTbl].lpTable)
222 lmem = S_MciCmdTable[uTbl].lpTable;
226 lmem += strlen(lmem) + 1;
227 flg = *(LPDWORD)lmem;
228 eid = *(LPWORD)(lmem + sizeof(DWORD));
229 lmem += sizeof(DWORD) + sizeof(WORD);
231 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
233 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
234 case MCI_STRING: if (inCst) return FALSE; break;
235 case MCI_INTEGER: if (!*str) return FALSE; break;
236 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
237 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
238 case MCI_FLAG: if (!*str) return FALSE; break;
239 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
240 case MCI_RECT: if (!*str || inCst) return FALSE; break;
241 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
242 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
243 default: return FALSE;
245 } while (eid != MCI_END_COMMAND_LIST);
246 } while (eid != MCI_END_COMMAND_LIST);
250 /**************************************************************************
251 * MCI_DumpCommandTable [internal]
253 static BOOL MCI_DumpCommandTable(UINT uTbl)
260 if (!MCI_IsCommandTableValid(uTbl)) {
261 ERR("Ooops: %d is not valid\n", uTbl);
265 lmem = S_MciCmdTable[uTbl].lpTable;
269 lmem += strlen(lmem) + 1;
270 flg = *(LPDWORD)lmem;
271 eid = *(LPWORD)(lmem + sizeof(DWORD));
272 TRACE("cmd='%s' %08lx %04x\n", str, flg, eid);
273 lmem += sizeof(DWORD) + sizeof(WORD);
274 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
275 TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : "");
276 } while (eid != MCI_END_COMMAND_LIST);
280 static UINT MCI_SetCommandTable(HANDLE hMem, UINT uDevType);
282 /**************************************************************************
283 * MCI_GetCommandTable [internal]
285 static UINT MCI_GetCommandTable(UINT uDevType)
291 /* first look up existing for existing devType */
292 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
293 if (S_MciCmdTable[uTbl].hMem && S_MciCmdTable[uTbl].uDevType == uDevType)
297 /* well try to load id */
298 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
299 if (LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
302 } else if (uDevType == 0) {
305 uTbl = MCI_NO_COMMAND_TABLE;
307 HRSRC hRsrc = FindResourceA(WINMM_IData->hWinMM32Instance, str, (LPCSTR)RT_RCDATAA);
310 if (hRsrc) hMem = LoadResource(WINMM_IData->hWinMM32Instance, hRsrc);
312 uTbl = MCI_SetCommandTable(hMem, uDevType);
314 WARN("No command table found in resource %04x[%s]\n",
315 WINMM_IData->hWinMM32Instance, str);
318 TRACE("=> %d\n", uTbl);
322 /**************************************************************************
323 * MCI_SetCommandTable [internal]
325 static UINT MCI_SetCommandTable(HANDLE hMem, UINT uDevType)
328 static BOOL bInitDone = FALSE;
331 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
332 * can be called with 0 as a uDevType to retrieve it.
337 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
338 S_MciCmdTable[uTbl].hMem = 0;
340 MCI_GetCommandTable(0);
343 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
344 if (S_MciCmdTable[uTbl].hMem == 0) {
349 S_MciCmdTable[uTbl].hMem = hMem;
350 S_MciCmdTable[uTbl].uDevType = uDevType;
351 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
354 MCI_DumpCommandTable(uTbl);
357 /* create the verbs table */
358 /* get # of entries */
359 lmem = S_MciCmdTable[uTbl].lpTable;
362 lmem += strlen(lmem) + 1;
363 eid = *(LPWORD)(lmem + sizeof(DWORD));
364 lmem += sizeof(DWORD) + sizeof(WORD);
365 if (eid == MCI_COMMAND_HEAD)
367 } while (eid != MCI_END_COMMAND_LIST);
369 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCSTR));
370 S_MciCmdTable[uTbl].nVerbs = count;
372 lmem = S_MciCmdTable[uTbl].lpTable;
376 lmem += strlen(lmem) + 1;
377 eid = *(LPWORD)(lmem + sizeof(DWORD));
378 lmem += sizeof(DWORD) + sizeof(WORD);
379 if (eid == MCI_COMMAND_HEAD)
380 S_MciCmdTable[uTbl].aVerbs[count++] = str;
381 } while (eid != MCI_END_COMMAND_LIST);
382 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
387 return MCI_NO_COMMAND_TABLE;
390 /**************************************************************************
391 * MCI_DeleteCommandTable [internal]
393 static BOOL MCI_DeleteCommandTable(UINT uTbl)
395 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].hMem)
398 FreeResource(S_MciCmdTable[uTbl].hMem);
399 S_MciCmdTable[uTbl].hMem = 0;
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))) {
456 switch (res = MCI_MapMsg32ATo16(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 MCI_UnMapMsg32ATo16(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->hCreatorTask = GetCurrentTask();
493 wmd->CreatorThread = GetCurrentThreadId();
495 EnterCriticalSection(&WINMM_IData->cs);
496 /* wmd must be inserted in list before sending opening the driver, coz' it
497 * may want to lookup at wDevID
499 wmd->lpNext = WINMM_IData->lpMciDrvs;
500 WINMM_IData->lpMciDrvs = wmd;
502 for (modp.wDeviceID = MCI_MAGIC;
503 MCI_GetDriver(modp.wDeviceID) != 0;
506 wmd->wDeviceID = modp.wDeviceID;
508 LeaveCriticalSection(&WINMM_IData->cs);
510 TRACE("wDevID=%04X \n", modp.wDeviceID);
512 modp.lpstrParams = NULL;
514 if (!MCI_OpenMciDriver(wmd, strDevTyp, (LPARAM)&modp)) {
515 /* silence warning if all is used... some bogus program use commands like
518 if (strcasecmp(strDevTyp, "all") != 0) {
519 dwRet = MCIERR_CANNOT_USE_ALL;
521 FIXME("Couldn't load driver for type %s.\n"
522 "If you don't have a windows installation accessible from Wine,\n"
523 "you perhaps forgot to create a [mci] section in system.ini\n",
525 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
530 /* FIXME: should also check that module's description is of the form
531 * MODULENAME:[MCI] comment
534 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
535 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
536 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
538 TRACE("Loaded driver %x (%s), type is %d, cmdTable=%08x\n",
539 wmd->hDriver, strDevTyp, modp.wType, modp.wCustomCommandTable);
541 wmd->lpstrDeviceType = strDevTyp;
542 wmd->wType = modp.wType;
544 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
545 modp.wDeviceID, modp.wType, modp.wDeviceID);
549 MCI_UnLoadMciDriver(wmd);
550 HeapFree(GetProcessHeap(), 0, strDevTyp);
555 /**************************************************************************
556 * MCI_FinishOpen [internal]
558 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSA lpParms,
561 if (dwParam & MCI_OPEN_ELEMENT)
563 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,strlen(lpParms->lpstrElementName)+1);
564 strcpy( wmd->lpstrElementName, lpParms->lpstrElementName );
566 if (dwParam & MCI_OPEN_ALIAS)
568 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, strlen(lpParms->lpstrAlias)+1);
569 strcpy( wmd->lpstrAlias, lpParms->lpstrAlias);
571 lpParms->wDeviceID = wmd->wDeviceID;
573 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
577 /**************************************************************************
578 * MCI_FindCommand [internal]
580 static LPCSTR MCI_FindCommand(UINT uTbl, LPCSTR verb)
584 if (uTbl >= MAX_MCICMDTABLE || S_MciCmdTable[uTbl].hMem == 0)
587 /* another improvement would be to have the aVerbs array sorted,
588 * so that we could use a dichotomic search on it, rather than this dumb
591 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
592 if (strcmp(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
593 return S_MciCmdTable[uTbl].aVerbs[idx];
599 /**************************************************************************
600 * MCI_GetReturnType [internal]
602 static DWORD MCI_GetReturnType(LPCSTR lpCmd)
604 lpCmd += strlen(lpCmd) + 1 + sizeof(DWORD) + sizeof(WORD);
605 if (*lpCmd == '\0' && *(LPWORD)(lpCmd + 1 + sizeof(DWORD)) == MCI_RETURN) {
606 return *(LPDWORD)(lpCmd + 1);
611 /**************************************************************************
612 * MCI_GetMessage [internal]
614 static WORD MCI_GetMessage(LPCSTR lpCmd)
616 return (WORD)*(LPDWORD)(lpCmd + strlen(lpCmd) + 1);
619 /**************************************************************************
620 * MCI_GetDWord [internal]
622 static BOOL MCI_GetDWord(LPDWORD data, LPSTR* ptr)
627 val = strtoul(*ptr, &ret, 0);
631 case ' ': ret++; break;
632 default: return FALSE;
640 /**************************************************************************
641 * MCI_GetString [internal]
643 static DWORD MCI_GetString(LPSTR* str, LPSTR* args)
647 /* see if we have a quoted string */
649 ptr = strchr(*str = ptr + 1, '"');
650 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
651 /* FIXME: shall we escape \" from string ?? */
652 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
653 *ptr++ = '\0'; /* remove trailing " */
654 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
657 ptr = strchr(ptr, ' ');
662 ptr = *args + strlen(*args);
671 #define MCI_DATA_SIZE 16
673 /**************************************************************************
674 * MCI_ParseOptArgs [internal]
676 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCSTR lpCmd,
677 LPSTR args, LPDWORD dwFlags)
681 DWORD dwRet, flg, cflg = 0;
685 /* loop on arguments */
688 found = inCst = FALSE;
691 /* skip any leading white space(s) */
692 while (*args == ' ') args++;
693 TRACE("args='%s' offset=%d\n", args, offset);
695 do { /* loop on options for command table for the requested verb */
697 lmem += (len = strlen(lmem)) + 1;
698 flg = *(LPDWORD)lmem;
699 eid = *(LPWORD)(lmem + sizeof(DWORD));
700 lmem += sizeof(DWORD) + sizeof(WORD);
701 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
705 inCst = TRUE; cflg = flg; break;
706 case MCI_END_CONSTANT:
707 /* there may be additional integral values after flag in constant */
708 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
711 inCst = FALSE; cflg = 0;
715 if (strncasecmp(args, str, len) == 0 &&
716 (args[len] == 0 || args[len] == ' ')) {
717 /* store good values into data[] */
719 while (*args == ' ') args++;
723 case MCI_COMMAND_HEAD:
725 case MCI_END_COMMAND:
726 case MCI_END_COMMAND_LIST:
727 case MCI_CONSTANT: /* done above */
728 case MCI_END_CONSTANT: /* done above */
740 if (!MCI_GetDWord(&(data[offset]), &args)) {
741 return MCIERR_BAD_INTEGER;
746 /* store rect in data (offset...offset+3) */
748 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
749 !MCI_GetDWord(&(data[offset+1]), &args) ||
750 !MCI_GetDWord(&(data[offset+2]), &args) ||
751 !MCI_GetDWord(&(data[offset+3]), &args)) {
752 ERR("Bad rect '%s'\n", args);
753 return MCIERR_BAD_INTEGER;
758 if ((dwRet = MCI_GetString((LPSTR*)&data[offset], &args)))
761 default: ERR("oops\n");
763 /* exit inside while loop, except if just entered in constant area definition */
764 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
766 /* have offset incremented if needed */
768 case MCI_COMMAND_HEAD:
770 case MCI_END_COMMAND:
771 case MCI_END_COMMAND_LIST:
773 case MCI_FLAG: break;
774 case MCI_INTEGER: if (!inCst) offset++; break;
775 case MCI_END_CONSTANT:
776 case MCI_STRING: offset++; break;
777 case MCI_RECT: offset += 4; break;
778 default: ERR("oops\n");
781 } while (eid != MCI_END_COMMAND);
783 WARN("Optarg '%s' not found\n", args);
784 return MCIERR_UNRECOGNIZED_COMMAND;
786 if (offset == MCI_DATA_SIZE) {
787 ERR("Internal data[] buffer overflow\n");
788 return MCIERR_PARSER_INTERNAL;
794 /**************************************************************************
795 * MCI_HandleReturnValues [internal]
797 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
798 LPDWORD data, LPSTR lpstrRet, UINT uRetLen)
802 case 0: /* nothing to return */
805 switch (dwRet & 0xFFFF0000ul) {
807 case MCI_INTEGER_RETURNED:
808 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
810 case MCI_RESOURCE_RETURNED:
811 /* return string which ID is HIWORD(data[1]),
812 * string is loaded from mmsystem.dll */
813 LoadStringA(WINMM_IData->hWinMM32Instance, HIWORD(data[1]),
816 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
817 /* return string which ID is HIWORD(data[1]),
818 * string is loaded from driver */
819 /* FIXME: this is wrong for a 16 bit handle */
820 LoadStringA(GetDriverModuleHandle(wmd->hDriver),
821 HIWORD(data[1]), lpstrRet, uRetLen);
823 case MCI_COLONIZED3_RETURN:
824 snprintf(lpstrRet, uRetLen, "%d:%d:%d",
825 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
826 LOBYTE(HIWORD(data[1])));
828 case MCI_COLONIZED4_RETURN:
829 snprintf(lpstrRet, uRetLen, "%d:%d:%d:%d",
830 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
831 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
833 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
837 switch (dwRet & 0xFFFF0000ul) {
839 /* nothing to do data[1] == lpstrRet */
841 case MCI_INTEGER_RETURNED:
842 data[1] = *(LPDWORD)lpstrRet;
843 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
846 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
851 if (dwRet & 0xFFFF0000ul)
852 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
853 snprintf(lpstrRet, uRetLen, "%ld %ld %ld %ld",
854 data[1], data[2], data[3], data[4]);
856 default: ERR("oops\n");
859 return LOWORD(dwRet);
862 /**************************************************************************
863 * mciSendStringA [WINMM.@]
865 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
866 UINT uRetLen, HWND hwndCallback)
868 LPSTR verb, dev, args;
869 LPWINE_MCIDRIVER wmd = 0;
870 DWORD dwFlags = 0, dwRet = 0;
872 DWORD data[MCI_DATA_SIZE];
875 LPSTR devAlias = NULL;
876 BOOL bAutoOpen = FALSE;
878 TRACE("('%s', %p, %d, %X)\n", lpstrCommand, lpstrRet, uRetLen, hwndCallback);
880 /* format is <command> <device> <optargs> */
881 if (!(verb = HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand)+1)))
882 return MCIERR_OUT_OF_MEMORY;
883 strcpy( verb, lpstrCommand );
885 memset(data, 0, sizeof(data));
887 if (!(args = strchr(verb, ' '))) {
888 dwRet = MCIERR_MISSING_DEVICE_NAME;
892 if ((dwRet = MCI_GetString(&dev, &args))) {
896 /* case dev == 'new' has to be handled */
897 if (!strcasecmp(dev, "new")) {
898 FIXME("'new': NIY as device name\n");
899 dwRet = MCIERR_MISSING_DEVICE_NAME;
903 /* otherwise, try to grab devType from open */
904 if (!strcmp(verb, "open")) {
907 if ((devType = strchr(dev, '!')) != NULL) {
909 tmp = devType; devType = dev; dev = tmp;
911 dwFlags |= MCI_OPEN_TYPE;
912 data[2] = (DWORD)devType;
913 devType = str_dup_upper(devType);
914 dwFlags |= MCI_OPEN_ELEMENT;
915 data[3] = (DWORD)dev;
916 } else if (strchr(dev, '.') == NULL) {
917 tmp = strchr(dev,' ');
918 if (tmp) *tmp = '\0';
919 data[2] = (DWORD)dev;
920 devType = str_dup_upper(dev);
922 dwFlags |= MCI_OPEN_TYPE;
924 if ((devType = strstr(args, "type ")) != NULL) {
926 tmp = strchr(devType, ' ');
927 if (tmp) *tmp = '\0';
928 devType = str_dup_upper(devType);
930 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
933 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
936 devType = str_dup_upper(buf);
938 dwFlags |= MCI_OPEN_ELEMENT;
939 data[3] = (DWORD)dev;
941 if ((devAlias = strstr(args," alias "))) {
944 if (!(tmp = strchr(devAlias,' '))) tmp = devAlias + strlen(devAlias);
945 if (tmp) *tmp = '\0';
946 tmp2 = HeapAlloc(GetProcessHeap(), 0, tmp - devAlias + 1 );
947 memcpy( tmp2, devAlias, tmp - devAlias );
948 tmp2[tmp - devAlias] = 0;
949 data[4] = (DWORD)tmp2;
950 /* should be done in regular options parsing */
951 /* dwFlags |= MCI_OPEN_ALIAS; */
954 dwRet = MCI_LoadMciDriver(devType, &wmd);
955 HeapFree(GetProcessHeap(), 0, devType);
957 MCI_UnLoadMciDriver(wmd);
960 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDA(dev)))) {
963 sprintf(buf, "open %s wait", dev);
965 if ((dwRet = mciSendStringA(buf, NULL, 0, 0)) != 0)
968 wmd = MCI_GetDriver(mciGetDeviceIDA(dev));
970 /* FIXME: memory leak, MCI driver is not closed */
971 dwRet = MCIERR_INVALID_DEVICE_ID;
976 /* get the verb in the different command tables */
978 /* try the device specific command table */
979 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
981 /* try the type specific command table */
982 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
983 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
984 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
985 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
988 /* try core command table */
989 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
992 TRACE("Command '%s' not found!\n", verb);
993 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
997 /* set up call back */
998 if (hwndCallback != 0) {
999 dwFlags |= MCI_NOTIFY;
1000 data[0] = (DWORD)hwndCallback;
1003 /* set return information */
1004 switch (retType = MCI_GetReturnType(lpCmd)) {
1005 case 0: offset = 1; break;
1006 case MCI_INTEGER: offset = 2; break;
1007 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1008 case MCI_RECT: offset = 5; break;
1009 default: ERR("oops\n");
1012 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb, dev, offset);
1014 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1017 if (bAutoOpen && (dwFlags & MCI_NOTIFY)) {
1018 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1021 /* FIXME: the command should get it's own notification window set up and
1022 * ask for device closing while processing the notification mechanism
1024 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1026 #define STR_OF(_x) (IsBadReadPtr((char*)_x,1)?"?":(char*)(_x))
1027 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1028 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1029 data[0], STR_OF(data[0]), data[1], STR_OF(data[1]),
1030 data[2], STR_OF(data[2]), data[3], STR_OF(data[3]),
1031 data[4], STR_OF(data[4]), data[5], STR_OF(data[5]));
1034 if (strcmp(verb, "open") == 0) {
1035 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSA)data, dwFlags)))
1036 MCI_UnLoadMciDriver(wmd);
1037 /* FIXME: notification is not properly shared across two opens */
1039 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
1041 TRACE("=> 1/ %lx (%s)\n", dwRet, lpstrRet);
1042 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1043 TRACE("=> 2/ %lx (%s)\n", dwRet, lpstrRet);
1046 HeapFree(GetProcessHeap(), 0, verb);
1047 HeapFree(GetProcessHeap(), 0, devAlias);
1051 /**************************************************************************
1052 * mciSendStringW [WINMM.@]
1054 DWORD WINAPI mciSendStringW(LPCWSTR lpwstrCommand, LPSTR lpstrRet,
1055 UINT uRetLen, HWND hwndCallback)
1061 /* FIXME: is there something to do with lpstrReturnString ? */
1062 len = WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, NULL, 0, NULL, NULL );
1063 lpstrCommand = HeapAlloc( GetProcessHeap(), 0, len );
1064 WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, lpstrCommand, len, NULL, NULL );
1065 ret = mciSendStringA(lpstrCommand, lpstrRet, uRetLen, hwndCallback);
1066 HeapFree(GetProcessHeap(), 0, lpstrCommand);
1070 /**************************************************************************
1071 * mciExecute [WINMM.@]
1072 * mciExecute [MMSYSTEM.712]
1074 DWORD WINAPI mciExecute(LPCSTR lpstrCommand)
1079 TRACE("(%s)!\n", lpstrCommand);
1081 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1083 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1084 sprintf(strRet, "Unknown MCI error (%ld)", ret);
1086 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1088 /* FIXME: what shall I return ? */
1092 /**************************************************************************
1093 * mciLoadCommandResource [WINMM.@]
1095 * Strangely, this function only exists as an UNICODE one.
1097 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1101 UINT16 ret = MCI_NO_COMMAND_TABLE;
1103 TRACE("(%04x, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1105 /* if a file named "resname.mci" exits, then load resource "resname" from it
1106 * otherwise directly from driver
1107 * We don't support it (who uses this feature ?), but we check anyway
1111 /* FIXME: we should put this back into order, but I never found a program
1112 * actually using this feature, so we not need it
1117 strcat(strcpy(buf, resname), ".mci");
1118 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1119 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1123 if (!(hRsrc = FindResourceW(hInst, resNameW, (LPCWSTR)RT_RCDATAA))) {
1124 WARN("No command table found in resource\n");
1125 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1126 ret = MCI_SetCommandTable(hMem, type);
1128 WARN("Couldn't load resource.\n");
1130 TRACE("=> %04x\n", ret);
1134 /**************************************************************************
1135 * mciFreeCommandResource [WINMM.@]
1137 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1139 TRACE("(%08x)!\n", uTable);
1141 return MCI_DeleteCommandTable(uTable);
1144 /**************************************************************************
1145 * MCI_SendCommandFrom32 [internal]
1147 DWORD MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1149 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1150 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1154 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1158 switch (res = MCI_MapMsg32ATo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1159 case WINMM_MAP_MSGERROR:
1160 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1161 dwRet = MCIERR_DRIVER_INTERNAL;
1163 case WINMM_MAP_NOMEM:
1164 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1165 dwRet = MCIERR_OUT_OF_MEMORY;
1168 case WINMM_MAP_OKMEM:
1169 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1170 if (res == WINMM_MAP_OKMEM)
1171 MCI_UnMapMsg32ATo16(wmd->wType, wMsg, dwParam1, dwParam2);
1179 /**************************************************************************
1180 * MCI_SendCommandFrom16 [internal]
1182 DWORD MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1184 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1185 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1188 dwRet = MCIERR_INVALID_DEVICE_ID;
1193 switch (res = MCI_MapMsg16To32A(wmd->wType, wMsg, &dwParam2)) {
1194 case WINMM_MAP_MSGERROR:
1195 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1196 dwRet = MCIERR_DRIVER_INTERNAL;
1198 case WINMM_MAP_NOMEM:
1199 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1200 dwRet = MCIERR_OUT_OF_MEMORY;
1203 case WINMM_MAP_OKMEM:
1204 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1205 if (res == WINMM_MAP_OKMEM)
1206 MCI_UnMapMsg16To32A(wmd->wType, wMsg, dwParam2);
1210 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1216 /**************************************************************************
1217 * MCI_Open [internal]
1219 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
1221 char strDevTyp[128];
1223 LPWINE_MCIDRIVER wmd = NULL;
1225 TRACE("(%08lX, %p)\n", dwParam, lpParms);
1226 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1228 /* only two low bytes are generic, the other ones are dev type specific */
1229 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1230 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1231 MCI_NOTIFY|MCI_WAIT)
1232 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1233 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1235 #undef WINE_MCIDRIVER_SUPP
1239 if (dwParam & MCI_OPEN_TYPE) {
1240 if (dwParam & MCI_OPEN_TYPE_ID) {
1241 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
1243 if (uDevType < MCI_DEVTYPE_FIRST ||
1244 uDevType > MCI_DEVTYPE_LAST ||
1245 !LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
1246 dwRet = MCIERR_BAD_INTEGER;
1251 if (lpParms->lpstrDeviceType == NULL) {
1252 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1255 strcpy(strDevTyp, lpParms->lpstrDeviceType);
1256 ptr = strchr(strDevTyp, '!');
1258 /* this behavior is not documented in windows. However, since, in
1259 * some occasions, MCI_OPEN handling is translated by WinMM into
1260 * a call to mciSendString("open <type>"); this code shall be correct
1262 if (dwParam & MCI_OPEN_ELEMENT) {
1263 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1264 lpParms->lpstrElementName, strDevTyp);
1265 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1268 dwParam |= MCI_OPEN_ELEMENT;
1270 /* FIXME: not a good idea to write in user supplied buffer */
1271 lpParms->lpstrElementName = ptr;
1275 TRACE("devType='%s' !\n", strDevTyp);
1278 if (dwParam & MCI_OPEN_ELEMENT) {
1279 TRACE("lpstrElementName='%s'\n", lpParms->lpstrElementName);
1281 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1282 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1283 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1287 if (!lpParms->lpstrElementName) {
1288 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1292 /* type, if given as a parameter, supersedes file extension */
1293 if (!strDevTyp[0] &&
1294 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1295 strDevTyp, sizeof(strDevTyp))) {
1296 if (GetDriveTypeA(lpParms->lpstrElementName) != DRIVE_CDROM) {
1297 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1300 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1301 strcpy(strDevTyp, "CDAUDIO");
1305 if (strDevTyp[0] == 0) {
1306 FIXME("Couldn't load driver\n");
1307 dwRet = MCIERR_INVALID_DEVICE_NAME;
1311 if (dwParam & MCI_OPEN_ALIAS) {
1312 TRACE("Alias='%s' !\n", lpParms->lpstrAlias);
1313 if (!lpParms->lpstrAlias) {
1314 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1319 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1323 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1324 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet);
1325 /* FIXME: is dwRet the correct ret code ? */
1329 /* only handled devices fall through */
1330 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1332 if (dwParam & MCI_NOTIFY)
1333 mciDriverNotify(lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1337 if (wmd) MCI_UnLoadMciDriver(wmd);
1339 if (dwParam & MCI_NOTIFY)
1340 mciDriverNotify(lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1344 /**************************************************************************
1345 * MCI_Close [internal]
1347 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1350 LPWINE_MCIDRIVER wmd;
1352 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
1354 if (wDevID == MCI_ALL_DEVICE_ID) {
1355 LPWINE_MCIDRIVER next;
1357 EnterCriticalSection(&WINMM_IData->cs);
1358 /* FIXME: shall I notify once after all is done, or for
1359 * each of the open drivers ? if the latest, which notif
1360 * to return when only one fails ?
1362 for (wmd = WINMM_IData->lpMciDrvs; wmd; ) {
1364 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
1367 LeaveCriticalSection(&WINMM_IData->cs);
1371 if (!(wmd = MCI_GetDriver(wDevID))) {
1372 return MCIERR_INVALID_DEVICE_ID;
1375 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
1377 MCI_UnLoadMciDriver(wmd);
1379 if (dwParam & MCI_NOTIFY)
1380 mciDriverNotify(lpParms->dwCallback, wDevID,
1381 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1386 /**************************************************************************
1387 * MCI_WriteString [internal]
1389 DWORD MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr)
1394 if (dstSize <= strlen(lpSrcStr)) {
1395 lstrcpynA(lpDstStr, lpSrcStr, dstSize - 1);
1396 ret = MCIERR_PARAM_OVERFLOW;
1398 strcpy(lpDstStr, lpSrcStr);
1406 /**************************************************************************
1407 * MCI_Sysinfo [internal]
1409 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParms)
1411 DWORD ret = MCIERR_INVALID_DEVICE_ID;
1412 LPWINE_MCIDRIVER wmd;
1414 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1416 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1417 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1419 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1420 case MCI_SYSINFO_QUANTITY:
1424 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST ||
1425 lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1426 if (dwFlags & MCI_SYSINFO_OPEN) {
1427 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1428 EnterCriticalSection(&WINMM_IData->cs);
1429 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1432 LeaveCriticalSection(&WINMM_IData->cs);
1434 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1435 cnt = MCI_InstalledCount;
1438 if (dwFlags & MCI_SYSINFO_OPEN) {
1439 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
1440 lpParms->wDeviceType);
1441 EnterCriticalSection(&WINMM_IData->cs);
1442 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1443 if (wmd->wType == lpParms->wDeviceType)
1446 LeaveCriticalSection(&WINMM_IData->cs);
1448 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
1449 lpParms->wDeviceType);
1450 FIXME("Don't know how to get # of MCI devices of a given type\n");
1454 *(DWORD*)lpParms->lpstrReturn = cnt;
1456 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1457 ret = MCI_INTEGER_RETURNED;
1459 case MCI_SYSINFO_INSTALLNAME:
1460 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1461 if ((wmd = MCI_GetDriver(uDevID))) {
1462 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1463 wmd->lpstrDeviceType);
1465 *lpParms->lpstrReturn = 0;
1466 ret = MCIERR_INVALID_DEVICE_ID;
1468 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1470 case MCI_SYSINFO_NAME:
1471 TRACE("MCI_SYSINFO_NAME\n");
1472 if (dwFlags & MCI_SYSINFO_OPEN) {
1473 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1474 ret = MCIERR_UNRECOGNIZED_COMMAND;
1475 } else if (lpParms->dwNumber > MCI_InstalledCount) {
1476 ret = MCIERR_OUTOFRANGE;
1478 DWORD count = lpParms->dwNumber;
1479 LPSTR ptr = MCI_lpInstallNames;
1481 while (--count > 0) ptr += strlen(ptr) + 1;
1482 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, ptr);
1484 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1487 TRACE("Unsupported flag value=%08lx\n", dwFlags);
1488 ret = MCIERR_UNRECOGNIZED_COMMAND;
1493 /**************************************************************************
1494 * MCI_Break [internal]
1496 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1500 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1502 if (dwFlags & MCI_NOTIFY)
1503 mciDriverNotify(lpParms->dwCallback, wDevID,
1504 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1509 /**************************************************************************
1510 * MCI_SendCommand [internal]
1512 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
1513 DWORD dwParam2, BOOL bFrom32)
1515 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1520 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1522 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
1524 case WINMM_MAP_OKMEM:
1525 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1526 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
1528 default: break; /* so that gcc does not bark */
1534 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1536 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
1538 case WINMM_MAP_OKMEM:
1539 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1540 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
1542 default: break; /* so that gcc does not bark */
1548 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1550 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
1552 case WINMM_MAP_OKMEM:
1553 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1554 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
1556 default: break; /* so that gcc doesnot bark */
1562 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1564 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
1566 case WINMM_MAP_OKMEM:
1567 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1568 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
1570 default: break; /* so that gcc does not bark */
1575 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
1576 * but I couldn't get any doc on this MCI message
1580 if (wDevID == MCI_ALL_DEVICE_ID) {
1581 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1582 dwRet = MCIERR_CANNOT_USE_ALL;
1585 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
1586 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
1593 /**************************************************************************
1594 * MCI_CleanUp [internal]
1596 * Some MCI commands need to be cleaned-up (when not called from
1597 * mciSendString), because MCI drivers return extra information for string
1598 * transformation. This function gets rid of them.
1600 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2, BOOL bIs32)
1603 return LOWORD(dwRet);
1606 case MCI_GETDEVCAPS:
1607 switch (dwRet & 0xFFFF0000ul) {
1609 case MCI_COLONIZED3_RETURN:
1610 case MCI_COLONIZED4_RETURN:
1611 case MCI_INTEGER_RETURNED:
1614 case MCI_RESOURCE_RETURNED:
1615 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1617 LPMCI_GETDEVCAPS_PARMS lmgp;
1619 lmgp = (LPMCI_GETDEVCAPS_PARMS)(bIs32 ? (void*)dwParam2 : MapSL(dwParam2));
1620 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
1621 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1625 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1626 HIWORD(dwRet), MCI_MessageToString(wMsg));
1630 switch (dwRet & 0xFFFF0000ul) {
1632 case MCI_COLONIZED3_RETURN:
1633 case MCI_COLONIZED4_RETURN:
1634 case MCI_INTEGER_RETURNED:
1637 case MCI_RESOURCE_RETURNED:
1638 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1640 LPMCI_STATUS_PARMS lsp;
1642 lsp = (LPMCI_STATUS_PARMS)(bIs32 ? (void*)dwParam2 : MapSL(dwParam2));
1643 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
1644 lsp->dwReturn = LOWORD(lsp->dwReturn);
1648 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1649 HIWORD(dwRet), MCI_MessageToString(wMsg));
1653 switch (dwRet & 0xFFFF0000ul) {
1655 case MCI_INTEGER_RETURNED:
1659 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
1663 if (HIWORD(dwRet)) {
1664 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1665 dwRet, MCI_MessageToString(wMsg));
1669 return LOWORD(dwRet);
1672 /**************************************************************************
1673 * MULTIMEDIA_MciInit [internal]
1675 * Initializes the MCI internal variables.
1678 BOOL MULTIMEDIA_MciInit(void)
1687 MCI_InstalledCount = 0;
1688 ptr1 = MCI_lpInstallNames = HeapAlloc(GetProcessHeap(), 0, count);
1690 if (!MCI_lpInstallNames)
1693 /* FIXME: should do also some registry diving here ? */
1694 if (!(err = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", &hWineConf)) &&
1695 !(err = RegOpenKeyA(hWineConf, "options", &hkey))) {
1696 err = RegQueryValueExA(hkey, "mci", 0, &type, MCI_lpInstallNames, &count);
1701 TRACE("Wine => '%s' \n", ptr1);
1702 while ((ptr2 = strchr(ptr1, ':')) != 0) {
1704 TRACE("---> '%s' \n", ptr1);
1705 MCI_InstalledCount++;
1708 MCI_InstalledCount++;
1709 TRACE("---> '%s' \n", ptr1);
1710 ptr1 += strlen(ptr1) + 1;
1712 GetPrivateProfileStringA("mci", NULL, "", MCI_lpInstallNames, count, "SYSTEM.INI");
1713 while (strlen(ptr1) > 0) {
1714 TRACE("---> '%s' \n", ptr1);
1715 ptr1 += strlen(ptr1) + 1;
1716 MCI_InstalledCount++;
1719 RegCloseKey(hWineConf);