1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * MCI internal functions
6 * Copyright 1998/1999 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
47 static int MCI_InstalledCount
;
48 static LPSTR MCI_lpInstallNames
/* = NULL */;
50 WINMM_MapType (*pFnMciMapMsg16To32A
) (WORD
,WORD
,DWORD
*) /* = NULL */;
51 WINMM_MapType (*pFnMciUnMapMsg16To32A
)(WORD
,WORD
,DWORD
) /* = NULL */;
52 WINMM_MapType (*pFnMciMapMsg32ATo16
) (WORD
,WORD
,DWORD
,DWORD
*) /* = NULL */;
53 WINMM_MapType (*pFnMciUnMapMsg32ATo16
)(WORD
,WORD
,DWORD
,DWORD
) /* = NULL */;
55 /* First MCI valid device ID (0 means error) */
56 #define MCI_MAGIC 0x0001
58 /* dup a string and uppercase it */
59 inline static LPSTR
str_dup_upper( LPCSTR str
)
61 INT len
= strlen(str
) + 1;
62 LPSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
65 memcpy( p
, str
, len
);
71 /**************************************************************************
72 * MCI_GetDriver [internal]
74 LPWINE_MCIDRIVER
MCI_GetDriver(UINT16 wDevID
)
76 LPWINE_MCIDRIVER wmd
= 0;
78 EnterCriticalSection(&WINMM_IData
->cs
);
79 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
80 if (wmd
->wDeviceID
== wDevID
)
83 LeaveCriticalSection(&WINMM_IData
->cs
);
87 /**************************************************************************
88 * MCI_GetDriverFromString [internal]
90 UINT
MCI_GetDriverFromString(LPCSTR lpstrName
)
98 if (!lstrcmpiA(lpstrName
, "ALL"))
99 return MCI_ALL_DEVICE_ID
;
101 EnterCriticalSection(&WINMM_IData
->cs
);
102 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
103 if (wmd
->lpstrElementName
&& strcmp(wmd
->lpstrElementName
, lpstrName
) == 0) {
104 ret
= wmd
->wDeviceID
;
107 if (wmd
->lpstrDeviceType
&& strcasecmp(wmd
->lpstrDeviceType
, lpstrName
) == 0) {
108 ret
= wmd
->wDeviceID
;
111 if (wmd
->lpstrAlias
&& strcasecmp(wmd
->lpstrAlias
, lpstrName
) == 0) {
112 ret
= wmd
->wDeviceID
;
116 LeaveCriticalSection(&WINMM_IData
->cs
);
121 /**************************************************************************
122 * MCI_MessageToString [internal]
124 const char* MCI_MessageToString(UINT16 wMsg
)
126 static char buffer
[100];
128 #define CASE(s) case (s): return #s
133 CASE(MCI_CLOSE_DRIVER
);
142 CASE(MCI_GETDEVCAPS
);
146 CASE(MCI_OPEN_DRIVER
);
164 /* constants for digital video */
178 sprintf(buffer
, "MCI_<<%04X>>", wMsg
);
183 /**************************************************************************
184 * MCI_GetDevTypeFromFileName [internal]
186 static DWORD
MCI_GetDevTypeFromFileName(LPCSTR fileName
, LPSTR buf
, UINT len
)
191 if ((tmp
= strrchr(fileName
, '.'))) {
192 if (RegOpenKeyExA( HKEY_LOCAL_MACHINE
, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions",
193 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
195 LONG lRet
= RegQueryValueExA( hKey
, tmp
+ 1, 0, 0, buf
, &dwLen
);
197 if (lRet
== ERROR_SUCCESS
) return 0;
199 TRACE("No ...\\MCI Extensions entry for '%s' found.\n", tmp
);
201 return MCIERR_EXTENSION_NOT_FOUND
;
204 #define MAX_MCICMDTABLE 20
205 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
207 typedef struct tagWINE_MCICMDTABLE
{
210 UINT nVerbs
; /* number of verbs in command table */
211 LPCSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
212 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
214 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
216 /**************************************************************************
217 * MCI_IsCommandTableValid [internal]
219 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
227 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
228 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
230 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
233 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
237 lmem
+= strlen(lmem
) + 1;
238 flg
= *(LPDWORD
)lmem
;
239 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
240 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
242 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
244 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
245 case MCI_STRING
: if (inCst
) return FALSE
; break;
246 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
247 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
248 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
249 case MCI_FLAG
: if (!*str
) return FALSE
; break;
250 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
251 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
252 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
253 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
254 default: return FALSE
;
256 } while (eid
!= MCI_END_COMMAND_LIST
);
257 } while (eid
!= MCI_END_COMMAND_LIST
);
261 /**************************************************************************
262 * MCI_DumpCommandTable [internal]
264 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
271 if (!MCI_IsCommandTableValid(uTbl
)) {
272 ERR("Ooops: %d is not valid\n", uTbl
);
276 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
280 lmem
+= strlen(lmem
) + 1;
281 flg
= *(LPDWORD
)lmem
;
282 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
283 TRACE("cmd='%s' %08lx %04x\n", str
, flg
, eid
);
284 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
285 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
286 TRACE(" => end of command%s\n", (eid
== MCI_END_COMMAND_LIST
) ? " list" : "");
287 } while (eid
!= MCI_END_COMMAND_LIST
);
292 /**************************************************************************
293 * MCI_GetCommandTable [internal]
295 static UINT
MCI_GetCommandTable(UINT uDevType
)
301 /* first look up existing for existing devType */
302 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
303 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
307 /* well try to load id */
308 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
309 if (LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, buf
, sizeof(buf
))) {
312 } else if (uDevType
== 0) {
315 uTbl
= MCI_NO_COMMAND_TABLE
;
317 HRSRC hRsrc
= FindResourceA(WINMM_IData
->hWinMM32Instance
, str
, (LPCSTR
)RT_RCDATA
);
320 if (hRsrc
) hMem
= LoadResource(WINMM_IData
->hWinMM32Instance
, hRsrc
);
322 uTbl
= MCI_SetCommandTable(LockResource(hMem
), uDevType
);
324 WARN("No command table found in resource %p[%s]\n",
325 WINMM_IData
->hWinMM32Instance
, str
);
328 TRACE("=> %d\n", uTbl
);
332 /**************************************************************************
333 * MCI_SetCommandTable [internal]
335 UINT
MCI_SetCommandTable(void *table
, UINT uDevType
)
338 static BOOL bInitDone
= FALSE
;
341 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
342 * can be called with 0 as a uDevType to retrieve it.
347 MCI_GetCommandTable(0);
350 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
351 if (!S_MciCmdTable
[uTbl
].lpTable
) {
356 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
357 S_MciCmdTable
[uTbl
].lpTable
= table
;
360 MCI_DumpCommandTable(uTbl
);
363 /* create the verbs table */
364 /* get # of entries */
365 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
368 lmem
+= strlen(lmem
) + 1;
369 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
370 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
371 if (eid
== MCI_COMMAND_HEAD
)
373 } while (eid
!= MCI_END_COMMAND_LIST
);
375 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCSTR
));
376 S_MciCmdTable
[uTbl
].nVerbs
= count
;
378 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
382 lmem
+= strlen(lmem
) + 1;
383 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
384 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
385 if (eid
== MCI_COMMAND_HEAD
)
386 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
387 } while (eid
!= MCI_END_COMMAND_LIST
);
388 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
393 return MCI_NO_COMMAND_TABLE
;
396 /**************************************************************************
397 * MCI_DeleteCommandTable [internal]
399 static BOOL
MCI_DeleteCommandTable(UINT uTbl
)
401 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
404 S_MciCmdTable
[uTbl
].lpTable
= NULL
;
405 if (S_MciCmdTable
[uTbl
].aVerbs
) {
406 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTbl
].aVerbs
);
407 S_MciCmdTable
[uTbl
].aVerbs
= 0;
412 /**************************************************************************
413 * MCI_UnLoadMciDriver [internal]
415 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
417 LPWINE_MCIDRIVER
* tmp
;
422 CloseDriver(wmd
->hDriver
, 0, 0);
424 if (wmd
->dwPrivate
!= 0)
425 WARN("Unloading mci driver with non nul dwPrivate field\n");
427 EnterCriticalSection(&WINMM_IData
->cs
);
428 for (tmp
= &WINMM_IData
->lpMciDrvs
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
434 LeaveCriticalSection(&WINMM_IData
->cs
);
436 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
437 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
438 HeapFree(GetProcessHeap(), 0, wmd
->lpstrElementName
);
440 HeapFree(GetProcessHeap(), 0, wmd
);
444 /**************************************************************************
445 * MCI_OpenMciDriver [internal]
447 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCSTR drvTyp
, LPARAM lp
)
451 if (!DRIVER_GetLibName(drvTyp
, "mci", libName
, sizeof(libName
)))
455 /* First load driver */
456 if ((wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
))) {
458 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32ATo16
) {
461 switch (res
= pFnMciMapMsg32ATo16(0, DRV_OPEN
, 0, &lp
)) {
462 case WINMM_MAP_MSGERROR
:
463 TRACE("Not handled yet (DRV_OPEN)\n");
465 case WINMM_MAP_NOMEM
:
466 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
469 case WINMM_MAP_OKMEM
:
470 if ((wmd
->hDriver
= OpenDriverA(drvTyp
, "mci", lp
)))
472 if (res
== WINMM_MAP_OKMEM
)
473 pFnMciUnMapMsg32ATo16(0, DRV_OPEN
, 0, lp
);
477 return (wmd
->bIs32
== 0xFFFF) ? FALSE
: TRUE
;
480 /**************************************************************************
481 * MCI_LoadMciDriver [internal]
483 static DWORD
MCI_LoadMciDriver(LPCSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
485 LPSTR strDevTyp
= str_dup_upper(_strDevTyp
);
486 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
487 MCI_OPEN_DRIVER_PARMSA modp
;
490 if (!wmd
|| !strDevTyp
) {
491 dwRet
= MCIERR_OUT_OF_MEMORY
;
495 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
496 wmd
->dwYieldData
= VK_CANCEL
;
497 wmd
->CreatorThread
= GetCurrentThreadId();
499 EnterCriticalSection(&WINMM_IData
->cs
);
500 /* wmd must be inserted in list before sending opening the driver, coz' it
501 * may want to lookup at wDevID
503 wmd
->lpNext
= WINMM_IData
->lpMciDrvs
;
504 WINMM_IData
->lpMciDrvs
= wmd
;
506 for (modp
.wDeviceID
= MCI_MAGIC
;
507 MCI_GetDriver(modp
.wDeviceID
) != 0;
510 wmd
->wDeviceID
= modp
.wDeviceID
;
512 LeaveCriticalSection(&WINMM_IData
->cs
);
514 TRACE("wDevID=%04X \n", modp
.wDeviceID
);
516 modp
.lpstrParams
= NULL
;
518 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (LPARAM
)&modp
)) {
519 /* silence warning if all is used... some bogus program use commands like
522 if (strcasecmp(strDevTyp
, "all") == 0) {
523 dwRet
= MCIERR_CANNOT_USE_ALL
;
525 FIXME("Couldn't load driver for type %s.\n"
526 "If you don't have a windows installation accessible from Wine,\n"
527 "you perhaps forgot to create a [mci] section in system.ini\n",
529 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
534 /* FIXME: should also check that module's description is of the form
535 * MODULENAME:[MCI] comment
538 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
539 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
540 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
542 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
543 wmd
->hDriver
, strDevTyp
, modp
.wType
, modp
.wCustomCommandTable
);
545 wmd
->lpstrDeviceType
= strDevTyp
;
546 wmd
->wType
= modp
.wType
;
548 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
549 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
553 MCI_UnLoadMciDriver(wmd
);
554 HeapFree(GetProcessHeap(), 0, strDevTyp
);
559 /**************************************************************************
560 * MCI_FinishOpen [internal]
562 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSA lpParms
,
565 if (dwParam
& MCI_OPEN_ELEMENT
)
567 wmd
->lpstrElementName
= HeapAlloc(GetProcessHeap(),0,strlen(lpParms
->lpstrElementName
)+1);
568 strcpy( wmd
->lpstrElementName
, lpParms
->lpstrElementName
);
570 if (dwParam
& MCI_OPEN_ALIAS
)
572 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, strlen(lpParms
->lpstrAlias
)+1);
573 strcpy( wmd
->lpstrAlias
, lpParms
->lpstrAlias
);
575 lpParms
->wDeviceID
= wmd
->wDeviceID
;
577 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
581 /**************************************************************************
582 * MCI_FindCommand [internal]
584 static LPCSTR
MCI_FindCommand(UINT uTbl
, LPCSTR verb
)
588 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
591 /* another improvement would be to have the aVerbs array sorted,
592 * so that we could use a dichotomic search on it, rather than this dumb
595 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
596 if (strcasecmp(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
597 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
603 /**************************************************************************
604 * MCI_GetReturnType [internal]
606 static DWORD
MCI_GetReturnType(LPCSTR lpCmd
)
608 lpCmd
+= strlen(lpCmd
) + 1 + sizeof(DWORD
) + sizeof(WORD
);
609 if (*lpCmd
== '\0' && *(LPWORD
)(lpCmd
+ 1 + sizeof(DWORD
)) == MCI_RETURN
) {
610 return *(LPDWORD
)(lpCmd
+ 1);
615 /**************************************************************************
616 * MCI_GetMessage [internal]
618 static WORD
MCI_GetMessage(LPCSTR lpCmd
)
620 return (WORD
)*(LPDWORD
)(lpCmd
+ strlen(lpCmd
) + 1);
623 /**************************************************************************
624 * MCI_GetDWord [internal]
626 static BOOL
MCI_GetDWord(LPDWORD data
, LPSTR
* ptr
)
631 val
= strtoul(*ptr
, &ret
, 0);
635 case ' ': ret
++; break;
636 default: return FALSE
;
644 /**************************************************************************
645 * MCI_GetString [internal]
647 static DWORD
MCI_GetString(LPSTR
* str
, LPSTR
* args
)
651 /* see if we have a quoted string */
653 ptr
= strchr(*str
= ptr
+ 1, '"');
654 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
655 /* FIXME: shall we escape \" from string ?? */
656 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
657 *ptr
++ = '\0'; /* remove trailing " */
658 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
661 ptr
= strchr(ptr
, ' ');
666 ptr
= *args
+ strlen(*args
);
675 #define MCI_DATA_SIZE 16
677 /**************************************************************************
678 * MCI_ParseOptArgs [internal]
680 static DWORD
MCI_ParseOptArgs(LPDWORD data
, int _offset
, LPCSTR lpCmd
,
681 LPSTR args
, LPDWORD dwFlags
)
685 DWORD dwRet
, flg
, cflg
= 0;
689 /* loop on arguments */
692 found
= inCst
= FALSE
;
695 /* skip any leading white space(s) */
696 while (*args
== ' ') args
++;
697 TRACE("args='%s' offset=%d\n", args
, offset
);
699 do { /* loop on options for command table for the requested verb */
701 lmem
+= (len
= strlen(lmem
)) + 1;
702 flg
= *(LPDWORD
)lmem
;
703 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
704 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
705 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
709 inCst
= TRUE
; cflg
= flg
; break;
710 case MCI_END_CONSTANT
:
711 /* there may be additional integral values after flag in constant */
712 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
715 inCst
= FALSE
; cflg
= 0;
719 if (strncasecmp(args
, str
, len
) == 0 &&
720 (args
[len
] == 0 || args
[len
] == ' ')) {
721 /* store good values into data[] */
723 while (*args
== ' ') args
++;
727 case MCI_COMMAND_HEAD
:
729 case MCI_END_COMMAND
:
730 case MCI_END_COMMAND_LIST
:
731 case MCI_CONSTANT
: /* done above */
732 case MCI_END_CONSTANT
: /* done above */
744 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
745 return MCIERR_BAD_INTEGER
;
750 /* store rect in data (offset...offset+3) */
752 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
753 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
754 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
755 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
756 ERR("Bad rect '%s'\n", args
);
757 return MCIERR_BAD_INTEGER
;
762 if ((dwRet
= MCI_GetString((LPSTR
*)&data
[offset
], &args
)))
765 default: ERR("oops\n");
767 /* exit inside while loop, except if just entered in constant area definition */
768 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
770 /* have offset incremented if needed */
772 case MCI_COMMAND_HEAD
:
774 case MCI_END_COMMAND
:
775 case MCI_END_COMMAND_LIST
:
777 case MCI_FLAG
: break;
778 case MCI_INTEGER
: if (!inCst
) offset
++; break;
779 case MCI_END_CONSTANT
:
780 case MCI_STRING
: offset
++; break;
781 case MCI_RECT
: offset
+= 4; break;
782 default: ERR("oops\n");
785 } while (eid
!= MCI_END_COMMAND
);
787 WARN("Optarg '%s' not found\n", args
);
788 return MCIERR_UNRECOGNIZED_COMMAND
;
790 if (offset
== MCI_DATA_SIZE
) {
791 ERR("Internal data[] buffer overflow\n");
792 return MCIERR_PARSER_INTERNAL
;
798 /**************************************************************************
799 * MCI_HandleReturnValues [internal]
801 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
802 LPDWORD data
, LPSTR lpstrRet
, UINT uRetLen
)
806 case 0: /* nothing to return */
809 switch (dwRet
& 0xFFFF0000ul
) {
811 case MCI_INTEGER_RETURNED
:
812 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
814 case MCI_RESOURCE_RETURNED
:
815 /* return string which ID is HIWORD(data[1]),
816 * string is loaded from mmsystem.dll */
817 LoadStringA(WINMM_IData
->hWinMM32Instance
, HIWORD(data
[1]),
820 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
821 /* return string which ID is HIWORD(data[1]),
822 * string is loaded from driver */
823 /* FIXME: this is wrong for a 16 bit handle */
824 LoadStringA(GetDriverModuleHandle(wmd
->hDriver
),
825 HIWORD(data
[1]), lpstrRet
, uRetLen
);
827 case MCI_COLONIZED3_RETURN
:
828 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d",
829 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
830 LOBYTE(HIWORD(data
[1])));
832 case MCI_COLONIZED4_RETURN
:
833 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d:%d",
834 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
835 LOBYTE(HIWORD(data
[1])), HIBYTE(HIWORD(data
[1])));
837 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
841 switch (dwRet
& 0xFFFF0000ul
) {
843 /* nothing to do data[1] == lpstrRet */
845 case MCI_INTEGER_RETURNED
:
846 data
[1] = *(LPDWORD
)lpstrRet
;
847 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
850 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
855 if (dwRet
& 0xFFFF0000ul
)
856 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
857 snprintf(lpstrRet
, uRetLen
, "%ld %ld %ld %ld",
858 data
[1], data
[2], data
[3], data
[4]);
860 default: ERR("oops\n");
863 return LOWORD(dwRet
);
866 /**************************************************************************
867 * mciSendStringA [WINMM.@]
869 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
870 UINT uRetLen
, HWND hwndCallback
)
872 LPSTR verb
, dev
, args
;
873 LPWINE_MCIDRIVER wmd
= 0;
874 DWORD dwFlags
= 0, dwRet
= 0;
876 DWORD data
[MCI_DATA_SIZE
];
879 LPSTR devAlias
= NULL
;
880 BOOL bAutoOpen
= FALSE
;
882 TRACE("('%s', %p, %d, %p)\n", lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
884 /* format is <command> <device> <optargs> */
885 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand
)+1)))
886 return MCIERR_OUT_OF_MEMORY
;
887 strcpy( verb
, lpstrCommand
);
890 memset(data
, 0, sizeof(data
));
892 if (!(args
= strchr(verb
, ' '))) {
893 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
897 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
901 /* case dev == 'new' has to be handled */
902 if (!strcmp(dev
, "new")) {
903 FIXME("'new': NIY as device name\n");
904 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
908 /* otherwise, try to grab devType from open */
909 if (!strcmp(verb
, "open")) {
912 if ((devType
= strchr(dev
, '!')) != NULL
) {
914 tmp
= devType
; devType
= dev
; dev
= tmp
;
916 dwFlags
|= MCI_OPEN_TYPE
;
917 data
[2] = (DWORD
)devType
;
918 devType
= str_dup_upper(devType
);
919 dwFlags
|= MCI_OPEN_ELEMENT
;
920 data
[3] = (DWORD
)dev
;
921 } else if (strchr(dev
, '.') == NULL
) {
922 tmp
= strchr(dev
,' ');
923 if (tmp
) *tmp
= '\0';
924 data
[2] = (DWORD
)dev
;
925 devType
= str_dup_upper(dev
);
927 dwFlags
|= MCI_OPEN_TYPE
;
929 if ((devType
= strstr(args
, "type ")) != NULL
) {
931 tmp
= strchr(devType
, ' ');
932 if (tmp
) *tmp
= '\0';
933 devType
= str_dup_upper(devType
);
935 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
938 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
941 devType
= str_dup_upper(buf
);
943 dwFlags
|= MCI_OPEN_ELEMENT
;
944 data
[3] = (DWORD
)dev
;
946 if ((devAlias
= strstr(args
," alias "))) {
949 if (!(tmp
= strchr(devAlias
,' '))) tmp
= devAlias
+ strlen(devAlias
);
950 if (tmp
) *tmp
= '\0';
951 tmp2
= HeapAlloc(GetProcessHeap(), 0, tmp
- devAlias
+ 1 );
952 memcpy( tmp2
, devAlias
, tmp
- devAlias
);
953 tmp2
[tmp
- devAlias
] = 0;
954 data
[4] = (DWORD
)tmp2
;
955 /* should be done in regular options parsing */
956 /* dwFlags |= MCI_OPEN_ALIAS; */
959 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
960 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
961 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
962 HeapFree(GetProcessHeap(), 0, devType
);
964 MCI_UnLoadMciDriver(wmd
);
967 } else if (!(wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
)))) {
970 sprintf(buf
, "open %s wait", dev
);
972 if ((dwRet
= mciSendStringA(buf
, NULL
, 0, 0)) != 0)
975 wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
));
977 /* FIXME: memory leak, MCI driver is not closed */
978 dwRet
= MCIERR_INVALID_DEVICE_ID
;
983 /* get the verb in the different command tables */
985 /* try the device specific command table */
986 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
988 /* try the type specific command table */
989 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
990 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
991 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
992 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
995 /* try core command table */
996 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
999 TRACE("Command '%s' not found!\n", verb
);
1000 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1004 /* set up call back */
1005 if (hwndCallback
!= 0) {
1006 dwFlags
|= MCI_NOTIFY
;
1007 data
[0] = (DWORD
)hwndCallback
;
1010 /* set return information */
1011 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1012 case 0: offset
= 1; break;
1013 case MCI_INTEGER
: offset
= 2; break;
1014 case MCI_STRING
: data
[1] = (DWORD
)lpstrRet
; data
[2] = uRetLen
; offset
= 3; break;
1015 case MCI_RECT
: offset
= 5; break;
1016 default: ERR("oops\n");
1019 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb
, dev
, offset
);
1021 if ((dwRet
= MCI_ParseOptArgs(data
, offset
, lpCmd
, args
, &dwFlags
)))
1024 if (bAutoOpen
&& (dwFlags
& MCI_NOTIFY
)) {
1025 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1028 /* FIXME: the command should get it's own notification window set up and
1029 * ask for device closing while processing the notification mechanism
1031 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1033 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1034 wmd
->wDeviceID
, MCI_MessageToString(MCI_GetMessage(lpCmd
)), dwFlags
,
1035 data
[0], debugstr_a((char *)data
[0]), data
[1], debugstr_a((char *)data
[1]),
1036 data
[2], debugstr_a((char *)data
[2]), data
[3], debugstr_a((char *)data
[3]),
1037 data
[4], debugstr_a((char *)data
[4]), data
[5], debugstr_a((char *)data
[5]));
1039 if (strcmp(verb
, "open") == 0) {
1040 if ((dwRet
= MCI_FinishOpen(wmd
, (LPMCI_OPEN_PARMSA
)data
, dwFlags
)))
1041 MCI_UnLoadMciDriver(wmd
);
1042 /* FIXME: notification is not properly shared across two opens */
1044 dwRet
= MCI_SendCommand(wmd
->wDeviceID
, MCI_GetMessage(lpCmd
), dwFlags
, (DWORD
)data
, TRUE
);
1046 TRACE("=> 1/ %lx (%s)\n", dwRet
, lpstrRet
);
1047 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, data
, lpstrRet
, uRetLen
);
1048 TRACE("=> 2/ %lx (%s)\n", dwRet
, lpstrRet
);
1051 HeapFree(GetProcessHeap(), 0, verb
);
1052 HeapFree(GetProcessHeap(), 0, devAlias
);
1056 /**************************************************************************
1057 * mciSendStringW [WINMM.@]
1059 DWORD WINAPI
mciSendStringW(LPCWSTR lpwstrCommand
, LPWSTR lpwstrRet
,
1060 UINT uRetLen
, HWND hwndCallback
)
1063 LPSTR lpstrRet
= NULL
;
1067 /* FIXME: is there something to do with lpstrReturnString ? */
1068 len
= WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, NULL
, 0, NULL
, NULL
);
1069 lpstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
);
1070 WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, lpstrCommand
, len
, NULL
, NULL
);
1073 lpstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1074 if (!lpstrRet
) return MMSYSERR_NOMEM
;
1076 ret
= mciSendStringA(lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
1078 MultiByteToWideChar( CP_ACP
, 0, lpstrRet
, -1, lpwstrRet
, uRetLen
);
1079 HeapFree(GetProcessHeap(), 0, lpstrCommand
);
1080 if (lpstrRet
) HeapFree(GetProcessHeap(), 0, lpstrRet
);
1084 /**************************************************************************
1085 * mciExecute [WINMM.@]
1086 * mciExecute [MMSYSTEM.712]
1088 DWORD WINAPI
mciExecute(LPCSTR lpstrCommand
)
1093 TRACE("(%s)!\n", lpstrCommand
);
1095 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1097 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1098 sprintf(strRet
, "Unknown MCI error (%ld)", ret
);
1100 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1102 /* FIXME: what shall I return ? */
1106 /**************************************************************************
1107 * mciLoadCommandResource [WINMM.@]
1109 * Strangely, this function only exists as an UNICODE one.
1111 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1115 UINT16 ret
= MCI_NO_COMMAND_TABLE
;
1117 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1119 /* if a file named "resname.mci" exits, then load resource "resname" from it
1120 * otherwise directly from driver
1121 * We don't support it (who uses this feature ?), but we check anyway
1125 /* FIXME: we should put this back into order, but I never found a program
1126 * actually using this feature, so we not need it
1131 strcat(strcpy(buf
, resname
), ".mci");
1132 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1133 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1137 if (!(hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
))) {
1138 WARN("No command table found in resource\n");
1139 } else if ((hMem
= LoadResource(hInst
, hRsrc
))) {
1140 ret
= MCI_SetCommandTable(LockResource(hMem
), type
);
1142 WARN("Couldn't load resource.\n");
1144 TRACE("=> %04x\n", ret
);
1148 /**************************************************************************
1149 * mciFreeCommandResource [WINMM.@]
1151 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1153 TRACE("(%08x)!\n", uTable
);
1155 return MCI_DeleteCommandTable(uTable
);
1158 /**************************************************************************
1159 * MCI_SendCommandFrom32 [internal]
1161 DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1163 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1164 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1168 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1169 } else if (pFnMciMapMsg32ATo16
) {
1172 switch (res
= pFnMciMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, &dwParam2
)) {
1173 case WINMM_MAP_MSGERROR
:
1174 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1175 dwRet
= MCIERR_DRIVER_INTERNAL
;
1177 case WINMM_MAP_NOMEM
:
1178 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg
));
1179 dwRet
= MCIERR_OUT_OF_MEMORY
;
1182 case WINMM_MAP_OKMEM
:
1183 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1184 if (res
== WINMM_MAP_OKMEM
)
1185 pFnMciUnMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, dwParam2
);
1193 /**************************************************************************
1194 * MCI_SendCommandFrom16 [internal]
1196 DWORD
MCI_SendCommandFrom16(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1198 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1199 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1202 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1204 if (wmd
->bIs32
&& pFnMciMapMsg16To32A
) {
1207 switch (res
= pFnMciMapMsg16To32A(wmd
->wType
, wMsg
, &dwParam2
)) {
1208 case WINMM_MAP_MSGERROR
:
1209 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1210 dwRet
= MCIERR_DRIVER_INTERNAL
;
1212 case WINMM_MAP_NOMEM
:
1213 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg
));
1214 dwRet
= MCIERR_OUT_OF_MEMORY
;
1217 case WINMM_MAP_OKMEM
:
1218 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1219 if (res
== WINMM_MAP_OKMEM
)
1220 pFnMciUnMapMsg16To32A(wmd
->wType
, wMsg
, dwParam2
);
1224 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1230 /**************************************************************************
1231 * MCI_Open [internal]
1233 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSA lpParms
)
1235 char strDevTyp
[128];
1237 LPWINE_MCIDRIVER wmd
= NULL
;
1239 TRACE("(%08lX, %p)\n", dwParam
, lpParms
);
1240 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1242 /* only two low bytes are generic, the other ones are dev type specific */
1243 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1244 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1245 MCI_NOTIFY|MCI_WAIT)
1246 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1247 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1249 #undef WINE_MCIDRIVER_SUPP
1253 if (dwParam
& MCI_OPEN_TYPE
) {
1254 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1255 WORD uDevType
= LOWORD((DWORD
)lpParms
->lpstrDeviceType
);
1257 if (uDevType
< MCI_DEVTYPE_FIRST
||
1258 uDevType
> MCI_DEVTYPE_LAST
||
1259 !LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, strDevTyp
, sizeof(strDevTyp
))) {
1260 dwRet
= MCIERR_BAD_INTEGER
;
1265 if (lpParms
->lpstrDeviceType
== NULL
) {
1266 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1269 strcpy(strDevTyp
, lpParms
->lpstrDeviceType
);
1270 ptr
= strchr(strDevTyp
, '!');
1272 /* this behavior is not documented in windows. However, since, in
1273 * some occasions, MCI_OPEN handling is translated by WinMM into
1274 * a call to mciSendString("open <type>"); this code shall be correct
1276 if (dwParam
& MCI_OPEN_ELEMENT
) {
1277 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1278 lpParms
->lpstrElementName
, strDevTyp
);
1279 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1282 dwParam
|= MCI_OPEN_ELEMENT
;
1284 /* FIXME: not a good idea to write in user supplied buffer */
1285 lpParms
->lpstrElementName
= ptr
;
1289 TRACE("devType='%s' !\n", strDevTyp
);
1292 if (dwParam
& MCI_OPEN_ELEMENT
) {
1293 TRACE("lpstrElementName='%s'\n", lpParms
->lpstrElementName
);
1295 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1296 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1297 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1301 if (!lpParms
->lpstrElementName
) {
1302 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1306 /* type, if given as a parameter, supersedes file extension */
1307 if (!strDevTyp
[0] &&
1308 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1309 strDevTyp
, sizeof(strDevTyp
))) {
1310 if (GetDriveTypeA(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1311 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1314 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1315 strcpy(strDevTyp
, "CDAUDIO");
1319 if (strDevTyp
[0] == 0) {
1320 FIXME("Couldn't load driver\n");
1321 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1325 if (dwParam
& MCI_OPEN_ALIAS
) {
1326 TRACE("Alias='%s' !\n", lpParms
->lpstrAlias
);
1327 if (!lpParms
->lpstrAlias
) {
1328 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1333 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1337 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1338 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet
);
1339 /* FIXME: is dwRet the correct ret code ? */
1343 /* only handled devices fall through */
1344 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1346 if (dwParam
& MCI_NOTIFY
)
1347 mciDriverNotify((HWND
)lpParms
->dwCallback
, wmd
->wDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1351 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1353 if (dwParam
& MCI_NOTIFY
)
1354 mciDriverNotify((HWND
)lpParms
->dwCallback
, 0, MCI_NOTIFY_FAILURE
);
1358 /**************************************************************************
1359 * MCI_Close [internal]
1361 static DWORD
MCI_Close(UINT16 wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1364 LPWINE_MCIDRIVER wmd
;
1366 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwParam
, lpParms
);
1368 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1369 LPWINE_MCIDRIVER next
;
1371 EnterCriticalSection(&WINMM_IData
->cs
);
1372 /* FIXME: shall I notify once after all is done, or for
1373 * each of the open drivers ? if the latest, which notif
1374 * to return when only one fails ?
1376 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; ) {
1378 MCI_Close(wmd
->wDeviceID
, dwParam
, lpParms
);
1381 LeaveCriticalSection(&WINMM_IData
->cs
);
1385 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1386 return MCIERR_INVALID_DEVICE_ID
;
1389 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD
)lpParms
);
1391 MCI_UnLoadMciDriver(wmd
);
1393 if (dwParam
& MCI_NOTIFY
)
1394 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1395 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1400 /**************************************************************************
1401 * MCI_WriteString [internal]
1403 DWORD
MCI_WriteString(LPSTR lpDstStr
, DWORD dstSize
, LPCSTR lpSrcStr
)
1408 if (dstSize
<= strlen(lpSrcStr
)) {
1409 lstrcpynA(lpDstStr
, lpSrcStr
, dstSize
- 1);
1410 ret
= MCIERR_PARAM_OVERFLOW
;
1412 strcpy(lpDstStr
, lpSrcStr
);
1420 /**************************************************************************
1421 * MCI_Sysinfo [internal]
1423 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSA lpParms
)
1425 DWORD ret
= MCIERR_INVALID_DEVICE_ID
;
1426 LPWINE_MCIDRIVER wmd
;
1428 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1430 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1431 uDevID
, dwFlags
, (DWORD
)lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1433 switch (dwFlags
& ~MCI_SYSINFO_OPEN
) {
1434 case MCI_SYSINFO_QUANTITY
:
1438 if (lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
||
1439 lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
) {
1440 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1441 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1442 EnterCriticalSection(&WINMM_IData
->cs
);
1443 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1446 LeaveCriticalSection(&WINMM_IData
->cs
);
1448 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1449 cnt
= MCI_InstalledCount
;
1452 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1453 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
1454 lpParms
->wDeviceType
);
1455 EnterCriticalSection(&WINMM_IData
->cs
);
1456 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1457 if (wmd
->wType
== lpParms
->wDeviceType
)
1460 LeaveCriticalSection(&WINMM_IData
->cs
);
1462 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
1463 lpParms
->wDeviceType
);
1464 FIXME("Don't know how to get # of MCI devices of a given type\n");
1468 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1470 TRACE("(%ld) => '%ld'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1471 ret
= MCI_INTEGER_RETURNED
;
1473 case MCI_SYSINFO_INSTALLNAME
:
1474 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1475 if ((wmd
= MCI_GetDriver(uDevID
))) {
1476 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1477 wmd
->lpstrDeviceType
);
1479 *lpParms
->lpstrReturn
= 0;
1480 ret
= MCIERR_INVALID_DEVICE_ID
;
1482 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1484 case MCI_SYSINFO_NAME
:
1485 TRACE("MCI_SYSINFO_NAME\n");
1486 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1487 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1488 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1489 } else if (lpParms
->dwNumber
> MCI_InstalledCount
) {
1490 ret
= MCIERR_OUTOFRANGE
;
1492 DWORD count
= lpParms
->dwNumber
;
1493 LPSTR ptr
= MCI_lpInstallNames
;
1495 while (--count
> 0) ptr
+= strlen(ptr
) + 1;
1496 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, ptr
);
1498 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1501 TRACE("Unsupported flag value=%08lx\n", dwFlags
);
1502 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1507 /**************************************************************************
1508 * MCI_Break [internal]
1510 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1514 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1516 if (dwFlags
& MCI_NOTIFY
)
1517 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1518 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1523 /**************************************************************************
1524 * MCI_SendCommand [internal]
1526 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
,
1527 DWORD dwParam2
, BOOL bFrom32
)
1529 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1534 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1535 } else if (pFnMciMapMsg16To32A
) {
1536 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1538 case WINMM_MAP_OKMEM
:
1539 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1540 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1542 default: break; /* so that gcc does not bark */
1548 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1549 } else if (pFnMciMapMsg16To32A
) {
1550 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1552 case WINMM_MAP_OKMEM
:
1553 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1554 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1556 default: break; /* so that gcc does not bark */
1562 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1563 } else if (pFnMciMapMsg16To32A
) {
1564 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1566 case WINMM_MAP_OKMEM
:
1567 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1568 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1570 default: break; /* so that gcc doesnot bark */
1576 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1577 } else if (pFnMciMapMsg16To32A
) {
1578 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1580 case WINMM_MAP_OKMEM
:
1581 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1582 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1584 default: break; /* so that gcc does not bark */
1589 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
1590 * but I couldn't get any doc on this MCI message
1594 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1595 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1596 dwRet
= MCIERR_CANNOT_USE_ALL
;
1599 MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
) :
1600 MCI_SendCommandFrom16(wDevID
, wMsg
, dwParam1
, dwParam2
);
1607 /**************************************************************************
1608 * MCI_CleanUp [internal]
1610 * Some MCI commands need to be cleaned-up (when not called from
1611 * mciSendString), because MCI drivers return extra information for string
1612 * transformation. This function gets rid of them.
1614 LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD dwParam2
)
1617 return LOWORD(dwRet
);
1620 case MCI_GETDEVCAPS
:
1621 switch (dwRet
& 0xFFFF0000ul
) {
1623 case MCI_COLONIZED3_RETURN
:
1624 case MCI_COLONIZED4_RETURN
:
1625 case MCI_INTEGER_RETURNED
:
1628 case MCI_RESOURCE_RETURNED
:
1629 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1631 LPMCI_GETDEVCAPS_PARMS lmgp
;
1633 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)(void*)dwParam2
;
1634 TRACE("Changing %08lx to %08lx\n", lmgp
->dwReturn
, (DWORD
)LOWORD(lmgp
->dwReturn
));
1635 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
1639 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1640 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1644 switch (dwRet
& 0xFFFF0000ul
) {
1646 case MCI_COLONIZED3_RETURN
:
1647 case MCI_COLONIZED4_RETURN
:
1648 case MCI_INTEGER_RETURNED
:
1651 case MCI_RESOURCE_RETURNED
:
1652 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1654 LPMCI_STATUS_PARMS lsp
;
1656 lsp
= (LPMCI_STATUS_PARMS
)(void*)dwParam2
;
1657 TRACE("Changing %08lx to %08lx\n", lsp
->dwReturn
, (DWORD
)LOWORD(lsp
->dwReturn
));
1658 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
1662 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1663 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1667 switch (dwRet
& 0xFFFF0000ul
) {
1669 case MCI_INTEGER_RETURNED
:
1673 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
1677 if (HIWORD(dwRet
)) {
1678 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1679 dwRet
, MCI_MessageToString(wMsg
));
1683 return LOWORD(dwRet
);
1686 /**************************************************************************
1687 * MCI_Init [internal]
1689 * Initializes the MCI internal variables.
1701 MCI_InstalledCount
= 0;
1702 ptr1
= MCI_lpInstallNames
= HeapAlloc(GetProcessHeap(), 0, count
);
1704 if (!MCI_lpInstallNames
)
1707 /* FIXME: should do also some registry diving here ? */
1708 if (!(err
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config", &hWineConf
)) &&
1709 !(err
= RegOpenKeyA(hWineConf
, "options", &hkey
))) {
1710 err
= RegQueryValueExA(hkey
, "mci", 0, &type
, MCI_lpInstallNames
, &count
);
1715 TRACE("Wine => '%s' \n", ptr1
);
1716 while ((ptr2
= strchr(ptr1
, ':')) != 0) {
1718 TRACE("---> '%s' \n", ptr1
);
1719 MCI_InstalledCount
++;
1722 MCI_InstalledCount
++;
1723 TRACE("---> '%s' \n", ptr1
);
1724 ptr1
+= strlen(ptr1
) + 1;
1726 GetPrivateProfileStringA("mci", NULL
, "", MCI_lpInstallNames
, count
, "SYSTEM.INI");
1727 while (strlen(ptr1
) > 0) {
1728 TRACE("---> '%s' \n", ptr1
);
1729 ptr1
+= strlen(ptr1
) + 1;
1730 MCI_InstalledCount
++;
1733 RegCloseKey(hWineConf
);