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"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mci);
47 static int MCI_InstalledCount;
48 static LPSTR MCI_lpInstallNames /* = NULL */;
50 WINMM_MapType (*pFnMciMapMsg16To32A) (WORD,WORD,DWORD*) /* = NULL */;
51 WINMM_MapType (*pFnMciUnMapMsg16To32A)(WORD,WORD,DWORD) /* = NULL */;
52 WINMM_MapType (*pFnMciMapMsg32ATo16) (WORD,WORD,DWORD,DWORD*) /* = NULL */;
53 WINMM_MapType (*pFnMciUnMapMsg32ATo16)(WORD,WORD,DWORD,DWORD) /* = NULL */;
55 /* First MCI valid device ID (0 means error) */
56 #define MCI_MAGIC 0x0001
58 /* dup a string and uppercase it */
59 inline static LPSTR str_dup_upper( LPCSTR str )
61 INT len = strlen(str) + 1;
62 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
65 memcpy( p, str, len );
71 /**************************************************************************
72 * MCI_GetDriver [internal]
74 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
76 LPWINE_MCIDRIVER wmd = 0;
78 EnterCriticalSection(&WINMM_IData->cs);
79 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
80 if (wmd->wDeviceID == wDevID)
83 LeaveCriticalSection(&WINMM_IData->cs);
87 /**************************************************************************
88 * MCI_GetDriverFromString [internal]
90 UINT MCI_GetDriverFromString(LPCSTR lpstrName)
98 if (!lstrcmpiA(lpstrName, "ALL"))
99 return MCI_ALL_DEVICE_ID;
101 EnterCriticalSection(&WINMM_IData->cs);
102 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
103 if (wmd->lpstrElementName && strcmp(wmd->lpstrElementName, lpstrName) == 0) {
104 ret = wmd->wDeviceID;
107 if (wmd->lpstrDeviceType && strcasecmp(wmd->lpstrDeviceType, lpstrName) == 0) {
108 ret = wmd->wDeviceID;
111 if (wmd->lpstrAlias && strcasecmp(wmd->lpstrAlias, lpstrName) == 0) {
112 ret = wmd->wDeviceID;
116 LeaveCriticalSection(&WINMM_IData->cs);
121 /**************************************************************************
122 * MCI_MessageToString [internal]
124 const char* MCI_MessageToString(UINT16 wMsg)
126 static char buffer[100];
128 #define CASE(s) case (s): return #s
133 CASE(MCI_CLOSE_DRIVER);
142 CASE(MCI_GETDEVCAPS);
146 CASE(MCI_OPEN_DRIVER);
164 /* constants for digital video */
178 sprintf(buffer, "MCI_<<%04X>>", wMsg);
183 /**************************************************************************
184 * MCI_GetDevTypeFromFileName [internal]
186 static DWORD MCI_GetDevTypeFromFileName(LPCSTR fileName, LPSTR buf, UINT len)
191 if ((tmp = strrchr(fileName, '.'))) {
192 if (RegOpenKeyExA( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions",
193 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
195 LONG lRet = RegQueryValueExA( hKey, tmp + 1, 0, 0, buf, &dwLen );
197 if (lRet == ERROR_SUCCESS) return 0;
199 TRACE("No ...\\MCI Extensions entry for '%s' found.\n", tmp);
201 return MCIERR_EXTENSION_NOT_FOUND;
204 #define MAX_MCICMDTABLE 20
205 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
207 typedef struct tagWINE_MCICMDTABLE {
210 UINT nVerbs; /* number of verbs in command table */
211 LPCSTR* aVerbs; /* array of verbs to speed up the verb look up process */
212 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
214 static WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
216 /**************************************************************************
217 * MCI_IsCommandTableValid [internal]
219 static BOOL MCI_IsCommandTableValid(UINT uTbl)
227 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
228 uTbl, S_MciCmdTable[uTbl].lpTable, S_MciCmdTable[uTbl].uDevType);
230 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
233 lmem = S_MciCmdTable[uTbl].lpTable;
237 lmem += strlen(lmem) + 1;
238 flg = *(LPDWORD)lmem;
239 eid = *(LPWORD)(lmem + sizeof(DWORD));
240 lmem += sizeof(DWORD) + sizeof(WORD);
242 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
244 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
245 case MCI_STRING: if (inCst) return FALSE; break;
246 case MCI_INTEGER: if (!*str) return FALSE; break;
247 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
248 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
249 case MCI_FLAG: if (!*str) return FALSE; break;
250 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
251 case MCI_RECT: if (!*str || inCst) return FALSE; break;
252 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
253 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
254 default: return FALSE;
256 } while (eid != MCI_END_COMMAND_LIST);
257 } while (eid != MCI_END_COMMAND_LIST);
261 /**************************************************************************
262 * MCI_DumpCommandTable [internal]
264 static BOOL MCI_DumpCommandTable(UINT uTbl)
271 if (!MCI_IsCommandTableValid(uTbl)) {
272 ERR("Ooops: %d is not valid\n", uTbl);
276 lmem = S_MciCmdTable[uTbl].lpTable;
280 lmem += strlen(lmem) + 1;
281 flg = *(LPDWORD)lmem;
282 eid = *(LPWORD)(lmem + sizeof(DWORD));
283 TRACE("cmd='%s' %08lx %04x\n", str, flg, eid);
284 lmem += sizeof(DWORD) + sizeof(WORD);
285 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
286 TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : "");
287 } while (eid != MCI_END_COMMAND_LIST);
292 /**************************************************************************
293 * MCI_GetCommandTable [internal]
295 static UINT MCI_GetCommandTable(UINT uDevType)
301 /* first look up existing for existing devType */
302 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
303 if (S_MciCmdTable[uTbl].lpTable && S_MciCmdTable[uTbl].uDevType == uDevType)
307 /* well try to load id */
308 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
309 if (LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
312 } else if (uDevType == 0) {
315 uTbl = MCI_NO_COMMAND_TABLE;
317 HRSRC hRsrc = FindResourceA(WINMM_IData->hWinMM32Instance, str, (LPCSTR)RT_RCDATA);
320 if (hRsrc) hMem = LoadResource(WINMM_IData->hWinMM32Instance, hRsrc);
322 uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType);
324 WARN("No command table found in resource %p[%s]\n",
325 WINMM_IData->hWinMM32Instance, str);
328 TRACE("=> %d\n", uTbl);
332 /**************************************************************************
333 * MCI_SetCommandTable [internal]
335 UINT MCI_SetCommandTable(void *table, UINT uDevType)
338 static BOOL bInitDone = FALSE;
341 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
342 * can be called with 0 as a uDevType to retrieve it.
347 MCI_GetCommandTable(0);
350 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
351 if (!S_MciCmdTable[uTbl].lpTable) {
356 S_MciCmdTable[uTbl].uDevType = uDevType;
357 S_MciCmdTable[uTbl].lpTable = table;
360 MCI_DumpCommandTable(uTbl);
363 /* create the verbs table */
364 /* get # of entries */
365 lmem = S_MciCmdTable[uTbl].lpTable;
368 lmem += strlen(lmem) + 1;
369 eid = *(LPWORD)(lmem + sizeof(DWORD));
370 lmem += sizeof(DWORD) + sizeof(WORD);
371 if (eid == MCI_COMMAND_HEAD)
373 } while (eid != MCI_END_COMMAND_LIST);
375 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCSTR));
376 S_MciCmdTable[uTbl].nVerbs = count;
378 lmem = S_MciCmdTable[uTbl].lpTable;
382 lmem += strlen(lmem) + 1;
383 eid = *(LPWORD)(lmem + sizeof(DWORD));
384 lmem += sizeof(DWORD) + sizeof(WORD);
385 if (eid == MCI_COMMAND_HEAD)
386 S_MciCmdTable[uTbl].aVerbs[count++] = str;
387 } while (eid != MCI_END_COMMAND_LIST);
388 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
393 return MCI_NO_COMMAND_TABLE;
396 /**************************************************************************
397 * MCI_DeleteCommandTable [internal]
399 static BOOL MCI_DeleteCommandTable(UINT uTbl)
401 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
404 S_MciCmdTable[uTbl].lpTable = NULL;
405 if (S_MciCmdTable[uTbl].aVerbs) {
406 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
407 S_MciCmdTable[uTbl].aVerbs = 0;
412 /**************************************************************************
413 * MCI_UnLoadMciDriver [internal]
415 static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
417 LPWINE_MCIDRIVER* tmp;
422 CloseDriver(wmd->hDriver, 0, 0);
424 if (wmd->dwPrivate != 0)
425 WARN("Unloading mci driver with non nul dwPrivate field\n");
427 EnterCriticalSection(&WINMM_IData->cs);
428 for (tmp = &WINMM_IData->lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
434 LeaveCriticalSection(&WINMM_IData->cs);
436 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
437 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
438 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
440 HeapFree(GetProcessHeap(), 0, wmd);
444 /**************************************************************************
445 * MCI_OpenMciDriver [internal]
447 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCSTR drvTyp, LPARAM lp)
451 if (!DRIVER_GetLibName(drvTyp, "mci", libName, sizeof(libName)))
455 /* First load driver */
456 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
458 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32ATo16) {
461 switch (res = pFnMciMapMsg32ATo16(0, DRV_OPEN, 0, &lp)) {
462 case WINMM_MAP_MSGERROR:
463 TRACE("Not handled yet (DRV_OPEN)\n");
465 case WINMM_MAP_NOMEM:
466 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
469 case WINMM_MAP_OKMEM:
470 if ((wmd->hDriver = OpenDriverA(drvTyp, "mci", lp)))
472 if (res == WINMM_MAP_OKMEM)
473 pFnMciUnMapMsg32ATo16(0, DRV_OPEN, 0, lp);
477 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
480 /**************************************************************************
481 * MCI_LoadMciDriver [internal]
483 static DWORD MCI_LoadMciDriver(LPCSTR _strDevTyp, LPWINE_MCIDRIVER* lpwmd)
485 LPSTR strDevTyp = str_dup_upper(_strDevTyp);
486 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
487 MCI_OPEN_DRIVER_PARMSA modp;
490 if (!wmd || !strDevTyp) {
491 dwRet = MCIERR_OUT_OF_MEMORY;
495 wmd->lpfnYieldProc = MCI_DefYieldProc;
496 wmd->dwYieldData = VK_CANCEL;
497 wmd->CreatorThread = GetCurrentThreadId();
499 EnterCriticalSection(&WINMM_IData->cs);
500 /* wmd must be inserted in list before sending opening the driver, coz' it
501 * may want to lookup at wDevID
503 wmd->lpNext = WINMM_IData->lpMciDrvs;
504 WINMM_IData->lpMciDrvs = wmd;
506 for (modp.wDeviceID = MCI_MAGIC;
507 MCI_GetDriver(modp.wDeviceID) != 0;
510 wmd->wDeviceID = modp.wDeviceID;
512 LeaveCriticalSection(&WINMM_IData->cs);
514 TRACE("wDevID=%04X \n", modp.wDeviceID);
516 modp.lpstrParams = NULL;
518 if (!MCI_OpenMciDriver(wmd, strDevTyp, (LPARAM)&modp)) {
519 /* silence warning if all is used... some bogus program use commands like
522 if (strcasecmp(strDevTyp, "all") == 0) {
523 dwRet = MCIERR_CANNOT_USE_ALL;
525 FIXME("Couldn't load driver for type %s.\n"
526 "If you don't have a windows installation accessible from Wine,\n"
527 "you perhaps forgot to create a [mci] section in system.ini\n",
529 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
534 /* FIXME: should also check that module's description is of the form
535 * MODULENAME:[MCI] comment
538 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
539 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
540 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
542 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
543 wmd->hDriver, strDevTyp, modp.wType, modp.wCustomCommandTable);
545 wmd->lpstrDeviceType = strDevTyp;
546 wmd->wType = modp.wType;
548 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
549 modp.wDeviceID, modp.wType, modp.wDeviceID);
553 MCI_UnLoadMciDriver(wmd);
554 HeapFree(GetProcessHeap(), 0, strDevTyp);
559 /**************************************************************************
560 * MCI_FinishOpen [internal]
562 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSA lpParms,
565 if (dwParam & MCI_OPEN_ELEMENT)
567 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,strlen(lpParms->lpstrElementName)+1);
568 strcpy( wmd->lpstrElementName, lpParms->lpstrElementName );
570 if (dwParam & MCI_OPEN_ALIAS)
572 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, strlen(lpParms->lpstrAlias)+1);
573 strcpy( wmd->lpstrAlias, lpParms->lpstrAlias);
575 lpParms->wDeviceID = wmd->wDeviceID;
577 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
581 /**************************************************************************
582 * MCI_FindCommand [internal]
584 static LPCSTR MCI_FindCommand(UINT uTbl, LPCSTR verb)
588 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
591 /* another improvement would be to have the aVerbs array sorted,
592 * so that we could use a dichotomic search on it, rather than this dumb
595 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
596 if (strcmp(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
597 return S_MciCmdTable[uTbl].aVerbs[idx];
603 /**************************************************************************
604 * MCI_GetReturnType [internal]
606 static DWORD MCI_GetReturnType(LPCSTR lpCmd)
608 lpCmd += strlen(lpCmd) + 1 + sizeof(DWORD) + sizeof(WORD);
609 if (*lpCmd == '\0' && *(LPWORD)(lpCmd + 1 + sizeof(DWORD)) == MCI_RETURN) {
610 return *(LPDWORD)(lpCmd + 1);
615 /**************************************************************************
616 * MCI_GetMessage [internal]
618 static WORD MCI_GetMessage(LPCSTR lpCmd)
620 return (WORD)*(LPDWORD)(lpCmd + strlen(lpCmd) + 1);
623 /**************************************************************************
624 * MCI_GetDWord [internal]
626 static BOOL MCI_GetDWord(LPDWORD data, LPSTR* ptr)
631 val = strtoul(*ptr, &ret, 0);
635 case ' ': ret++; break;
636 default: return FALSE;
644 /**************************************************************************
645 * MCI_GetString [internal]
647 static DWORD MCI_GetString(LPSTR* str, LPSTR* args)
651 /* see if we have a quoted string */
653 ptr = strchr(*str = ptr + 1, '"');
654 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
655 /* FIXME: shall we escape \" from string ?? */
656 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
657 *ptr++ = '\0'; /* remove trailing " */
658 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
661 ptr = strchr(ptr, ' ');
666 ptr = *args + strlen(*args);
675 #define MCI_DATA_SIZE 16
677 /**************************************************************************
678 * MCI_ParseOptArgs [internal]
680 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCSTR lpCmd,
681 LPSTR args, LPDWORD dwFlags)
685 DWORD dwRet, flg, cflg = 0;
689 /* loop on arguments */
692 found = inCst = FALSE;
695 /* skip any leading white space(s) */
696 while (*args == ' ') args++;
697 TRACE("args='%s' offset=%d\n", args, offset);
699 do { /* loop on options for command table for the requested verb */
701 lmem += (len = strlen(lmem)) + 1;
702 flg = *(LPDWORD)lmem;
703 eid = *(LPWORD)(lmem + sizeof(DWORD));
704 lmem += sizeof(DWORD) + sizeof(WORD);
705 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
709 inCst = TRUE; cflg = flg; break;
710 case MCI_END_CONSTANT:
711 /* there may be additional integral values after flag in constant */
712 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
715 inCst = FALSE; cflg = 0;
719 if (strncasecmp(args, str, len) == 0 &&
720 (args[len] == 0 || args[len] == ' ')) {
721 /* store good values into data[] */
723 while (*args == ' ') args++;
727 case MCI_COMMAND_HEAD:
729 case MCI_END_COMMAND:
730 case MCI_END_COMMAND_LIST:
731 case MCI_CONSTANT: /* done above */
732 case MCI_END_CONSTANT: /* done above */
744 if (!MCI_GetDWord(&(data[offset]), &args)) {
745 return MCIERR_BAD_INTEGER;
750 /* store rect in data (offset...offset+3) */
752 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
753 !MCI_GetDWord(&(data[offset+1]), &args) ||
754 !MCI_GetDWord(&(data[offset+2]), &args) ||
755 !MCI_GetDWord(&(data[offset+3]), &args)) {
756 ERR("Bad rect '%s'\n", args);
757 return MCIERR_BAD_INTEGER;
762 if ((dwRet = MCI_GetString((LPSTR*)&data[offset], &args)))
765 default: ERR("oops\n");
767 /* exit inside while loop, except if just entered in constant area definition */
768 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
770 /* have offset incremented if needed */
772 case MCI_COMMAND_HEAD:
774 case MCI_END_COMMAND:
775 case MCI_END_COMMAND_LIST:
777 case MCI_FLAG: break;
778 case MCI_INTEGER: if (!inCst) offset++; break;
779 case MCI_END_CONSTANT:
780 case MCI_STRING: offset++; break;
781 case MCI_RECT: offset += 4; break;
782 default: ERR("oops\n");
785 } while (eid != MCI_END_COMMAND);
787 WARN("Optarg '%s' not found\n", args);
788 return MCIERR_UNRECOGNIZED_COMMAND;
790 if (offset == MCI_DATA_SIZE) {
791 ERR("Internal data[] buffer overflow\n");
792 return MCIERR_PARSER_INTERNAL;
798 /**************************************************************************
799 * MCI_HandleReturnValues [internal]
801 static DWORD MCI_HandleReturnValues(DWORD dwRet, LPWINE_MCIDRIVER wmd, DWORD retType,
802 LPDWORD data, LPSTR lpstrRet, UINT uRetLen)
806 case 0: /* nothing to return */
809 switch (dwRet & 0xFFFF0000ul) {
811 case MCI_INTEGER_RETURNED:
812 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
814 case MCI_RESOURCE_RETURNED:
815 /* return string which ID is HIWORD(data[1]),
816 * string is loaded from mmsystem.dll */
817 LoadStringA(WINMM_IData->hWinMM32Instance, HIWORD(data[1]),
820 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
821 /* return string which ID is HIWORD(data[1]),
822 * string is loaded from driver */
823 /* FIXME: this is wrong for a 16 bit handle */
824 LoadStringA(GetDriverModuleHandle(wmd->hDriver),
825 HIWORD(data[1]), lpstrRet, uRetLen);
827 case MCI_COLONIZED3_RETURN:
828 snprintf(lpstrRet, uRetLen, "%d:%d:%d",
829 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
830 LOBYTE(HIWORD(data[1])));
832 case MCI_COLONIZED4_RETURN:
833 snprintf(lpstrRet, uRetLen, "%d:%d:%d:%d",
834 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
835 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
837 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
841 switch (dwRet & 0xFFFF0000ul) {
843 /* nothing to do data[1] == lpstrRet */
845 case MCI_INTEGER_RETURNED:
846 data[1] = *(LPDWORD)lpstrRet;
847 snprintf(lpstrRet, uRetLen, "%ld", data[1]);
850 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
855 if (dwRet & 0xFFFF0000ul)
856 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
857 snprintf(lpstrRet, uRetLen, "%ld %ld %ld %ld",
858 data[1], data[2], data[3], data[4]);
860 default: ERR("oops\n");
863 return LOWORD(dwRet);
866 /**************************************************************************
867 * mciSendStringA [WINMM.@]
869 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
870 UINT uRetLen, HWND hwndCallback)
872 LPSTR verb, dev, args;
873 LPWINE_MCIDRIVER wmd = 0;
874 DWORD dwFlags = 0, dwRet = 0;
876 DWORD data[MCI_DATA_SIZE];
879 LPSTR devAlias = NULL;
880 BOOL bAutoOpen = FALSE;
882 TRACE("('%s', %p, %d, %p)\n", lpstrCommand, lpstrRet, uRetLen, hwndCallback);
884 /* format is <command> <device> <optargs> */
885 if (!(verb = HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand)+1)))
886 return MCIERR_OUT_OF_MEMORY;
887 strcpy( verb, lpstrCommand );
889 memset(data, 0, sizeof(data));
891 if (!(args = strchr(verb, ' '))) {
892 dwRet = MCIERR_MISSING_DEVICE_NAME;
896 if ((dwRet = MCI_GetString(&dev, &args))) {
900 /* case dev == 'new' has to be handled */
901 if (!strcasecmp(dev, "new")) {
902 FIXME("'new': NIY as device name\n");
903 dwRet = MCIERR_MISSING_DEVICE_NAME;
907 /* otherwise, try to grab devType from open */
908 if (!strcmp(verb, "open")) {
911 if ((devType = strchr(dev, '!')) != NULL) {
913 tmp = devType; devType = dev; dev = tmp;
915 dwFlags |= MCI_OPEN_TYPE;
916 data[2] = (DWORD)devType;
917 devType = str_dup_upper(devType);
918 dwFlags |= MCI_OPEN_ELEMENT;
919 data[3] = (DWORD)dev;
920 } else if (strchr(dev, '.') == NULL) {
921 tmp = strchr(dev,' ');
922 if (tmp) *tmp = '\0';
923 data[2] = (DWORD)dev;
924 devType = str_dup_upper(dev);
926 dwFlags |= MCI_OPEN_TYPE;
928 if ((devType = strstr(args, "type ")) != NULL) {
930 tmp = strchr(devType, ' ');
931 if (tmp) *tmp = '\0';
932 devType = str_dup_upper(devType);
934 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
937 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
940 devType = str_dup_upper(buf);
942 dwFlags |= MCI_OPEN_ELEMENT;
943 data[3] = (DWORD)dev;
945 if ((devAlias = strstr(args," alias "))) {
948 if (!(tmp = strchr(devAlias,' '))) tmp = devAlias + strlen(devAlias);
949 if (tmp) *tmp = '\0';
950 tmp2 = HeapAlloc(GetProcessHeap(), 0, tmp - devAlias + 1 );
951 memcpy( tmp2, devAlias, tmp - devAlias );
952 tmp2[tmp - devAlias] = 0;
953 data[4] = (DWORD)tmp2;
954 /* should be done in regular options parsing */
955 /* dwFlags |= MCI_OPEN_ALIAS; */
958 dwRet = MCI_LoadMciDriver(devType, &wmd);
959 HeapFree(GetProcessHeap(), 0, devType);
961 MCI_UnLoadMciDriver(wmd);
964 } else if (!(wmd = MCI_GetDriver(mciGetDeviceIDA(dev)))) {
967 sprintf(buf, "open %s wait", dev);
969 if ((dwRet = mciSendStringA(buf, NULL, 0, 0)) != 0)
972 wmd = MCI_GetDriver(mciGetDeviceIDA(dev));
974 /* FIXME: memory leak, MCI driver is not closed */
975 dwRet = MCIERR_INVALID_DEVICE_ID;
980 /* get the verb in the different command tables */
982 /* try the device specific command table */
983 lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
985 /* try the type specific command table */
986 if (wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
987 wmd->uTypeCmdTable = MCI_GetCommandTable(wmd->wType);
988 if (wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
989 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
992 /* try core command table */
993 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(0), verb);
996 TRACE("Command '%s' not found!\n", verb);
997 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1001 /* set up call back */
1002 if (hwndCallback != 0) {
1003 dwFlags |= MCI_NOTIFY;
1004 data[0] = (DWORD)hwndCallback;
1007 /* set return information */
1008 switch (retType = MCI_GetReturnType(lpCmd)) {
1009 case 0: offset = 1; break;
1010 case MCI_INTEGER: offset = 2; break;
1011 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
1012 case MCI_RECT: offset = 5; break;
1013 default: ERR("oops\n");
1016 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb, dev, offset);
1018 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
1021 if (bAutoOpen && (dwFlags & MCI_NOTIFY)) {
1022 dwRet = MCIERR_NOTIFY_ON_AUTO_OPEN;
1025 /* FIXME: the command should get it's own notification window set up and
1026 * ask for device closing while processing the notification mechanism
1028 if (lpstrRet && uRetLen) *lpstrRet = '\0';
1030 #define STR_OF(_x) (IsBadReadPtr((char*)_x,1)?"?":(char*)(_x))
1031 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1032 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
1033 data[0], STR_OF(data[0]), data[1], STR_OF(data[1]),
1034 data[2], STR_OF(data[2]), data[3], STR_OF(data[3]),
1035 data[4], STR_OF(data[4]), data[5], STR_OF(data[5]));
1038 if (strcmp(verb, "open") == 0) {
1039 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSA)data, dwFlags)))
1040 MCI_UnLoadMciDriver(wmd);
1041 /* FIXME: notification is not properly shared across two opens */
1043 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
1045 TRACE("=> 1/ %lx (%s)\n", dwRet, lpstrRet);
1046 dwRet = MCI_HandleReturnValues(dwRet, wmd, retType, data, lpstrRet, uRetLen);
1047 TRACE("=> 2/ %lx (%s)\n", dwRet, lpstrRet);
1050 HeapFree(GetProcessHeap(), 0, verb);
1051 HeapFree(GetProcessHeap(), 0, devAlias);
1055 /**************************************************************************
1056 * mciSendStringW [WINMM.@]
1058 DWORD WINAPI mciSendStringW(LPCWSTR lpwstrCommand, LPWSTR lpwstrRet,
1059 UINT uRetLen, HWND hwndCallback)
1062 LPSTR lpstrRet = NULL;
1066 /* FIXME: is there something to do with lpstrReturnString ? */
1067 len = WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, NULL, 0, NULL, NULL );
1068 lpstrCommand = HeapAlloc( GetProcessHeap(), 0, len );
1069 WideCharToMultiByte( CP_ACP, 0, lpwstrCommand, -1, lpstrCommand, len, NULL, NULL );
1072 lpstrRet = HeapAlloc(GetProcessHeap(), 0, uRetLen * sizeof(WCHAR));
1073 if (!lpstrRet) return MMSYSERR_NOMEM;
1075 ret = mciSendStringA(lpstrCommand, lpstrRet, uRetLen, hwndCallback);
1077 MultiByteToWideChar( CP_ACP, 0, lpstrRet, -1, lpwstrRet, uRetLen );
1078 HeapFree(GetProcessHeap(), 0, lpstrCommand);
1079 if (lpstrRet) HeapFree(GetProcessHeap(), 0, lpstrRet);
1083 /**************************************************************************
1084 * mciExecute [WINMM.@]
1085 * mciExecute [MMSYSTEM.712]
1087 DWORD WINAPI mciExecute(LPCSTR lpstrCommand)
1092 TRACE("(%s)!\n", lpstrCommand);
1094 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1096 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1097 sprintf(strRet, "Unknown MCI error (%ld)", ret);
1099 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1101 /* FIXME: what shall I return ? */
1105 /**************************************************************************
1106 * mciLoadCommandResource [WINMM.@]
1108 * Strangely, this function only exists as an UNICODE one.
1110 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1114 UINT16 ret = MCI_NO_COMMAND_TABLE;
1116 TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1118 /* if a file named "resname.mci" exits, then load resource "resname" from it
1119 * otherwise directly from driver
1120 * We don't support it (who uses this feature ?), but we check anyway
1124 /* FIXME: we should put this back into order, but I never found a program
1125 * actually using this feature, so we not need it
1130 strcat(strcpy(buf, resname), ".mci");
1131 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1132 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1136 if (!(hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA))) {
1137 WARN("No command table found in resource\n");
1138 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1139 ret = MCI_SetCommandTable(LockResource(hMem), type);
1141 WARN("Couldn't load resource.\n");
1143 TRACE("=> %04x\n", ret);
1147 /**************************************************************************
1148 * mciFreeCommandResource [WINMM.@]
1150 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1152 TRACE("(%08x)!\n", uTable);
1154 return MCI_DeleteCommandTable(uTable);
1157 /**************************************************************************
1158 * MCI_SendCommandFrom32 [internal]
1160 DWORD MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1162 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1163 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1167 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1168 } else if (pFnMciMapMsg32ATo16) {
1171 switch (res = pFnMciMapMsg32ATo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1172 case WINMM_MAP_MSGERROR:
1173 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1174 dwRet = MCIERR_DRIVER_INTERNAL;
1176 case WINMM_MAP_NOMEM:
1177 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1178 dwRet = MCIERR_OUT_OF_MEMORY;
1181 case WINMM_MAP_OKMEM:
1182 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1183 if (res == WINMM_MAP_OKMEM)
1184 pFnMciUnMapMsg32ATo16(wmd->wType, wMsg, dwParam1, dwParam2);
1192 /**************************************************************************
1193 * MCI_SendCommandFrom16 [internal]
1195 DWORD MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1197 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
1198 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1201 dwRet = MCIERR_INVALID_DEVICE_ID;
1203 if (wmd->bIs32 && pFnMciMapMsg16To32A) {
1206 switch (res = pFnMciMapMsg16To32A(wmd->wType, wMsg, &dwParam2)) {
1207 case WINMM_MAP_MSGERROR:
1208 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1209 dwRet = MCIERR_DRIVER_INTERNAL;
1211 case WINMM_MAP_NOMEM:
1212 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1213 dwRet = MCIERR_OUT_OF_MEMORY;
1216 case WINMM_MAP_OKMEM:
1217 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1218 if (res == WINMM_MAP_OKMEM)
1219 pFnMciUnMapMsg16To32A(wmd->wType, wMsg, dwParam2);
1223 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
1229 /**************************************************************************
1230 * MCI_Open [internal]
1232 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
1234 char strDevTyp[128];
1236 LPWINE_MCIDRIVER wmd = NULL;
1238 TRACE("(%08lX, %p)\n", dwParam, lpParms);
1239 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1241 /* only two low bytes are generic, the other ones are dev type specific */
1242 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1243 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1244 MCI_NOTIFY|MCI_WAIT)
1245 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
1246 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
1248 #undef WINE_MCIDRIVER_SUPP
1252 if (dwParam & MCI_OPEN_TYPE) {
1253 if (dwParam & MCI_OPEN_TYPE_ID) {
1254 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
1256 if (uDevType < MCI_DEVTYPE_FIRST ||
1257 uDevType > MCI_DEVTYPE_LAST ||
1258 !LoadStringA(WINMM_IData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
1259 dwRet = MCIERR_BAD_INTEGER;
1264 if (lpParms->lpstrDeviceType == NULL) {
1265 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1268 strcpy(strDevTyp, lpParms->lpstrDeviceType);
1269 ptr = strchr(strDevTyp, '!');
1271 /* this behavior is not documented in windows. However, since, in
1272 * some occasions, MCI_OPEN handling is translated by WinMM into
1273 * a call to mciSendString("open <type>"); this code shall be correct
1275 if (dwParam & MCI_OPEN_ELEMENT) {
1276 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1277 lpParms->lpstrElementName, strDevTyp);
1278 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1281 dwParam |= MCI_OPEN_ELEMENT;
1283 /* FIXME: not a good idea to write in user supplied buffer */
1284 lpParms->lpstrElementName = ptr;
1288 TRACE("devType='%s' !\n", strDevTyp);
1291 if (dwParam & MCI_OPEN_ELEMENT) {
1292 TRACE("lpstrElementName='%s'\n", lpParms->lpstrElementName);
1294 if (dwParam & MCI_OPEN_ELEMENT_ID) {
1295 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1296 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
1300 if (!lpParms->lpstrElementName) {
1301 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1305 /* type, if given as a parameter, supersedes file extension */
1306 if (!strDevTyp[0] &&
1307 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
1308 strDevTyp, sizeof(strDevTyp))) {
1309 if (GetDriveTypeA(lpParms->lpstrElementName) != DRIVE_CDROM) {
1310 dwRet = MCIERR_EXTENSION_NOT_FOUND;
1313 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1314 strcpy(strDevTyp, "CDAUDIO");
1318 if (strDevTyp[0] == 0) {
1319 FIXME("Couldn't load driver\n");
1320 dwRet = MCIERR_INVALID_DEVICE_NAME;
1324 if (dwParam & MCI_OPEN_ALIAS) {
1325 TRACE("Alias='%s' !\n", lpParms->lpstrAlias);
1326 if (!lpParms->lpstrAlias) {
1327 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
1332 if ((dwRet = MCI_LoadMciDriver(strDevTyp, &wmd))) {
1336 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
1337 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet);
1338 /* FIXME: is dwRet the correct ret code ? */
1342 /* only handled devices fall through */
1343 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
1345 if (dwParam & MCI_NOTIFY)
1346 mciDriverNotify((HWND)lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
1350 if (wmd) MCI_UnLoadMciDriver(wmd);
1352 if (dwParam & MCI_NOTIFY)
1353 mciDriverNotify((HWND)lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
1357 /**************************************************************************
1358 * MCI_Close [internal]
1360 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
1363 LPWINE_MCIDRIVER wmd;
1365 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
1367 if (wDevID == MCI_ALL_DEVICE_ID) {
1368 LPWINE_MCIDRIVER next;
1370 EnterCriticalSection(&WINMM_IData->cs);
1371 /* FIXME: shall I notify once after all is done, or for
1372 * each of the open drivers ? if the latest, which notif
1373 * to return when only one fails ?
1375 for (wmd = WINMM_IData->lpMciDrvs; wmd; ) {
1377 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
1380 LeaveCriticalSection(&WINMM_IData->cs);
1384 if (!(wmd = MCI_GetDriver(wDevID))) {
1385 return MCIERR_INVALID_DEVICE_ID;
1388 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
1390 MCI_UnLoadMciDriver(wmd);
1392 if (dwParam & MCI_NOTIFY)
1393 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1394 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1399 /**************************************************************************
1400 * MCI_WriteString [internal]
1402 DWORD MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr)
1407 if (dstSize <= strlen(lpSrcStr)) {
1408 lstrcpynA(lpDstStr, lpSrcStr, dstSize - 1);
1409 ret = MCIERR_PARAM_OVERFLOW;
1411 strcpy(lpDstStr, lpSrcStr);
1419 /**************************************************************************
1420 * MCI_Sysinfo [internal]
1422 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParms)
1424 DWORD ret = MCIERR_INVALID_DEVICE_ID;
1425 LPWINE_MCIDRIVER wmd;
1427 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1429 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1430 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
1432 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
1433 case MCI_SYSINFO_QUANTITY:
1437 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST ||
1438 lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
1439 if (dwFlags & MCI_SYSINFO_OPEN) {
1440 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1441 EnterCriticalSection(&WINMM_IData->cs);
1442 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1445 LeaveCriticalSection(&WINMM_IData->cs);
1447 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1448 cnt = MCI_InstalledCount;
1451 if (dwFlags & MCI_SYSINFO_OPEN) {
1452 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
1453 lpParms->wDeviceType);
1454 EnterCriticalSection(&WINMM_IData->cs);
1455 for (wmd = WINMM_IData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
1456 if (wmd->wType == lpParms->wDeviceType)
1459 LeaveCriticalSection(&WINMM_IData->cs);
1461 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
1462 lpParms->wDeviceType);
1463 FIXME("Don't know how to get # of MCI devices of a given type\n");
1467 *(DWORD*)lpParms->lpstrReturn = cnt;
1469 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
1470 ret = MCI_INTEGER_RETURNED;
1472 case MCI_SYSINFO_INSTALLNAME:
1473 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1474 if ((wmd = MCI_GetDriver(uDevID))) {
1475 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
1476 wmd->lpstrDeviceType);
1478 *lpParms->lpstrReturn = 0;
1479 ret = MCIERR_INVALID_DEVICE_ID;
1481 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1483 case MCI_SYSINFO_NAME:
1484 TRACE("MCI_SYSINFO_NAME\n");
1485 if (dwFlags & MCI_SYSINFO_OPEN) {
1486 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1487 ret = MCIERR_UNRECOGNIZED_COMMAND;
1488 } else if (lpParms->dwNumber > MCI_InstalledCount) {
1489 ret = MCIERR_OUTOFRANGE;
1491 DWORD count = lpParms->dwNumber;
1492 LPSTR ptr = MCI_lpInstallNames;
1494 while (--count > 0) ptr += strlen(ptr) + 1;
1495 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, ptr);
1497 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
1500 TRACE("Unsupported flag value=%08lx\n", dwFlags);
1501 ret = MCIERR_UNRECOGNIZED_COMMAND;
1506 /**************************************************************************
1507 * MCI_Break [internal]
1509 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
1513 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1515 if (dwFlags & MCI_NOTIFY)
1516 mciDriverNotify((HWND)lpParms->dwCallback, wDevID,
1517 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
1522 /**************************************************************************
1523 * MCI_SendCommand [internal]
1525 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
1526 DWORD dwParam2, BOOL bFrom32)
1528 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
1533 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1534 } else if (pFnMciMapMsg16To32A) {
1535 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1537 case WINMM_MAP_OKMEM:
1538 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
1539 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1541 default: break; /* so that gcc does not bark */
1547 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1548 } else if (pFnMciMapMsg16To32A) {
1549 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1551 case WINMM_MAP_OKMEM:
1552 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
1553 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1555 default: break; /* so that gcc does not bark */
1561 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1562 } else if (pFnMciMapMsg16To32A) {
1563 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1565 case WINMM_MAP_OKMEM:
1566 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
1567 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1569 default: break; /* so that gcc doesnot bark */
1575 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1576 } else if (pFnMciMapMsg16To32A) {
1577 switch (pFnMciMapMsg16To32A(0, wMsg, &dwParam2)) {
1579 case WINMM_MAP_OKMEM:
1580 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
1581 pFnMciUnMapMsg16To32A(0, wMsg, dwParam2);
1583 default: break; /* so that gcc does not bark */
1588 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
1589 * but I couldn't get any doc on this MCI message
1593 if (wDevID == MCI_ALL_DEVICE_ID) {
1594 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1595 dwRet = MCIERR_CANNOT_USE_ALL;
1598 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
1599 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
1606 /**************************************************************************
1607 * MCI_CleanUp [internal]
1609 * Some MCI commands need to be cleaned-up (when not called from
1610 * mciSendString), because MCI drivers return extra information for string
1611 * transformation. This function gets rid of them.
1613 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2)
1616 return LOWORD(dwRet);
1619 case MCI_GETDEVCAPS:
1620 switch (dwRet & 0xFFFF0000ul) {
1622 case MCI_COLONIZED3_RETURN:
1623 case MCI_COLONIZED4_RETURN:
1624 case MCI_INTEGER_RETURNED:
1627 case MCI_RESOURCE_RETURNED:
1628 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1630 LPMCI_GETDEVCAPS_PARMS lmgp;
1632 lmgp = (LPMCI_GETDEVCAPS_PARMS)(void*)dwParam2;
1633 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
1634 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
1638 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1639 HIWORD(dwRet), MCI_MessageToString(wMsg));
1643 switch (dwRet & 0xFFFF0000ul) {
1645 case MCI_COLONIZED3_RETURN:
1646 case MCI_COLONIZED4_RETURN:
1647 case MCI_INTEGER_RETURNED:
1650 case MCI_RESOURCE_RETURNED:
1651 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
1653 LPMCI_STATUS_PARMS lsp;
1655 lsp = (LPMCI_STATUS_PARMS)(void*)dwParam2;
1656 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
1657 lsp->dwReturn = LOWORD(lsp->dwReturn);
1661 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1662 HIWORD(dwRet), MCI_MessageToString(wMsg));
1666 switch (dwRet & 0xFFFF0000ul) {
1668 case MCI_INTEGER_RETURNED:
1672 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
1676 if (HIWORD(dwRet)) {
1677 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1678 dwRet, MCI_MessageToString(wMsg));
1682 return LOWORD(dwRet);
1685 /**************************************************************************
1686 * MCI_Init [internal]
1688 * Initializes the MCI internal variables.
1700 MCI_InstalledCount = 0;
1701 ptr1 = MCI_lpInstallNames = HeapAlloc(GetProcessHeap(), 0, count);
1703 if (!MCI_lpInstallNames)
1706 /* FIXME: should do also some registry diving here ? */
1707 if (!(err = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", &hWineConf)) &&
1708 !(err = RegOpenKeyA(hWineConf, "options", &hkey))) {
1709 err = RegQueryValueExA(hkey, "mci", 0, &type, MCI_lpInstallNames, &count);
1714 TRACE("Wine => '%s' \n", ptr1);
1715 while ((ptr2 = strchr(ptr1, ':')) != 0) {
1717 TRACE("---> '%s' \n", ptr1);
1718 MCI_InstalledCount++;
1721 MCI_InstalledCount++;
1722 TRACE("---> '%s' \n", ptr1);
1723 ptr1 += strlen(ptr1) + 1;
1725 GetPrivateProfileStringA("mci", NULL, "", MCI_lpInstallNames, count, "SYSTEM.INI");
1726 while (strlen(ptr1) > 0) {
1727 TRACE("---> '%s' \n", ptr1);
1728 ptr1 += strlen(ptr1) + 1;
1729 MCI_InstalledCount++;
1732 RegCloseKey(hWineConf);