1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * MCI internal functions
6 * Copyright 1998/1999 Eric Pouech
19 #include "wine/mmsystem16.h"
20 #include "wine/winbase16.h"
24 #include "debugtools.h"
26 DEFAULT_DEBUG_CHANNEL(mci);
28 static int MCI_InstalledCount;
29 static LPSTR MCI_lpInstallNames = NULL;
32 MCI_MAP_NOMEM, /* ko, memory problem */
33 MCI_MAP_MSGERROR, /* ko, unknown message */
34 MCI_MAP_OK, /* ok, no memory allocated. to be sent to the proc. */
35 MCI_MAP_OKMEM, /* ok, some memory allocated, need to call UnMapMsg. to be sent to the proc. */
38 static MCI_MapType MCI_MapMsg16To32A (WORD uDevType, WORD wMsg, DWORD* lParam);
39 static MCI_MapType MCI_UnMapMsg16To32A(WORD uDevType, WORD wMsg, DWORD lParam);
40 static MCI_MapType MCI_MapMsg32ATo16 (WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD* lParam);
41 static MCI_MapType MCI_UnMapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD lParam);
43 /* First MCI valid device ID (0 means error) */
44 #define MCI_MAGIC 0x0001
46 /* dup a string and uppercase it */
47 inline static LPSTR str_dup_upper( LPCSTR str )
49 INT len = strlen(str) + 1;
50 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
53 memcpy( p, str, len );
59 /**************************************************************************
60 * MCI_GetDriver [internal]
62 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
64 LPWINE_MCIDRIVER wmd = 0;
65 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
67 EnterCriticalSection(&iData->cs);
68 for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
69 if (wmd->wDeviceID == wDevID)
72 LeaveCriticalSection(&iData->cs);
76 /**************************************************************************
77 * MCI_GetDriverFromString [internal]
79 UINT MCI_GetDriverFromString(LPCSTR lpstrName)
82 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
88 if (!lstrcmpiA(lpstrName, "ALL"))
89 return MCI_ALL_DEVICE_ID;
91 EnterCriticalSection(&iData->cs);
92 for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
93 if (wmd->lpstrElementName && strcmp(wmd->lpstrElementName, lpstrName) == 0) {
97 if (wmd->lpstrDeviceType && strcasecmp(wmd->lpstrDeviceType, lpstrName) == 0) {
101 if (wmd->lpstrAlias && strcasecmp(wmd->lpstrAlias, lpstrName) == 0) {
102 ret = wmd->wDeviceID;
106 LeaveCriticalSection(&iData->cs);
111 /**************************************************************************
112 * MCI_MessageToString [internal]
114 const char* MCI_MessageToString(UINT16 wMsg)
116 static char buffer[100];
118 #define CASE(s) case (s): return #s
123 CASE(MCI_CLOSE_DRIVER);
132 CASE(MCI_GETDEVCAPS);
136 CASE(MCI_OPEN_DRIVER);
154 /* constants for digital video */
168 sprintf(buffer, "MCI_<<%04X>>", wMsg);
173 /**************************************************************************
174 * MCI_GetDevTypeFromFileName [internal]
176 static DWORD MCI_GetDevTypeFromFileName(LPCSTR fileName, LPSTR buf, UINT len)
180 if ((tmp = strrchr(fileName, '.'))) {
181 GetProfileStringA("mci extensions", tmp + 1, "*", buf, len);
182 if (strcmp(buf, "*") != 0) {
185 TRACE("No [mci extensions] entry for '%s' found.\n", tmp);
187 return MCIERR_EXTENSION_NOT_FOUND;
190 #define MAX_MCICMDTABLE 20
191 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
193 typedef struct tagWINE_MCICMDTABLE {
197 UINT nVerbs; /* number of verbs in command table */
198 LPCSTR* aVerbs; /* array of verbs to speed up the verb look up process */
199 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
200 WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
202 /**************************************************************************
203 * MCI_IsCommandTableValid [internal]
205 static BOOL MCI_IsCommandTableValid(UINT uTbl)
213 TRACE("Dumping cmdTbl=%d [hMem=%08x devType=%d]\n",
214 uTbl, S_MciCmdTable[uTbl].hMem, S_MciCmdTable[uTbl].uDevType);
216 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].hMem || !S_MciCmdTable[uTbl].lpTable)
219 lmem = S_MciCmdTable[uTbl].lpTable;
223 lmem += strlen(lmem) + 1;
224 flg = *(LPDWORD)lmem;
225 eid = *(LPWORD)(lmem + sizeof(DWORD));
226 lmem += sizeof(DWORD) + sizeof(WORD);
228 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
230 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
231 case MCI_STRING: if (inCst) return FALSE; break;
232 case MCI_INTEGER: if (!*str) return FALSE; break;
233 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
234 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
235 case MCI_FLAG: if (!*str) return FALSE; break;
236 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
237 case MCI_RECT: if (!*str || inCst) return FALSE; break;
238 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
239 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
240 default: return FALSE;
242 } while (eid != MCI_END_COMMAND_LIST);
243 } while (eid != MCI_END_COMMAND_LIST);
247 /**************************************************************************
248 * MCI_DumpCommandTable [internal]
250 static BOOL MCI_DumpCommandTable(UINT uTbl)
257 if (!MCI_IsCommandTableValid(uTbl)) {
258 ERR("Ooops: %d is not valid\n", uTbl);
262 lmem = S_MciCmdTable[uTbl].lpTable;
266 lmem += strlen(lmem) + 1;
267 flg = *(LPDWORD)lmem;
268 eid = *(LPWORD)(lmem + sizeof(DWORD));
269 TRACE("cmd='%s' %08lx %04x\n", str, flg, eid);
270 lmem += sizeof(DWORD) + sizeof(WORD);
271 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
272 TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : "");
273 } while (eid != MCI_END_COMMAND_LIST);
277 static UINT MCI_SetCommandTable(LPWINE_MM_IDATA iData, HANDLE hMem, UINT uDevType);
279 /**************************************************************************
280 * MCI_GetCommandTable [internal]
282 static UINT MCI_GetCommandTable(LPWINE_MM_IDATA iData, UINT uDevType)
288 /* first look up existing for existing devType */
289 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
290 if (S_MciCmdTable[uTbl].hMem && S_MciCmdTable[uTbl].uDevType == uDevType)
294 /* well try to load id */
295 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
296 if (LoadStringA(iData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
299 } else if (uDevType == 0) {
302 uTbl = MCI_NO_COMMAND_TABLE;
304 HRSRC hRsrc = FindResourceA(iData->hWinMM32Instance, str, (LPCSTR)RT_RCDATAA);
307 if (hRsrc) hMem = LoadResource(iData->hWinMM32Instance, hRsrc);
309 uTbl = MCI_SetCommandTable(iData, hMem, uDevType);
311 WARN("No command table found in resource %04x[%s]\n",
312 iData->hWinMM32Instance, str);
315 TRACE("=> %d\n", uTbl);
319 /**************************************************************************
320 * MCI_SetCommandTable [internal]
322 static UINT MCI_SetCommandTable(LPWINE_MM_IDATA iData, HANDLE hMem,
326 static BOOL bInitDone = FALSE;
329 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
330 * can be called with 0 as a uDevType to retrieve it.
335 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
336 S_MciCmdTable[uTbl].hMem = 0;
338 MCI_GetCommandTable(iData, 0);
341 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
342 if (S_MciCmdTable[uTbl].hMem == 0) {
347 S_MciCmdTable[uTbl].hMem = hMem;
348 S_MciCmdTable[uTbl].uDevType = uDevType;
349 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
352 MCI_DumpCommandTable(uTbl);
355 /* create the verbs table */
356 /* get # of entries */
357 lmem = S_MciCmdTable[uTbl].lpTable;
360 lmem += strlen(lmem) + 1;
361 eid = *(LPWORD)(lmem + sizeof(DWORD));
362 lmem += sizeof(DWORD) + sizeof(WORD);
363 if (eid == MCI_COMMAND_HEAD)
365 } while (eid != MCI_END_COMMAND_LIST);
367 S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCSTR));
368 S_MciCmdTable[uTbl].nVerbs = count;
370 lmem = S_MciCmdTable[uTbl].lpTable;
374 lmem += strlen(lmem) + 1;
375 eid = *(LPWORD)(lmem + sizeof(DWORD));
376 lmem += sizeof(DWORD) + sizeof(WORD);
377 if (eid == MCI_COMMAND_HEAD)
378 S_MciCmdTable[uTbl].aVerbs[count++] = str;
379 } while (eid != MCI_END_COMMAND_LIST);
380 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
385 return MCI_NO_COMMAND_TABLE;
388 /**************************************************************************
389 * MCI_DeleteCommandTable [internal]
391 static BOOL MCI_DeleteCommandTable(UINT uTbl)
393 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].hMem)
396 FreeResource(S_MciCmdTable[uTbl].hMem);
397 S_MciCmdTable[uTbl].hMem = 0;
398 if (S_MciCmdTable[uTbl].aVerbs) {
399 HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
400 S_MciCmdTable[uTbl].aVerbs = 0;
405 /**************************************************************************
406 * MCI_UnLoadMciDriver [internal]
408 static BOOL MCI_UnLoadMciDriver(LPWINE_MM_IDATA iData, LPWINE_MCIDRIVER wmd)
410 LPWINE_MCIDRIVER* tmp;
415 CloseDriver(wmd->hDriver, 0, 0);
417 if (wmd->dwPrivate != 0)
418 WARN("Unloading mci driver with non nul dwPrivate field\n");
420 EnterCriticalSection(&iData->cs);
421 for (tmp = &iData->lpMciDrvs; *tmp; tmp = &(*tmp)->lpNext) {
427 LeaveCriticalSection(&iData->cs);
429 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
430 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
431 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
433 HeapFree(GetProcessHeap(), 0, wmd);
437 /**************************************************************************
438 * MCI_OpenMciDriver [internal]
440 static BOOL MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd, LPCSTR drvTyp, LPARAM lp)
444 if (!DRIVER_GetLibName(drvTyp, "mci", libName, sizeof(libName)))
448 /* First load driver */
449 if ((wmd->hDriver = (HDRVR)DRIVER_TryOpenDriver32(libName, lp))) {
454 switch (res = MCI_MapMsg32ATo16(0, DRV_OPEN, 0, &lp)) {
455 case MCI_MAP_MSGERROR:
456 TRACE("Not handled yet (DRV_OPEN)\n");
459 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
463 if ((wmd->hDriver = OpenDriverA(drvTyp, "mci", lp)))
465 if (res == MCI_MAP_OKMEM)
466 MCI_UnMapMsg32ATo16(0, DRV_OPEN, 0, lp);
470 return (wmd->bIs32 == 0xFFFF) ? FALSE : TRUE;
473 /**************************************************************************
474 * MCI_LoadMciDriver [internal]
476 static DWORD MCI_LoadMciDriver(LPWINE_MM_IDATA iData, LPCSTR _strDevTyp,
477 LPWINE_MCIDRIVER* lpwmd)
479 LPSTR strDevTyp = str_dup_upper(_strDevTyp);
480 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
481 MCI_OPEN_DRIVER_PARMSA modp;
484 if (!wmd || !strDevTyp) {
485 dwRet = MCIERR_OUT_OF_MEMORY;
489 wmd->lpfnYieldProc = MCI_DefYieldProc;
490 wmd->dwYieldData = VK_CANCEL;
491 wmd->hCreatorTask = GetCurrentTask();
493 EnterCriticalSection(&iData->cs);
494 /* wmd must be inserted in list before sending opening the driver, coz' it
495 * may want to lookup at wDevID
497 wmd->lpNext = iData->lpMciDrvs;
498 iData->lpMciDrvs = wmd;
500 for (modp.wDeviceID = MCI_MAGIC;
501 MCI_GetDriver(modp.wDeviceID) != 0;
504 wmd->wDeviceID = modp.wDeviceID;
506 LeaveCriticalSection(&iData->cs);
508 TRACE("wDevID=%04X \n", modp.wDeviceID);
510 modp.lpstrParams = NULL;
512 if (!MCI_OpenMciDriver(wmd, strDevTyp, (LPARAM)&modp)) {
513 /* silence warning if all is used... some bogus program use commands like
516 if (strcasecmp(strDevTyp, "all") != 0) {
517 dwRet = MCIERR_CANNOT_USE_ALL;
519 FIXME("Couldn't load driver for type %s.\n"
520 "If you don't have a windows installation accessible from Wine,\n"
521 "you perhaps forgot to create a [mci] section in system.ini\n",
523 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
528 /* FIXME: should also check that module's description is of the form
529 * MODULENAME:[MCI] comment
532 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
533 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
534 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
536 TRACE("Loaded driver %x (%s), type is %d, cmdTable=%08x\n",
537 wmd->hDriver, strDevTyp, modp.wType, modp.wCustomCommandTable);
539 wmd->lpstrDeviceType = strDevTyp;
540 wmd->wType = modp.wType;
542 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
543 modp.wDeviceID, modp.wType, modp.wDeviceID);
547 MCI_UnLoadMciDriver(iData, wmd);
548 HeapFree(GetProcessHeap(), 0, strDevTyp);
553 /**************************************************************************
554 * MCI_FinishOpen [internal]
556 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSA lpParms,
559 if (dwParam & MCI_OPEN_ELEMENT)
561 wmd->lpstrElementName = HeapAlloc(GetProcessHeap(),0,strlen(lpParms->lpstrElementName)+1);
562 strcpy( wmd->lpstrElementName, lpParms->lpstrElementName );
564 if (dwParam & MCI_OPEN_ALIAS)
566 wmd->lpstrAlias = HeapAlloc(GetProcessHeap(), 0, strlen(lpParms->lpstrAlias)+1);
567 strcpy( wmd->lpstrAlias, lpParms->lpstrAlias);
569 lpParms->wDeviceID = wmd->wDeviceID;
571 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
575 /**************************************************************************
576 * MCI_FindCommand [internal]
578 static LPCSTR MCI_FindCommand(UINT uTbl, LPCSTR verb)
582 if (uTbl >= MAX_MCICMDTABLE || S_MciCmdTable[uTbl].hMem == 0)
585 /* another improvement would be to have the aVerbs array sorted,
586 * so that we could use a dichotomic search on it, rather than this dumb
589 for (idx = 0; idx < S_MciCmdTable[uTbl].nVerbs; idx++) {
590 if (strcmp(S_MciCmdTable[uTbl].aVerbs[idx], verb) == 0)
591 return S_MciCmdTable[uTbl].aVerbs[idx];
597 /**************************************************************************
598 * MCI_GetReturnType [internal]
600 static DWORD MCI_GetReturnType(LPCSTR lpCmd)
602 lpCmd += strlen(lpCmd) + 1 + sizeof(DWORD) + sizeof(WORD);
603 if (*lpCmd == '\0' && *(LPWORD)(lpCmd + 1 + sizeof(DWORD)) == MCI_RETURN) {
604 return *(LPDWORD)(lpCmd + 1);
609 /**************************************************************************
610 * MCI_GetMessage [internal]
612 static WORD MCI_GetMessage(LPCSTR lpCmd)
614 return (WORD)*(LPDWORD)(lpCmd + strlen(lpCmd) + 1);
617 /**************************************************************************
618 * MCI_GetDWord [internal]
620 static BOOL MCI_GetDWord(LPDWORD data, LPSTR* ptr)
625 val = strtoul(*ptr, &ret, 0);
629 case ' ': ret++; break;
630 default: return FALSE;
638 /**************************************************************************
639 * MCI_GetString [internal]
641 static DWORD MCI_GetString(LPSTR* str, LPSTR* args)
645 /* see if we have a quoted string */
647 ptr = strchr(*str = ptr + 1, '"');
648 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
649 /* FIXME: shall we escape \" from string ?? */
650 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
651 *ptr++ = '\0'; /* remove trailing " */
652 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
655 ptr = strchr(ptr, ' ');
660 ptr = *args + strlen(*args);
669 #define MCI_DATA_SIZE 16
671 /**************************************************************************
672 * MCI_ParseOptArgs [internal]
674 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCSTR lpCmd,
675 LPSTR args, LPDWORD dwFlags)
679 DWORD dwRet, flg, cflg = 0;
683 /* loop on arguments */
686 found = inCst = FALSE;
689 /* skip any leading white space(s) */
690 while (*args == ' ') args++;
691 TRACE("args='%s' offset=%d\n", args, offset);
693 do { /* loop on options for command table for the requested verb */
695 lmem += (len = strlen(lmem)) + 1;
696 flg = *(LPDWORD)lmem;
697 eid = *(LPWORD)(lmem + sizeof(DWORD));
698 lmem += sizeof(DWORD) + sizeof(WORD);
699 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
703 inCst = TRUE; cflg = flg; break;
704 case MCI_END_CONSTANT:
705 /* there may be additional integral values after flag in constant */
706 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
709 inCst = FALSE; cflg = 0;
713 if (strncasecmp(args, str, len) == 0 &&
714 (args[len] == 0 || args[len] == ' ')) {
715 /* store good values into data[] */
717 while (*args == ' ') args++;
721 case MCI_COMMAND_HEAD:
723 case MCI_END_COMMAND:
724 case MCI_END_COMMAND_LIST:
725 case MCI_CONSTANT: /* done above */
726 case MCI_END_CONSTANT: /* done above */
738 if (!MCI_GetDWord(&(data[offset]), &args)) {
739 return MCIERR_BAD_INTEGER;
744 /* store rect in data (offset...offset+3) */
746 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
747 !MCI_GetDWord(&(data[offset+1]), &args) ||
748 !MCI_GetDWord(&(data[offset+2]), &args) ||
749 !MCI_GetDWord(&(data[offset+3]), &args)) {
750 ERR("Bad rect '%s'\n", args);
751 return MCIERR_BAD_INTEGER;
756 if ((dwRet = MCI_GetString((LPSTR*)&data[offset], &args)))
759 default: ERR("oops\n");
761 /* exit inside while loop, except if just entered in constant area definition */
762 if (!inCst || eid != MCI_CONSTANT) eid = MCI_END_COMMAND;
764 /* have offset incremented if needed */
766 case MCI_COMMAND_HEAD:
768 case MCI_END_COMMAND:
769 case MCI_END_COMMAND_LIST:
771 case MCI_FLAG: break;
772 case MCI_INTEGER: if (!inCst) offset++; break;
773 case MCI_END_CONSTANT:
774 case MCI_STRING: offset++; break;
775 case MCI_RECT: offset += 4; break;
776 default: ERR("oops\n");
779 } while (eid != MCI_END_COMMAND);
781 WARN("Optarg '%s' not found\n", args);
782 return MCIERR_UNRECOGNIZED_COMMAND;
784 if (offset == MCI_DATA_SIZE) {
785 ERR("Internal data[] buffer overflow\n");
786 return MCIERR_PARSER_INTERNAL;
792 /**************************************************************************
793 * MCI_HandleReturnValues [internal]
795 static DWORD MCI_HandleReturnValues(LPWINE_MM_IDATA iData, DWORD dwRet,
796 LPWINE_MCIDRIVER wmd, LPCSTR lpCmd, LPDWORD data,
797 LPSTR lpstrRet, UINT uRetLen)
800 switch (MCI_GetReturnType(lpCmd)) {
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(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];
873 LPSTR devAlias = NULL;
874 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
875 BOOL bAutoOpen = FALSE;
877 TRACE("('%s', %p, %d, %X)\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(iData, devType, &wmd);
954 HeapFree(GetProcessHeap(), 0, devType);
956 MCI_UnLoadMciDriver(iData, 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(iData, 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(iData, 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 (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(iData, 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(iData, dwRet, wmd, lpCmd, 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 * mciSendString [MMSYSTEM.702]
1072 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
1073 UINT16 uRetLen, HWND16 hwndCallback)
1075 return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, hwndCallback);
1078 /**************************************************************************
1079 * mciExecute [WINMM.@]
1080 * mciExecute [MMSYSTEM.712]
1082 DWORD WINAPI mciExecute(LPCSTR lpstrCommand)
1087 TRACE("(%s)!\n", lpstrCommand);
1089 ret = mciSendStringA(lpstrCommand, strRet, sizeof(strRet), 0);
1091 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
1092 sprintf(strRet, "Unknown MCI error (%ld)", ret);
1094 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
1096 /* FIXME: what shall I return ? */
1100 /**************************************************************************
1101 * mciLoadCommandResource [MMSYSTEM.705]
1103 UINT16 WINAPI mciLoadCommandResource16(HANDLE16 hInst, LPCSTR resname, UINT16 type)
1107 UINT16 ret = MCI_NO_COMMAND_TABLE;
1108 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
1110 TRACE("(%04x, %s, %d)!\n", hInst, resname, type);
1112 /* if file exists "resname.mci", then load resource "resname" from it
1113 * otherwise directly from driver
1114 * We don't support it (who uses this feature ?), but we check anyway
1120 strcat(strcpy(buf, resname), ".mci");
1121 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1122 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1125 if (!(hRsrc = FindResourceA(hInst, resname, (LPCSTR)RT_RCDATAA))) {
1126 WARN("No command table found in resource\n");
1127 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1128 ret = MCI_SetCommandTable(iData, hMem, type);
1130 WARN("Couldn't load resource.\n");
1132 TRACE("=> %04x\n", ret);
1136 /**************************************************************************
1137 * mciFreeCommandResource [MMSYSTEM.713]
1139 BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
1141 TRACE("(%04x)!\n", uTable);
1143 return MCI_DeleteCommandTable(uTable);
1146 /**************************************************************************
1147 * mciLoadCommandResource [WINMM.@]
1149 * Strangely, this function only exists as an UNICODE one.
1151 UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
1155 UINT16 ret = MCI_NO_COMMAND_TABLE;
1156 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
1158 TRACE("(%04x, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
1161 /* if file exists "resname.mci", then load resource "resname" from it
1162 * otherwise directly from driver
1163 * We don't support it (who uses this feature ?), but we check anyway
1169 strcat(strcpy(buf, resname), ".mci");
1170 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
1171 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
1175 if (!(hRsrc = FindResourceW(hInst, resNameW, (LPCWSTR)RT_RCDATAA))) {
1176 WARN("No command table found in resource\n");
1177 } else if ((hMem = LoadResource(hInst, hRsrc))) {
1178 ret = MCI_SetCommandTable(iData, hMem, type);
1180 WARN("Couldn't load resource.\n");
1182 TRACE("=> %04x\n", ret);
1190 TRACE("(%04x, %s, %d)!\n", hinst, debugstr_w(resNameW), type);
1192 resNameA = HEAP_strdupWtoA(GetProcessHeap(), 0, resNameW);
1193 ret = mciLoadCommandResource16(hinst, resNameA, type);
1194 HeapFree(GetProcessHeap(), 0, resNameA);
1198 /**************************************************************************
1199 * mciFreeCommandResource [WINMM.@]
1201 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1203 TRACE("(%08x)!\n", uTable);
1205 return MCI_DeleteCommandTable(uTable);
1208 /**************************************************************************
1209 * MCI_MapMsg16To32A [internal]
1211 static MCI_MapType MCI_MapMsg16To32A(WORD uDevType, WORD wMsg, DWORD* lParam)
1215 /* FIXME: to add also (with seg/linear modifications to do):
1216 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
1217 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
1220 /* case MCI_CAPTURE */
1222 case MCI_CLOSE_DRIVER:
1229 case MCI_GETDEVCAPS:
1230 /* case MCI_INDEX: */
1231 /* case MCI_MARK: */
1232 /* case MCI_MONITOR: */
1242 /* case MCI_SETTIMECODE:*/
1243 /* case MCI_SIGNAL:*/
1245 case MCI_STATUS: /* FIXME: is wrong for digital video */
1248 /* case MCI_UNDO: */
1252 *lParam = (DWORD)MapSL(*lParam);
1255 /* in fact, I would also need the dwFlags... to see
1256 * which members of lParam are effectively used
1258 *lParam = (DWORD)MapSL(*lParam);
1259 FIXME("Current mapping may be wrong\n");
1263 LPMCI_BREAK_PARMS mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_BREAK_PARMS));
1264 LPMCI_BREAK_PARMS16 mbp16 = MapSL(*lParam);
1267 mbp32->dwCallback = mbp16->dwCallback;
1268 mbp32->nVirtKey = mbp16->nVirtKey;
1269 mbp32->hwndBreak = mbp16->hwndBreak;
1271 return MCI_MAP_NOMEM;
1273 *lParam = (DWORD)mbp32;
1275 return MCI_MAP_OKMEM;
1278 LPMCI_VD_ESCAPE_PARMSA mvep32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_VD_ESCAPE_PARMSA));
1279 LPMCI_VD_ESCAPE_PARMS16 mvep16 = MapSL(*lParam);
1282 mvep32a->dwCallback = mvep16->dwCallback;
1283 mvep32a->lpstrCommand = MapSL(mvep16->lpstrCommand);
1285 return MCI_MAP_NOMEM;
1287 *lParam = (DWORD)mvep32a;
1289 return MCI_MAP_OKMEM;
1292 LPMCI_INFO_PARMSA mip32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_INFO_PARMSA));
1293 LPMCI_INFO_PARMS16 mip16 = MapSL(*lParam);
1295 /* FIXME this is wrong if device is of type
1296 * MCI_DEVTYPE_DIGITAL_VIDEO, some members are not mapped
1299 mip32a->dwCallback = mip16->dwCallback;
1300 mip32a->lpstrReturn = MapSL(mip16->lpstrReturn);
1301 mip32a->dwRetSize = mip16->dwRetSize;
1303 return MCI_MAP_NOMEM;
1305 *lParam = (DWORD)mip32a;
1307 return MCI_MAP_OKMEM;
1309 case MCI_OPEN_DRIVER:
1311 LPMCI_OPEN_PARMSA mop32a = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_OPEN_PARMSA) + 2 * sizeof(DWORD));
1312 LPMCI_OPEN_PARMS16 mop16 = MapSL(*lParam);
1315 *(LPMCI_OPEN_PARMS16*)(mop32a) = mop16;
1316 mop32a = (LPMCI_OPEN_PARMSA)((char*)mop32a + sizeof(LPMCI_OPEN_PARMS16));
1317 mop32a->dwCallback = mop16->dwCallback;
1318 mop32a->wDeviceID = mop16->wDeviceID;
1319 mop32a->lpstrDeviceType = MapSL(mop16->lpstrDeviceType);
1320 mop32a->lpstrElementName = MapSL(mop16->lpstrElementName);
1321 mop32a->lpstrAlias = MapSL(mop16->lpstrAlias);
1322 /* copy extended information if any...
1323 * FIXME: this may seg fault if initial structure does not contain them and
1324 * the reads after msip16 fail under LDT limits...
1325 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
1326 * should not take care of extended parameters, and should be used by MCI_Open
1327 * to fetch uDevType. When, this is known, the mapping for sending the
1328 * MCI_OPEN_DRIVER shall be done depending on uDevType.
1330 memcpy(mop32a + 1, mop16 + 1, 2 * sizeof(DWORD));
1332 return MCI_MAP_NOMEM;
1334 *lParam = (DWORD)mop32a;
1336 return MCI_MAP_OKMEM;
1339 LPMCI_SYSINFO_PARMSA msip32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_SYSINFO_PARMSA));
1340 LPMCI_SYSINFO_PARMS16 msip16 = MapSL(*lParam);
1343 msip32a->dwCallback = msip16->dwCallback;
1344 msip32a->lpstrReturn = MapSL(msip16->lpstrReturn);
1345 msip32a->dwRetSize = msip16->dwRetSize;
1346 msip32a->dwNumber = msip16->dwNumber;
1347 msip32a->wDeviceType = msip16->wDeviceType;
1349 return MCI_MAP_NOMEM;
1351 *lParam = (DWORD)msip32a;
1353 return MCI_MAP_OKMEM;
1361 case DRV_QUERYCONFIGURE:
1364 case DRV_EXITSESSION:
1365 case DRV_EXITAPPLICATION:
1367 FIXME("This is a hack\n");
1371 WARN("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
1373 return MCI_MAP_MSGERROR;
1376 /**************************************************************************
1377 * MCI_UnMapMsg16To32A [internal]
1379 static MCI_MapType MCI_UnMapMsg16To32A(WORD uDevType, WORD wMsg, DWORD lParam)
1382 /* case MCI_CAPTURE */
1384 case MCI_CLOSE_DRIVER:
1391 case MCI_GETDEVCAPS:
1392 /* case MCI_INDEX: */
1393 /* case MCI_MARK: */
1394 /* case MCI_MONITOR: */
1404 /* case MCI_SETTIMECODE:*/
1405 /* case MCI_SIGNAL:*/
1410 /* case MCI_UNDO: */
1417 /* FIXME ?? see Map function */
1424 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
1427 case MCI_OPEN_DRIVER:
1429 LPMCI_OPEN_PARMSA mop32a = (LPMCI_OPEN_PARMSA)lParam;
1430 LPMCI_OPEN_PARMS16 mop16 = *(LPMCI_OPEN_PARMS16*)((char*)mop32a - sizeof(LPMCI_OPEN_PARMS16));
1432 mop16->wDeviceID = mop32a->wDeviceID;
1433 if (!HeapFree(GetProcessHeap(), 0, (LPVOID)(lParam - sizeof(LPMCI_OPEN_PARMS16))))
1434 FIXME("bad free line=%d\n", __LINE__);
1444 case DRV_QUERYCONFIGURE:
1447 case DRV_EXITSESSION:
1448 case DRV_EXITAPPLICATION:
1450 FIXME("This is a hack\n");
1453 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
1455 return MCI_MAP_MSGERROR;
1460 * 0001 squeeze signed 4 bytes to 2 bytes *( LPINT16)D = ( INT16)*( LPINT16)S; D += 2; S += 4
1461 * 0010 squeeze unsigned 4 bytes to 2 bytes *(LPUINT16)D = (UINT16)*(LPUINT16)S; D += 2; S += 4
1464 * 0110 zero 4 bytes *(DWORD)D = 0 D += 4; S += 4
1465 * 0111 copy string *(LPSTR*)D = seg dup(*(LPSTR*)S) D += 4; S += 4
1466 * 1xxx copy xxx + 1 bytes memcpy(D, S, xxx + 1); D += xxx+1; S += xxx+1
1469 /**************************************************************************
1470 * MCI_MsgMapper32To16_Create [internal]
1472 * Helper for MCI_MapMsg32ATo16.
1473 * Maps the 32 bit pointer (*ptr), of size bytes, to an allocated 16 bit
1474 * segmented pointer.
1475 * map contains a list of action to be performed for the mapping (see list
1477 * if keep is TRUE, keeps track of in 32 bit ptr in allocated 16 bit area.
1479 static MCI_MapType MCI_MsgMapper32To16_Create(void** ptr, int size16, DWORD map, BOOLEAN keep)
1481 void* lp = HeapAlloc( GetProcessHeap(), 0, (keep ? sizeof(void**) : 0) + size16 );
1485 return MCI_MAP_NOMEM;
1487 p32 = (LPBYTE)(*ptr);
1490 p16 = (LPBYTE)lp + sizeof(void**);
1491 *ptr = (char*)MapLS(lp) + sizeof(void**);
1494 *ptr = (void*)MapLS(lp);
1498 memcpy(p16, p32, size16);
1506 sz = (nibble & 7) + 1;
1507 memcpy(p16, p32, sz);
1510 size16 -= sz; /* DEBUG only */
1514 *(LPINT16)p16 = *(LPINT)p32;
1515 p16 += sizeof(INT16);
1517 size16 -= sizeof(INT16);
1520 *(LPUINT16)p16 = *(LPUINT)p32;
1521 p16 += sizeof(UINT16);
1522 p32 += sizeof(UINT);
1523 size16 -= sizeof(UINT16);
1527 p16 += sizeof(DWORD);
1528 p32 += sizeof(DWORD);
1529 size16 -= sizeof(DWORD);
1532 *(SEGPTR *)p16 = MapLS( *(LPSTR *)p32 );
1533 p16 += sizeof(SEGPTR);
1534 p32 += sizeof(LPSTR);
1535 size16 -= sizeof(SEGPTR);
1538 FIXME("Unknown nibble for mapping (%x)\n", nibble);
1543 if (size16 != 0) /* DEBUG only */
1544 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
1546 return MCI_MAP_OKMEM;
1549 /**************************************************************************
1550 * MCI_MsgMapper32To16_Destroy [internal]
1552 * Helper for MCI_UnMapMsg32ATo16.
1554 static MCI_MapType MCI_MsgMapper32To16_Destroy(void* ptr, int size16, DWORD map, BOOLEAN kept)
1557 void* msg16 = MapSL((SEGPTR)ptr);
1562 UnMapLS( (SEGPTR)ptr );
1564 alloc = (char*)msg16 - sizeof(void**);
1565 p32 = *(void**)alloc;
1569 memcpy(p32, p16, size16);
1574 memcpy(p32, p16, (nibble & 7) + 1);
1575 p16 += (nibble & 7) + 1;
1576 p32 += (nibble & 7) + 1;
1577 size16 -= (nibble & 7) + 1;
1581 *(LPINT)p32 = *(LPINT16)p16;
1582 p16 += sizeof(INT16);
1584 size16 -= sizeof(INT16);
1587 *(LPUINT)p32 = *(LPUINT16)p16;
1588 p16 += sizeof(UINT16);
1589 p32 += sizeof(UINT);
1590 size16 -= sizeof(UINT16);
1593 p16 += sizeof(UINT);
1594 p32 += sizeof(UINT);
1595 size16 -= sizeof(UINT);
1598 UnMapLS( *(SEGPTR *)p16 );
1599 p16 += sizeof(SEGPTR);
1600 p32 += sizeof(char*);
1601 size16 -= sizeof(SEGPTR);
1604 FIXME("Unknown nibble for mapping (%x)\n", nibble);
1609 if (size16 != 0) /* DEBUG only */
1610 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
1616 HeapFree( GetProcessHeap(), 0, alloc );
1621 /**************************************************************************
1622 * MCI_MapMsg32ATo16 [internal]
1624 * Map a 32-A bit MCI message to a 16 bit MCI message.
1626 static MCI_MapType MCI_MapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD* lParam)
1629 BOOLEAN keep = FALSE;
1635 /* FIXME: to add also (with seg/linear modifications to do):
1636 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
1637 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
1641 size = sizeof(MCI_BREAK_PARMS);
1643 /* case MCI_CAPTURE */
1645 case MCI_CLOSE_DRIVER:
1647 size = sizeof(MCI_GENERIC_PARMS);
1649 /* case MCI_COPY: */
1652 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_CUE_PARMS); break;
1653 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_CUE_PARMS); break;*/ FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1654 default: size = sizeof(MCI_GENERIC_PARMS); break;
1660 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_DELETE_PARMS16); map = 0x0F1111FB; break;
1661 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_DELETE_PARMS); break;
1662 default: size = sizeof(MCI_GENERIC_PARMS); break;
1665 /* case MCI_ESCAPE: */
1668 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_FREEZE_PARMS); map = 0x0001111B; break;
1669 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
1670 default: size = sizeof(MCI_GENERIC_PARMS); break;
1673 case MCI_GETDEVCAPS:
1675 size = sizeof(MCI_GETDEVCAPS_PARMS);
1677 /* case MCI_INDEX: */
1680 LPMCI_INFO_PARMSA mip32a = (LPMCI_INFO_PARMSA)(*lParam);
1681 LPMCI_INFO_PARMS16 mip16;
1684 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_INFO_PARMS16); break;
1685 default: size = sizeof(MCI_INFO_PARMS16); break;
1687 mip16 = HeapAlloc( GetProcessHeap(), 0, size);
1690 mip16->dwCallback = mip32a->dwCallback;
1691 mip16->lpstrReturn = MapLS( mip32a->lpstrReturn );
1692 mip16->dwRetSize = mip32a->dwRetSize;
1693 if (uDevType == MCI_DEVTYPE_DIGITAL_VIDEO) {
1694 ((LPMCI_DGV_INFO_PARMS16)mip16)->dwItem = ((LPMCI_DGV_INFO_PARMSA)mip32a)->dwItem;
1697 return MCI_MAP_NOMEM;
1699 *lParam = MapLS(mip16);
1701 return MCI_MAP_OKMEM;
1702 /* case MCI_MARK: */
1703 /* case MCI_MONITOR: */
1705 case MCI_OPEN_DRIVER:
1707 LPMCI_OPEN_PARMSA mop32a = (LPMCI_OPEN_PARMSA)(*lParam);
1708 char* ptr = HeapAlloc( GetProcessHeap(), 0,
1709 sizeof(LPMCI_OPEN_PARMSA) + sizeof(MCI_OPEN_PARMS16) + 2 * sizeof(DWORD));
1710 LPMCI_OPEN_PARMS16 mop16;
1714 *(LPMCI_OPEN_PARMSA*)(ptr) = mop32a;
1715 mop16 = (LPMCI_OPEN_PARMS16)(ptr + sizeof(LPMCI_OPEN_PARMSA));
1716 mop16->dwCallback = mop32a->dwCallback;
1717 mop16->wDeviceID = mop32a->wDeviceID;
1718 if (dwFlags & MCI_OPEN_TYPE) {
1719 if (dwFlags & MCI_OPEN_TYPE_ID) {
1720 /* dword "transparent" value */
1721 mop16->lpstrDeviceType = (SEGPTR)mop32a->lpstrDeviceType;
1724 mop16->lpstrDeviceType = MapLS( mop32a->lpstrDeviceType );
1728 mop16->lpstrDeviceType = 0;
1730 if (dwFlags & MCI_OPEN_ELEMENT) {
1731 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
1732 mop16->lpstrElementName = (SEGPTR)mop32a->lpstrElementName;
1734 mop16->lpstrElementName = MapLS( mop32a->lpstrElementName );
1737 mop16->lpstrElementName = 0;
1739 if (dwFlags & MCI_OPEN_ALIAS) {
1740 mop16->lpstrAlias = MapLS( mop32a->lpstrAlias );
1742 mop16->lpstrAlias = 0;
1744 /* copy extended information if any...
1745 * FIXME: this may seg fault if initial structure does not contain them and
1746 * the reads after msip16 fail under LDT limits...
1747 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
1748 * should not take care of extended parameters, and should be used by MCI_Open
1749 * to fetch uDevType. When, this is known, the mapping for sending the
1750 * MCI_OPEN_DRIVER shall be done depending on uDevType.
1752 memcpy(mop16 + 1, mop32a + 1, 2 * sizeof(DWORD));
1754 return MCI_MAP_NOMEM;
1756 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_PARMSA);
1758 return MCI_MAP_OKMEM;
1759 /* case MCI_PASTE:*/
1761 size = sizeof(MCI_GENERIC_PARMS);
1764 size = sizeof(MCI_PLAY_PARMS);
1768 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
1769 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
1770 default: size = sizeof(MCI_GENERIC_PARMS); break;
1774 size = sizeof(MCI_GENERIC_PARMS);
1778 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECORD_PARMS16); map = 0x0F1111FB; break;
1779 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_RECORD_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1780 default: size = sizeof(MCI_RECORD_PARMS); break;
1784 size = sizeof(MCI_GENERIC_PARMS);
1788 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SEEK_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1789 default: size = sizeof(MCI_SEEK_PARMS); break;
1794 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SET_PARMS); break;
1795 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SET_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1796 case MCI_DEVTYPE_SEQUENCER: size = sizeof(MCI_SEQ_SET_PARMS); break;
1797 /* FIXME: normally the 16 and 32 bit structures are byte by byte aligned,
1798 * so not doing anything should work...
1800 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_SET_PARMS); break;
1801 default: size = sizeof(MCI_SET_PARMS); break;
1806 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SETAUDIO_PARMS16);map = 0x0000077FF; break;
1807 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1808 default: size = sizeof(MCI_GENERIC_PARMS); break;
1811 /* case MCI_SETTIMECODE:*/
1812 /* case MCI_SIGNAL:*/
1814 size = sizeof(MCI_SET_PARMS);
1820 * don't know if buffer for value is the one passed through lpstrDevice
1821 * or is provided by MCI driver.
1822 * Assuming solution 2: provided by MCI driver, so zeroing on entry
1824 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STATUS_PARMS16); map = 0x0B6FF; break;
1825 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1826 default: size = sizeof(MCI_STATUS_PARMS); break;
1831 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STEP_PARMS); break;
1832 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STEP_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1833 case MCI_DEVTYPE_VIDEODISC: size = sizeof(MCI_VD_STEP_PARMS); break;
1834 default: size = sizeof(MCI_GENERIC_PARMS); break;
1838 size = sizeof(MCI_SET_PARMS);
1842 LPMCI_SYSINFO_PARMSA msip32a = (LPMCI_SYSINFO_PARMSA)(*lParam);
1843 LPMCI_SYSINFO_PARMS16 msip16;
1844 char* ptr = HeapAlloc( GetProcessHeap(), 0,
1845 sizeof(LPMCI_SYSINFO_PARMSA) + sizeof(MCI_SYSINFO_PARMS16) );
1848 *(LPMCI_SYSINFO_PARMSA*)(ptr) = msip32a;
1849 msip16 = (LPMCI_SYSINFO_PARMS16)(ptr + sizeof(LPMCI_SYSINFO_PARMSA));
1851 msip16->dwCallback = msip32a->dwCallback;
1852 msip16->lpstrReturn = MapLS( msip32a->lpstrReturn );
1853 msip16->dwRetSize = msip32a->dwRetSize;
1854 msip16->dwNumber = msip32a->dwNumber;
1855 msip16->wDeviceType = msip32a->wDeviceType;
1857 return MCI_MAP_NOMEM;
1859 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_SYSINFO_PARMSA);
1861 return MCI_MAP_OKMEM;
1862 /* case MCI_UNDO: */
1865 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
1866 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; break;
1867 default: size = sizeof(MCI_GENERIC_PARMS); break;
1872 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_UPDATE_PARMS16); map = 0x000B1111B; break;
1873 default: size = sizeof(MCI_GENERIC_PARMS); break;
1878 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
1879 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
1880 default: size = sizeof(MCI_GENERIC_PARMS); break;
1885 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7FB; break;
1886 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7FB; break;
1887 default: size = sizeof(MCI_GENERIC_PARMS); break;
1892 LPMCI_OPEN_DRIVER_PARMSA modp32a = (LPMCI_OPEN_DRIVER_PARMSA)(*lParam);
1893 LPMCI_OPEN_DRIVER_PARMS16 modp16;
1894 char *ptr = HeapAlloc( GetProcessHeap(), 0,
1895 sizeof(LPMCI_OPEN_DRIVER_PARMSA) + sizeof(MCI_OPEN_DRIVER_PARMS16));
1898 *(LPMCI_OPEN_DRIVER_PARMSA*)(ptr) = modp32a;
1899 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)(ptr + sizeof(LPMCI_OPEN_DRIVER_PARMSA));
1900 modp16->wDeviceID = modp32a->wDeviceID;
1901 modp16->lpstrParams = MapLS( modp32a->lpstrParams );
1902 /* other fields are gonna be filled by the driver, don't copy them */
1904 return MCI_MAP_NOMEM;
1906 *lParam = (LPARAM)MapLS(ptr) + sizeof(LPMCI_OPEN_DRIVER_PARMSA);
1908 return MCI_MAP_OKMEM;
1915 case DRV_QUERYCONFIGURE:
1918 case DRV_EXITSESSION:
1919 case DRV_EXITAPPLICATION:
1924 WARN("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
1925 return MCI_MAP_MSGERROR;
1927 return MCI_MsgMapper32To16_Create((void**)lParam, size, map, keep);
1930 /**************************************************************************
1931 * MCI_UnMapMsg32ATo16 [internal]
1933 static MCI_MapType MCI_UnMapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD lParam)
1936 BOOLEAN kept = FALSE; /* there is no need to compute size when kept is FALSE */
1942 /* case MCI_CAPTURE */
1944 case MCI_CLOSE_DRIVER:
1947 /* case MCI_COPY: */
1953 /* case MCI_ESCAPE: */
1956 case MCI_GETDEVCAPS:
1958 size = sizeof(MCI_GETDEVCAPS_PARMS);
1960 /* case MCI_INDEX: */
1963 LPMCI_INFO_PARMS16 mip16 = (LPMCI_INFO_PARMS16)MapSL(lParam);
1965 UnMapLS( mip16->lpstrReturn );
1966 HeapFree( GetProcessHeap(), 0, mip16 );
1969 /* case MCI_MARK: */
1970 /* case MCI_MONITOR: */
1972 case MCI_OPEN_DRIVER:
1974 LPMCI_OPEN_PARMS16 mop16 = (LPMCI_OPEN_PARMS16)MapSL(lParam);
1975 LPMCI_OPEN_PARMSA mop32a = *(LPMCI_OPEN_PARMSA*)((char*)mop16 - sizeof(LPMCI_OPEN_PARMSA));
1977 mop32a->wDeviceID = mop16->wDeviceID;
1978 if ((dwFlags & MCI_OPEN_TYPE) && !(dwFlags & MCI_OPEN_TYPE_ID))
1979 UnMapLS( mop16->lpstrDeviceType );
1980 if ((dwFlags & MCI_OPEN_ELEMENT) && !(dwFlags & MCI_OPEN_ELEMENT_ID))
1981 UnMapLS( mop16->lpstrElementName );
1982 if (dwFlags & MCI_OPEN_ALIAS)
1983 UnMapLS( mop16->lpstrAlias );
1984 HeapFree( GetProcessHeap(), 0, (char*)mop16 - sizeof(LPMCI_OPEN_PARMSA) );
1987 /* case MCI_PASTE:*/
2006 case MCI_DEVTYPE_DIGITAL_VIDEO: map = 0x0000077FF; break;
2007 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SETAUDIO_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
2010 /* case MCI_SETTIMECODE:*/
2011 /* case MCI_SIGNAL:*/
2017 case MCI_DEVTYPE_DIGITAL_VIDEO:
2019 LPMCI_DGV_STATUS_PARMS16 mdsp16 = (LPMCI_DGV_STATUS_PARMS16)MapSL(lParam);
2020 LPMCI_DGV_STATUS_PARMSA mdsp32a = *(LPMCI_DGV_STATUS_PARMSA*)((char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA));
2024 mdsp32a->dwReturn = mdsp16->dwReturn;
2025 if (dwFlags & MCI_DGV_STATUS_DISKSPACE) {
2026 TRACE("MCI_STATUS (DGV) lpstrDrive=%08lx\n", mdsp16->lpstrDrive);
2027 TRACE("MCI_STATUS (DGV) lpstrDrive=%s\n", (LPSTR)MapSL(mdsp16->lpstrDrive));
2028 UnMapLS( mdsp16->lpstrDrive );
2030 HeapFree( GetProcessHeap(), 0, (char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA) );
2032 return MCI_MAP_NOMEM;
2035 return MCI_MAP_OKMEM;
2036 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
2037 default: size = sizeof(MCI_STATUS_PARMS); break;
2046 LPMCI_SYSINFO_PARMS16 msip16 = (LPMCI_SYSINFO_PARMS16)MapSL(lParam);
2047 LPMCI_SYSINFO_PARMSA msip32a = *(LPMCI_SYSINFO_PARMSA*)((char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA));
2051 msip16->dwCallback = msip32a->dwCallback;
2052 UnMapLS( msip16->lpstrReturn );
2053 HeapFree( GetProcessHeap(), 0, (char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA) );
2055 return MCI_MAP_NOMEM;
2058 return MCI_MAP_OKMEM;
2059 /* case MCI_UNDO: */
2066 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
2067 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
2073 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7666; break;
2074 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7666; break;
2077 /* FIXME: see map function */
2082 LPMCI_OPEN_DRIVER_PARMS16 modp16 = (LPMCI_OPEN_DRIVER_PARMS16)MapSL(lParam);
2083 LPMCI_OPEN_DRIVER_PARMSA modp32a = *(LPMCI_OPEN_DRIVER_PARMSA*)((char*)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA));
2086 modp32a->wCustomCommandTable = modp16->wCustomCommandTable;
2087 modp32a->wType = modp16->wType;
2088 UnMapLS( modp16->lpstrParams );
2089 HeapFree( GetProcessHeap(), 0, (char *)modp16 - sizeof(LPMCI_OPEN_DRIVER_PARMSA) );
2098 case DRV_QUERYCONFIGURE:
2101 case DRV_EXITSESSION:
2102 case DRV_EXITAPPLICATION:
2104 FIXME("This is a hack\n");
2107 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
2108 return MCI_MAP_MSGERROR;
2110 return MCI_MsgMapper32To16_Destroy((void*)lParam, size, map, kept);
2113 /**************************************************************************
2114 * MCI_SendCommandFrom32 [internal]
2116 DWORD MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
2118 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
2119 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
2123 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
2127 switch (res = MCI_MapMsg32ATo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
2128 case MCI_MAP_MSGERROR:
2129 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
2130 dwRet = MCIERR_DRIVER_INTERNAL;
2133 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
2134 dwRet = MCIERR_OUT_OF_MEMORY;
2138 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
2139 if (res == MCI_MAP_OKMEM)
2140 MCI_UnMapMsg32ATo16(wmd->wType, wMsg, dwParam1, dwParam2);
2148 /**************************************************************************
2149 * MCI_SendCommandFrom16 [internal]
2151 DWORD MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
2153 DWORD dwRet = MCIERR_INVALID_DEVICE_ID;
2154 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
2157 dwRet = MCIERR_INVALID_DEVICE_ID;
2162 switch (res = MCI_MapMsg16To32A(wmd->wType, wMsg, &dwParam2)) {
2163 case MCI_MAP_MSGERROR:
2164 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
2165 dwRet = MCIERR_DRIVER_INTERNAL;
2168 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
2169 dwRet = MCIERR_OUT_OF_MEMORY;
2173 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
2174 if (res == MCI_MAP_OKMEM)
2175 MCI_UnMapMsg16To32A(wmd->wType, wMsg, dwParam2);
2179 dwRet = SendDriverMessage(wmd->hDriver, wMsg, dwParam1, dwParam2);
2185 /**************************************************************************
2186 * MCI_Open [internal]
2188 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
2190 char strDevTyp[128];
2192 LPWINE_MCIDRIVER wmd = NULL;
2193 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
2195 TRACE("(%08lX, %p)\n", dwParam, lpParms);
2196 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
2198 /* only two low bytes are generic, the other ones are dev type specific */
2199 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
2200 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
2201 MCI_NOTIFY|MCI_WAIT)
2202 if ((dwParam & ~WINE_MCIDRIVER_SUPP) != 0) {
2203 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCIDRIVER_SUPP);
2205 #undef WINE_MCIDRIVER_SUPP
2209 if (dwParam & MCI_OPEN_TYPE) {
2210 if (dwParam & MCI_OPEN_TYPE_ID) {
2211 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
2213 if (uDevType < MCI_DEVTYPE_FIRST ||
2214 uDevType > MCI_DEVTYPE_LAST ||
2215 !LoadStringA(iData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
2216 dwRet = MCIERR_BAD_INTEGER;
2221 if (lpParms->lpstrDeviceType == NULL) {
2222 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
2225 strcpy(strDevTyp, lpParms->lpstrDeviceType);
2226 ptr = strchr(strDevTyp, '!');
2228 /* this behavior is not documented in windows. However, since, in
2229 * some occasions, MCI_OPEN handling is translated by WinMM into
2230 * a call to mciSendString("open <type>"); this code shall be correct
2232 if (dwParam & MCI_OPEN_ELEMENT) {
2233 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
2234 lpParms->lpstrElementName, strDevTyp);
2235 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
2238 dwParam |= MCI_OPEN_ELEMENT;
2240 /* FIXME: not a good idea to write in user supplied buffer */
2241 lpParms->lpstrElementName = ptr;
2245 TRACE("devType='%s' !\n", strDevTyp);
2248 if (dwParam & MCI_OPEN_ELEMENT) {
2249 TRACE("lpstrElementName='%s'\n", lpParms->lpstrElementName);
2251 if (dwParam & MCI_OPEN_ELEMENT_ID) {
2252 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
2253 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
2257 if (!lpParms->lpstrElementName) {
2258 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
2262 /* type, if given as a parameter, supersedes file extension */
2263 if (!strDevTyp[0] &&
2264 MCI_GetDevTypeFromFileName(lpParms->lpstrElementName,
2265 strDevTyp, sizeof(strDevTyp))) {
2266 if (GetDriveTypeA(lpParms->lpstrElementName) != DRIVE_CDROM) {
2267 dwRet = MCIERR_EXTENSION_NOT_FOUND;
2270 /* FIXME: this will not work if several CDROM drives are installed on the machine */
2271 strcpy(strDevTyp, "CDAUDIO");
2275 if (strDevTyp[0] == 0) {
2276 FIXME("Couldn't load driver\n");
2277 dwRet = MCIERR_INVALID_DEVICE_NAME;
2281 if (dwParam & MCI_OPEN_ALIAS) {
2282 TRACE("Alias='%s' !\n", lpParms->lpstrAlias);
2283 if (!lpParms->lpstrAlias) {
2284 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
2289 if ((dwRet = MCI_LoadMciDriver(iData, strDevTyp, &wmd))) {
2293 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
2294 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet);
2295 /* FIXME: is dwRet the correct ret code ? */
2299 /* only handled devices fall through */
2300 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
2302 if (dwParam & MCI_NOTIFY)
2303 mciDriverNotify16(lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
2307 if (wmd) MCI_UnLoadMciDriver(iData, wmd);
2309 if (dwParam & MCI_NOTIFY)
2310 mciDriverNotify16(lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
2314 /**************************************************************************
2315 * MCI_Close [internal]
2317 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
2320 LPWINE_MCIDRIVER wmd;
2321 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
2323 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
2325 if (wDevID == MCI_ALL_DEVICE_ID) {
2326 LPWINE_MCIDRIVER next;
2328 EnterCriticalSection(&iData->cs);
2329 /* FIXME: shall I notify once after all is done, or for
2330 * each of the open drivers ? if the latest, which notif
2331 * to return when only one fails ?
2333 for (wmd = iData->lpMciDrvs; wmd; ) {
2335 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
2338 LeaveCriticalSection(&iData->cs);
2342 if (!(wmd = MCI_GetDriver(wDevID))) {
2343 return MCIERR_INVALID_DEVICE_ID;
2346 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
2348 MCI_UnLoadMciDriver(iData, wmd);
2350 if (dwParam & MCI_NOTIFY)
2351 mciDriverNotify16(lpParms->dwCallback, wDevID,
2352 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
2357 /**************************************************************************
2358 * MCI_WriteString [internal]
2360 DWORD MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr)
2365 if (dstSize <= strlen(lpSrcStr)) {
2366 lstrcpynA(lpDstStr, lpSrcStr, dstSize - 1);
2367 ret = MCIERR_PARAM_OVERFLOW;
2369 strcpy(lpDstStr, lpSrcStr);
2377 /**************************************************************************
2378 * MCI_Sysinfo [internal]
2380 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParms)
2382 DWORD ret = MCIERR_INVALID_DEVICE_ID;
2383 LPWINE_MCIDRIVER wmd;
2384 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
2386 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
2388 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
2389 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
2391 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
2392 case MCI_SYSINFO_QUANTITY:
2396 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST ||
2397 lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
2398 if (dwFlags & MCI_SYSINFO_OPEN) {
2399 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
2400 EnterCriticalSection(&iData->cs);
2401 for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
2404 LeaveCriticalSection(&iData->cs);
2406 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
2407 cnt = MCI_InstalledCount;
2410 if (dwFlags & MCI_SYSINFO_OPEN) {
2411 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
2412 lpParms->wDeviceType);
2413 EnterCriticalSection(&iData->cs);
2414 for (wmd = iData->lpMciDrvs; wmd; wmd = wmd->lpNext) {
2415 if (wmd->wType == lpParms->wDeviceType)
2418 LeaveCriticalSection(&iData->cs);
2420 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
2421 lpParms->wDeviceType);
2422 FIXME("Don't know how to get # of MCI devices of a given type\n");
2426 *(DWORD*)lpParms->lpstrReturn = cnt;
2428 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
2429 ret = MCI_INTEGER_RETURNED;
2431 case MCI_SYSINFO_INSTALLNAME:
2432 TRACE("MCI_SYSINFO_INSTALLNAME \n");
2433 if ((wmd = MCI_GetDriver(uDevID))) {
2434 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
2435 wmd->lpstrDeviceType);
2437 *lpParms->lpstrReturn = 0;
2438 ret = MCIERR_INVALID_DEVICE_ID;
2440 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
2442 case MCI_SYSINFO_NAME:
2443 TRACE("MCI_SYSINFO_NAME\n");
2444 if (dwFlags & MCI_SYSINFO_OPEN) {
2445 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
2446 ret = MCIERR_UNRECOGNIZED_COMMAND;
2447 } else if (lpParms->dwNumber > MCI_InstalledCount) {
2448 ret = MCIERR_OUTOFRANGE;
2450 DWORD count = lpParms->dwNumber;
2451 LPSTR ptr = MCI_lpInstallNames;
2453 while (--count > 0) ptr += strlen(ptr) + 1;
2454 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, ptr);
2456 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
2459 TRACE("Unsupported flag value=%08lx\n", dwFlags);
2460 ret = MCIERR_UNRECOGNIZED_COMMAND;
2465 /**************************************************************************
2466 * MCI_Break [internal]
2468 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
2472 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
2474 if (dwFlags & MCI_NOTIFY)
2475 mciDriverNotify16(lpParms->dwCallback, wDevID,
2476 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
2481 /**************************************************************************
2482 * MCI_SendCommand [internal]
2484 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
2485 DWORD dwParam2, BOOL bFrom32)
2487 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
2492 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
2494 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
2497 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
2498 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
2500 default: break; /* so that gcc does not bark */
2506 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
2508 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
2511 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
2512 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
2514 default: break; /* so that gcc does not bark */
2520 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
2522 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
2525 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
2526 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
2528 default: break; /* so that gcc doesnot bark */
2534 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2536 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
2539 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2540 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
2542 default: break; /* so that gcc does not bark */
2547 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
2548 * but I couldn't get any doc on this MCI message
2552 if (wDevID == MCI_ALL_DEVICE_ID) {
2553 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2554 dwRet = MCIERR_CANNOT_USE_ALL;
2557 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
2558 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
2565 /**************************************************************************
2566 * MCI_CleanUp [internal]
2568 * Some MCI commands need to be cleaned-up (when not called from
2569 * mciSendString), because MCI drivers return extra information for string
2570 * transformation. This function gets rid of them.
2572 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2, BOOL bIs32)
2575 return LOWORD(dwRet);
2578 case MCI_GETDEVCAPS:
2579 switch (dwRet & 0xFFFF0000ul) {
2581 case MCI_COLONIZED3_RETURN:
2582 case MCI_COLONIZED4_RETURN:
2583 case MCI_INTEGER_RETURNED:
2586 case MCI_RESOURCE_RETURNED:
2587 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2589 LPMCI_GETDEVCAPS_PARMS lmgp;
2591 lmgp = (LPMCI_GETDEVCAPS_PARMS)(bIs32 ? (void*)dwParam2 : MapSL(dwParam2));
2592 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
2593 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
2597 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2598 HIWORD(dwRet), MCI_MessageToString(wMsg));
2602 switch (dwRet & 0xFFFF0000ul) {
2604 case MCI_COLONIZED3_RETURN:
2605 case MCI_COLONIZED4_RETURN:
2606 case MCI_INTEGER_RETURNED:
2609 case MCI_RESOURCE_RETURNED:
2610 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2612 LPMCI_STATUS_PARMS lsp;
2614 lsp = (LPMCI_STATUS_PARMS)(bIs32 ? (void*)dwParam2 : MapSL(dwParam2));
2615 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
2616 lsp->dwReturn = LOWORD(lsp->dwReturn);
2620 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2621 HIWORD(dwRet), MCI_MessageToString(wMsg));
2625 switch (dwRet & 0xFFFF0000ul) {
2627 case MCI_INTEGER_RETURNED:
2631 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2635 if (HIWORD(dwRet)) {
2636 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2637 dwRet, MCI_MessageToString(wMsg));
2641 return LOWORD(dwRet);
2644 /**************************************************************************
2645 * MULTIMEDIA_MciInit [internal]
2647 * Initializes the MCI internal variables.
2650 BOOL MULTIMEDIA_MciInit(void)
2659 MCI_InstalledCount = 0;
2660 ptr1 = MCI_lpInstallNames = HeapAlloc(GetProcessHeap(), 0, count);
2662 if (!MCI_lpInstallNames)
2665 /* FIXME: should do also some registry diving here ? */
2666 if (!(err = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", &hWineConf)) &&
2667 !(err = RegOpenKeyA(hWineConf, "options", &hkey))) {
2668 err = RegQueryValueExA(hkey, "mci", 0, &type, MCI_lpInstallNames, &count);
2673 TRACE("Wine => '%s' \n", ptr1);
2674 while ((ptr2 = strchr(ptr1, ':')) != 0) {
2676 TRACE("---> '%s' \n", ptr1);
2677 MCI_InstalledCount++;
2680 MCI_InstalledCount++;
2681 TRACE("---> '%s' \n", ptr1);
2682 ptr1 += strlen(ptr1) + 1;
2684 GetPrivateProfileStringA("mci", NULL, "", MCI_lpInstallNames, count, "SYSTEM.INI");
2685 while (strlen(ptr1) > 0) {
2686 TRACE("---> '%s' \n", ptr1);
2687 ptr1 += strlen(ptr1) + 1;
2688 MCI_InstalledCount++;
2691 RegCloseKey(hWineConf);