1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * MCI internal functions
6 * Copyright 1998/1999 Eric Pouech
16 #include "multimedia.h"
17 #include "selectors.h"
20 #include "wine/winbase16.h"
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(mci)
26 static int MCI_InstalledCount;
27 static LPSTR MCI_lpInstallNames = NULL;
29 /* First MCI valid device ID (0 means error) */
30 #define MCI_MAGIC 0x0001
32 /**************************************************************************
33 * MCI_GetDriver [internal]
35 LPWINE_MCIDRIVER MCI_GetDriver(UINT16 wDevID)
37 LPWINE_MCIDRIVER wmd = 0;
38 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
40 EnterCriticalSection(&iData->cs);
42 for (wmd = iData->lpMciDrv; wmd; wmd = wmd->lpNext) {
43 if (wmd->wDeviceID == wDevID)
47 LeaveCriticalSection(&iData->cs);
51 /**************************************************************************
52 * MCI_GetDriverFromString [internal]
54 UINT MCI_GetDriverFromString(LPCSTR lpstrName)
57 LPWINE_MM_IDATA iData;
63 if (!lstrcmpiA(lpstrName, "ALL"))
64 return MCI_ALL_DEVICE_ID;
66 if ((iData = MULTIMEDIA_GetIData())) {
67 EnterCriticalSection(&iData->cs);
68 for (wmd = iData->lpMciDrv; wmd; wmd = wmd->lpNext) {
69 if (wmd->lpstrElementName && strcmp(wmd->lpstrElementName, lpstrName) == 0) {
74 if (wmd->lpstrDeviceType && strcmp(wmd->lpstrDeviceType, lpstrName) == 0) {
79 if (wmd->lpstrAlias && strcmp(wmd->lpstrAlias, lpstrName) == 0) {
84 LeaveCriticalSection(&iData->cs);
90 /**************************************************************************
91 * MCI_MessageToString [internal]
93 const char* MCI_MessageToString(UINT16 wMsg)
95 static char buffer[100];
97 #define CASE(s) case (s): return #s
102 CASE(MCI_CLOSE_DRIVER);
111 CASE(MCI_GETDEVCAPS);
115 CASE(MCI_OPEN_DRIVER);
133 /* constants for digital video */
147 sprintf(buffer, "MCI_<<%04X>>", wMsg);
152 /**************************************************************************
153 * MCI_GetDevTypeFromFileName [internal]
155 static DWORD MCI_GetDevTypeFromFileName(LPCSTR fileName, LPSTR buf, UINT len)
159 if ((tmp = strrchr(fileName, '.'))) {
160 GetProfileStringA("mci extensions", tmp + 1, "*", buf, len);
161 if (strcmp(buf, "*") != 0) {
164 TRACE("No [mci extensions] entry for '%s' found.\n", tmp);
166 return MCIERR_EXTENSION_NOT_FOUND;
169 #define MAX_MCICMDTABLE 20
170 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
172 typedef struct tagWINE_MCICMDTABLE {
176 /* could also some more info to parse faster the lpTable
177 * an array of indexes to lpTable for all the commands
178 * could be a good start
180 } WINE_MCICMDTABLE, *LPWINE_MCICMDTABLE;
181 WINE_MCICMDTABLE S_MciCmdTable[MAX_MCICMDTABLE];
183 /**************************************************************************
184 * MCI_IsCommandTableValid [internal]
186 static BOOL MCI_IsCommandTableValid(UINT uTbl)
194 TRACE("Dumping cmdTbl=%d [hMem=%08x devType=%d]\n",
195 uTbl, S_MciCmdTable[uTbl].hMem, S_MciCmdTable[uTbl].uDevType);
197 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].hMem || !S_MciCmdTable[uTbl].lpTable)
200 lmem = S_MciCmdTable[uTbl].lpTable;
204 lmem += strlen(lmem) + 1;
205 flg = *(LPDWORD)lmem;
206 eid = *(LPWORD)(lmem + sizeof(DWORD));
207 lmem += sizeof(DWORD) + sizeof(WORD);
209 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
211 case MCI_COMMAND_HEAD: if (!*str || !flg) return FALSE; idx = 0; break; /* check unicity of str in table */
212 case MCI_STRING: if (inCst) return FALSE; break;
213 case MCI_INTEGER: if (!*str) return FALSE; break;
214 case MCI_END_COMMAND: if (*str || flg || idx == 0) return FALSE; idx = 0; break;
215 case MCI_RETURN: if (*str || idx != 1) return FALSE; break;
216 case MCI_FLAG: if (!*str) return FALSE; break;
217 case MCI_END_COMMAND_LIST: if (*str || flg) return FALSE; idx = 0; break;
218 case MCI_RECT: if (!*str || inCst) return FALSE; break;
219 case MCI_CONSTANT: if (inCst) return FALSE; inCst = TRUE; break;
220 case MCI_END_CONSTANT: if (*str || flg || !inCst) return FALSE; inCst = FALSE; break;
221 default: return FALSE;
223 } while (eid != MCI_END_COMMAND_LIST);
224 } while (eid != MCI_END_COMMAND_LIST);
228 /**************************************************************************
229 * MCI_DumpCommandTable [internal]
231 static BOOL MCI_DumpCommandTable(UINT uTbl)
238 if (!MCI_IsCommandTableValid(uTbl)) {
239 ERR("Ooops: %d is not valid\n", uTbl);
243 lmem = S_MciCmdTable[uTbl].lpTable;
247 lmem += strlen(lmem) + 1;
248 flg = *(LPDWORD)lmem;
249 eid = *(LPWORD)(lmem + sizeof(DWORD));
250 TRACE("cmd='%s' %08lx %04x\n", str, flg, eid);
251 lmem += sizeof(DWORD) + sizeof(WORD);
252 } while (eid != MCI_END_COMMAND && eid != MCI_END_COMMAND_LIST);
253 TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : "");
254 } while (eid != MCI_END_COMMAND_LIST);
258 static UINT MCI_SetCommandTable(LPWINE_MM_IDATA iData, HANDLE hMem, UINT uDevType);
260 /**************************************************************************
261 * MCI_GetCommandTable [internal]
263 static UINT MCI_GetCommandTable(LPWINE_MM_IDATA iData, UINT uDevType)
269 /* first look up existing for existing devType */
270 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
271 if (S_MciCmdTable[uTbl].hMem && S_MciCmdTable[uTbl].uDevType == uDevType)
275 /* well try to load id */
276 if (uDevType >= MCI_DEVTYPE_FIRST && uDevType <= MCI_DEVTYPE_LAST) {
277 if (LoadStringA(iData->hWinMM32Instance, uDevType, buf, sizeof(buf))) {
280 } else if (uDevType == 0) {
283 uTbl = MCI_NO_COMMAND_TABLE;
285 HRSRC hRsrc = FindResourceA(iData->hWinMM32Instance, str, (LPCSTR)RT_RCDATAA);
288 if (hRsrc) hMem = LoadResource(iData->hWinMM32Instance, hRsrc);
290 uTbl = MCI_SetCommandTable(iData, hMem, uDevType);
292 WARN("No command table found in resource %04x[%s]\n",
293 iData->hWinMM32Instance, str);
296 TRACE("=> %d\n", uTbl);
300 /**************************************************************************
301 * MCI_SetCommandTable [internal]
303 static UINT MCI_SetCommandTable(LPWINE_MM_IDATA iData, HANDLE hMem,
307 static BOOL bInitDone = FALSE;
310 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
311 * can be called with 0 as a uDevType to retrieve it.
316 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
317 S_MciCmdTable[uTbl].hMem = 0;
319 MCI_GetCommandTable(iData, 0);
322 for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
323 if (S_MciCmdTable[uTbl].hMem == 0) {
324 S_MciCmdTable[uTbl].hMem = hMem;
325 S_MciCmdTable[uTbl].uDevType = uDevType;
326 S_MciCmdTable[uTbl].lpTable = LockResource(hMem);
329 MCI_DumpCommandTable(uTbl);
336 return MCI_NO_COMMAND_TABLE;
339 /**************************************************************************
340 * MCI_DeleteCommandTable [internal]
342 static BOOL MCI_DeleteCommandTable(UINT uTbl)
344 if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].hMem)
347 FreeResource16(S_MciCmdTable[uTbl].hMem);
348 S_MciCmdTable[uTbl].hMem = 0;
352 /**************************************************************************
353 * MCI_UnLoadMciDriver [internal]
355 static BOOL MCI_UnLoadMciDriver(LPWINE_MM_IDATA iData, LPWINE_MCIDRIVER wmd)
357 LPWINE_MCIDRIVER* tmp;
363 CloseDriver(wmd->hDrv, 0, 0);
365 if (wmd->dwPrivate != 0)
366 WARN("Unloading mci driver with non nul dwPrivate field\n");
368 EnterCriticalSection(&iData->cs);
369 for (tmp = &iData->lpMciDrv; *tmp; tmp = &(*tmp)->lpNext) {
375 LeaveCriticalSection(&iData->cs);
377 HeapFree(GetProcessHeap(), 0, wmd->lpstrDeviceType);
378 HeapFree(GetProcessHeap(), 0, wmd->lpstrAlias);
379 HeapFree(GetProcessHeap(), 0, wmd->lpstrElementName);
381 HeapFree(GetProcessHeap(), 0, wmd);
385 /**************************************************************************
386 * MCI_LoadMciDriver [internal]
388 static DWORD MCI_LoadMciDriver(LPWINE_MM_IDATA iData, LPCSTR _strDevTyp,
389 LPWINE_MCIDRIVER* lpwmd)
391 LPSTR strDevTyp = CharUpperA(HEAP_strdupA(GetProcessHeap(), 0, _strDevTyp));
392 LPWINE_MCIDRIVER wmd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmd));
393 MCI_OPEN_DRIVER_PARMSA modp;
397 if (!wmd || !strDevTyp) {
398 dwRet = MCIERR_OUT_OF_MEMORY;
402 EnterCriticalSection(&iData->cs);
403 /* wmd must be inserted in list before sending opening the driver, coz' it
404 * may want to lookup at wDevID
406 wmd->lpNext = iData->lpMciDrv;
407 iData->lpMciDrv = wmd;
409 for (modp.wDeviceID = MCI_MAGIC;
410 MCI_GetDriver(modp.wDeviceID) != 0;
413 wmd->wDeviceID = modp.wDeviceID;
414 wmd->lpfnYieldProc = MCI_DefYieldProc;
415 wmd->dwYieldData = VK_CANCEL;
416 wmd->hCreatorTask = GetCurrentTask();
418 LeaveCriticalSection(&iData->cs);
420 TRACE("wDevID=%04X \n", modp.wDeviceID);
422 modp.lpstrParams = NULL;
424 hDrv = OpenDriverA(strDevTyp, "mci", (LPARAM)&modp);
427 FIXME("Couldn't load driver for type %s.\n", strDevTyp);
428 dwRet = MCIERR_DEVICE_NOT_INSTALLED;
432 /* FIXME: should also check that module's description is of the form
433 * MODULENAME:[MCI] comment
437 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
438 wmd->uSpecificCmdTable = LOWORD(modp.wCustomCommandTable);
439 wmd->uTypeCmdTable = MCI_COMMAND_TABLE_NOT_LOADED;
441 TRACE("Loaded driver %u (%s), type is %d, cmdTable=%08x\n",
442 hDrv, strDevTyp, modp.wType, modp.wCustomCommandTable);
444 wmd->lpstrDeviceType = strDevTyp;
445 wmd->wType = modp.wType;
447 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
448 modp.wDeviceID, modp.wType, modp.wDeviceID);
452 MCI_UnLoadMciDriver(iData, wmd);
453 HeapFree(GetProcessHeap(), 0, strDevTyp);
458 /**************************************************************************
459 * MCI_FinishOpen [internal]
461 static DWORD MCI_FinishOpen(LPWINE_MCIDRIVER wmd, LPMCI_OPEN_PARMSA lpParms,
464 if (dwParam & MCI_OPEN_ELEMENT)
465 wmd->lpstrElementName = HEAP_strdupA(GetProcessHeap(), 0,
466 lpParms->lpstrElementName);
468 if (dwParam & MCI_OPEN_ALIAS)
469 wmd->lpstrAlias = HEAP_strdupA(GetProcessHeap(), 0, lpParms->lpstrAlias);
471 lpParms->wDeviceID = wmd->wDeviceID;
473 return MCI_SendCommandFrom32(wmd->wDeviceID, MCI_OPEN_DRIVER, dwParam,
477 /**************************************************************************
478 * MCI_FindCommand [internal]
480 static LPCSTR MCI_FindCommand(UINT uTbl, LPCSTR verb)
486 if (uTbl >= MAX_MCICMDTABLE || S_MciCmdTable[uTbl].hMem == 0)
489 lmem = S_MciCmdTable[uTbl].lpTable;
494 lmem += strlen(lmem) + 1;
495 flg = *(LPDWORD)lmem;
496 eid = *(LPWORD)(lmem + sizeof(DWORD));
497 lmem += sizeof(DWORD) + sizeof(WORD);
498 if (eid == MCI_COMMAND_HEAD && strcmp(str, verb) == 0)
500 } while (eid != MCI_END_COMMAND_LIST);
501 } while (eid != MCI_END_COMMAND_LIST);
505 /**************************************************************************
506 * MCI_GetReturnType [internal]
508 static DWORD MCI_GetReturnType(LPCSTR lpCmd)
510 lpCmd += strlen(lpCmd) + 1 + sizeof(DWORD) + sizeof(WORD);
511 if (*lpCmd == '\0' && *(LPWORD)(lpCmd + 1 + sizeof(DWORD)) == MCI_RETURN) {
512 return *(LPDWORD)(lpCmd + 1);
517 /**************************************************************************
518 * MCI_GetMessage [internal]
520 static WORD MCI_GetMessage(LPCSTR lpCmd)
522 return (WORD)*(LPDWORD)(lpCmd + strlen(lpCmd) + 1);
525 /**************************************************************************
526 * MCI_GetDWord [internal]
528 static BOOL MCI_GetDWord(LPDWORD data, LPSTR* ptr)
533 val = strtoul(*ptr, &ret, 0);
537 case ' ': ret++; break;
538 default: return FALSE;
546 /**************************************************************************
547 * MCI_GetString [internal]
549 static DWORD MCI_GetString(LPSTR* str, LPSTR* args)
553 /* see if we have a quoted string */
555 ptr = strchr(*str = ptr + 1, '"');
556 if (!ptr) return MCIERR_NO_CLOSING_QUOTE;
557 /* FIXME: shall we escape \" from string ?? */
558 if (ptr[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
559 *ptr++ = '\0'; /* remove trailing " */
560 if (*ptr != ' ' && *ptr != '\0') return MCIERR_EXTRA_CHARACTERS;
563 ptr = strchr(ptr, ' ');
568 ptr = *args + strlen(*args);
577 #define MCI_DATA_SIZE 16
579 /**************************************************************************
580 * MCI_ParseOptArgs [internal]
582 static DWORD MCI_ParseOptArgs(LPDWORD data, int _offset, LPCSTR lpCmd,
583 LPSTR args, LPDWORD dwFlags)
587 DWORD dwRet, flg, cflg = 0;
591 /* loop on arguments */
594 found = inCst = FALSE;
596 TRACE("args='%s' offset=%d\n", args, offset);
598 do { /* loop on options for command table for the requested verb */
600 lmem += (len = strlen(lmem)) + 1;
601 flg = *(LPDWORD)lmem;
602 eid = *(LPWORD)(lmem + sizeof(DWORD));
603 lmem += sizeof(DWORD) + sizeof(WORD);
604 /* EPP TRACE("\tcmd='%s' inCst=%s\n", str, inCst ? "Y" : "N"); */
608 inCst = TRUE; cflg = flg; break;
609 case MCI_END_CONSTANT:
610 /* there may be additional integral values after flag in constant */
611 if (inCst && MCI_GetDWord(&(data[offset]), &args)) {
614 inCst = FALSE; cflg = 0;
618 if (strncasecmp(args, str, len) == 0 &&
619 (args[len] == 0 || args[len] == ' ')) {
620 /* store good values into data[] */
622 if (*args == ' ') args++;
626 case MCI_COMMAND_HEAD:
628 case MCI_END_COMMAND:
629 case MCI_END_COMMAND_LIST:
630 case MCI_CONSTANT: /* done above */
631 case MCI_END_CONSTANT: /* done above */
643 if (!MCI_GetDWord(&(data[offset]), &args)) {
644 return MCIERR_BAD_INTEGER;
649 /* store rect in data (offset...offset+3) */
651 if (!MCI_GetDWord(&(data[offset+0]), &args) ||
652 !MCI_GetDWord(&(data[offset+1]), &args) ||
653 !MCI_GetDWord(&(data[offset+2]), &args) ||
654 !MCI_GetDWord(&(data[offset+3]), &args)) {
655 ERR("Bad rect '%s'\n", args);
656 return MCIERR_BAD_INTEGER;
661 if ((dwRet = MCI_GetString((LPSTR*)&data[offset], &args)))
664 default: ERR("oops");
666 /* exit inside while loop */
667 eid = MCI_END_COMMAND;
669 /* have offset incremented if needed */
671 case MCI_COMMAND_HEAD:
673 case MCI_END_COMMAND:
674 case MCI_END_COMMAND_LIST:
676 case MCI_FLAG: break;
677 case MCI_INTEGER: if (!inCst) offset++; break;
678 case MCI_END_CONSTANT:
679 case MCI_STRING: offset++; break;
680 case MCI_RECT: offset += 4; break;
681 default: ERR("oops");
684 } while (eid != MCI_END_COMMAND);
686 TRACE("Optarg '%s' not found\n", args);
687 return MCIERR_UNRECOGNIZED_COMMAND;
689 if (offset == MCI_DATA_SIZE) {
690 ERR("Internal data[] buffer overflow\n");
691 return MCIERR_PARSER_INTERNAL;
697 /**************************************************************************
698 * MCI_HandleReturnValues [internal]
700 static DWORD MCI_HandleReturnValues(LPWINE_MM_IDATA iData, DWORD dwRet, LPWINE_MCIDRIVER wmd,
701 LPCSTR lpCmd, LPDWORD data, LPSTR lpstrRet, UINT uRetLen)
704 switch (MCI_GetReturnType(lpCmd)) {
705 case 0: /* nothing to return */
708 switch (dwRet & 0xFFFF0000ul) {
710 case MCI_INTEGER_RETURNED:
711 snprintf(lpstrRet, uRetLen, "%d", data[1]);
713 case MCI_RESOURCE_RETURNED:
714 /* return string which ID is HIWORD(data[1]),
715 * string is loaded from mmsystem.dll */
716 LoadStringA(iData->hWinMM32Instance, HIWORD(data[1]),
719 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
720 /* return string which ID is HIWORD(data[1]),
721 * string is loaded from driver */
722 LoadStringA(wmd->hDrv, HIWORD(data[1]), lpstrRet, uRetLen);
724 case MCI_COLONIZED3_RETURN:
725 snprintf(lpstrRet, uRetLen, "%d:%d:%d",
726 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
727 LOBYTE(HIWORD(data[1])));
729 case MCI_COLONIZED4_RETURN:
730 snprintf(lpstrRet, uRetLen, "%d:%d:%d:%d",
731 LOBYTE(LOWORD(data[1])), HIBYTE(LOWORD(data[1])),
732 LOBYTE(HIWORD(data[1])), HIBYTE(HIWORD(data[1])));
734 default: ERR("Ooops (%04X)\n", HIWORD(dwRet));
738 switch (dwRet & 0xFFFF0000ul) {
740 /* nothing to do data[1] == lpstrRet */
742 case MCI_INTEGER_RETURNED:
743 data[1] = *(LPDWORD)lpstrRet;
744 snprintf(lpstrRet, uRetLen, "%d", data[1]);
747 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
752 if (dwRet & 0xFFFF0000ul)
753 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet));
754 snprintf(lpstrRet, uRetLen, "%d %d %d %d",
755 data[1], data[2], data[3], data[4]);
757 default: ERR("oops\n");
760 return LOWORD(dwRet);
763 /**************************************************************************
764 * mciSendStringA [MMSYSTEM.702][WINMM.51]
766 DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet,
767 UINT uRetLen, HWND hwndCallback)
769 LPSTR verb, dev, args;
770 LPWINE_MCIDRIVER wmd = 0;
771 DWORD dwFlags = 0, dwRet = 0;
773 DWORD data[MCI_DATA_SIZE];
775 LPWINE_MM_IDATA iData;
777 TRACE("('%s', %p, %d, %X)\n", lpstrCommand, lpstrRet, uRetLen, hwndCallback);
779 if (!(iData = MULTIMEDIA_GetIData()))
780 return MCIERR_INTERNAL;
782 /* format is <command> <device> <optargs> */
783 if (!(verb = HEAP_strdupA(GetProcessHeap(), 0, lpstrCommand)))
784 return MCIERR_OUT_OF_MEMORY;
786 memset(data, 0, sizeof(data));
788 if (!(args = strchr(verb, ' '))) {
789 dwRet = MCIERR_MISSING_DEVICE_NAME;
793 if ((dwRet = MCI_GetString(&dev, &args))) {
797 /* case dev == 'new' has to be handled */
798 if (!strcasecmp(dev, "new")) {
799 FIXME("'new': NIY as device name\n");
800 dwRet = MCIERR_MISSING_DEVICE_NAME;
804 /* otherwise, try to grab devType from open */
805 if (!strcmp(verb, "open")) {
808 if ((devType = strchr(dev, '!')) != NULL) {
810 tmp = devType; devType = dev; dev = tmp;
812 dwFlags |= MCI_OPEN_TYPE;
813 data[2] = (DWORD)devType;
814 devType = CharUpperA(HEAP_strdupA(GetProcessHeap(), 0, devType));
816 if ((devType = strstr(args, "type ")) != NULL) {
818 tmp = strchr(devType, ' ');
819 if (tmp) *tmp = '\0';
820 devType = CharUpperA(HEAP_strdupA(GetProcessHeap(), 0, devType));
822 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
825 if ((dwRet = MCI_GetDevTypeFromFileName(dev, buf, sizeof(buf))))
828 devType = CharUpperA(HEAP_strdupA(GetProcessHeap(), 0, buf));
830 dwFlags |= MCI_OPEN_ELEMENT;
831 data[3] = (DWORD)dev;
833 dwRet = MCI_LoadMciDriver(iData, devType, &wmd);
834 HeapFree(GetProcessHeap(), 0, devType);
836 MCI_UnLoadMciDriver(iData, wmd);
840 wmd = MCI_GetDriver(mciGetDeviceIDA(dev));
842 FIXME("Oooch: couldn't find driver for '%s'; automatic open not implemented\n", dev);
845 /* get the verb in the different command tables */
846 /* try the device specific command table */
847 if (wmd) lpCmd = MCI_FindCommand(wmd->uSpecificCmdTable, verb);
848 /* try the type specific command table */
850 if (wmd && wmd->uTypeCmdTable == MCI_COMMAND_TABLE_NOT_LOADED)
851 wmd->uTypeCmdTable = MCI_GetCommandTable(iData, wmd->wType);
852 if (wmd && wmd->uTypeCmdTable != MCI_NO_COMMAND_TABLE)
853 lpCmd = MCI_FindCommand(wmd->uTypeCmdTable, verb);
855 /* try core command table */
856 if (!lpCmd) lpCmd = MCI_FindCommand(MCI_GetCommandTable(iData, 0), verb);
859 TRACE("Command '%s' not found!\n", verb);
860 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
864 /* set up call back */
865 if (hwndCallback != 0) {
866 dwFlags |= MCI_NOTIFY;
867 data[0] = (DWORD)hwndCallback;
870 /* set return information */
871 switch (MCI_GetReturnType(lpCmd)) {
872 case 0: offset = 1; break;
873 case MCI_INTEGER: offset = 2; break;
874 case MCI_STRING: data[1] = (DWORD)lpstrRet; data[2] = uRetLen; offset = 3; break;
875 case MCI_RECT: offset = 5; break;
876 default: ERR("oops\n");
879 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb, dev, offset);
881 if ((dwRet = MCI_ParseOptArgs(data, offset, lpCmd, args, &dwFlags)))
884 if (lpstrRet && uRetLen) *lpstrRet = '\0';
886 #define STR_OF(_x) (((_x)&0xFF000000)?(char*)(_x):"?")
887 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
888 wmd->wDeviceID, MCI_MessageToString(MCI_GetMessage(lpCmd)), dwFlags,
889 data[0], STR_OF(data[0]), data[1], STR_OF(data[1]),
890 data[2], STR_OF(data[2]), data[3], STR_OF(data[3]),
891 data[4], STR_OF(data[4]), data[5], STR_OF(data[5]));
894 if (strcmp(verb, "open") == 0) {
895 if ((dwRet = MCI_FinishOpen(wmd, (LPMCI_OPEN_PARMSA)data, dwFlags)))
896 MCI_UnLoadMciDriver(iData, wmd);
897 /* FIXME: notification is not properly shared across two opens */
899 dwRet = MCI_SendCommand(wmd->wDeviceID, MCI_GetMessage(lpCmd), dwFlags, (DWORD)data, TRUE);
901 TRACE("=> 1/ %lx (%s)\n", dwRet, lpstrRet);
902 if (dwRet) goto errCleanUp;
904 dwRet = MCI_HandleReturnValues(iData, dwRet, wmd, lpCmd, data, lpstrRet, uRetLen);
905 TRACE("=> 2/ %lx (%s)\n", dwRet, lpstrRet);
908 HeapFree(GetProcessHeap(), 0, verb);
912 /**************************************************************************
913 * mciSendStringW [WINMM.52]
915 DWORD WINAPI mciSendStringW(LPCWSTR lpwstrCommand, LPSTR lpstrRet,
916 UINT uRetLen, HWND hwndCallback)
921 /* FIXME: is there something to do with lpstrReturnString ? */
922 lpstrCommand = HEAP_strdupWtoA(GetProcessHeap(), 0, lpwstrCommand);
923 ret = mciSendStringA(lpstrCommand, lpstrRet, uRetLen, hwndCallback);
924 HeapFree(GetProcessHeap(), 0, lpstrCommand);
928 /**************************************************************************
929 * mciSendString16 [MMSYSTEM.702]
931 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
932 UINT16 uRetLen, HWND16 hwndCallback)
934 return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, hwndCallback);
937 /**************************************************************************
938 * mciExecute [WINMM.38]
940 DWORD WINAPI mciExecute(LPCSTR lpstrCommand)
945 TRACE("(%s)!\n", lpstrCommand);
947 ret = mciSendString16(lpstrCommand, strRet, sizeof(strRet), 0);
949 if (!mciGetErrorStringA(ret, strRet, sizeof(strRet))) {
950 sprintf(strRet, "Unknown MCI error (%ld)", ret);
952 MessageBoxA(0, strRet, "Error in mciExecute()", MB_OK);
954 /* FIXME: what shall I return ? */
958 /**************************************************************************
959 * mciLoadCommandResource [MMSYSTEM.705]
961 UINT16 WINAPI mciLoadCommandResource16(HANDLE16 hInst, LPCSTR resname, UINT16 type)
965 UINT16 ret = MCI_NO_COMMAND_TABLE;
966 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIData();
968 TRACE("(%04x, %s, %d)!\n", hInst, resname, type);
973 /* if file exists "resname.mci", then load resource "resname" from it
974 * otherwise directly from driver
975 * We don't support it (who uses this feature ?), but we check anyway
981 strcat(strcpy(buf, resname), ".mci");
982 if (OpenFile(buf, &ofs, OF_EXIST) != HFILE_ERROR) {
983 FIXME("NIY: command table to be loaded from '%s'\n", ofs.szPathName);
986 if (!(hRsrc = FindResourceA(hInst, resname, (LPCSTR)RT_RCDATAA))) {
987 WARN("No command table found in resource\n");
988 } else if ((hMem = LoadResource(hInst, hRsrc))) {
989 ret = MCI_SetCommandTable(iData, hMem, type);
991 WARN("Couldn't load resource.\n");
993 TRACE("=> %04x\n", ret);
997 /**************************************************************************
998 * mciFreeCommandResource [MMSYSTEM.713]
1000 BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
1002 TRACE("(%04x)!\n", uTable);
1004 return MCI_DeleteCommandTable(uTable);
1007 /**************************************************************************
1008 * mciLoadCommandResource [WINMM.48]
1010 * Strangely, this function only exists as an UNICODE one.
1012 UINT WINAPI mciLoadCommandResource(HINSTANCE hinst, LPCWSTR resNameW, UINT type)
1017 TRACE("(%04x, %s, %d)!\n", hinst, debugstr_w(resNameW), type);
1019 resNameA = HEAP_strdupWtoA(GetProcessHeap(), 0, resNameW);
1020 ret = mciLoadCommandResource16(hinst, resNameA, type);
1021 HeapFree(GetProcessHeap(), 0, resNameA);
1025 /**************************************************************************
1026 * mciFreeCommandResource [WINMM.39]
1028 BOOL WINAPI mciFreeCommandResource(UINT uTable)
1030 TRACE("(%08x)!\n", uTable);
1032 return mciFreeCommandResource16(uTable);
1035 /**************************************************************************
1036 * MCI_MapMsg16To32A [internal]
1038 static MCI_MapType MCI_MapMsg16To32A(WORD uDevType, WORD wMsg, DWORD* lParam)
1042 /* FIXME: to add also (with seg/linear modifications to do):
1043 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
1044 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
1047 /* case MCI_CAPTURE */
1049 case MCI_CLOSE_DRIVER:
1050 /* case MCI_CONFIGURE:*/
1056 case MCI_GETDEVCAPS:
1057 /* case MCI_INDEX: */
1058 /* case MCI_MARK: */
1059 /* case MCI_MONITOR: */
1069 /* case MCI_SETTIMECODE:*/
1070 /* case MCI_SIGNAL:*/
1072 case MCI_STATUS: /* FIXME: is wrong for digital video */
1075 /* case MCI_UNDO: */
1079 *lParam = (DWORD)PTR_SEG_TO_LIN(*lParam);
1082 /* in fact, I would also need the dwFlags... to see
1083 * which members of lParam are effectively used
1085 *lParam = (DWORD)PTR_SEG_TO_LIN(*lParam);
1086 FIXME("Current mapping may be wrong\n");
1090 LPMCI_BREAK_PARMS mbp32 = HeapAlloc(SystemHeap, 0, sizeof(MCI_BREAK_PARMS));
1091 LPMCI_BREAK_PARMS16 mbp16 = PTR_SEG_TO_LIN(*lParam);
1094 mbp32->dwCallback = mbp16->dwCallback;
1095 mbp32->nVirtKey = mbp16->nVirtKey;
1096 mbp32->hwndBreak = mbp16->hwndBreak;
1098 return MCI_MAP_NOMEM;
1100 *lParam = (DWORD)mbp32;
1102 return MCI_MAP_OKMEM;
1105 LPMCI_VD_ESCAPE_PARMSA mvep32a = HeapAlloc(SystemHeap, 0, sizeof(MCI_VD_ESCAPE_PARMSA));
1106 LPMCI_VD_ESCAPE_PARMS16 mvep16 = PTR_SEG_TO_LIN(*lParam);
1109 mvep32a->dwCallback = mvep16->dwCallback;
1110 mvep32a->lpstrCommand = PTR_SEG_TO_LIN(mvep16->lpstrCommand);
1112 return MCI_MAP_NOMEM;
1114 *lParam = (DWORD)mvep32a;
1116 return MCI_MAP_OKMEM;
1119 LPMCI_INFO_PARMSA mip32a = HeapAlloc(SystemHeap, 0, sizeof(MCI_INFO_PARMSA));
1120 LPMCI_INFO_PARMS16 mip16 = PTR_SEG_TO_LIN(*lParam);
1122 /* FIXME this is wrong if device is of type
1123 * MCI_DEVTYPE_DIGITAL_VIDEO, some members are not mapped
1126 mip32a->dwCallback = mip16->dwCallback;
1127 mip32a->lpstrReturn = PTR_SEG_TO_LIN(mip16->lpstrReturn);
1128 mip32a->dwRetSize = mip16->dwRetSize;
1130 return MCI_MAP_NOMEM;
1132 *lParam = (DWORD)mip32a;
1134 return MCI_MAP_OKMEM;
1136 case MCI_OPEN_DRIVER:
1138 LPMCI_OPEN_PARMSA mop32a = HeapAlloc(SystemHeap, 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_OPEN_PARMSA) + 2 * sizeof(DWORD));
1139 LPMCI_OPEN_PARMS16 mop16 = PTR_SEG_TO_LIN(*lParam);
1142 *(LPMCI_OPEN_PARMS16*)(mop32a) = mop16;
1143 mop32a = (LPMCI_OPEN_PARMSA)((char*)mop32a + sizeof(LPMCI_OPEN_PARMS16));
1144 mop32a->dwCallback = mop16->dwCallback;
1145 mop32a->wDeviceID = mop16->wDeviceID;
1146 mop32a->lpstrDeviceType = PTR_SEG_TO_LIN(mop16->lpstrDeviceType);
1147 mop32a->lpstrElementName = PTR_SEG_TO_LIN(mop16->lpstrElementName);
1148 mop32a->lpstrAlias = PTR_SEG_TO_LIN(mop16->lpstrAlias);
1149 /* copy extended information if any...
1150 * FIXME: this may seg fault if initial structure does not contain them and
1151 * the reads after msip16 fail under LDT limits...
1152 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
1153 * should not take care of extended parameters, and should be used by MCI_Open
1154 * to fetch uDevType. When, this is known, the mapping for sending the
1155 * MCI_OPEN_DRIVER shall be done depending on uDevType.
1157 memcpy(mop32a + 1, mop16 + 1, 2 * sizeof(DWORD));
1159 return MCI_MAP_NOMEM;
1161 *lParam = (DWORD)mop32a;
1163 return MCI_MAP_OKMEM;
1166 LPMCI_SYSINFO_PARMSA msip32a = HeapAlloc(SystemHeap, 0, sizeof(MCI_SYSINFO_PARMSA));
1167 LPMCI_SYSINFO_PARMS16 msip16 = PTR_SEG_TO_LIN(*lParam);
1170 msip32a->dwCallback = msip16->dwCallback;
1171 msip32a->lpstrReturn = PTR_SEG_TO_LIN(msip16->lpstrReturn);
1172 msip32a->dwRetSize = msip16->dwRetSize;
1173 msip32a->dwNumber = msip16->dwNumber;
1174 msip32a->wDeviceType = msip16->wDeviceType;
1176 return MCI_MAP_NOMEM;
1178 *lParam = (DWORD)msip32a;
1180 return MCI_MAP_OKMEM;
1188 case DRV_QUERYCONFIGURE:
1191 case DRV_EXITSESSION:
1192 case DRV_EXITAPPLICATION:
1194 FIXME("This is a hack\n");
1198 WARN("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
1200 return MCI_MAP_MSGERROR;
1203 /**************************************************************************
1204 * MCI_UnMapMsg16To32A [internal]
1206 static MCI_MapType MCI_UnMapMsg16To32A(WORD uDevType, WORD wMsg, DWORD lParam)
1209 /* case MCI_CAPTURE */
1211 case MCI_CLOSE_DRIVER:
1212 /* case MCI_CONFIGURE:*/
1218 case MCI_GETDEVCAPS:
1219 /* case MCI_INDEX: */
1220 /* case MCI_MARK: */
1221 /* case MCI_MONITOR: */
1231 /* case MCI_SETTIMECODE:*/
1232 /* case MCI_SIGNAL:*/
1237 /* case MCI_UNDO: */
1244 /* FIXME ?? see Map function */
1251 HeapFree(SystemHeap, 0, (LPVOID)lParam);
1254 case MCI_OPEN_DRIVER:
1256 LPMCI_OPEN_PARMSA mop32a = (LPMCI_OPEN_PARMSA)lParam;
1257 LPMCI_OPEN_PARMS16 mop16 = *(LPMCI_OPEN_PARMS16*)((char*)mop32a - sizeof(LPMCI_OPEN_PARMS16*));
1259 mop16->wDeviceID = mop32a->wDeviceID;
1260 if (!HeapFree(SystemHeap, 0, (LPVOID)(lParam - sizeof(LPMCI_OPEN_PARMS16))))
1261 FIXME("bad free line=%d\n", __LINE__);
1271 case DRV_QUERYCONFIGURE:
1274 case DRV_EXITSESSION:
1275 case DRV_EXITAPPLICATION:
1277 FIXME("This is a hack\n");
1280 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
1282 return MCI_MAP_MSGERROR;
1287 * 0001 squeeze signed 4 bytes to 2 bytes *( LPINT16)D = ( INT16)*( LPINT16)S; D += 2; S += 4
1288 * 0010 squeeze unsigned 4 bytes to 2 bytes *(LPUINT16)D = (UINT16)*(LPUINT16)S; D += 2; S += 4
1291 * 0110 zero 4 bytes *(DWORD)D = 0 D += 4; S += 4
1292 * 0111 copy string *(LPSTR*)D = seg dup(*(LPSTR*)S) D += 4; S += 4
1293 * 1xxx copy xxx + 1 bytes memcpy(D, S, xxx + 1); D += xxx+1; S += xxx+1
1296 /**************************************************************************
1297 * MCI_MsgMapper32To16_Create [internal]
1299 * Helper for MCI_MapMsg32ATo16.
1300 * Maps the 32 bit pointer (*ptr), of size bytes, to an allocated 16 bit
1301 * segmented pointer.
1302 * map contains a list of action to be performed for the mapping (see list
1304 * if keep is TRUE, keeps track of in 32 bit ptr in allocated 16 bit area.
1306 static MCI_MapType MCI_MsgMapper32To16_Create(void** ptr, int size16, DWORD map, BOOLEAN keep)
1308 void* lp = SEGPTR_ALLOC((keep ? sizeof(void**) : 0) + size16);
1312 return MCI_MAP_NOMEM;
1314 p32 = (LPBYTE)(*ptr);
1317 p16 = (LPBYTE)lp + sizeof(void**);
1318 *ptr = (char*)SEGPTR_GET(lp) + sizeof(void**);
1321 *ptr = (void*)SEGPTR_GET(lp);
1325 memcpy(p16, p32, size16);
1333 sz = (nibble & 7) + 1;
1334 memcpy(p16, p32, sz);
1337 size16 -= sz; /* DEBUG only */
1340 case 0x1: *( LPINT16)p16 = ( INT16)*( LPINT16)p32; p16 += 2; p32 += 4; size16 -= 2; break;
1341 case 0x2: *(LPUINT16)p16 = (UINT16)*(LPUINT16)p32; p16 += 2; p32 += 4; size16 -= 2; break;
1342 case 0x6: *(LPDWORD)p16 = 0; p16 += 4; p32 += 4; size16 -= 4; break;
1343 case 0x7: *(LPDWORD)p16 = SEGPTR_GET(SEGPTR_STRDUP(*(LPSTR*)p32));p16 += 4; p32 += 4; size16 -= 4; break;
1344 default: FIXME("Unknown nibble for mapping (%x)\n", nibble);
1349 if (size16 != 0) /* DEBUG only */
1350 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
1352 return MCI_MAP_OKMEM;
1355 /**************************************************************************
1356 * MCI_MsgMapper32To16_Destroy [internal]
1358 * Helper for MCI_UnMapMsg32ATo16.
1360 static MCI_MapType MCI_MsgMapper32To16_Destroy(void* ptr, int size16, DWORD map, BOOLEAN kept)
1363 void* msg16 = PTR_SEG_TO_LIN(ptr);
1369 alloc = (char*)msg16 - sizeof(void**);
1370 p32 = *(void**)alloc;
1374 memcpy(p32, p16, size16);
1379 memcpy(p32, p16, (nibble & 7) + 1);
1380 p16 += (nibble & 7) + 1;
1381 p32 += (nibble & 7) + 1;
1382 size16 -= (nibble & 7) + 1;
1385 case 0x1: *( LPINT)p32 = *( LPINT16)p16; p16 += 2; p32 += 4; size16 -= 2; break;
1386 case 0x2: *(LPUINT)p32 = *(LPUINT16)p16; p16 += 2; p32 += 4; size16 -= 2; break;
1387 case 0x6: p16 += 4; p32 += 4; size16 -= 4; break;
1388 case 0x7: strcpy(*(LPSTR*)p32, PTR_SEG_TO_LIN(*(DWORD*)p16));
1389 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(*(DWORD*)p16))) {
1390 FIXME("bad free line=%d\n", __LINE__);
1392 p16 += 4; p32 += 4; size16 -= 4; break;
1393 default: FIXME("Unknown nibble for mapping (%x)\n", nibble);
1398 if (size16 != 0) /* DEBUG only */
1399 FIXME("Mismatch between 16 bit struct size and map nibbles serie\n");
1405 if (!SEGPTR_FREE(alloc)) {
1406 FIXME("bad free line=%d\n", __LINE__);
1412 /**************************************************************************
1413 * MCI_MapMsg32ATo16 [internal]
1415 * Map a 32-A bit MCI message to a 16 bit MCI message.
1417 static MCI_MapType MCI_MapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD* lParam)
1420 BOOLEAN keep = FALSE;
1426 /* FIXME: to add also (with seg/linear modifications to do):
1427 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
1428 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
1432 size = sizeof(MCI_BREAK_PARMS);
1434 /* case MCI_CAPTURE */
1436 case MCI_CLOSE_DRIVER:
1437 size = sizeof(MCI_GENERIC_PARMS);
1439 /* case MCI_CONFIGURE:*/
1440 /* case MCI_COPY: */
1443 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_CUE_PARMS); break;
1444 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_CUE_PARMS); break;*/ FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1445 default: size = sizeof(MCI_GENERIC_PARMS); break;
1451 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_DELETE_PARMS16); map = 0x0F1111FB; break;
1452 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_DELETE_PARMS); break;
1453 default: size = sizeof(MCI_GENERIC_PARMS); break;
1456 /* case MCI_ESCAPE: */
1459 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_FREEZE_PARMS); map = 0x0001111B; break;
1460 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
1461 default: size = sizeof(MCI_GENERIC_PARMS); break;
1464 case MCI_GETDEVCAPS:
1466 size = sizeof(MCI_GETDEVCAPS_PARMS);
1468 /* case MCI_INDEX: */
1471 LPMCI_INFO_PARMSA mip32a = (LPMCI_INFO_PARMSA)(*lParam);
1473 LPMCI_INFO_PARMS16 mip16;
1476 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_INFO_PARMS16); break;
1477 default: size = sizeof(MCI_INFO_PARMS16); break;
1479 ptr = SEGPTR_ALLOC(sizeof(LPMCI_INFO_PARMSA) + size);
1482 *(LPMCI_INFO_PARMSA*)ptr = mip32a;
1483 mip16 = (LPMCI_INFO_PARMS16)(ptr + sizeof(LPMCI_INFO_PARMSA));
1484 mip16->dwCallback = mip32a->dwCallback;
1485 mip16->lpstrReturn = (LPSTR)SEGPTR_GET(SEGPTR_ALLOC(mip32a->dwRetSize));
1486 mip16->dwRetSize = mip32a->dwRetSize;
1487 if (uDevType == MCI_DEVTYPE_DIGITAL_VIDEO) {
1488 ((LPMCI_DGV_INFO_PARMS16)mip16)->dwItem = ((LPMCI_DGV_INFO_PARMSA)mip32a)->dwItem;
1491 return MCI_MAP_NOMEM;
1493 *lParam = (LPARAM)SEGPTR_GET(ptr) + sizeof(LPMCI_INFO_PARMSA);
1495 return MCI_MAP_OKMEM;
1496 /* case MCI_MARK: */
1497 /* case MCI_MONITOR: */
1499 case MCI_OPEN_DRIVER:
1501 LPMCI_OPEN_PARMSA mop32a = (LPMCI_OPEN_PARMSA)(*lParam);
1502 char* ptr = SEGPTR_ALLOC(sizeof(LPMCI_OPEN_PARMSA) + sizeof(MCI_OPEN_PARMS16) + 2 * sizeof(DWORD));
1503 LPMCI_OPEN_PARMS16 mop16;
1507 *(LPMCI_OPEN_PARMSA*)(ptr) = mop32a;
1508 mop16 = (LPMCI_OPEN_PARMS16)(ptr + sizeof(LPMCI_OPEN_PARMSA));
1509 mop16->dwCallback = mop32a->dwCallback;
1510 mop16->wDeviceID = mop32a->wDeviceID;
1511 if (dwFlags & MCI_OPEN_TYPE) {
1512 if (dwFlags & MCI_OPEN_TYPE_ID) {
1513 /* dword "transparent" value */
1514 mop16->lpstrDeviceType = mop32a->lpstrDeviceType;
1517 mop16->lpstrDeviceType = mop32a->lpstrDeviceType ? (LPSTR)SEGPTR_GET(SEGPTR_STRDUP(mop32a->lpstrDeviceType)) : 0;
1521 mop16->lpstrDeviceType = 0;
1523 if (dwFlags & MCI_OPEN_ELEMENT) {
1524 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
1525 mop16->lpstrElementName = mop32a->lpstrElementName;
1527 mop16->lpstrElementName = mop32a->lpstrElementName ? (LPSTR)SEGPTR_GET(SEGPTR_STRDUP(mop32a->lpstrElementName)) : 0;
1530 mop16->lpstrElementName = 0;
1532 if (dwFlags & MCI_OPEN_ALIAS) {
1533 mop16->lpstrAlias = mop32a->lpstrAlias ? (LPSTR)SEGPTR_GET(SEGPTR_STRDUP(mop32a->lpstrAlias)) : 0;
1535 mop16->lpstrAlias = 0;
1537 /* copy extended information if any...
1538 * FIXME: this may seg fault if initial structure does not contain them and
1539 * the reads after msip16 fail under LDT limits...
1540 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
1541 * should not take care of extended parameters, and should be used by MCI_Open
1542 * to fetch uDevType. When, this is known, the mapping for sending the
1543 * MCI_OPEN_DRIVER shall be done depending on uDevType.
1545 memcpy(mop16 + 1, mop32a + 1, 2 * sizeof(DWORD));
1547 return MCI_MAP_NOMEM;
1549 *lParam = (LPARAM)SEGPTR_GET(ptr) + sizeof(LPMCI_OPEN_PARMSA);
1551 return MCI_MAP_OKMEM;
1552 /* case MCI_PASTE:*/
1554 size = sizeof(MCI_GENERIC_PARMS);
1557 size = sizeof(MCI_PLAY_PARMS);
1561 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
1562 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS); map = 0x0001111B; break;
1563 default: size = sizeof(MCI_GENERIC_PARMS); break;
1567 size = sizeof(MCI_GENERIC_PARMS);
1571 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECORD_PARMS16); map = 0x0F1111FB; break;
1572 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_RECORD_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1573 default: size = sizeof(MCI_RECORD_PARMS); break;
1577 size = sizeof(MCI_GENERIC_PARMS);
1581 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SEEK_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1582 default: size = sizeof(MCI_SEEK_PARMS); break;
1587 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_SET_PARMS); break;
1588 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_SET_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1589 case MCI_DEVTYPE_SEQUENCER: size = sizeof(MCI_SEQ_SET_PARMS); break;
1590 /* FIXME: normally the 16 and 32 bit structures are byte by byte aligned,
1591 * so not doing anything should work...
1593 case MCI_DEVTYPE_WAVEFORM_AUDIO:size = sizeof(MCI_WAVE_SET_PARMS); break;
1594 default: size = sizeof(MCI_SET_PARMS); break;
1597 /* case MCI_SETTIMECODE:*/
1598 /* case MCI_SIGNAL:*/
1600 size = sizeof(MCI_SET_PARMS);
1606 * don't know if buffer for value is the one passed thru lpstrDevice
1607 * or is provided by MCI driver.
1608 * Assuming solution 2: provided by MCI driver, so zeroing on entry
1610 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STATUS_PARMS16); map = 0x0B6FF; break;
1611 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1612 default: size = sizeof(MCI_STATUS_PARMS); break;
1617 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_STEP_PARMS); break;
1618 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STEP_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1619 case MCI_DEVTYPE_VIDEODISC: size = sizeof(MCI_VD_STEP_PARMS); break;
1620 default: size = sizeof(MCI_GENERIC_PARMS); break;
1624 size = sizeof(MCI_SET_PARMS);
1628 LPMCI_SYSINFO_PARMSA msip32a = (LPMCI_SYSINFO_PARMSA)(*lParam);
1629 char* ptr = SEGPTR_ALLOC(sizeof(LPMCI_SYSINFO_PARMSA) + sizeof(MCI_SYSINFO_PARMS16));
1630 LPMCI_SYSINFO_PARMS16 msip16;
1633 *(LPMCI_SYSINFO_PARMSA*)(ptr) = msip32a;
1634 msip16 = (LPMCI_SYSINFO_PARMS16)(ptr + sizeof(LPMCI_SYSINFO_PARMSA));
1636 msip16->dwCallback = msip32a->dwCallback;
1637 msip16->lpstrReturn = (LPSTR)SEGPTR_GET(SEGPTR_ALLOC(msip32a->dwRetSize));
1638 msip16->dwRetSize = msip32a->dwRetSize;
1639 msip16->dwNumber = msip32a->dwNumber;
1640 msip16->wDeviceType = msip32a->wDeviceType;
1642 return MCI_MAP_NOMEM;
1644 *lParam = (LPARAM)SEGPTR_GET(ptr) + sizeof(LPMCI_SYSINFO_PARMSA);
1646 return MCI_MAP_OKMEM;
1647 /* case MCI_UNDO: */
1650 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; break;
1651 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; break;
1652 default: size = sizeof(MCI_GENERIC_PARMS); break;
1657 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_UPDATE_PARMS16); map = 0x000B1111B; break;
1658 default: size = sizeof(MCI_GENERIC_PARMS); break;
1663 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
1664 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; keep = TRUE; break;
1665 default: size = sizeof(MCI_GENERIC_PARMS); break;
1670 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7FB; break;
1671 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7FB; break;
1672 default: size = sizeof(MCI_GENERIC_PARMS); break;
1682 case DRV_QUERYCONFIGURE:
1685 case DRV_EXITSESSION:
1686 case DRV_EXITAPPLICATION:
1688 return MCI_MAP_PASS;
1691 WARN("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
1692 return MCI_MAP_MSGERROR;
1694 return MCI_MsgMapper32To16_Create((void**)lParam, size, map, keep);
1697 /**************************************************************************
1698 * MCI_UnMapMsg32ATo16 [internal]
1700 static MCI_MapType MCI_UnMapMsg32ATo16(WORD uDevType, WORD wMsg, DWORD dwFlags, DWORD lParam)
1703 BOOLEAN kept = FALSE; /* there is no need to compute size when kept is FALSE */
1709 /* case MCI_CAPTURE */
1711 case MCI_CLOSE_DRIVER:
1713 /* case MCI_CONFIGURE:*/
1714 /* case MCI_COPY: */
1720 /* case MCI_ESCAPE: */
1723 case MCI_GETDEVCAPS:
1725 size = sizeof(MCI_GETDEVCAPS_PARMS);
1727 /* case MCI_INDEX: */
1730 LPMCI_INFO_PARMS16 mip16 = (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(lParam);
1731 LPMCI_INFO_PARMSA mip32a = *(LPMCI_INFO_PARMSA*)((char*)mip16 - sizeof(LPMCI_INFO_PARMSA));
1733 memcpy(mip32a->lpstrReturn, PTR_SEG_TO_LIN(mip16->lpstrReturn), mip32a->dwRetSize);
1735 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(mip16->lpstrReturn)))
1736 FIXME("bad free line=%d\n", __LINE__);
1737 if (!SEGPTR_FREE((char*)mip16 - sizeof(LPMCI_INFO_PARMSA)))
1738 FIXME("bad free line=%d\n", __LINE__);
1741 /* case MCI_MARK: */
1742 /* case MCI_MONITOR: */
1744 case MCI_OPEN_DRIVER:
1746 LPMCI_OPEN_PARMS16 mop16 = (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(lParam);
1747 LPMCI_OPEN_PARMSA mop32a = *(LPMCI_OPEN_PARMSA*)((char*)mop16 - sizeof(LPMCI_OPEN_PARMSA));
1749 mop32a->wDeviceID = mop16->wDeviceID;
1750 if ((dwFlags & MCI_OPEN_TYPE) && !
1751 (dwFlags & MCI_OPEN_TYPE_ID) &&
1752 !SEGPTR_FREE(PTR_SEG_TO_LIN(mop16->lpstrDeviceType)))
1753 FIXME("bad free line=%d\n", __LINE__);
1754 if ((dwFlags & MCI_OPEN_ELEMENT) &&
1755 !(dwFlags & MCI_OPEN_ELEMENT_ID) &&
1756 !SEGPTR_FREE(PTR_SEG_TO_LIN(mop16->lpstrElementName)))
1757 FIXME("bad free line=%d\n", __LINE__);
1758 if ((dwFlags & MCI_OPEN_ALIAS) &&
1759 !SEGPTR_FREE(PTR_SEG_TO_LIN(mop16->lpstrAlias)))
1760 FIXME("bad free line=%d\n", __LINE__);
1762 if (!SEGPTR_FREE((char*)mop16 - sizeof(LPMCI_OPEN_PARMSA)))
1763 FIXME("bad free line=%d\n", __LINE__);
1766 /* case MCI_PASTE:*/
1783 /* case MCI_SETTIMECODE:*/
1784 /* case MCI_SIGNAL:*/
1790 case MCI_DEVTYPE_DIGITAL_VIDEO:
1792 LPMCI_DGV_STATUS_PARMS16 mdsp16 = (LPMCI_DGV_STATUS_PARMS16)PTR_SEG_TO_LIN(lParam);
1793 LPMCI_DGV_STATUS_PARMSA mdsp32a = *(LPMCI_DGV_STATUS_PARMSA*)((char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA));
1796 mdsp32a->dwReturn = mdsp16->dwReturn;
1797 if (dwFlags & MCI_DGV_STATUS_DISKSPACE) {
1798 TRACE("MCI_STATUS (DGV) lpstrDrive=%p\n", mdsp16->lpstrDrive);
1799 TRACE("MCI_STATUS (DGV) lpstrDrive=%s\n", (LPSTR)PTR_SEG_TO_LIN(mdsp16->lpstrDrive));
1801 /* FIXME: see map function */
1802 strcpy(mdsp32a->lpstrDrive, (LPSTR)PTR_SEG_TO_LIN(mdsp16->lpstrDrive));
1805 if (!SEGPTR_FREE((char*)mdsp16 - sizeof(LPMCI_DGV_STATUS_PARMSA)))
1806 FIXME("bad free line=%d\n", __LINE__);
1808 return MCI_MAP_NOMEM;
1811 return MCI_MAP_OKMEM;
1812 case MCI_DEVTYPE_VCR: /*size = sizeof(MCI_VCR_STATUS_PARMS); break;*/FIXME("NIY vcr\n"); return MCI_MAP_NOMEM;
1813 default: size = sizeof(MCI_STATUS_PARMS); break;
1822 LPMCI_SYSINFO_PARMS16 msip16 = (LPMCI_SYSINFO_PARMS16)PTR_SEG_TO_LIN(lParam);
1823 LPMCI_SYSINFO_PARMSA msip32a = *(LPMCI_SYSINFO_PARMSA*)((char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA));
1826 msip16->dwCallback = msip32a->dwCallback;
1827 memcpy(msip32a->lpstrReturn, PTR_SEG_TO_LIN(msip16->lpstrReturn), msip32a->dwRetSize);
1828 if (!SEGPTR_FREE(PTR_SEG_TO_LIN(msip16->lpstrReturn)))
1829 FIXME("bad free line=%d\n", __LINE__);
1831 if (!SEGPTR_FREE((char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSA)))
1832 FIXME("bad free line=%d\n", __LINE__);
1834 return MCI_MAP_NOMEM;
1837 return MCI_MAP_OKMEM;
1838 /* case MCI_UNDO: */
1845 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
1846 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_RECT_PARMS16); map = 0x0001111B; kept = TRUE; break;
1852 case MCI_DEVTYPE_DIGITAL_VIDEO: size = sizeof(MCI_DGV_WINDOW_PARMS16); if (dwFlags & MCI_DGV_WINDOW_TEXT) map = 0x7666; break;
1853 case MCI_DEVTYPE_OVERLAY: size = sizeof(MCI_OVLY_WINDOW_PARMS16); if (dwFlags & MCI_OVLY_WINDOW_TEXT) map = 0x7666; break;
1856 /* FIXME: see map function */
1866 case DRV_QUERYCONFIGURE:
1869 case DRV_EXITSESSION:
1870 case DRV_EXITAPPLICATION:
1872 FIXME("This is a hack\n");
1873 return MCI_MAP_PASS;
1875 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
1876 return MCI_MAP_MSGERROR;
1878 return MCI_MsgMapper32To16_Destroy((void*)lParam, size, map, kept);
1881 /**************************************************************************
1882 * MCI_SendCommandFrom32 [internal]
1884 DWORD MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1886 DWORD dwRet = MCIERR_DEVICE_NOT_INSTALLED;
1887 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1890 dwRet = MCIERR_INVALID_DEVICE_ID;
1892 switch (DRIVER_GetType(wmd->hDrv)) {
1893 case WINE_DI_TYPE_16:
1897 switch (res = MCI_MapMsg32ATo16(wmd->wType, wMsg, dwParam1, &dwParam2)) {
1898 case MCI_MAP_MSGERROR:
1899 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1900 dwRet = MCIERR_DRIVER_INTERNAL;
1903 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg));
1904 dwRet = MCIERR_OUT_OF_MEMORY;
1908 dwRet = SendDriverMessage16(wmd->hDrv, wMsg, dwParam1, dwParam2);
1909 if (res == MCI_MAP_OKMEM)
1910 MCI_UnMapMsg32ATo16(wmd->wType, wMsg, dwParam1, dwParam2);
1913 dwRet = SendDriverMessage(wmd->hDrv, wMsg, dwParam1, dwParam2);
1918 case WINE_DI_TYPE_32:
1919 dwRet = SendDriverMessage(wmd->hDrv, wMsg, dwParam1, dwParam2);
1922 WARN("Unknown driver type=%u\n", DRIVER_GetType(wmd->hDrv));
1923 dwRet = MCIERR_DRIVER_INTERNAL;
1929 /**************************************************************************
1930 * MCI_SendCommandFrom16 [internal]
1932 DWORD MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1934 DWORD dwRet = MCIERR_DEVICE_NOT_INSTALLED;
1935 LPWINE_MCIDRIVER wmd = MCI_GetDriver(wDevID);
1938 dwRet = MCIERR_INVALID_DEVICE_ID;
1942 switch (DRIVER_GetType(wmd->hDrv)) {
1943 case WINE_DI_TYPE_16:
1944 dwRet = SendDriverMessage16(wmd->hDrv, wMsg, dwParam1, dwParam2);
1946 case WINE_DI_TYPE_32:
1947 switch (res = MCI_MapMsg16To32A(wmd->wType, wMsg, &dwParam2)) {
1948 case MCI_MAP_MSGERROR:
1949 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg));
1950 dwRet = MCIERR_DRIVER_INTERNAL;
1953 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg));
1954 dwRet = MCIERR_OUT_OF_MEMORY;
1958 dwRet = SendDriverMessage(wDevID, wMsg, dwParam1, dwParam2);
1959 if (res == MCI_MAP_OKMEM)
1960 MCI_UnMapMsg16To32A(wmd->wType, wMsg, dwParam2);
1963 dwRet = SendDriverMessage16(wmd->hDrv, wMsg, dwParam1, dwParam2);
1968 WARN("Unknown driver type=%u\n", DRIVER_GetType(wmd->hDrv));
1969 dwRet = MCIERR_DRIVER_INTERNAL;
1975 /**************************************************************************
1976 * MCI_Open [internal]
1978 static DWORD MCI_Open(DWORD dwParam, LPMCI_OPEN_PARMSA lpParms)
1980 char strDevTyp[128];
1982 LPWINE_MCIDRIVER wmd;
1983 LPWINE_MM_IDATA iData;
1985 TRACE("(%08lX, %p)\n", dwParam, lpParms);
1986 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1988 if (!(iData = MULTIMEDIA_GetIData()))
1989 return MCIERR_INTERNAL;
1991 /* only two low bytes are generic, the other ones are dev type specific */
1992 #define WINE_MCI_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT|MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID|MCI_NOTIFY|MCI_WAIT)
1993 if ((dwParam & ~WINE_MCI_SUPP) != 0) {
1994 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam & ~WINE_MCI_SUPP);
1996 #undef WINE_MCI_SUPP
2000 if (dwParam & MCI_OPEN_ELEMENT) {
2001 TRACE("lpstrElementName='%s'\n", lpParms->lpstrElementName);
2003 if (dwParam & MCI_OPEN_ELEMENT_ID) {
2004 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
2005 dwRet = MCIERR_UNRECOGNIZED_KEYWORD;
2009 if (!lpParms->lpstrElementName) {
2010 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
2014 if (MCI_GetDevTypeFromFileName(lpParms->lpstrElementName, strDevTyp, sizeof(strDevTyp))) {
2015 if (GetDriveTypeA(lpParms->lpstrElementName) == DRIVE_CDROM) {
2016 /* FIXME: this will not work if several CDROM drives are installed on the machine */
2017 strcpy(strDevTyp, "CDAUDIO");
2019 dwRet = MCIERR_EXTENSION_NOT_FOUND;
2025 if (dwParam & MCI_OPEN_TYPE) {
2026 if (dwParam & MCI_OPEN_TYPE_ID) {
2027 WORD uDevType = LOWORD((DWORD)lpParms->lpstrDeviceType);
2029 if (uDevType < MCI_DEVTYPE_FIRST ||
2030 uDevType > MCI_DEVTYPE_LAST ||
2031 !LoadStringA(iData->hWinMM32Instance, uDevType, strDevTyp, sizeof(strDevTyp))) {
2032 dwRet = MCIERR_BAD_INTEGER;
2036 if (lpParms->lpstrDeviceType == NULL) {
2037 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
2040 strcpy(strDevTyp, lpParms->lpstrDeviceType);
2042 TRACE("devType='%s' !\n", strDevTyp);
2045 if (strDevTyp[0] == 0) {
2046 FIXME("Couldn't load driver\n");
2047 dwRet = MCIERR_INVALID_DEVICE_NAME;
2051 if (dwParam & MCI_OPEN_ALIAS) {
2052 TRACE("Alias='%s' !\n", lpParms->lpstrAlias);
2053 if (!lpParms->lpstrAlias) {
2054 dwRet = MCIERR_NULL_PARAMETER_BLOCK;
2059 if ((dwRet = MCI_LoadMciDriver(iData, strDevTyp, &wmd))) {
2063 if ((dwRet = MCI_FinishOpen(wmd, lpParms, dwParam))) {
2064 TRACE("Failed to open driver (MCI_OPEN_DRIVER msg) [%08lx], closing\n", dwRet);
2065 /* FIXME: is dwRet the correct ret code ? */
2069 /* only handled devices fall through */
2070 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd->wDeviceID, lpParms->wDeviceID, dwRet);
2072 if (dwParam & MCI_NOTIFY)
2073 mciDriverNotify16(lpParms->dwCallback, wmd->wDeviceID, MCI_NOTIFY_SUCCESSFUL);
2077 MCI_UnLoadMciDriver(iData, wmd);
2079 if (dwParam & MCI_NOTIFY)
2080 mciDriverNotify16(lpParms->dwCallback, 0, MCI_NOTIFY_FAILURE);
2084 /**************************************************************************
2085 * MCI_Close [internal]
2087 static DWORD MCI_Close(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
2090 LPWINE_MCIDRIVER wmd;
2091 LPWINE_MM_IDATA iData;
2093 TRACE("(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms);
2095 if (!(iData = MULTIMEDIA_GetIData()))
2096 return MCIERR_INTERNAL;
2098 if (wDevID == MCI_ALL_DEVICE_ID) {
2099 LPWINE_MCIDRIVER next;
2101 EnterCriticalSection(&iData->cs);
2102 /* FIXME: shall I notify once after all is done, or for
2103 * each of the open drivers ? if the latest, which notif
2104 * to return when only one fails ?
2106 for (wmd = iData->lpMciDrv; wmd; ) {
2108 MCI_Close(wmd->wDeviceID, dwParam, lpParms);
2111 LeaveCriticalSection(&iData->cs);
2115 if (!(wmd = MCI_GetDriver(wDevID))) {
2116 return MCIERR_INVALID_DEVICE_ID;
2119 dwRet = MCI_SendCommandFrom32(wDevID, MCI_CLOSE_DRIVER, dwParam, (DWORD)lpParms);
2121 MCI_UnLoadMciDriver(iData, wmd);
2123 if (dwParam & MCI_NOTIFY)
2124 mciDriverNotify16(lpParms->dwCallback, wDevID,
2125 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
2130 /**************************************************************************
2131 * MCI_WriteString [internal]
2133 DWORD MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr)
2138 if (dstSize <= strlen(lpSrcStr)) {
2139 lstrcpynA(lpDstStr, lpSrcStr, dstSize - 1);
2140 ret = MCIERR_PARAM_OVERFLOW;
2142 strcpy(lpDstStr, lpSrcStr);
2150 /**************************************************************************
2151 * MCI_Sysinfo [internal]
2153 static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSA lpParms)
2155 DWORD ret = MCIERR_INVALID_DEVICE_ID;
2156 LPWINE_MCIDRIVER wmd;
2157 LPWINE_MM_IDATA iData;
2159 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
2160 if (!(iData = MULTIMEDIA_GetIData())) return MCIERR_INTERNAL;
2162 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
2163 uDevID, dwFlags, (DWORD)lpParms, lpParms->dwNumber, lpParms->wDeviceType);
2165 switch (dwFlags & ~MCI_SYSINFO_OPEN) {
2166 case MCI_SYSINFO_QUANTITY:
2170 if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST ||
2171 lpParms->wDeviceType > MCI_DEVTYPE_LAST) {
2172 if (dwFlags & MCI_SYSINFO_OPEN) {
2173 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
2174 EnterCriticalSection(&iData->cs);
2175 for (wmd = iData->lpMciDrv; wmd; wmd = wmd->lpNext) {
2178 LeaveCriticalSection(&iData->cs);
2180 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
2181 cnt = MCI_InstalledCount;
2184 if (dwFlags & MCI_SYSINFO_OPEN) {
2185 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
2186 lpParms->wDeviceType);
2187 EnterCriticalSection(&iData->cs);
2188 for (wmd = iData->lpMciDrv; wmd; wmd = wmd->lpNext) {
2189 if (wmd->wType == lpParms->wDeviceType)
2192 LeaveCriticalSection(&iData->cs);
2194 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
2195 lpParms->wDeviceType);
2196 FIXME("Don't know how to get # of MCI devices of a given type\n");
2200 *(DWORD*)lpParms->lpstrReturn = cnt;
2202 TRACE("(%ld) => '%ld'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
2203 ret = MCI_INTEGER_RETURNED;
2205 case MCI_SYSINFO_INSTALLNAME:
2206 TRACE("MCI_SYSINFO_INSTALLNAME \n");
2207 if ((wmd = MCI_GetDriver(uDevID))) {
2208 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize,
2209 wmd->lpstrDeviceType);
2211 *lpParms->lpstrReturn = 0;
2212 ret = MCIERR_INVALID_DEVICE_ID;
2214 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
2216 case MCI_SYSINFO_NAME:
2217 TRACE("MCI_SYSINFO_NAME\n");
2218 if (dwFlags & MCI_SYSINFO_OPEN) {
2219 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
2220 ret = MCIERR_UNRECOGNIZED_COMMAND;
2221 } else if (lpParms->dwNumber > MCI_InstalledCount) {
2222 ret = MCIERR_OUTOFRANGE;
2224 DWORD count = lpParms->dwNumber;
2225 LPSTR ptr = MCI_lpInstallNames;
2227 while (--count > 0) ptr += strlen(ptr) + 1;
2228 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, ptr);
2230 TRACE("(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn);
2233 TRACE("Unsupported flag value=%08lx\n", dwFlags);
2234 ret = MCIERR_UNRECOGNIZED_COMMAND;
2239 /**************************************************************************
2240 * MCI_Break [internal]
2242 static DWORD MCI_Break(UINT wDevID, DWORD dwFlags, LPMCI_BREAK_PARMS lpParms)
2246 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
2248 if (dwFlags & MCI_NOTIFY)
2249 mciDriverNotify16(lpParms->dwCallback, wDevID,
2250 (dwRet == 0) ? MCI_NOTIFY_SUCCESSFUL : MCI_NOTIFY_FAILURE);
2255 /**************************************************************************
2256 * MCI_SendCommand [internal]
2258 DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1,
2259 DWORD dwParam2, BOOL bFrom32)
2261 DWORD dwRet = MCIERR_UNRECOGNIZED_COMMAND;
2266 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
2268 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
2271 dwRet = MCI_Open(dwParam1, (LPMCI_OPEN_PARMSA)dwParam2);
2272 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
2274 default: break; /* so that gcc does not bark */
2280 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
2282 switch (MCI_MapMsg16To32A(0, wMsg, &dwParam2)) {
2285 dwRet = MCI_Close(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
2286 MCI_UnMapMsg16To32A(0, wMsg, dwParam2);
2288 default: break; /* so that gcc does not bark */
2294 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
2296 switch (MCI_MapMsg16To32A(0, wDevID, &dwParam2)) {
2299 dwRet = MCI_SysInfo(wDevID, dwParam1, (LPMCI_SYSINFO_PARMSA)dwParam2);
2300 MCI_UnMapMsg16To32A(0, wDevID, dwParam2);
2302 default: break; /* so that gcc doesnot bark */
2308 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2310 switch (MCI_MapMsg16To32A(0, wDevID, &dwParam2)) {
2313 dwRet = MCI_Break(wDevID, dwParam1, (LPMCI_BREAK_PARMS)dwParam2);
2314 MCI_UnMapMsg16To32A(0, wDevID, dwParam2);
2316 default: break; /* so that gcc does not bark */
2321 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
2322 * but I couldn't get any doc on this MCI message
2326 if (wDevID == MCI_ALL_DEVICE_ID) {
2327 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2328 dwRet = MCIERR_CANNOT_USE_ALL;
2331 MCI_SendCommandFrom32(wDevID, wMsg, dwParam1, dwParam2) :
2332 MCI_SendCommandFrom16(wDevID, wMsg, dwParam1, dwParam2);
2339 /* FIXME: should be using the new mmThreadXXXX functions from WINMM
2341 * it would require to add a wine internal flag to mmThreadCreate
2342 * in order to pass a 32 bit function instead of a 16 bit
2353 DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2);
2355 /**************************************************************************
2356 * MCI_SCAStarter [internal]
2358 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
2360 struct SCA* sca = (struct SCA*)arg;
2363 TRACE("In thread before async command (%08x,%s,%08lx,%08lx)\n",
2364 sca->wDevID, MCI_MessageToString(sca->wMsg), sca->dwParam1, sca->dwParam2);
2365 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
2366 TRACE("In thread after async command (%08x,%s,%08lx,%08lx)\n",
2367 sca->wDevID, MCI_MessageToString(sca->wMsg), sca->dwParam1, sca->dwParam2);
2368 if (sca->allocatedCopy)
2369 HeapFree(GetProcessHeap(), 0, (LPVOID)sca->dwParam2);
2370 HeapFree(GetProcessHeap(), 0, sca);
2372 WARN("Should not happen ? what's wrong \n");
2373 /* should not go after this point */
2377 /**************************************************************************
2378 * MCI_SendCommandAsync [internal]
2380 DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
2381 DWORD dwParam2, UINT size)
2383 struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA));
2386 return MCIERR_OUT_OF_MEMORY;
2388 sca->wDevID = wDevID;
2390 sca->dwParam1 = dwParam1;
2393 sca->dwParam2 = (DWORD)HeapAlloc(GetProcessHeap(), 0, size);
2394 if (sca->dwParam2 == 0) {
2395 HeapFree(GetProcessHeap(), 0, sca);
2396 return MCIERR_OUT_OF_MEMORY;
2398 sca->allocatedCopy = TRUE;
2399 /* copy structure passed by program in dwParam2 to be sure
2400 * we can still use it whatever the program does
2402 memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
2404 sca->dwParam2 = dwParam2;
2405 sca->allocatedCopy = FALSE;
2408 if (CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL) == 0) {
2409 WARN("Couldn't allocate thread for async command handling, sending synchonously\n");
2410 return MCI_SCAStarter(&sca);
2415 /**************************************************************************
2416 * MCI_CleanUp [internal]
2418 * Some MCI commands need to be cleaned-up (when not called from
2419 * mciSendString), because MCI drivers return extra information for string
2420 * transformation. This function gets read of them.
2422 LRESULT MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2, BOOL bIs32)
2425 return LOWORD(dwRet);
2428 case MCI_GETDEVCAPS:
2429 switch (dwRet & 0xFFFF0000ul) {
2432 case MCI_RESOURCE_RETURNED:
2433 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2434 case MCI_COLONIZED3_RETURN:
2435 case MCI_COLONIZED4_RETURN:
2436 case MCI_INTEGER_RETURNED:
2438 LPMCI_GETDEVCAPS_PARMS lmgp;
2440 lmgp = (LPMCI_GETDEVCAPS_PARMS)(bIs32 ? (void*)dwParam2 : PTR_SEG_TO_LIN(dwParam2));
2441 dwRet = LOWORD(dwRet);
2442 TRACE("Changing %08lx to %08lx\n", lmgp->dwReturn, (DWORD)LOWORD(lmgp->dwReturn));
2443 lmgp->dwReturn = LOWORD(lmgp->dwReturn);
2447 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2448 HIWORD(dwRet), MCI_MessageToString(wMsg));
2452 switch (dwRet & 0xFFFF0000ul) {
2455 case MCI_RESOURCE_RETURNED:
2456 case MCI_RESOURCE_RETURNED|MCI_RESOURCE_DRIVER:
2457 case MCI_COLONIZED3_RETURN:
2458 case MCI_COLONIZED4_RETURN:
2459 case MCI_INTEGER_RETURNED:
2461 LPMCI_STATUS_PARMS lsp;
2463 lsp = (LPMCI_STATUS_PARMS)(bIs32 ? (void*)dwParam2 : PTR_SEG_TO_LIN(dwParam2));
2464 dwRet = LOWORD(dwRet);
2465 TRACE("Changing %08lx to %08lx\n", lsp->dwReturn, (DWORD)LOWORD(lsp->dwReturn));
2466 lsp->dwReturn = LOWORD(lsp->dwReturn);
2470 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2471 HIWORD(dwRet), MCI_MessageToString(wMsg));
2475 switch (dwRet & 0xFFFF0000ul) {
2478 case MCI_INTEGER_RETURNED:
2479 dwRet = LOWORD(dwRet);
2482 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet));
2486 if (dwRet & 0xFFFF0000ul) {
2487 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2488 dwRet, MCI_MessageToString(wMsg));
2495 /**************************************************************************
2496 * MULTIMEDIA_MciInit [internal]
2498 * Initializes the MCI internal variables.
2501 BOOL MULTIMEDIA_MciInit(void)
2505 MCI_InstalledCount = 0;
2506 ptr1 = MCI_lpInstallNames = HeapAlloc(SystemHeap, 0, 2048);
2508 if (!MCI_lpInstallNames)
2511 /* FIXME: should do also some registry diving here ? */
2512 if (PROFILE_GetWineIniString("options", "mci", "", MCI_lpInstallNames, 2048) > 0) {
2513 TRACE("Wine => '%s' \n", ptr1);
2514 while ((ptr2 = strchr(ptr1, ':')) != 0) {
2516 TRACE("---> '%s' \n", ptr1);
2517 MCI_InstalledCount++;
2520 MCI_InstalledCount++;
2521 TRACE("---> '%s' \n", ptr1);
2522 ptr1 += strlen(ptr1) + 1;
2524 GetPrivateProfileStringA("mci", NULL, "", MCI_lpInstallNames, 2048, "SYSTEM.INI");
2525 while (strlen(ptr1) > 0) {
2526 TRACE("---> '%s' \n", ptr1);
2527 ptr1 += strlen(ptr1) + 1;
2528 MCI_InstalledCount++;