2 * MCI internal functions
4 * Copyright 1998/1999 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - implement WINMM (32bit) multitasking and use it in all MCI drivers
23 * instead of the home grown one
24 * - 16bit mmTaskXXX functions are currently broken because the 16
25 * loader does not support binary command lines => provide Wine's
26 * own mmtask.tsk not using binary command line.
27 * - correctly handle the MCI_ALL_DEVICE_ID in functions.
28 * - finish mapping 16 <=> 32 of MCI structures and commands
29 * - implement auto-open feature (ie, when a string command is issued
30 * for a not yet opened device, MCI automatically opens it)
31 * - use a default registry setting to replace the [mci] section in
32 * configuration file (layout of info in registry should be compatible
33 * with all Windows' version - which use different layouts of course)
37 #include "wine/port.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
60 WINMM_MapType (*pFnMciMapMsg16To32A
) (WORD
,WORD
,DWORD
*) /* = NULL */;
61 WINMM_MapType (*pFnMciUnMapMsg16To32A
)(WORD
,WORD
,DWORD
) /* = NULL */;
62 WINMM_MapType (*pFnMciMapMsg32ATo16
) (WORD
,WORD
,DWORD
,DWORD
*) /* = NULL */;
63 WINMM_MapType (*pFnMciUnMapMsg32ATo16
)(WORD
,WORD
,DWORD
,DWORD
) /* = NULL */;
65 /* First MCI valid device ID (0 means error) */
66 #define MCI_MAGIC 0x0001
69 #define HKLM_MCI "Software\\Microsoft\\Windows NT\\CurrentVersion\\MCI"
71 /* dup a string and uppercase it */
72 inline static LPSTR
str_dup_upper( LPCSTR str
)
74 INT len
= strlen(str
) + 1;
75 LPSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
78 memcpy( p
, str
, len
);
84 /**************************************************************************
85 * MCI_GetDriver [internal]
87 LPWINE_MCIDRIVER
MCI_GetDriver(UINT16 wDevID
)
89 LPWINE_MCIDRIVER wmd
= 0;
91 EnterCriticalSection(&WINMM_IData
->cs
);
92 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
93 if (wmd
->wDeviceID
== wDevID
)
96 LeaveCriticalSection(&WINMM_IData
->cs
);
100 /**************************************************************************
101 * MCI_GetDriverFromString [internal]
103 UINT
MCI_GetDriverFromString(LPCSTR lpstrName
)
105 LPWINE_MCIDRIVER wmd
;
111 if (!lstrcmpiA(lpstrName
, "ALL"))
112 return MCI_ALL_DEVICE_ID
;
114 EnterCriticalSection(&WINMM_IData
->cs
);
115 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
116 if (wmd
->lpstrElementName
&& strcmp(wmd
->lpstrElementName
, lpstrName
) == 0) {
117 ret
= wmd
->wDeviceID
;
120 if (wmd
->lpstrDeviceType
&& strcasecmp(wmd
->lpstrDeviceType
, lpstrName
) == 0) {
121 ret
= wmd
->wDeviceID
;
124 if (wmd
->lpstrAlias
&& strcasecmp(wmd
->lpstrAlias
, lpstrName
) == 0) {
125 ret
= wmd
->wDeviceID
;
129 LeaveCriticalSection(&WINMM_IData
->cs
);
134 /**************************************************************************
135 * MCI_MessageToString [internal]
137 const char* MCI_MessageToString(UINT16 wMsg
)
139 static char buffer
[100];
141 #define CASE(s) case (s): return #s
146 CASE(MCI_CLOSE_DRIVER
);
155 CASE(MCI_GETDEVCAPS
);
159 CASE(MCI_OPEN_DRIVER
);
177 /* constants for digital video */
191 sprintf(buffer
, "MCI_<<%04X>>", wMsg
);
196 /**************************************************************************
197 * MCI_GetDevTypeFromFileName [internal]
199 static DWORD
MCI_GetDevTypeFromFileName(LPCSTR fileName
, LPSTR buf
, UINT len
)
204 if ((tmp
= strrchr(fileName
, '.'))) {
205 if (RegOpenKeyExA( HKEY_LOCAL_MACHINE
, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions",
206 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
208 LONG lRet
= RegQueryValueExA( hKey
, tmp
+ 1, 0, 0, buf
, &dwLen
);
210 if (lRet
== ERROR_SUCCESS
) return 0;
212 TRACE("No ...\\MCI Extensions entry for '%s' found.\n", tmp
);
214 return MCIERR_EXTENSION_NOT_FOUND
;
217 #define MAX_MCICMDTABLE 20
218 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
220 typedef struct tagWINE_MCICMDTABLE
{
223 UINT nVerbs
; /* number of verbs in command table */
224 LPCSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
225 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
227 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
229 /**************************************************************************
230 * MCI_IsCommandTableValid [internal]
232 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
240 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
241 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
243 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
246 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
250 lmem
+= strlen(lmem
) + 1;
251 flg
= *(const DWORD
*)lmem
;
252 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
253 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
255 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
257 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
258 case MCI_STRING
: if (inCst
) return FALSE
; break;
259 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
260 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
261 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
262 case MCI_FLAG
: if (!*str
) return FALSE
; break;
263 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
264 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
265 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
266 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
267 default: return FALSE
;
269 } while (eid
!= MCI_END_COMMAND_LIST
);
270 } while (eid
!= MCI_END_COMMAND_LIST
);
274 /**************************************************************************
275 * MCI_DumpCommandTable [internal]
277 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
284 if (!MCI_IsCommandTableValid(uTbl
)) {
285 ERR("Ooops: %d is not valid\n", uTbl
);
289 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
293 lmem
+= strlen(lmem
) + 1;
294 flg
= *(const DWORD
*)lmem
;
295 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
296 TRACE("cmd='%s' %08lx %04x\n", str
, flg
, eid
);
297 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
298 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
299 TRACE(" => end of command%s\n", (eid
== MCI_END_COMMAND_LIST
) ? " list" : "");
300 } while (eid
!= MCI_END_COMMAND_LIST
);
305 /**************************************************************************
306 * MCI_GetCommandTable [internal]
308 static UINT
MCI_GetCommandTable(UINT uDevType
)
314 /* first look up existing for existing devType */
315 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
316 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
320 /* well try to load id */
321 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
322 if (LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, buf
, sizeof(buf
))) {
325 } else if (uDevType
== 0) {
328 uTbl
= MCI_NO_COMMAND_TABLE
;
330 HRSRC hRsrc
= FindResourceA(WINMM_IData
->hWinMM32Instance
, str
, (LPCSTR
)RT_RCDATA
);
333 if (hRsrc
) hMem
= LoadResource(WINMM_IData
->hWinMM32Instance
, hRsrc
);
335 uTbl
= MCI_SetCommandTable(LockResource(hMem
), uDevType
);
337 WARN("No command table found in resource %p[%s]\n",
338 WINMM_IData
->hWinMM32Instance
, str
);
341 TRACE("=> %d\n", uTbl
);
345 /**************************************************************************
346 * MCI_SetCommandTable [internal]
348 UINT
MCI_SetCommandTable(void *table
, UINT uDevType
)
351 static BOOL bInitDone
= FALSE
;
354 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
355 * can be called with 0 as a uDevType to retrieve it.
360 MCI_GetCommandTable(0);
363 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
364 if (!S_MciCmdTable
[uTbl
].lpTable
) {
369 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
370 S_MciCmdTable
[uTbl
].lpTable
= table
;
373 MCI_DumpCommandTable(uTbl
);
376 /* create the verbs table */
377 /* get # of entries */
378 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
381 lmem
+= strlen(lmem
) + 1;
382 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
383 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
384 if (eid
== MCI_COMMAND_HEAD
)
386 } while (eid
!= MCI_END_COMMAND_LIST
);
388 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCSTR
));
389 S_MciCmdTable
[uTbl
].nVerbs
= count
;
391 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
395 lmem
+= strlen(lmem
) + 1;
396 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
397 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
398 if (eid
== MCI_COMMAND_HEAD
)
399 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
400 } while (eid
!= MCI_END_COMMAND_LIST
);
401 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
406 return MCI_NO_COMMAND_TABLE
;
409 /**************************************************************************
410 * MCI_DeleteCommandTable [internal]
412 static BOOL
MCI_DeleteCommandTable(UINT uTbl
)
414 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
417 S_MciCmdTable
[uTbl
].lpTable
= NULL
;
418 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTbl
].aVerbs
);
419 S_MciCmdTable
[uTbl
].aVerbs
= 0;
423 /**************************************************************************
424 * MCI_UnLoadMciDriver [internal]
426 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
428 LPWINE_MCIDRIVER
* tmp
;
433 CloseDriver(wmd
->hDriver
, 0, 0);
435 if (wmd
->dwPrivate
!= 0)
436 WARN("Unloading mci driver with non nul dwPrivate field\n");
438 EnterCriticalSection(&WINMM_IData
->cs
);
439 for (tmp
= &WINMM_IData
->lpMciDrvs
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
445 LeaveCriticalSection(&WINMM_IData
->cs
);
447 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
448 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
449 HeapFree(GetProcessHeap(), 0, wmd
->lpstrElementName
);
451 HeapFree(GetProcessHeap(), 0, wmd
);
455 /**************************************************************************
456 * MCI_OpenMciDriver [internal]
458 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCSTR drvTyp
, LPARAM lp
)
462 if (!DRIVER_GetLibName(drvTyp
, "mci", libName
, sizeof(libName
)))
466 /* First load driver */
467 if ((wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
))) {
469 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32ATo16
) {
472 switch (res
= pFnMciMapMsg32ATo16(0, DRV_OPEN
, 0, &lp
)) {
473 case WINMM_MAP_MSGERROR
:
474 TRACE("Not handled yet (DRV_OPEN)\n");
476 case WINMM_MAP_NOMEM
:
477 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
480 case WINMM_MAP_OKMEM
:
481 if ((wmd
->hDriver
= OpenDriverA(drvTyp
, "mci", lp
)))
483 if (res
== WINMM_MAP_OKMEM
)
484 pFnMciUnMapMsg32ATo16(0, DRV_OPEN
, 0, lp
);
488 return (wmd
->bIs32
== 0xFFFF) ? FALSE
: TRUE
;
491 /**************************************************************************
492 * MCI_LoadMciDriver [internal]
494 static DWORD
MCI_LoadMciDriver(LPCSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
496 LPSTR strDevTyp
= str_dup_upper(_strDevTyp
);
497 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
498 MCI_OPEN_DRIVER_PARMSA modp
;
501 if (!wmd
|| !strDevTyp
) {
502 dwRet
= MCIERR_OUT_OF_MEMORY
;
506 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
507 wmd
->dwYieldData
= VK_CANCEL
;
508 wmd
->CreatorThread
= GetCurrentThreadId();
510 EnterCriticalSection(&WINMM_IData
->cs
);
511 /* wmd must be inserted in list before sending opening the driver, coz' it
512 * may want to lookup at wDevID
514 wmd
->lpNext
= WINMM_IData
->lpMciDrvs
;
515 WINMM_IData
->lpMciDrvs
= wmd
;
517 for (modp
.wDeviceID
= MCI_MAGIC
;
518 MCI_GetDriver(modp
.wDeviceID
) != 0;
521 wmd
->wDeviceID
= modp
.wDeviceID
;
523 LeaveCriticalSection(&WINMM_IData
->cs
);
525 TRACE("wDevID=%04X \n", modp
.wDeviceID
);
527 modp
.lpstrParams
= NULL
;
529 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (LPARAM
)&modp
)) {
530 /* silence warning if all is used... some bogus program use commands like
533 if (strcasecmp(strDevTyp
, "all") == 0) {
534 dwRet
= MCIERR_CANNOT_USE_ALL
;
536 FIXME("Couldn't load driver for type %s.\n"
537 "If you don't have a windows installation accessible from Wine,\n"
538 "you perhaps forgot to create a [mci] section in system.ini\n",
540 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
545 /* FIXME: should also check that module's description is of the form
546 * MODULENAME:[MCI] comment
549 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
550 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
551 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
553 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
554 wmd
->hDriver
, strDevTyp
, modp
.wType
, modp
.wCustomCommandTable
);
556 wmd
->lpstrDeviceType
= strDevTyp
;
557 wmd
->wType
= modp
.wType
;
559 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
560 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
564 MCI_UnLoadMciDriver(wmd
);
565 HeapFree(GetProcessHeap(), 0, strDevTyp
);
570 /**************************************************************************
571 * MCI_FinishOpen [internal]
573 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSA lpParms
,
576 if (dwParam
& MCI_OPEN_ELEMENT
)
578 wmd
->lpstrElementName
= HeapAlloc(GetProcessHeap(),0,strlen(lpParms
->lpstrElementName
)+1);
579 strcpy( wmd
->lpstrElementName
, lpParms
->lpstrElementName
);
581 if (dwParam
& MCI_OPEN_ALIAS
)
583 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, strlen(lpParms
->lpstrAlias
)+1);
584 strcpy( wmd
->lpstrAlias
, lpParms
->lpstrAlias
);
586 lpParms
->wDeviceID
= wmd
->wDeviceID
;
588 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
592 /**************************************************************************
593 * MCI_FindCommand [internal]
595 static LPCSTR
MCI_FindCommand(UINT uTbl
, LPCSTR verb
)
599 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
602 /* another improvement would be to have the aVerbs array sorted,
603 * so that we could use a dichotomic search on it, rather than this dumb
606 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
607 if (strcasecmp(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
608 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
614 /**************************************************************************
615 * MCI_GetReturnType [internal]
617 static DWORD
MCI_GetReturnType(LPCSTR lpCmd
)
619 lpCmd
+= strlen(lpCmd
) + 1 + sizeof(DWORD
) + sizeof(WORD
);
620 if (*lpCmd
== '\0' && *(const WORD
*)(lpCmd
+ 1 + sizeof(DWORD
)) == MCI_RETURN
) {
621 return *(const DWORD
*)(lpCmd
+ 1);
626 /**************************************************************************
627 * MCI_GetMessage [internal]
629 static WORD
MCI_GetMessage(LPCSTR lpCmd
)
631 return (WORD
)*(const DWORD
*)(lpCmd
+ strlen(lpCmd
) + 1);
634 /**************************************************************************
635 * MCI_GetDWord [internal]
637 static BOOL
MCI_GetDWord(LPDWORD data
, LPSTR
* ptr
)
642 val
= strtoul(*ptr
, &ret
, 0);
646 case ' ': ret
++; break;
647 default: return FALSE
;
655 /**************************************************************************
656 * MCI_GetString [internal]
658 static DWORD
MCI_GetString(LPSTR
* str
, LPSTR
* args
)
662 /* see if we have a quoted string */
664 ptr
= strchr(*str
= ptr
+ 1, '"');
665 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
666 /* FIXME: shall we escape \" from string ?? */
667 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
668 *ptr
++ = '\0'; /* remove trailing " */
669 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
672 ptr
= strchr(ptr
, ' ');
677 ptr
= *args
+ strlen(*args
);
686 #define MCI_DATA_SIZE 16
688 /**************************************************************************
689 * MCI_ParseOptArgs [internal]
691 static DWORD
MCI_ParseOptArgs(LPDWORD data
, int _offset
, LPCSTR lpCmd
,
692 LPSTR args
, LPDWORD dwFlags
)
696 DWORD dwRet
, flg
, cflg
= 0;
700 /* loop on arguments */
703 found
= inCst
= FALSE
;
706 /* skip any leading white space(s) */
707 while (*args
== ' ') args
++;
708 TRACE("args='%s' offset=%d\n", args
, offset
);
710 do { /* loop on options for command table for the requested verb */
712 lmem
+= (len
= strlen(lmem
)) + 1;
713 flg
= *(const DWORD
*)lmem
;
714 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
715 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
716 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
720 inCst
= TRUE
; cflg
= flg
; break;
721 case MCI_END_CONSTANT
:
722 /* there may be additional integral values after flag in constant */
723 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
726 inCst
= FALSE
; cflg
= 0;
730 if (strncasecmp(args
, str
, len
) == 0 &&
731 (args
[len
] == 0 || args
[len
] == ' ')) {
732 /* store good values into data[] */
734 while (*args
== ' ') args
++;
738 case MCI_COMMAND_HEAD
:
740 case MCI_END_COMMAND
:
741 case MCI_END_COMMAND_LIST
:
742 case MCI_CONSTANT
: /* done above */
743 case MCI_END_CONSTANT
: /* done above */
755 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
756 return MCIERR_BAD_INTEGER
;
761 /* store rect in data (offset...offset+3) */
763 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
764 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
765 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
766 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
767 ERR("Bad rect '%s'\n", args
);
768 return MCIERR_BAD_INTEGER
;
773 if ((dwRet
= MCI_GetString((LPSTR
*)&data
[offset
], &args
)))
776 default: ERR("oops\n");
778 /* exit inside while loop, except if just entered in constant area definition */
779 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
781 /* have offset incremented if needed */
783 case MCI_COMMAND_HEAD
:
785 case MCI_END_COMMAND
:
786 case MCI_END_COMMAND_LIST
:
788 case MCI_FLAG
: break;
789 case MCI_INTEGER
: if (!inCst
) offset
++; break;
790 case MCI_END_CONSTANT
:
791 case MCI_STRING
: offset
++; break;
792 case MCI_RECT
: offset
+= 4; break;
793 default: ERR("oops\n");
796 } while (eid
!= MCI_END_COMMAND
);
798 WARN("Optarg '%s' not found\n", args
);
799 return MCIERR_UNRECOGNIZED_COMMAND
;
801 if (offset
== MCI_DATA_SIZE
) {
802 ERR("Internal data[] buffer overflow\n");
803 return MCIERR_PARSER_INTERNAL
;
809 /**************************************************************************
810 * MCI_HandleReturnValues [internal]
812 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
813 LPDWORD data
, LPSTR lpstrRet
, UINT uRetLen
)
817 case 0: /* nothing to return */
820 switch (dwRet
& 0xFFFF0000ul
) {
822 case MCI_INTEGER_RETURNED
:
823 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
825 case MCI_RESOURCE_RETURNED
:
826 /* return string which ID is HIWORD(data[1]),
827 * string is loaded from mmsystem.dll */
828 LoadStringA(WINMM_IData
->hWinMM32Instance
, HIWORD(data
[1]),
831 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
832 /* return string which ID is HIWORD(data[1]),
833 * string is loaded from driver */
834 /* FIXME: this is wrong for a 16 bit handle */
835 LoadStringA(GetDriverModuleHandle(wmd
->hDriver
),
836 HIWORD(data
[1]), lpstrRet
, uRetLen
);
838 case MCI_COLONIZED3_RETURN
:
839 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d",
840 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
841 LOBYTE(HIWORD(data
[1])));
843 case MCI_COLONIZED4_RETURN
:
844 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d:%d",
845 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
846 LOBYTE(HIWORD(data
[1])), HIBYTE(HIWORD(data
[1])));
848 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
852 switch (dwRet
& 0xFFFF0000ul
) {
854 /* nothing to do data[1] == lpstrRet */
856 case MCI_INTEGER_RETURNED
:
857 data
[1] = *(LPDWORD
)lpstrRet
;
858 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
861 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
866 if (dwRet
& 0xFFFF0000ul
)
867 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
868 snprintf(lpstrRet
, uRetLen
, "%ld %ld %ld %ld",
869 data
[1], data
[2], data
[3], data
[4]);
871 default: ERR("oops\n");
874 return LOWORD(dwRet
);
877 /**************************************************************************
878 * mciSendStringA [WINMM.@]
880 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
881 UINT uRetLen
, HWND hwndCallback
)
883 LPSTR verb
, dev
, args
;
884 LPWINE_MCIDRIVER wmd
= 0;
885 DWORD dwFlags
= 0, dwRet
= 0;
887 DWORD data
[MCI_DATA_SIZE
];
890 LPSTR devAlias
= NULL
;
891 BOOL bAutoOpen
= FALSE
;
893 TRACE("('%s', %p, %d, %p)\n", lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
895 /* format is <command> <device> <optargs> */
896 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand
)+1)))
897 return MCIERR_OUT_OF_MEMORY
;
898 strcpy( verb
, lpstrCommand
);
901 memset(data
, 0, sizeof(data
));
903 if (!(args
= strchr(verb
, ' '))) {
904 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
908 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
912 /* case dev == 'new' has to be handled */
913 if (!strcmp(dev
, "new")) {
914 FIXME("'new': NIY as device name\n");
915 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
919 /* otherwise, try to grab devType from open */
920 if (!strcmp(verb
, "open")) {
923 if ((devType
= strchr(dev
, '!')) != NULL
) {
925 tmp
= devType
; devType
= dev
; dev
= tmp
;
927 dwFlags
|= MCI_OPEN_TYPE
;
928 data
[2] = (DWORD
)devType
;
929 devType
= str_dup_upper(devType
);
930 dwFlags
|= MCI_OPEN_ELEMENT
;
931 data
[3] = (DWORD
)dev
;
932 } else if (strchr(dev
, '.') == NULL
) {
933 tmp
= strchr(dev
,' ');
934 if (tmp
) *tmp
= '\0';
935 data
[2] = (DWORD
)dev
;
936 devType
= str_dup_upper(dev
);
938 dwFlags
|= MCI_OPEN_TYPE
;
940 if ((devType
= strstr(args
, "type ")) != NULL
) {
942 tmp
= strchr(devType
, ' ');
943 if (tmp
) *tmp
= '\0';
944 devType
= str_dup_upper(devType
);
946 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
949 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
952 devType
= str_dup_upper(buf
);
954 dwFlags
|= MCI_OPEN_ELEMENT
;
955 data
[3] = (DWORD
)dev
;
957 if ((devAlias
= strstr(args
," alias "))) {
960 if (!(tmp
= strchr(devAlias
,' '))) tmp
= devAlias
+ strlen(devAlias
);
961 if (tmp
) *tmp
= '\0';
962 tmp2
= HeapAlloc(GetProcessHeap(), 0, tmp
- devAlias
+ 1 );
963 memcpy( tmp2
, devAlias
, tmp
- devAlias
);
964 tmp2
[tmp
- devAlias
] = 0;
965 data
[4] = (DWORD
)tmp2
;
966 /* should be done in regular options parsing */
967 /* dwFlags |= MCI_OPEN_ALIAS; */
970 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
971 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
972 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
973 HeapFree(GetProcessHeap(), 0, devType
);
975 MCI_UnLoadMciDriver(wmd
);
978 } else if (!(wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
)))) {
981 sprintf(buf
, "open %s wait", dev
);
983 if ((dwRet
= mciSendStringA(buf
, NULL
, 0, 0)) != 0)
986 wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
));
988 /* FIXME: memory leak, MCI driver is not closed */
989 dwRet
= MCIERR_INVALID_DEVICE_ID
;
994 /* get the verb in the different command tables */
996 /* try the device specific command table */
997 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
999 /* try the type specific command table */
1000 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1001 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1002 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1003 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1006 /* try core command table */
1007 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1010 TRACE("Command '%s' not found!\n", verb
);
1011 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1015 /* set up call back */
1016 if (hwndCallback
!= 0) {
1017 dwFlags
|= MCI_NOTIFY
;
1018 data
[0] = (DWORD
)hwndCallback
;
1021 /* set return information */
1022 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1023 case 0: offset
= 1; break;
1024 case MCI_INTEGER
: offset
= 2; break;
1025 case MCI_STRING
: data
[1] = (DWORD
)lpstrRet
; data
[2] = uRetLen
; offset
= 3; break;
1026 case MCI_RECT
: offset
= 5; break;
1027 default: ERR("oops\n");
1030 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb
, dev
, offset
);
1032 if ((dwRet
= MCI_ParseOptArgs(data
, offset
, lpCmd
, args
, &dwFlags
)))
1035 if (bAutoOpen
&& (dwFlags
& MCI_NOTIFY
)) {
1036 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1039 /* FIXME: the command should get it's own notification window set up and
1040 * ask for device closing while processing the notification mechanism
1042 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1044 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1045 wmd
->wDeviceID
, MCI_MessageToString(MCI_GetMessage(lpCmd
)), dwFlags
,
1046 data
[0], debugstr_a((char *)data
[0]), data
[1], debugstr_a((char *)data
[1]),
1047 data
[2], debugstr_a((char *)data
[2]), data
[3], debugstr_a((char *)data
[3]),
1048 data
[4], debugstr_a((char *)data
[4]), data
[5], debugstr_a((char *)data
[5]));
1050 if (strcmp(verb
, "open") == 0) {
1051 if ((dwRet
= MCI_FinishOpen(wmd
, (LPMCI_OPEN_PARMSA
)data
, dwFlags
)))
1052 MCI_UnLoadMciDriver(wmd
);
1053 /* FIXME: notification is not properly shared across two opens */
1055 dwRet
= MCI_SendCommand(wmd
->wDeviceID
, MCI_GetMessage(lpCmd
), dwFlags
, (DWORD
)data
, TRUE
);
1057 TRACE("=> 1/ %lx (%s)\n", dwRet
, lpstrRet
);
1058 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, data
, lpstrRet
, uRetLen
);
1059 TRACE("=> 2/ %lx (%s)\n", dwRet
, lpstrRet
);
1062 HeapFree(GetProcessHeap(), 0, verb
);
1063 HeapFree(GetProcessHeap(), 0, devAlias
);
1067 /**************************************************************************
1068 * mciSendStringW [WINMM.@]
1070 DWORD WINAPI
mciSendStringW(LPCWSTR lpwstrCommand
, LPWSTR lpwstrRet
,
1071 UINT uRetLen
, HWND hwndCallback
)
1074 LPSTR lpstrRet
= NULL
;
1078 /* FIXME: is there something to do with lpstrReturnString ? */
1079 len
= WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, NULL
, 0, NULL
, NULL
);
1080 lpstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
);
1081 WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, lpstrCommand
, len
, NULL
, NULL
);
1084 lpstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1085 if (!lpstrRet
) return MMSYSERR_NOMEM
;
1087 ret
= mciSendStringA(lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
1089 MultiByteToWideChar( CP_ACP
, 0, lpstrRet
, -1, lpwstrRet
, uRetLen
);
1090 HeapFree(GetProcessHeap(), 0, lpstrCommand
);
1091 HeapFree(GetProcessHeap(), 0, lpstrRet
);
1095 /**************************************************************************
1096 * mciExecute [WINMM.@]
1097 * mciExecute [MMSYSTEM.712]
1099 DWORD WINAPI
mciExecute(LPCSTR lpstrCommand
)
1104 TRACE("(%s)!\n", lpstrCommand
);
1106 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1108 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1109 sprintf(strRet
, "Unknown MCI error (%ld)", ret
);
1111 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1113 /* FIXME: what shall I return ? */
1117 /**************************************************************************
1118 * mciLoadCommandResource [WINMM.@]
1120 * Strangely, this function only exists as an UNICODE one.
1122 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1126 UINT16 ret
= MCI_NO_COMMAND_TABLE
;
1128 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1130 /* if a file named "resname.mci" exits, then load resource "resname" from it
1131 * otherwise directly from driver
1132 * We don't support it (who uses this feature ?), but we check anyway
1136 /* FIXME: we should put this back into order, but I never found a program
1137 * actually using this feature, so we not need it
1142 strcat(strcpy(buf
, resname
), ".mci");
1143 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1144 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1148 if (!(hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
))) {
1149 WARN("No command table found in resource\n");
1150 } else if ((hMem
= LoadResource(hInst
, hRsrc
))) {
1151 ret
= MCI_SetCommandTable(LockResource(hMem
), type
);
1153 WARN("Couldn't load resource.\n");
1155 TRACE("=> %04x\n", ret
);
1159 /**************************************************************************
1160 * mciFreeCommandResource [WINMM.@]
1162 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1164 TRACE("(%08x)!\n", uTable
);
1166 return MCI_DeleteCommandTable(uTable
);
1169 /**************************************************************************
1170 * MCI_SendCommandFrom32 [internal]
1172 DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1174 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1175 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1179 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1180 } else if (pFnMciMapMsg32ATo16
) {
1183 switch (res
= pFnMciMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, &dwParam2
)) {
1184 case WINMM_MAP_MSGERROR
:
1185 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1186 dwRet
= MCIERR_DRIVER_INTERNAL
;
1188 case WINMM_MAP_NOMEM
:
1189 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg
));
1190 dwRet
= MCIERR_OUT_OF_MEMORY
;
1193 case WINMM_MAP_OKMEM
:
1194 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1195 if (res
== WINMM_MAP_OKMEM
)
1196 pFnMciUnMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, dwParam2
);
1204 /**************************************************************************
1205 * MCI_SendCommandFrom16 [internal]
1207 DWORD
MCI_SendCommandFrom16(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1209 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1210 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1213 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1215 if (wmd
->bIs32
&& pFnMciMapMsg16To32A
) {
1218 switch (res
= pFnMciMapMsg16To32A(wmd
->wType
, wMsg
, &dwParam2
)) {
1219 case WINMM_MAP_MSGERROR
:
1220 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1221 dwRet
= MCIERR_DRIVER_INTERNAL
;
1223 case WINMM_MAP_NOMEM
:
1224 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg
));
1225 dwRet
= MCIERR_OUT_OF_MEMORY
;
1228 case WINMM_MAP_OKMEM
:
1229 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1230 if (res
== WINMM_MAP_OKMEM
)
1231 pFnMciUnMapMsg16To32A(wmd
->wType
, wMsg
, dwParam2
);
1235 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1241 /**************************************************************************
1242 * MCI_Open [internal]
1244 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSA lpParms
)
1246 char strDevTyp
[128];
1248 LPWINE_MCIDRIVER wmd
= NULL
;
1250 TRACE("(%08lX, %p)\n", dwParam
, lpParms
);
1251 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1253 /* only two low bytes are generic, the other ones are dev type specific */
1254 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1255 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1256 MCI_NOTIFY|MCI_WAIT)
1257 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1258 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1260 #undef WINE_MCIDRIVER_SUPP
1264 if (dwParam
& MCI_OPEN_TYPE
) {
1265 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1266 WORD uDevType
= LOWORD((DWORD
)lpParms
->lpstrDeviceType
);
1268 if (uDevType
< MCI_DEVTYPE_FIRST
||
1269 uDevType
> MCI_DEVTYPE_LAST
||
1270 !LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, strDevTyp
, sizeof(strDevTyp
))) {
1271 dwRet
= MCIERR_BAD_INTEGER
;
1276 if (lpParms
->lpstrDeviceType
== NULL
) {
1277 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1280 strcpy(strDevTyp
, lpParms
->lpstrDeviceType
);
1281 ptr
= strchr(strDevTyp
, '!');
1283 /* this behavior is not documented in windows. However, since, in
1284 * some occasions, MCI_OPEN handling is translated by WinMM into
1285 * a call to mciSendString("open <type>"); this code shall be correct
1287 if (dwParam
& MCI_OPEN_ELEMENT
) {
1288 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1289 lpParms
->lpstrElementName
, strDevTyp
);
1290 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1293 dwParam
|= MCI_OPEN_ELEMENT
;
1295 /* FIXME: not a good idea to write in user supplied buffer */
1296 lpParms
->lpstrElementName
= ptr
;
1300 TRACE("devType='%s' !\n", strDevTyp
);
1303 if (dwParam
& MCI_OPEN_ELEMENT
) {
1304 TRACE("lpstrElementName='%s'\n", lpParms
->lpstrElementName
);
1306 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1307 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1308 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1312 if (!lpParms
->lpstrElementName
) {
1313 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1317 /* type, if given as a parameter, supersedes file extension */
1318 if (!strDevTyp
[0] &&
1319 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1320 strDevTyp
, sizeof(strDevTyp
))) {
1321 if (GetDriveTypeA(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1322 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1325 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1326 strcpy(strDevTyp
, "CDAUDIO");
1330 if (strDevTyp
[0] == 0) {
1331 FIXME("Couldn't load driver\n");
1332 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1336 if (dwParam
& MCI_OPEN_ALIAS
) {
1337 TRACE("Alias='%s' !\n", lpParms
->lpstrAlias
);
1338 if (!lpParms
->lpstrAlias
) {
1339 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1344 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1348 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1349 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet
);
1350 /* FIXME: is dwRet the correct ret code ? */
1354 /* only handled devices fall through */
1355 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1357 if (dwParam
& MCI_NOTIFY
)
1358 mciDriverNotify((HWND
)lpParms
->dwCallback
, wmd
->wDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1362 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1364 if (dwParam
& MCI_NOTIFY
)
1365 mciDriverNotify((HWND
)lpParms
->dwCallback
, 0, MCI_NOTIFY_FAILURE
);
1369 /**************************************************************************
1370 * MCI_Close [internal]
1372 static DWORD
MCI_Close(UINT16 wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1375 LPWINE_MCIDRIVER wmd
;
1377 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwParam
, lpParms
);
1379 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1380 LPWINE_MCIDRIVER next
;
1382 EnterCriticalSection(&WINMM_IData
->cs
);
1383 /* FIXME: shall I notify once after all is done, or for
1384 * each of the open drivers ? if the latest, which notif
1385 * to return when only one fails ?
1387 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; ) {
1389 MCI_Close(wmd
->wDeviceID
, dwParam
, lpParms
);
1392 LeaveCriticalSection(&WINMM_IData
->cs
);
1396 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1397 return MCIERR_INVALID_DEVICE_ID
;
1400 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD
)lpParms
);
1402 MCI_UnLoadMciDriver(wmd
);
1404 if (dwParam
& MCI_NOTIFY
)
1405 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1406 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1411 /**************************************************************************
1412 * MCI_WriteString [internal]
1414 DWORD
MCI_WriteString(LPSTR lpDstStr
, DWORD dstSize
, LPCSTR lpSrcStr
)
1419 if (dstSize
<= strlen(lpSrcStr
)) {
1420 lstrcpynA(lpDstStr
, lpSrcStr
, dstSize
- 1);
1421 ret
= MCIERR_PARAM_OVERFLOW
;
1423 strcpy(lpDstStr
, lpSrcStr
);
1431 /**************************************************************************
1432 * MCI_Sysinfo [internal]
1434 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSA lpParms
)
1436 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1437 CHAR buf
[2048], *s
= buf
, *p
;
1438 LPWINE_MCIDRIVER wmd
;
1441 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1443 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1444 uDevID
, dwFlags
, (DWORD
)lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1446 switch (dwFlags
& ~MCI_SYSINFO_OPEN
) {
1447 case MCI_SYSINFO_QUANTITY
:
1448 if (lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
) {
1449 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1450 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1451 EnterCriticalSection(&WINMM_IData
->cs
);
1452 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1455 LeaveCriticalSection(&WINMM_IData
->cs
);
1457 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1458 if (RegOpenKeyExA( HKEY_LOCAL_MACHINE
, HKLM_MCI
,
1459 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1460 RegQueryInfoKeyA( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1461 RegCloseKey( hKey
);
1463 if (GetPrivateProfileStringA("mci", 0, "", buf
, sizeof(buf
), "system.ini"))
1464 for(s
= buf
; *s
; s
+= strlen(s
) + 1) cnt
++;
1467 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1468 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms
->wDeviceType
);
1469 EnterCriticalSection(&WINMM_IData
->cs
);
1470 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1471 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1473 LeaveCriticalSection(&WINMM_IData
->cs
);
1475 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms
->wDeviceType
);
1476 FIXME("Don't know how to get # of MCI devices of a given type\n");
1480 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1481 TRACE("(%ld) => '%ld'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1482 ret
= MCI_INTEGER_RETURNED
;
1484 case MCI_SYSINFO_INSTALLNAME
:
1485 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1486 if ((wmd
= MCI_GetDriver(uDevID
))) {
1487 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1488 wmd
->lpstrDeviceType
);
1490 *lpParms
->lpstrReturn
= 0;
1491 ret
= MCIERR_INVALID_DEVICE_ID
;
1493 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1495 case MCI_SYSINFO_NAME
:
1496 TRACE("MCI_SYSINFO_NAME\n");
1497 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1498 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1499 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1503 lRet
= RegOpenKeyExA( HKEY_LOCAL_MACHINE
, HKLM_MCI
, 0, KEY_QUERY_VALUE
, &hKey
);
1504 if (lRet
== ERROR_SUCCESS
) {
1505 lRet
= RegQueryInfoKeyA( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1506 if (lRet
== ERROR_SUCCESS
&& lpParms
->dwNumber
<= cnt
) {
1507 DWORD bufLen
= sizeof(buf
);
1508 lRet
= RegEnumKeyExA(hKey
, lpParms
->dwNumber
- 1, buf
, &bufLen
, 0, 0, 0, 0);
1509 if (lRet
== ERROR_SUCCESS
) s
= buf
;
1511 RegCloseKey( hKey
);
1514 if (GetPrivateProfileStringA("mci", 0, "", buf
, sizeof(buf
), "system.ini")) {
1515 for(p
= buf
; *p
; p
+= strlen(p
) + 1, cnt
++) {
1516 TRACE("%ld: %s\n", cnt
, p
);
1517 if (cnt
== lpParms
->dwNumber
- 1) {
1524 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
1526 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1529 TRACE("Unsupported flag value=%08lx\n", dwFlags
);
1530 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1535 /**************************************************************************
1536 * MCI_Break [internal]
1538 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1542 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1544 if (dwFlags
& MCI_NOTIFY
)
1545 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1546 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1551 /**************************************************************************
1552 * MCI_Sound [internal]
1554 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMS lpParms
)
1558 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1560 if (dwFlags
& MCI_SOUND_NAME
)
1561 dwRet
= sndPlaySoundA(lpParms
->lpstrSoundName
, SND_SYNC
) ? MMSYSERR_NOERROR
: MMSYSERR_ERROR
;
1563 dwRet
= MMSYSERR_ERROR
; /* what should be done ??? */
1564 if (dwFlags
& MCI_NOTIFY
)
1565 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1566 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1571 /**************************************************************************
1572 * MCI_SendCommand [internal]
1574 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
,
1575 DWORD dwParam2
, BOOL bFrom32
)
1577 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1582 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1583 } else if (pFnMciMapMsg16To32A
) {
1584 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1586 case WINMM_MAP_OKMEM
:
1587 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1588 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1590 default: break; /* so that gcc does not bark */
1596 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1597 } else if (pFnMciMapMsg16To32A
) {
1598 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1600 case WINMM_MAP_OKMEM
:
1601 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1602 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1604 default: break; /* so that gcc does not bark */
1610 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1611 } else if (pFnMciMapMsg16To32A
) {
1612 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1614 case WINMM_MAP_OKMEM
:
1615 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1616 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1618 default: break; /* so that gcc does not bark */
1624 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1625 } else if (pFnMciMapMsg16To32A
) {
1626 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1628 case WINMM_MAP_OKMEM
:
1629 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1630 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1632 default: break; /* so that gcc does not bark */
1638 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMS
)dwParam2
);
1639 } else if (pFnMciMapMsg16To32A
) {
1640 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1642 case WINMM_MAP_OKMEM
:
1643 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMS
)dwParam2
);
1644 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1646 default: break; /* so that gcc does not bark */
1651 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1652 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1653 dwRet
= MCIERR_CANNOT_USE_ALL
;
1656 MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
) :
1657 MCI_SendCommandFrom16(wDevID
, wMsg
, dwParam1
, dwParam2
);
1664 /**************************************************************************
1665 * MCI_CleanUp [internal]
1667 * Some MCI commands need to be cleaned-up (when not called from
1668 * mciSendString), because MCI drivers return extra information for string
1669 * transformation. This function gets rid of them.
1671 LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD dwParam2
)
1674 return LOWORD(dwRet
);
1677 case MCI_GETDEVCAPS
:
1678 switch (dwRet
& 0xFFFF0000ul
) {
1680 case MCI_COLONIZED3_RETURN
:
1681 case MCI_COLONIZED4_RETURN
:
1682 case MCI_INTEGER_RETURNED
:
1685 case MCI_RESOURCE_RETURNED
:
1686 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1688 LPMCI_GETDEVCAPS_PARMS lmgp
;
1690 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)(void*)dwParam2
;
1691 TRACE("Changing %08lx to %08lx\n", lmgp
->dwReturn
, (DWORD
)LOWORD(lmgp
->dwReturn
));
1692 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
1696 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1697 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1701 switch (dwRet
& 0xFFFF0000ul
) {
1703 case MCI_COLONIZED3_RETURN
:
1704 case MCI_COLONIZED4_RETURN
:
1705 case MCI_INTEGER_RETURNED
:
1708 case MCI_RESOURCE_RETURNED
:
1709 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1711 LPMCI_STATUS_PARMS lsp
;
1713 lsp
= (LPMCI_STATUS_PARMS
)(void*)dwParam2
;
1714 TRACE("Changing %08lx to %08lx\n", lsp
->dwReturn
, (DWORD
)LOWORD(lsp
->dwReturn
));
1715 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
1719 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1720 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1724 switch (dwRet
& 0xFFFF0000ul
) {
1726 case MCI_INTEGER_RETURNED
:
1730 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
1734 if (HIWORD(dwRet
)) {
1735 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1736 dwRet
, MCI_MessageToString(wMsg
));
1740 return LOWORD(dwRet
);