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"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
46 static int MCI_InstalledCount
;
47 static LPSTR MCI_lpInstallNames
/* = NULL */;
49 WINMM_MapType (*pFnMciMapMsg16To32A
) (WORD
,WORD
,DWORD
*) /* = NULL */;
50 WINMM_MapType (*pFnMciUnMapMsg16To32A
)(WORD
,WORD
,DWORD
) /* = NULL */;
51 WINMM_MapType (*pFnMciMapMsg32ATo16
) (WORD
,WORD
,DWORD
,DWORD
*) /* = NULL */;
52 WINMM_MapType (*pFnMciUnMapMsg32ATo16
)(WORD
,WORD
,DWORD
,DWORD
) /* = NULL */;
54 /* First MCI valid device ID (0 means error) */
55 #define MCI_MAGIC 0x0001
57 /* dup a string and uppercase it */
58 inline static LPSTR
str_dup_upper( LPCSTR str
)
60 INT len
= strlen(str
) + 1;
61 LPSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
64 memcpy( p
, str
, len
);
70 /**************************************************************************
71 * MCI_GetDriver [internal]
73 LPWINE_MCIDRIVER
MCI_GetDriver(UINT16 wDevID
)
75 LPWINE_MCIDRIVER wmd
= 0;
77 EnterCriticalSection(&WINMM_IData
->cs
);
78 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
79 if (wmd
->wDeviceID
== wDevID
)
82 LeaveCriticalSection(&WINMM_IData
->cs
);
86 /**************************************************************************
87 * MCI_GetDriverFromString [internal]
89 UINT
MCI_GetDriverFromString(LPCSTR lpstrName
)
97 if (!lstrcmpiA(lpstrName
, "ALL"))
98 return MCI_ALL_DEVICE_ID
;
100 EnterCriticalSection(&WINMM_IData
->cs
);
101 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
102 if (wmd
->lpstrElementName
&& strcmp(wmd
->lpstrElementName
, lpstrName
) == 0) {
103 ret
= wmd
->wDeviceID
;
106 if (wmd
->lpstrDeviceType
&& strcasecmp(wmd
->lpstrDeviceType
, lpstrName
) == 0) {
107 ret
= wmd
->wDeviceID
;
110 if (wmd
->lpstrAlias
&& strcasecmp(wmd
->lpstrAlias
, lpstrName
) == 0) {
111 ret
= wmd
->wDeviceID
;
115 LeaveCriticalSection(&WINMM_IData
->cs
);
120 /**************************************************************************
121 * MCI_MessageToString [internal]
123 const char* MCI_MessageToString(UINT16 wMsg
)
125 static char buffer
[100];
127 #define CASE(s) case (s): return #s
132 CASE(MCI_CLOSE_DRIVER
);
141 CASE(MCI_GETDEVCAPS
);
145 CASE(MCI_OPEN_DRIVER
);
163 /* constants for digital video */
177 sprintf(buffer
, "MCI_<<%04X>>", wMsg
);
182 /**************************************************************************
183 * MCI_GetDevTypeFromFileName [internal]
185 static DWORD
MCI_GetDevTypeFromFileName(LPCSTR fileName
, LPSTR buf
, UINT len
)
189 if ((tmp
= strrchr(fileName
, '.'))) {
190 GetProfileStringA("mci extensions", tmp
+ 1, "*", buf
, len
);
191 if (strcmp(buf
, "*") != 0) {
194 TRACE("No [mci extensions] entry for '%s' found.\n", tmp
);
196 return MCIERR_EXTENSION_NOT_FOUND
;
199 #define MAX_MCICMDTABLE 20
200 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
202 typedef struct tagWINE_MCICMDTABLE
{
205 UINT nVerbs
; /* number of verbs in command table */
206 LPCSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
207 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
209 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
211 /**************************************************************************
212 * MCI_IsCommandTableValid [internal]
214 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
222 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
223 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
225 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
228 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
232 lmem
+= strlen(lmem
) + 1;
233 flg
= *(LPDWORD
)lmem
;
234 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
235 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
237 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
239 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
240 case MCI_STRING
: if (inCst
) return FALSE
; break;
241 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
242 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
243 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
244 case MCI_FLAG
: if (!*str
) return FALSE
; break;
245 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
246 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
247 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
248 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
249 default: return FALSE
;
251 } while (eid
!= MCI_END_COMMAND_LIST
);
252 } while (eid
!= MCI_END_COMMAND_LIST
);
256 /**************************************************************************
257 * MCI_DumpCommandTable [internal]
259 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
266 if (!MCI_IsCommandTableValid(uTbl
)) {
267 ERR("Ooops: %d is not valid\n", uTbl
);
271 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
275 lmem
+= strlen(lmem
) + 1;
276 flg
= *(LPDWORD
)lmem
;
277 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
278 TRACE("cmd='%s' %08lx %04x\n", str
, flg
, eid
);
279 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
280 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
281 TRACE(" => end of command%s\n", (eid
== MCI_END_COMMAND_LIST
) ? " list" : "");
282 } while (eid
!= MCI_END_COMMAND_LIST
);
287 /**************************************************************************
288 * MCI_GetCommandTable [internal]
290 static UINT
MCI_GetCommandTable(UINT uDevType
)
296 /* first look up existing for existing devType */
297 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
298 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
302 /* well try to load id */
303 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
304 if (LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, buf
, sizeof(buf
))) {
307 } else if (uDevType
== 0) {
310 uTbl
= MCI_NO_COMMAND_TABLE
;
312 HRSRC hRsrc
= FindResourceA(WINMM_IData
->hWinMM32Instance
, str
, (LPCSTR
)RT_RCDATA
);
315 if (hRsrc
) hMem
= LoadResource(WINMM_IData
->hWinMM32Instance
, hRsrc
);
317 uTbl
= MCI_SetCommandTable(LockResource(hMem
), uDevType
);
319 WARN("No command table found in resource %p[%s]\n",
320 WINMM_IData
->hWinMM32Instance
, str
);
323 TRACE("=> %d\n", uTbl
);
327 /**************************************************************************
328 * MCI_SetCommandTable [internal]
330 UINT
MCI_SetCommandTable(void *table
, UINT uDevType
)
333 static BOOL bInitDone
= FALSE
;
336 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
337 * can be called with 0 as a uDevType to retrieve it.
342 MCI_GetCommandTable(0);
345 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
346 if (!S_MciCmdTable
[uTbl
].lpTable
) {
351 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
352 S_MciCmdTable
[uTbl
].lpTable
= table
;
355 MCI_DumpCommandTable(uTbl
);
358 /* create the verbs table */
359 /* get # of entries */
360 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
363 lmem
+= strlen(lmem
) + 1;
364 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
365 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
366 if (eid
== MCI_COMMAND_HEAD
)
368 } while (eid
!= MCI_END_COMMAND_LIST
);
370 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCSTR
));
371 S_MciCmdTable
[uTbl
].nVerbs
= count
;
373 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
377 lmem
+= strlen(lmem
) + 1;
378 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
379 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
380 if (eid
== MCI_COMMAND_HEAD
)
381 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
382 } while (eid
!= MCI_END_COMMAND_LIST
);
383 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
388 return MCI_NO_COMMAND_TABLE
;
391 /**************************************************************************
392 * MCI_DeleteCommandTable [internal]
394 static BOOL
MCI_DeleteCommandTable(UINT uTbl
)
396 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
399 S_MciCmdTable
[uTbl
].lpTable
= NULL
;
400 if (S_MciCmdTable
[uTbl
].aVerbs
) {
401 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTbl
].aVerbs
);
402 S_MciCmdTable
[uTbl
].aVerbs
= 0;
407 /**************************************************************************
408 * MCI_UnLoadMciDriver [internal]
410 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
412 LPWINE_MCIDRIVER
* tmp
;
417 CloseDriver(wmd
->hDriver
, 0, 0);
419 if (wmd
->dwPrivate
!= 0)
420 WARN("Unloading mci driver with non nul dwPrivate field\n");
422 EnterCriticalSection(&WINMM_IData
->cs
);
423 for (tmp
= &WINMM_IData
->lpMciDrvs
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
429 LeaveCriticalSection(&WINMM_IData
->cs
);
431 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
432 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
433 HeapFree(GetProcessHeap(), 0, wmd
->lpstrElementName
);
435 HeapFree(GetProcessHeap(), 0, wmd
);
439 /**************************************************************************
440 * MCI_OpenMciDriver [internal]
442 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCSTR drvTyp
, LPARAM lp
)
446 if (!DRIVER_GetLibName(drvTyp
, "mci", libName
, sizeof(libName
)))
450 /* First load driver */
451 if ((wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
))) {
453 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32ATo16
) {
456 switch (res
= pFnMciMapMsg32ATo16(0, DRV_OPEN
, 0, &lp
)) {
457 case WINMM_MAP_MSGERROR
:
458 TRACE("Not handled yet (DRV_OPEN)\n");
460 case WINMM_MAP_NOMEM
:
461 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
464 case WINMM_MAP_OKMEM
:
465 if ((wmd
->hDriver
= OpenDriverA(drvTyp
, "mci", lp
)))
467 if (res
== WINMM_MAP_OKMEM
)
468 pFnMciUnMapMsg32ATo16(0, DRV_OPEN
, 0, lp
);
472 return (wmd
->bIs32
== 0xFFFF) ? FALSE
: TRUE
;
475 /**************************************************************************
476 * MCI_LoadMciDriver [internal]
478 static DWORD
MCI_LoadMciDriver(LPCSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
480 LPSTR strDevTyp
= str_dup_upper(_strDevTyp
);
481 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
482 MCI_OPEN_DRIVER_PARMSA modp
;
485 if (!wmd
|| !strDevTyp
) {
486 dwRet
= MCIERR_OUT_OF_MEMORY
;
490 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
491 wmd
->dwYieldData
= VK_CANCEL
;
492 wmd
->CreatorThread
= GetCurrentThreadId();
494 EnterCriticalSection(&WINMM_IData
->cs
);
495 /* wmd must be inserted in list before sending opening the driver, coz' it
496 * may want to lookup at wDevID
498 wmd
->lpNext
= WINMM_IData
->lpMciDrvs
;
499 WINMM_IData
->lpMciDrvs
= wmd
;
501 for (modp
.wDeviceID
= MCI_MAGIC
;
502 MCI_GetDriver(modp
.wDeviceID
) != 0;
505 wmd
->wDeviceID
= modp
.wDeviceID
;
507 LeaveCriticalSection(&WINMM_IData
->cs
);
509 TRACE("wDevID=%04X \n", modp
.wDeviceID
);
511 modp
.lpstrParams
= NULL
;
513 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (LPARAM
)&modp
)) {
514 /* silence warning if all is used... some bogus program use commands like
517 if (strcasecmp(strDevTyp
, "all") == 0) {
518 dwRet
= MCIERR_CANNOT_USE_ALL
;
520 FIXME("Couldn't load driver for type %s.\n"
521 "If you don't have a windows installation accessible from Wine,\n"
522 "you perhaps forgot to create a [mci] section in system.ini\n",
524 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
529 /* FIXME: should also check that module's description is of the form
530 * MODULENAME:[MCI] comment
533 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
534 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
535 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
537 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
538 wmd
->hDriver
, strDevTyp
, modp
.wType
, modp
.wCustomCommandTable
);
540 wmd
->lpstrDeviceType
= strDevTyp
;
541 wmd
->wType
= modp
.wType
;
543 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
544 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
548 MCI_UnLoadMciDriver(wmd
);
549 HeapFree(GetProcessHeap(), 0, strDevTyp
);
554 /**************************************************************************
555 * MCI_FinishOpen [internal]
557 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSA lpParms
,
560 if (dwParam
& MCI_OPEN_ELEMENT
)
562 wmd
->lpstrElementName
= HeapAlloc(GetProcessHeap(),0,strlen(lpParms
->lpstrElementName
)+1);
563 strcpy( wmd
->lpstrElementName
, lpParms
->lpstrElementName
);
565 if (dwParam
& MCI_OPEN_ALIAS
)
567 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, strlen(lpParms
->lpstrAlias
)+1);
568 strcpy( wmd
->lpstrAlias
, lpParms
->lpstrAlias
);
570 lpParms
->wDeviceID
= wmd
->wDeviceID
;
572 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
576 /**************************************************************************
577 * MCI_FindCommand [internal]
579 static LPCSTR
MCI_FindCommand(UINT uTbl
, LPCSTR verb
)
583 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
586 /* another improvement would be to have the aVerbs array sorted,
587 * so that we could use a dichotomic search on it, rather than this dumb
590 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
591 if (strcmp(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
592 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
598 /**************************************************************************
599 * MCI_GetReturnType [internal]
601 static DWORD
MCI_GetReturnType(LPCSTR lpCmd
)
603 lpCmd
+= strlen(lpCmd
) + 1 + sizeof(DWORD
) + sizeof(WORD
);
604 if (*lpCmd
== '\0' && *(LPWORD
)(lpCmd
+ 1 + sizeof(DWORD
)) == MCI_RETURN
) {
605 return *(LPDWORD
)(lpCmd
+ 1);
610 /**************************************************************************
611 * MCI_GetMessage [internal]
613 static WORD
MCI_GetMessage(LPCSTR lpCmd
)
615 return (WORD
)*(LPDWORD
)(lpCmd
+ strlen(lpCmd
) + 1);
618 /**************************************************************************
619 * MCI_GetDWord [internal]
621 static BOOL
MCI_GetDWord(LPDWORD data
, LPSTR
* ptr
)
626 val
= strtoul(*ptr
, &ret
, 0);
630 case ' ': ret
++; break;
631 default: return FALSE
;
639 /**************************************************************************
640 * MCI_GetString [internal]
642 static DWORD
MCI_GetString(LPSTR
* str
, LPSTR
* args
)
646 /* see if we have a quoted string */
648 ptr
= strchr(*str
= ptr
+ 1, '"');
649 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
650 /* FIXME: shall we escape \" from string ?? */
651 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
652 *ptr
++ = '\0'; /* remove trailing " */
653 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
656 ptr
= strchr(ptr
, ' ');
661 ptr
= *args
+ strlen(*args
);
670 #define MCI_DATA_SIZE 16
672 /**************************************************************************
673 * MCI_ParseOptArgs [internal]
675 static DWORD
MCI_ParseOptArgs(LPDWORD data
, int _offset
, LPCSTR lpCmd
,
676 LPSTR args
, LPDWORD dwFlags
)
680 DWORD dwRet
, flg
, cflg
= 0;
684 /* loop on arguments */
687 found
= inCst
= FALSE
;
690 /* skip any leading white space(s) */
691 while (*args
== ' ') args
++;
692 TRACE("args='%s' offset=%d\n", args
, offset
);
694 do { /* loop on options for command table for the requested verb */
696 lmem
+= (len
= strlen(lmem
)) + 1;
697 flg
= *(LPDWORD
)lmem
;
698 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
699 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
700 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
704 inCst
= TRUE
; cflg
= flg
; break;
705 case MCI_END_CONSTANT
:
706 /* there may be additional integral values after flag in constant */
707 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
710 inCst
= FALSE
; cflg
= 0;
714 if (strncasecmp(args
, str
, len
) == 0 &&
715 (args
[len
] == 0 || args
[len
] == ' ')) {
716 /* store good values into data[] */
718 while (*args
== ' ') args
++;
722 case MCI_COMMAND_HEAD
:
724 case MCI_END_COMMAND
:
725 case MCI_END_COMMAND_LIST
:
726 case MCI_CONSTANT
: /* done above */
727 case MCI_END_CONSTANT
: /* done above */
739 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
740 return MCIERR_BAD_INTEGER
;
745 /* store rect in data (offset...offset+3) */
747 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
748 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
749 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
750 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
751 ERR("Bad rect '%s'\n", args
);
752 return MCIERR_BAD_INTEGER
;
757 if ((dwRet
= MCI_GetString((LPSTR
*)&data
[offset
], &args
)))
760 default: ERR("oops\n");
762 /* exit inside while loop, except if just entered in constant area definition */
763 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
765 /* have offset incremented if needed */
767 case MCI_COMMAND_HEAD
:
769 case MCI_END_COMMAND
:
770 case MCI_END_COMMAND_LIST
:
772 case MCI_FLAG
: break;
773 case MCI_INTEGER
: if (!inCst
) offset
++; break;
774 case MCI_END_CONSTANT
:
775 case MCI_STRING
: offset
++; break;
776 case MCI_RECT
: offset
+= 4; break;
777 default: ERR("oops\n");
780 } while (eid
!= MCI_END_COMMAND
);
782 WARN("Optarg '%s' not found\n", args
);
783 return MCIERR_UNRECOGNIZED_COMMAND
;
785 if (offset
== MCI_DATA_SIZE
) {
786 ERR("Internal data[] buffer overflow\n");
787 return MCIERR_PARSER_INTERNAL
;
793 /**************************************************************************
794 * MCI_HandleReturnValues [internal]
796 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
797 LPDWORD data
, LPSTR lpstrRet
, UINT uRetLen
)
801 case 0: /* nothing to return */
804 switch (dwRet
& 0xFFFF0000ul
) {
806 case MCI_INTEGER_RETURNED
:
807 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
809 case MCI_RESOURCE_RETURNED
:
810 /* return string which ID is HIWORD(data[1]),
811 * string is loaded from mmsystem.dll */
812 LoadStringA(WINMM_IData
->hWinMM32Instance
, HIWORD(data
[1]),
815 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
816 /* return string which ID is HIWORD(data[1]),
817 * string is loaded from driver */
818 /* FIXME: this is wrong for a 16 bit handle */
819 LoadStringA(GetDriverModuleHandle(wmd
->hDriver
),
820 HIWORD(data
[1]), lpstrRet
, uRetLen
);
822 case MCI_COLONIZED3_RETURN
:
823 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d",
824 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
825 LOBYTE(HIWORD(data
[1])));
827 case MCI_COLONIZED4_RETURN
:
828 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d:%d",
829 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
830 LOBYTE(HIWORD(data
[1])), HIBYTE(HIWORD(data
[1])));
832 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
836 switch (dwRet
& 0xFFFF0000ul
) {
838 /* nothing to do data[1] == lpstrRet */
840 case MCI_INTEGER_RETURNED
:
841 data
[1] = *(LPDWORD
)lpstrRet
;
842 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
845 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
850 if (dwRet
& 0xFFFF0000ul
)
851 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
852 snprintf(lpstrRet
, uRetLen
, "%ld %ld %ld %ld",
853 data
[1], data
[2], data
[3], data
[4]);
855 default: ERR("oops\n");
858 return LOWORD(dwRet
);
861 /**************************************************************************
862 * mciSendStringA [WINMM.@]
864 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
865 UINT uRetLen
, HWND hwndCallback
)
867 LPSTR verb
, dev
, args
;
868 LPWINE_MCIDRIVER wmd
= 0;
869 DWORD dwFlags
= 0, dwRet
= 0;
871 DWORD data
[MCI_DATA_SIZE
];
874 LPSTR devAlias
= NULL
;
875 BOOL bAutoOpen
= FALSE
;
877 TRACE("('%s', %p, %d, %p)\n", lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
879 /* format is <command> <device> <optargs> */
880 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand
)+1)))
881 return MCIERR_OUT_OF_MEMORY
;
882 strcpy( verb
, lpstrCommand
);
884 memset(data
, 0, sizeof(data
));
886 if (!(args
= strchr(verb
, ' '))) {
887 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
891 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
895 /* case dev == 'new' has to be handled */
896 if (!strcasecmp(dev
, "new")) {
897 FIXME("'new': NIY as device name\n");
898 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
902 /* otherwise, try to grab devType from open */
903 if (!strcmp(verb
, "open")) {
906 if ((devType
= strchr(dev
, '!')) != NULL
) {
908 tmp
= devType
; devType
= dev
; dev
= tmp
;
910 dwFlags
|= MCI_OPEN_TYPE
;
911 data
[2] = (DWORD
)devType
;
912 devType
= str_dup_upper(devType
);
913 dwFlags
|= MCI_OPEN_ELEMENT
;
914 data
[3] = (DWORD
)dev
;
915 } else if (strchr(dev
, '.') == NULL
) {
916 tmp
= strchr(dev
,' ');
917 if (tmp
) *tmp
= '\0';
918 data
[2] = (DWORD
)dev
;
919 devType
= str_dup_upper(dev
);
921 dwFlags
|= MCI_OPEN_TYPE
;
923 if ((devType
= strstr(args
, "type ")) != NULL
) {
925 tmp
= strchr(devType
, ' ');
926 if (tmp
) *tmp
= '\0';
927 devType
= str_dup_upper(devType
);
929 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
932 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
935 devType
= str_dup_upper(buf
);
937 dwFlags
|= MCI_OPEN_ELEMENT
;
938 data
[3] = (DWORD
)dev
;
940 if ((devAlias
= strstr(args
," alias "))) {
943 if (!(tmp
= strchr(devAlias
,' '))) tmp
= devAlias
+ strlen(devAlias
);
944 if (tmp
) *tmp
= '\0';
945 tmp2
= HeapAlloc(GetProcessHeap(), 0, tmp
- devAlias
+ 1 );
946 memcpy( tmp2
, devAlias
, tmp
- devAlias
);
947 tmp2
[tmp
- devAlias
] = 0;
948 data
[4] = (DWORD
)tmp2
;
949 /* should be done in regular options parsing */
950 /* dwFlags |= MCI_OPEN_ALIAS; */
953 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
954 HeapFree(GetProcessHeap(), 0, devType
);
956 MCI_UnLoadMciDriver(wmd
);
959 } else if (!(wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
)))) {
962 sprintf(buf
, "open %s wait", dev
);
964 if ((dwRet
= mciSendStringA(buf
, NULL
, 0, 0)) != 0)
967 wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
));
969 /* FIXME: memory leak, MCI driver is not closed */
970 dwRet
= MCIERR_INVALID_DEVICE_ID
;
975 /* get the verb in the different command tables */
977 /* try the device specific command table */
978 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
980 /* try the type specific command table */
981 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
982 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
983 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
984 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
987 /* try core command table */
988 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
991 TRACE("Command '%s' not found!\n", verb
);
992 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
996 /* set up call back */
997 if (hwndCallback
!= 0) {
998 dwFlags
|= MCI_NOTIFY
;
999 data
[0] = (DWORD
)hwndCallback
;
1002 /* set return information */
1003 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1004 case 0: offset
= 1; break;
1005 case MCI_INTEGER
: offset
= 2; break;
1006 case MCI_STRING
: data
[1] = (DWORD
)lpstrRet
; data
[2] = uRetLen
; offset
= 3; break;
1007 case MCI_RECT
: offset
= 5; break;
1008 default: ERR("oops\n");
1011 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb
, dev
, offset
);
1013 if ((dwRet
= MCI_ParseOptArgs(data
, offset
, lpCmd
, args
, &dwFlags
)))
1016 if (bAutoOpen
&& (dwFlags
& MCI_NOTIFY
)) {
1017 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1020 /* FIXME: the command should get it's own notification window set up and
1021 * ask for device closing while processing the notification mechanism
1023 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1025 #define STR_OF(_x) (IsBadReadPtr((char*)_x,1)?"?":(char*)(_x))
1026 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1027 wmd
->wDeviceID
, MCI_MessageToString(MCI_GetMessage(lpCmd
)), dwFlags
,
1028 data
[0], STR_OF(data
[0]), data
[1], STR_OF(data
[1]),
1029 data
[2], STR_OF(data
[2]), data
[3], STR_OF(data
[3]),
1030 data
[4], STR_OF(data
[4]), data
[5], STR_OF(data
[5]));
1033 if (strcmp(verb
, "open") == 0) {
1034 if ((dwRet
= MCI_FinishOpen(wmd
, (LPMCI_OPEN_PARMSA
)data
, dwFlags
)))
1035 MCI_UnLoadMciDriver(wmd
);
1036 /* FIXME: notification is not properly shared across two opens */
1038 dwRet
= MCI_SendCommand(wmd
->wDeviceID
, MCI_GetMessage(lpCmd
), dwFlags
, (DWORD
)data
, TRUE
);
1040 TRACE("=> 1/ %lx (%s)\n", dwRet
, lpstrRet
);
1041 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, data
, lpstrRet
, uRetLen
);
1042 TRACE("=> 2/ %lx (%s)\n", dwRet
, lpstrRet
);
1045 HeapFree(GetProcessHeap(), 0, verb
);
1046 HeapFree(GetProcessHeap(), 0, devAlias
);
1050 /**************************************************************************
1051 * mciSendStringW [WINMM.@]
1053 DWORD WINAPI
mciSendStringW(LPCWSTR lpwstrCommand
, LPWSTR lpwstrRet
,
1054 UINT uRetLen
, HWND hwndCallback
)
1057 LPSTR lpstrRet
= NULL
;
1061 /* FIXME: is there something to do with lpstrReturnString ? */
1062 len
= WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, NULL
, 0, NULL
, NULL
);
1063 lpstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
);
1064 WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, lpstrCommand
, len
, NULL
, NULL
);
1067 lpstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1068 if (!lpstrRet
) return MMSYSERR_NOMEM
;
1070 ret
= mciSendStringA(lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
1072 MultiByteToWideChar( CP_ACP
, 0, lpstrRet
, -1, lpwstrRet
, uRetLen
);
1073 HeapFree(GetProcessHeap(), 0, lpstrCommand
);
1074 if (lpstrRet
) HeapFree(GetProcessHeap(), 0, lpstrRet
);
1078 /**************************************************************************
1079 * mciExecute [WINMM.@]
1080 * mciExecute [MMSYSTEM.712]
1082 DWORD WINAPI
mciExecute(LPCSTR lpstrCommand
)
1087 TRACE("(%s)!\n", lpstrCommand
);
1089 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1091 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1092 sprintf(strRet
, "Unknown MCI error (%ld)", ret
);
1094 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1096 /* FIXME: what shall I return ? */
1100 /**************************************************************************
1101 * mciLoadCommandResource [WINMM.@]
1103 * Strangely, this function only exists as an UNICODE one.
1105 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1109 UINT16 ret
= MCI_NO_COMMAND_TABLE
;
1111 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1113 /* if a file named "resname.mci" exits, then load resource "resname" from it
1114 * otherwise directly from driver
1115 * We don't support it (who uses this feature ?), but we check anyway
1119 /* FIXME: we should put this back into order, but I never found a program
1120 * actually using this feature, so we not need it
1125 strcat(strcpy(buf
, resname
), ".mci");
1126 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1127 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1131 if (!(hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
))) {
1132 WARN("No command table found in resource\n");
1133 } else if ((hMem
= LoadResource(hInst
, hRsrc
))) {
1134 ret
= MCI_SetCommandTable(LockResource(hMem
), type
);
1136 WARN("Couldn't load resource.\n");
1138 TRACE("=> %04x\n", ret
);
1142 /**************************************************************************
1143 * mciFreeCommandResource [WINMM.@]
1145 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1147 TRACE("(%08x)!\n", uTable
);
1149 return MCI_DeleteCommandTable(uTable
);
1152 /**************************************************************************
1153 * MCI_SendCommandFrom32 [internal]
1155 DWORD
MCI_SendCommandFrom32(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1157 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1158 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1162 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1163 } else if (pFnMciMapMsg32ATo16
) {
1166 switch (res
= pFnMciMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, &dwParam2
)) {
1167 case WINMM_MAP_MSGERROR
:
1168 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1169 dwRet
= MCIERR_DRIVER_INTERNAL
;
1171 case WINMM_MAP_NOMEM
:
1172 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg
));
1173 dwRet
= MCIERR_OUT_OF_MEMORY
;
1176 case WINMM_MAP_OKMEM
:
1177 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1178 if (res
== WINMM_MAP_OKMEM
)
1179 pFnMciUnMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, dwParam2
);
1187 /**************************************************************************
1188 * MCI_SendCommandFrom16 [internal]
1190 DWORD
MCI_SendCommandFrom16(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1192 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1193 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1196 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1198 if (wmd
->bIs32
&& pFnMciMapMsg16To32A
) {
1201 switch (res
= pFnMciMapMsg16To32A(wmd
->wType
, wMsg
, &dwParam2
)) {
1202 case WINMM_MAP_MSGERROR
:
1203 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1204 dwRet
= MCIERR_DRIVER_INTERNAL
;
1206 case WINMM_MAP_NOMEM
:
1207 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg
));
1208 dwRet
= MCIERR_OUT_OF_MEMORY
;
1211 case WINMM_MAP_OKMEM
:
1212 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1213 if (res
== WINMM_MAP_OKMEM
)
1214 pFnMciUnMapMsg16To32A(wmd
->wType
, wMsg
, dwParam2
);
1218 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1224 /**************************************************************************
1225 * MCI_Open [internal]
1227 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSA lpParms
)
1229 char strDevTyp
[128];
1231 LPWINE_MCIDRIVER wmd
= NULL
;
1233 TRACE("(%08lX, %p)\n", dwParam
, lpParms
);
1234 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1236 /* only two low bytes are generic, the other ones are dev type specific */
1237 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1238 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1239 MCI_NOTIFY|MCI_WAIT)
1240 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1241 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1243 #undef WINE_MCIDRIVER_SUPP
1247 if (dwParam
& MCI_OPEN_TYPE
) {
1248 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1249 WORD uDevType
= LOWORD((DWORD
)lpParms
->lpstrDeviceType
);
1251 if (uDevType
< MCI_DEVTYPE_FIRST
||
1252 uDevType
> MCI_DEVTYPE_LAST
||
1253 !LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, strDevTyp
, sizeof(strDevTyp
))) {
1254 dwRet
= MCIERR_BAD_INTEGER
;
1259 if (lpParms
->lpstrDeviceType
== NULL
) {
1260 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1263 strcpy(strDevTyp
, lpParms
->lpstrDeviceType
);
1264 ptr
= strchr(strDevTyp
, '!');
1266 /* this behavior is not documented in windows. However, since, in
1267 * some occasions, MCI_OPEN handling is translated by WinMM into
1268 * a call to mciSendString("open <type>"); this code shall be correct
1270 if (dwParam
& MCI_OPEN_ELEMENT
) {
1271 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1272 lpParms
->lpstrElementName
, strDevTyp
);
1273 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1276 dwParam
|= MCI_OPEN_ELEMENT
;
1278 /* FIXME: not a good idea to write in user supplied buffer */
1279 lpParms
->lpstrElementName
= ptr
;
1283 TRACE("devType='%s' !\n", strDevTyp
);
1286 if (dwParam
& MCI_OPEN_ELEMENT
) {
1287 TRACE("lpstrElementName='%s'\n", lpParms
->lpstrElementName
);
1289 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1290 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1291 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1295 if (!lpParms
->lpstrElementName
) {
1296 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1300 /* type, if given as a parameter, supersedes file extension */
1301 if (!strDevTyp
[0] &&
1302 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1303 strDevTyp
, sizeof(strDevTyp
))) {
1304 if (GetDriveTypeA(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1305 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1308 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1309 strcpy(strDevTyp
, "CDAUDIO");
1313 if (strDevTyp
[0] == 0) {
1314 FIXME("Couldn't load driver\n");
1315 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1319 if (dwParam
& MCI_OPEN_ALIAS
) {
1320 TRACE("Alias='%s' !\n", lpParms
->lpstrAlias
);
1321 if (!lpParms
->lpstrAlias
) {
1322 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1327 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1331 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1332 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet
);
1333 /* FIXME: is dwRet the correct ret code ? */
1337 /* only handled devices fall through */
1338 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1340 if (dwParam
& MCI_NOTIFY
)
1341 mciDriverNotify((HWND
)lpParms
->dwCallback
, wmd
->wDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1345 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1347 if (dwParam
& MCI_NOTIFY
)
1348 mciDriverNotify((HWND
)lpParms
->dwCallback
, 0, MCI_NOTIFY_FAILURE
);
1352 /**************************************************************************
1353 * MCI_Close [internal]
1355 static DWORD
MCI_Close(UINT16 wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1358 LPWINE_MCIDRIVER wmd
;
1360 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwParam
, lpParms
);
1362 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1363 LPWINE_MCIDRIVER next
;
1365 EnterCriticalSection(&WINMM_IData
->cs
);
1366 /* FIXME: shall I notify once after all is done, or for
1367 * each of the open drivers ? if the latest, which notif
1368 * to return when only one fails ?
1370 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; ) {
1372 MCI_Close(wmd
->wDeviceID
, dwParam
, lpParms
);
1375 LeaveCriticalSection(&WINMM_IData
->cs
);
1379 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1380 return MCIERR_INVALID_DEVICE_ID
;
1383 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD
)lpParms
);
1385 MCI_UnLoadMciDriver(wmd
);
1387 if (dwParam
& MCI_NOTIFY
)
1388 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1389 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1394 /**************************************************************************
1395 * MCI_WriteString [internal]
1397 DWORD
MCI_WriteString(LPSTR lpDstStr
, DWORD dstSize
, LPCSTR lpSrcStr
)
1402 if (dstSize
<= strlen(lpSrcStr
)) {
1403 lstrcpynA(lpDstStr
, lpSrcStr
, dstSize
- 1);
1404 ret
= MCIERR_PARAM_OVERFLOW
;
1406 strcpy(lpDstStr
, lpSrcStr
);
1414 /**************************************************************************
1415 * MCI_Sysinfo [internal]
1417 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSA lpParms
)
1419 DWORD ret
= MCIERR_INVALID_DEVICE_ID
;
1420 LPWINE_MCIDRIVER wmd
;
1422 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1424 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1425 uDevID
, dwFlags
, (DWORD
)lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1427 switch (dwFlags
& ~MCI_SYSINFO_OPEN
) {
1428 case MCI_SYSINFO_QUANTITY
:
1432 if (lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
||
1433 lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
) {
1434 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1435 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1436 EnterCriticalSection(&WINMM_IData
->cs
);
1437 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1440 LeaveCriticalSection(&WINMM_IData
->cs
);
1442 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1443 cnt
= MCI_InstalledCount
;
1446 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1447 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
1448 lpParms
->wDeviceType
);
1449 EnterCriticalSection(&WINMM_IData
->cs
);
1450 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1451 if (wmd
->wType
== lpParms
->wDeviceType
)
1454 LeaveCriticalSection(&WINMM_IData
->cs
);
1456 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
1457 lpParms
->wDeviceType
);
1458 FIXME("Don't know how to get # of MCI devices of a given type\n");
1462 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1464 TRACE("(%ld) => '%ld'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1465 ret
= MCI_INTEGER_RETURNED
;
1467 case MCI_SYSINFO_INSTALLNAME
:
1468 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1469 if ((wmd
= MCI_GetDriver(uDevID
))) {
1470 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1471 wmd
->lpstrDeviceType
);
1473 *lpParms
->lpstrReturn
= 0;
1474 ret
= MCIERR_INVALID_DEVICE_ID
;
1476 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1478 case MCI_SYSINFO_NAME
:
1479 TRACE("MCI_SYSINFO_NAME\n");
1480 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1481 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1482 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1483 } else if (lpParms
->dwNumber
> MCI_InstalledCount
) {
1484 ret
= MCIERR_OUTOFRANGE
;
1486 DWORD count
= lpParms
->dwNumber
;
1487 LPSTR ptr
= MCI_lpInstallNames
;
1489 while (--count
> 0) ptr
+= strlen(ptr
) + 1;
1490 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, ptr
);
1492 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1495 TRACE("Unsupported flag value=%08lx\n", dwFlags
);
1496 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1501 /**************************************************************************
1502 * MCI_Break [internal]
1504 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1508 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1510 if (dwFlags
& MCI_NOTIFY
)
1511 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1512 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1517 /**************************************************************************
1518 * MCI_SendCommand [internal]
1520 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
,
1521 DWORD dwParam2
, BOOL bFrom32
)
1523 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1528 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1529 } else if (pFnMciMapMsg16To32A
) {
1530 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1532 case WINMM_MAP_OKMEM
:
1533 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1534 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1536 default: break; /* so that gcc does not bark */
1542 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1543 } else if (pFnMciMapMsg16To32A
) {
1544 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1546 case WINMM_MAP_OKMEM
:
1547 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1548 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1550 default: break; /* so that gcc does not bark */
1556 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1557 } else if (pFnMciMapMsg16To32A
) {
1558 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1560 case WINMM_MAP_OKMEM
:
1561 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1562 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1564 default: break; /* so that gcc doesnot bark */
1570 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1571 } else if (pFnMciMapMsg16To32A
) {
1572 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1574 case WINMM_MAP_OKMEM
:
1575 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1576 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1578 default: break; /* so that gcc does not bark */
1583 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
1584 * but I couldn't get any doc on this MCI message
1588 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1589 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1590 dwRet
= MCIERR_CANNOT_USE_ALL
;
1593 MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
) :
1594 MCI_SendCommandFrom16(wDevID
, wMsg
, dwParam1
, dwParam2
);
1601 /**************************************************************************
1602 * MCI_CleanUp [internal]
1604 * Some MCI commands need to be cleaned-up (when not called from
1605 * mciSendString), because MCI drivers return extra information for string
1606 * transformation. This function gets rid of them.
1608 LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD dwParam2
)
1611 return LOWORD(dwRet
);
1614 case MCI_GETDEVCAPS
:
1615 switch (dwRet
& 0xFFFF0000ul
) {
1617 case MCI_COLONIZED3_RETURN
:
1618 case MCI_COLONIZED4_RETURN
:
1619 case MCI_INTEGER_RETURNED
:
1622 case MCI_RESOURCE_RETURNED
:
1623 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1625 LPMCI_GETDEVCAPS_PARMS lmgp
;
1627 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)(void*)dwParam2
;
1628 TRACE("Changing %08lx to %08lx\n", lmgp
->dwReturn
, (DWORD
)LOWORD(lmgp
->dwReturn
));
1629 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
1633 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1634 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1638 switch (dwRet
& 0xFFFF0000ul
) {
1640 case MCI_COLONIZED3_RETURN
:
1641 case MCI_COLONIZED4_RETURN
:
1642 case MCI_INTEGER_RETURNED
:
1645 case MCI_RESOURCE_RETURNED
:
1646 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1648 LPMCI_STATUS_PARMS lsp
;
1650 lsp
= (LPMCI_STATUS_PARMS
)(void*)dwParam2
;
1651 TRACE("Changing %08lx to %08lx\n", lsp
->dwReturn
, (DWORD
)LOWORD(lsp
->dwReturn
));
1652 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
1656 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1657 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1661 switch (dwRet
& 0xFFFF0000ul
) {
1663 case MCI_INTEGER_RETURNED
:
1667 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
1671 if (HIWORD(dwRet
)) {
1672 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1673 dwRet
, MCI_MessageToString(wMsg
));
1677 return LOWORD(dwRet
);
1680 /**************************************************************************
1681 * MCI_Init [internal]
1683 * Initializes the MCI internal variables.
1695 MCI_InstalledCount
= 0;
1696 ptr1
= MCI_lpInstallNames
= HeapAlloc(GetProcessHeap(), 0, count
);
1698 if (!MCI_lpInstallNames
)
1701 /* FIXME: should do also some registry diving here ? */
1702 if (!(err
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config", &hWineConf
)) &&
1703 !(err
= RegOpenKeyA(hWineConf
, "options", &hkey
))) {
1704 err
= RegQueryValueExA(hkey
, "mci", 0, &type
, MCI_lpInstallNames
, &count
);
1709 TRACE("Wine => '%s' \n", ptr1
);
1710 while ((ptr2
= strchr(ptr1
, ':')) != 0) {
1712 TRACE("---> '%s' \n", ptr1
);
1713 MCI_InstalledCount
++;
1716 MCI_InstalledCount
++;
1717 TRACE("---> '%s' \n", ptr1
);
1718 ptr1
+= strlen(ptr1
) + 1;
1720 GetPrivateProfileStringA("mci", NULL
, "", MCI_lpInstallNames
, count
, "SYSTEM.INI");
1721 while (strlen(ptr1
) > 0) {
1722 TRACE("---> '%s' \n", ptr1
);
1723 ptr1
+= strlen(ptr1
) + 1;
1724 MCI_InstalledCount
++;
1727 RegCloseKey(hWineConf
);