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 (strcmp(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
);
889 memset(data
, 0, sizeof(data
));
891 if (!(args
= strchr(verb
, ' '))) {
892 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
896 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
900 /* case dev == 'new' has to be handled */
901 if (!strcasecmp(dev
, "new")) {
902 FIXME("'new': NIY as device name\n");
903 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
907 /* otherwise, try to grab devType from open */
908 if (!strcmp(verb
, "open")) {
911 if ((devType
= strchr(dev
, '!')) != NULL
) {
913 tmp
= devType
; devType
= dev
; dev
= tmp
;
915 dwFlags
|= MCI_OPEN_TYPE
;
916 data
[2] = (DWORD
)devType
;
917 devType
= str_dup_upper(devType
);
918 dwFlags
|= MCI_OPEN_ELEMENT
;
919 data
[3] = (DWORD
)dev
;
920 } else if (strchr(dev
, '.') == NULL
) {
921 tmp
= strchr(dev
,' ');
922 if (tmp
) *tmp
= '\0';
923 data
[2] = (DWORD
)dev
;
924 devType
= str_dup_upper(dev
);
926 dwFlags
|= MCI_OPEN_TYPE
;
928 if ((devType
= strstr(args
, "type ")) != NULL
) {
930 tmp
= strchr(devType
, ' ');
931 if (tmp
) *tmp
= '\0';
932 devType
= str_dup_upper(devType
);
934 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
937 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
940 devType
= str_dup_upper(buf
);
942 dwFlags
|= MCI_OPEN_ELEMENT
;
943 data
[3] = (DWORD
)dev
;
945 if ((devAlias
= strstr(args
," alias "))) {
948 if (!(tmp
= strchr(devAlias
,' '))) tmp
= devAlias
+ strlen(devAlias
);
949 if (tmp
) *tmp
= '\0';
950 tmp2
= HeapAlloc(GetProcessHeap(), 0, tmp
- devAlias
+ 1 );
951 memcpy( tmp2
, devAlias
, tmp
- devAlias
);
952 tmp2
[tmp
- devAlias
] = 0;
953 data
[4] = (DWORD
)tmp2
;
954 /* should be done in regular options parsing */
955 /* dwFlags |= MCI_OPEN_ALIAS; */
958 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
959 HeapFree(GetProcessHeap(), 0, devType
);
961 MCI_UnLoadMciDriver(wmd
);
964 } else if (!(wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
)))) {
967 sprintf(buf
, "open %s wait", dev
);
969 if ((dwRet
= mciSendStringA(buf
, NULL
, 0, 0)) != 0)
972 wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
));
974 /* FIXME: memory leak, MCI driver is not closed */
975 dwRet
= MCIERR_INVALID_DEVICE_ID
;
980 /* get the verb in the different command tables */
982 /* try the device specific command table */
983 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
985 /* try the type specific command table */
986 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
987 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
988 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
989 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
992 /* try core command table */
993 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
996 TRACE("Command '%s' not found!\n", verb
);
997 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1001 /* set up call back */
1002 if (hwndCallback
!= 0) {
1003 dwFlags
|= MCI_NOTIFY
;
1004 data
[0] = (DWORD
)hwndCallback
;
1007 /* set return information */
1008 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1009 case 0: offset
= 1; break;
1010 case MCI_INTEGER
: offset
= 2; break;
1011 case MCI_STRING
: data
[1] = (DWORD
)lpstrRet
; data
[2] = uRetLen
; offset
= 3; break;
1012 case MCI_RECT
: offset
= 5; break;
1013 default: ERR("oops\n");
1016 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb
, dev
, offset
);
1018 if ((dwRet
= MCI_ParseOptArgs(data
, offset
, lpCmd
, args
, &dwFlags
)))
1021 if (bAutoOpen
&& (dwFlags
& MCI_NOTIFY
)) {
1022 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1025 /* FIXME: the command should get it's own notification window set up and
1026 * ask for device closing while processing the notification mechanism
1028 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1030 TRACE("[%d, %s, %08lx, %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s %08lx/%s]\n",
1031 wmd
->wDeviceID
, MCI_MessageToString(MCI_GetMessage(lpCmd
)), dwFlags
,
1032 data
[0], debugstr_a((char *)data
[0]), data
[1], debugstr_a((char *)data
[1]),
1033 data
[2], debugstr_a((char *)data
[2]), data
[3], debugstr_a((char *)data
[3]),
1034 data
[4], debugstr_a((char *)data
[4]), data
[5], debugstr_a((char *)data
[5]));
1036 if (strcmp(verb
, "open") == 0) {
1037 if ((dwRet
= MCI_FinishOpen(wmd
, (LPMCI_OPEN_PARMSA
)data
, dwFlags
)))
1038 MCI_UnLoadMciDriver(wmd
);
1039 /* FIXME: notification is not properly shared across two opens */
1041 dwRet
= MCI_SendCommand(wmd
->wDeviceID
, MCI_GetMessage(lpCmd
), dwFlags
, (DWORD
)data
, TRUE
);
1043 TRACE("=> 1/ %lx (%s)\n", dwRet
, lpstrRet
);
1044 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, data
, lpstrRet
, uRetLen
);
1045 TRACE("=> 2/ %lx (%s)\n", dwRet
, lpstrRet
);
1048 HeapFree(GetProcessHeap(), 0, verb
);
1049 HeapFree(GetProcessHeap(), 0, devAlias
);
1053 /**************************************************************************
1054 * mciSendStringW [WINMM.@]
1056 DWORD WINAPI
mciSendStringW(LPCWSTR lpwstrCommand
, LPWSTR lpwstrRet
,
1057 UINT uRetLen
, HWND hwndCallback
)
1060 LPSTR lpstrRet
= NULL
;
1064 /* FIXME: is there something to do with lpstrReturnString ? */
1065 len
= WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, NULL
, 0, NULL
, NULL
);
1066 lpstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
);
1067 WideCharToMultiByte( CP_ACP
, 0, lpwstrCommand
, -1, lpstrCommand
, len
, NULL
, NULL
);
1070 lpstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1071 if (!lpstrRet
) return MMSYSERR_NOMEM
;
1073 ret
= mciSendStringA(lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
1075 MultiByteToWideChar( CP_ACP
, 0, lpstrRet
, -1, lpwstrRet
, uRetLen
);
1076 HeapFree(GetProcessHeap(), 0, lpstrCommand
);
1077 if (lpstrRet
) HeapFree(GetProcessHeap(), 0, lpstrRet
);
1081 /**************************************************************************
1082 * mciExecute [WINMM.@]
1083 * mciExecute [MMSYSTEM.712]
1085 DWORD WINAPI
mciExecute(LPCSTR lpstrCommand
)
1090 TRACE("(%s)!\n", lpstrCommand
);
1092 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1094 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1095 sprintf(strRet
, "Unknown MCI error (%ld)", ret
);
1097 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1099 /* FIXME: what shall I return ? */
1103 /**************************************************************************
1104 * mciLoadCommandResource [WINMM.@]
1106 * Strangely, this function only exists as an UNICODE one.
1108 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1112 UINT16 ret
= MCI_NO_COMMAND_TABLE
;
1114 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1116 /* if a file named "resname.mci" exits, then load resource "resname" from it
1117 * otherwise directly from driver
1118 * We don't support it (who uses this feature ?), but we check anyway
1122 /* FIXME: we should put this back into order, but I never found a program
1123 * actually using this feature, so we not need it
1128 strcat(strcpy(buf
, resname
), ".mci");
1129 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1130 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1134 if (!(hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
))) {
1135 WARN("No command table found in resource\n");
1136 } else if ((hMem
= LoadResource(hInst
, hRsrc
))) {
1137 ret
= MCI_SetCommandTable(LockResource(hMem
), type
);
1139 WARN("Couldn't load resource.\n");
1141 TRACE("=> %04x\n", ret
);
1145 /**************************************************************************
1146 * mciFreeCommandResource [WINMM.@]
1148 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1150 TRACE("(%08x)!\n", uTable
);
1152 return MCI_DeleteCommandTable(uTable
);
1155 /**************************************************************************
1156 * MCI_SendCommandFrom32 [internal]
1158 DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1160 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1161 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1165 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1166 } else if (pFnMciMapMsg32ATo16
) {
1169 switch (res
= pFnMciMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, &dwParam2
)) {
1170 case WINMM_MAP_MSGERROR
:
1171 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1172 dwRet
= MCIERR_DRIVER_INTERNAL
;
1174 case WINMM_MAP_NOMEM
:
1175 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg
));
1176 dwRet
= MCIERR_OUT_OF_MEMORY
;
1179 case WINMM_MAP_OKMEM
:
1180 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1181 if (res
== WINMM_MAP_OKMEM
)
1182 pFnMciUnMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, dwParam2
);
1190 /**************************************************************************
1191 * MCI_SendCommandFrom16 [internal]
1193 DWORD
MCI_SendCommandFrom16(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1195 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1196 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1199 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1201 if (wmd
->bIs32
&& pFnMciMapMsg16To32A
) {
1204 switch (res
= pFnMciMapMsg16To32A(wmd
->wType
, wMsg
, &dwParam2
)) {
1205 case WINMM_MAP_MSGERROR
:
1206 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1207 dwRet
= MCIERR_DRIVER_INTERNAL
;
1209 case WINMM_MAP_NOMEM
:
1210 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg
));
1211 dwRet
= MCIERR_OUT_OF_MEMORY
;
1214 case WINMM_MAP_OKMEM
:
1215 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1216 if (res
== WINMM_MAP_OKMEM
)
1217 pFnMciUnMapMsg16To32A(wmd
->wType
, wMsg
, dwParam2
);
1221 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1227 /**************************************************************************
1228 * MCI_Open [internal]
1230 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSA lpParms
)
1232 char strDevTyp
[128];
1234 LPWINE_MCIDRIVER wmd
= NULL
;
1236 TRACE("(%08lX, %p)\n", dwParam
, lpParms
);
1237 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1239 /* only two low bytes are generic, the other ones are dev type specific */
1240 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1241 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1242 MCI_NOTIFY|MCI_WAIT)
1243 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1244 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1246 #undef WINE_MCIDRIVER_SUPP
1250 if (dwParam
& MCI_OPEN_TYPE
) {
1251 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1252 WORD uDevType
= LOWORD((DWORD
)lpParms
->lpstrDeviceType
);
1254 if (uDevType
< MCI_DEVTYPE_FIRST
||
1255 uDevType
> MCI_DEVTYPE_LAST
||
1256 !LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, strDevTyp
, sizeof(strDevTyp
))) {
1257 dwRet
= MCIERR_BAD_INTEGER
;
1262 if (lpParms
->lpstrDeviceType
== NULL
) {
1263 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1266 strcpy(strDevTyp
, lpParms
->lpstrDeviceType
);
1267 ptr
= strchr(strDevTyp
, '!');
1269 /* this behavior is not documented in windows. However, since, in
1270 * some occasions, MCI_OPEN handling is translated by WinMM into
1271 * a call to mciSendString("open <type>"); this code shall be correct
1273 if (dwParam
& MCI_OPEN_ELEMENT
) {
1274 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1275 lpParms
->lpstrElementName
, strDevTyp
);
1276 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1279 dwParam
|= MCI_OPEN_ELEMENT
;
1281 /* FIXME: not a good idea to write in user supplied buffer */
1282 lpParms
->lpstrElementName
= ptr
;
1286 TRACE("devType='%s' !\n", strDevTyp
);
1289 if (dwParam
& MCI_OPEN_ELEMENT
) {
1290 TRACE("lpstrElementName='%s'\n", lpParms
->lpstrElementName
);
1292 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1293 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1294 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1298 if (!lpParms
->lpstrElementName
) {
1299 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1303 /* type, if given as a parameter, supersedes file extension */
1304 if (!strDevTyp
[0] &&
1305 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1306 strDevTyp
, sizeof(strDevTyp
))) {
1307 if (GetDriveTypeA(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1308 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1311 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1312 strcpy(strDevTyp
, "CDAUDIO");
1316 if (strDevTyp
[0] == 0) {
1317 FIXME("Couldn't load driver\n");
1318 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1322 if (dwParam
& MCI_OPEN_ALIAS
) {
1323 TRACE("Alias='%s' !\n", lpParms
->lpstrAlias
);
1324 if (!lpParms
->lpstrAlias
) {
1325 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1330 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1334 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1335 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet
);
1336 /* FIXME: is dwRet the correct ret code ? */
1340 /* only handled devices fall through */
1341 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1343 if (dwParam
& MCI_NOTIFY
)
1344 mciDriverNotify((HWND
)lpParms
->dwCallback
, wmd
->wDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1348 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1350 if (dwParam
& MCI_NOTIFY
)
1351 mciDriverNotify((HWND
)lpParms
->dwCallback
, 0, MCI_NOTIFY_FAILURE
);
1355 /**************************************************************************
1356 * MCI_Close [internal]
1358 static DWORD
MCI_Close(UINT16 wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1361 LPWINE_MCIDRIVER wmd
;
1363 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwParam
, lpParms
);
1365 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1366 LPWINE_MCIDRIVER next
;
1368 EnterCriticalSection(&WINMM_IData
->cs
);
1369 /* FIXME: shall I notify once after all is done, or for
1370 * each of the open drivers ? if the latest, which notif
1371 * to return when only one fails ?
1373 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; ) {
1375 MCI_Close(wmd
->wDeviceID
, dwParam
, lpParms
);
1378 LeaveCriticalSection(&WINMM_IData
->cs
);
1382 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1383 return MCIERR_INVALID_DEVICE_ID
;
1386 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD
)lpParms
);
1388 MCI_UnLoadMciDriver(wmd
);
1390 if (dwParam
& MCI_NOTIFY
)
1391 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1392 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1397 /**************************************************************************
1398 * MCI_WriteString [internal]
1400 DWORD
MCI_WriteString(LPSTR lpDstStr
, DWORD dstSize
, LPCSTR lpSrcStr
)
1405 if (dstSize
<= strlen(lpSrcStr
)) {
1406 lstrcpynA(lpDstStr
, lpSrcStr
, dstSize
- 1);
1407 ret
= MCIERR_PARAM_OVERFLOW
;
1409 strcpy(lpDstStr
, lpSrcStr
);
1417 /**************************************************************************
1418 * MCI_Sysinfo [internal]
1420 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSA lpParms
)
1422 DWORD ret
= MCIERR_INVALID_DEVICE_ID
;
1423 LPWINE_MCIDRIVER wmd
;
1425 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1427 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1428 uDevID
, dwFlags
, (DWORD
)lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1430 switch (dwFlags
& ~MCI_SYSINFO_OPEN
) {
1431 case MCI_SYSINFO_QUANTITY
:
1435 if (lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
||
1436 lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
) {
1437 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1438 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1439 EnterCriticalSection(&WINMM_IData
->cs
);
1440 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1443 LeaveCriticalSection(&WINMM_IData
->cs
);
1445 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1446 cnt
= MCI_InstalledCount
;
1449 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1450 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
1451 lpParms
->wDeviceType
);
1452 EnterCriticalSection(&WINMM_IData
->cs
);
1453 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1454 if (wmd
->wType
== lpParms
->wDeviceType
)
1457 LeaveCriticalSection(&WINMM_IData
->cs
);
1459 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
1460 lpParms
->wDeviceType
);
1461 FIXME("Don't know how to get # of MCI devices of a given type\n");
1465 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1467 TRACE("(%ld) => '%ld'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1468 ret
= MCI_INTEGER_RETURNED
;
1470 case MCI_SYSINFO_INSTALLNAME
:
1471 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1472 if ((wmd
= MCI_GetDriver(uDevID
))) {
1473 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1474 wmd
->lpstrDeviceType
);
1476 *lpParms
->lpstrReturn
= 0;
1477 ret
= MCIERR_INVALID_DEVICE_ID
;
1479 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1481 case MCI_SYSINFO_NAME
:
1482 TRACE("MCI_SYSINFO_NAME\n");
1483 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1484 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1485 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1486 } else if (lpParms
->dwNumber
> MCI_InstalledCount
) {
1487 ret
= MCIERR_OUTOFRANGE
;
1489 DWORD count
= lpParms
->dwNumber
;
1490 LPSTR ptr
= MCI_lpInstallNames
;
1492 while (--count
> 0) ptr
+= strlen(ptr
) + 1;
1493 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, ptr
);
1495 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1498 TRACE("Unsupported flag value=%08lx\n", dwFlags
);
1499 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1504 /**************************************************************************
1505 * MCI_Break [internal]
1507 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1511 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1513 if (dwFlags
& MCI_NOTIFY
)
1514 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1515 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1520 /**************************************************************************
1521 * MCI_SendCommand [internal]
1523 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
,
1524 DWORD dwParam2
, BOOL bFrom32
)
1526 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1531 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1532 } else if (pFnMciMapMsg16To32A
) {
1533 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1535 case WINMM_MAP_OKMEM
:
1536 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1537 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1539 default: break; /* so that gcc does not bark */
1545 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1546 } else if (pFnMciMapMsg16To32A
) {
1547 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1549 case WINMM_MAP_OKMEM
:
1550 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1551 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1553 default: break; /* so that gcc does not bark */
1559 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1560 } else if (pFnMciMapMsg16To32A
) {
1561 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1563 case WINMM_MAP_OKMEM
:
1564 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1565 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1567 default: break; /* so that gcc doesnot bark */
1573 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1574 } else if (pFnMciMapMsg16To32A
) {
1575 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1577 case WINMM_MAP_OKMEM
:
1578 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1579 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1581 default: break; /* so that gcc does not bark */
1586 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
1587 * but I couldn't get any doc on this MCI message
1591 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1592 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1593 dwRet
= MCIERR_CANNOT_USE_ALL
;
1596 MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
) :
1597 MCI_SendCommandFrom16(wDevID
, wMsg
, dwParam1
, dwParam2
);
1604 /**************************************************************************
1605 * MCI_CleanUp [internal]
1607 * Some MCI commands need to be cleaned-up (when not called from
1608 * mciSendString), because MCI drivers return extra information for string
1609 * transformation. This function gets rid of them.
1611 LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD dwParam2
)
1614 return LOWORD(dwRet
);
1617 case MCI_GETDEVCAPS
:
1618 switch (dwRet
& 0xFFFF0000ul
) {
1620 case MCI_COLONIZED3_RETURN
:
1621 case MCI_COLONIZED4_RETURN
:
1622 case MCI_INTEGER_RETURNED
:
1625 case MCI_RESOURCE_RETURNED
:
1626 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1628 LPMCI_GETDEVCAPS_PARMS lmgp
;
1630 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)(void*)dwParam2
;
1631 TRACE("Changing %08lx to %08lx\n", lmgp
->dwReturn
, (DWORD
)LOWORD(lmgp
->dwReturn
));
1632 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
1636 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1637 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1641 switch (dwRet
& 0xFFFF0000ul
) {
1643 case MCI_COLONIZED3_RETURN
:
1644 case MCI_COLONIZED4_RETURN
:
1645 case MCI_INTEGER_RETURNED
:
1648 case MCI_RESOURCE_RETURNED
:
1649 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1651 LPMCI_STATUS_PARMS lsp
;
1653 lsp
= (LPMCI_STATUS_PARMS
)(void*)dwParam2
;
1654 TRACE("Changing %08lx to %08lx\n", lsp
->dwReturn
, (DWORD
)LOWORD(lsp
->dwReturn
));
1655 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
1659 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1660 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1664 switch (dwRet
& 0xFFFF0000ul
) {
1666 case MCI_INTEGER_RETURNED
:
1670 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
1674 if (HIWORD(dwRet
)) {
1675 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1676 dwRet
, MCI_MessageToString(wMsg
));
1680 return LOWORD(dwRet
);
1683 /**************************************************************************
1684 * MCI_Init [internal]
1686 * Initializes the MCI internal variables.
1698 MCI_InstalledCount
= 0;
1699 ptr1
= MCI_lpInstallNames
= HeapAlloc(GetProcessHeap(), 0, count
);
1701 if (!MCI_lpInstallNames
)
1704 /* FIXME: should do also some registry diving here ? */
1705 if (!(err
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config", &hWineConf
)) &&
1706 !(err
= RegOpenKeyA(hWineConf
, "options", &hkey
))) {
1707 err
= RegQueryValueExA(hkey
, "mci", 0, &type
, MCI_lpInstallNames
, &count
);
1712 TRACE("Wine => '%s' \n", ptr1
);
1713 while ((ptr2
= strchr(ptr1
, ':')) != 0) {
1715 TRACE("---> '%s' \n", ptr1
);
1716 MCI_InstalledCount
++;
1719 MCI_InstalledCount
++;
1720 TRACE("---> '%s' \n", ptr1
);
1721 ptr1
+= strlen(ptr1
) + 1;
1723 GetPrivateProfileStringA("mci", NULL
, "", MCI_lpInstallNames
, count
, "SYSTEM.INI");
1724 while (strlen(ptr1
) > 0) {
1725 TRACE("---> '%s' \n", ptr1
);
1726 ptr1
+= strlen(ptr1
) + 1;
1727 MCI_InstalledCount
++;
1730 RegCloseKey(hWineConf
);