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"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
44 static int MCI_InstalledCount
;
45 static LPSTR MCI_lpInstallNames
/* = NULL */;
47 WINMM_MapType (*pFnMciMapMsg16To32A
) (WORD
,WORD
,DWORD
*) /* = NULL */;
48 WINMM_MapType (*pFnMciUnMapMsg16To32A
)(WORD
,WORD
,DWORD
) /* = NULL */;
49 WINMM_MapType (*pFnMciMapMsg32ATo16
) (WORD
,WORD
,DWORD
,DWORD
*) /* = NULL */;
50 WINMM_MapType (*pFnMciUnMapMsg32ATo16
)(WORD
,WORD
,DWORD
,DWORD
) /* = NULL */;
52 /* First MCI valid device ID (0 means error) */
53 #define MCI_MAGIC 0x0001
55 /* dup a string and uppercase it */
56 inline static LPSTR
str_dup_upper( LPCSTR str
)
58 INT len
= strlen(str
) + 1;
59 LPSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
62 memcpy( p
, str
, len
);
68 /**************************************************************************
69 * MCI_GetDriver [internal]
71 LPWINE_MCIDRIVER
MCI_GetDriver(UINT16 wDevID
)
73 LPWINE_MCIDRIVER wmd
= 0;
75 EnterCriticalSection(&WINMM_IData
->cs
);
76 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
77 if (wmd
->wDeviceID
== wDevID
)
80 LeaveCriticalSection(&WINMM_IData
->cs
);
84 /**************************************************************************
85 * MCI_GetDriverFromString [internal]
87 UINT
MCI_GetDriverFromString(LPCSTR lpstrName
)
95 if (!lstrcmpiA(lpstrName
, "ALL"))
96 return MCI_ALL_DEVICE_ID
;
98 EnterCriticalSection(&WINMM_IData
->cs
);
99 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
100 if (wmd
->lpstrElementName
&& strcmp(wmd
->lpstrElementName
, lpstrName
) == 0) {
101 ret
= wmd
->wDeviceID
;
104 if (wmd
->lpstrDeviceType
&& strcasecmp(wmd
->lpstrDeviceType
, lpstrName
) == 0) {
105 ret
= wmd
->wDeviceID
;
108 if (wmd
->lpstrAlias
&& strcasecmp(wmd
->lpstrAlias
, lpstrName
) == 0) {
109 ret
= wmd
->wDeviceID
;
113 LeaveCriticalSection(&WINMM_IData
->cs
);
118 /**************************************************************************
119 * MCI_MessageToString [internal]
121 const char* MCI_MessageToString(UINT16 wMsg
)
123 static char buffer
[100];
125 #define CASE(s) case (s): return #s
130 CASE(MCI_CLOSE_DRIVER
);
139 CASE(MCI_GETDEVCAPS
);
143 CASE(MCI_OPEN_DRIVER
);
161 /* constants for digital video */
175 sprintf(buffer
, "MCI_<<%04X>>", wMsg
);
180 /**************************************************************************
181 * MCI_GetDevTypeFromFileName [internal]
183 static DWORD
MCI_GetDevTypeFromFileName(LPCSTR fileName
, LPSTR buf
, UINT len
)
187 if ((tmp
= strrchr(fileName
, '.'))) {
188 GetProfileStringA("mci extensions", tmp
+ 1, "*", buf
, len
);
189 if (strcmp(buf
, "*") != 0) {
192 TRACE("No [mci extensions] entry for '%s' found.\n", tmp
);
194 return MCIERR_EXTENSION_NOT_FOUND
;
197 #define MAX_MCICMDTABLE 20
198 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
200 typedef struct tagWINE_MCICMDTABLE
{
204 UINT nVerbs
; /* number of verbs in command table */
205 LPCSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
206 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
207 WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
209 /**************************************************************************
210 * MCI_IsCommandTableValid [internal]
212 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
220 TRACE("Dumping cmdTbl=%d [hMem=%08x devType=%d]\n",
221 uTbl
, S_MciCmdTable
[uTbl
].hMem
, S_MciCmdTable
[uTbl
].uDevType
);
223 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].hMem
|| !S_MciCmdTable
[uTbl
].lpTable
)
226 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
230 lmem
+= strlen(lmem
) + 1;
231 flg
= *(LPDWORD
)lmem
;
232 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
233 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
235 /* EPP TRACE("cmd='%s' %08lx %04x\n", str, flg, eid); */
237 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
238 case MCI_STRING
: if (inCst
) return FALSE
; break;
239 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
240 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
241 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
242 case MCI_FLAG
: if (!*str
) return FALSE
; break;
243 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
244 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
245 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
246 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
247 default: return FALSE
;
249 } while (eid
!= MCI_END_COMMAND_LIST
);
250 } while (eid
!= MCI_END_COMMAND_LIST
);
254 /**************************************************************************
255 * MCI_DumpCommandTable [internal]
257 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
264 if (!MCI_IsCommandTableValid(uTbl
)) {
265 ERR("Ooops: %d is not valid\n", uTbl
);
269 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
273 lmem
+= strlen(lmem
) + 1;
274 flg
= *(LPDWORD
)lmem
;
275 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
276 TRACE("cmd='%s' %08lx %04x\n", str
, flg
, eid
);
277 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
278 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
279 TRACE(" => end of command%s\n", (eid
== MCI_END_COMMAND_LIST
) ? " list" : "");
280 } while (eid
!= MCI_END_COMMAND_LIST
);
284 static UINT
MCI_SetCommandTable(HANDLE hMem
, UINT uDevType
);
286 /**************************************************************************
287 * MCI_GetCommandTable [internal]
289 static UINT
MCI_GetCommandTable(UINT uDevType
)
295 /* first look up existing for existing devType */
296 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
297 if (S_MciCmdTable
[uTbl
].hMem
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
301 /* well try to load id */
302 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
303 if (LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, buf
, sizeof(buf
))) {
306 } else if (uDevType
== 0) {
309 uTbl
= MCI_NO_COMMAND_TABLE
;
311 HRSRC hRsrc
= FindResourceA(WINMM_IData
->hWinMM32Instance
, str
, (LPCSTR
)RT_RCDATAA
);
314 if (hRsrc
) hMem
= LoadResource(WINMM_IData
->hWinMM32Instance
, hRsrc
);
316 uTbl
= MCI_SetCommandTable(hMem
, uDevType
);
318 WARN("No command table found in resource %04x[%s]\n",
319 WINMM_IData
->hWinMM32Instance
, str
);
322 TRACE("=> %d\n", uTbl
);
326 /**************************************************************************
327 * MCI_SetCommandTable [internal]
329 static UINT
MCI_SetCommandTable(HANDLE hMem
, UINT uDevType
)
332 static BOOL bInitDone
= FALSE
;
335 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
336 * can be called with 0 as a uDevType to retrieve it.
341 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
342 S_MciCmdTable
[uTbl
].hMem
= 0;
344 MCI_GetCommandTable(0);
347 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
348 if (S_MciCmdTable
[uTbl
].hMem
== 0) {
353 S_MciCmdTable
[uTbl
].hMem
= hMem
;
354 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
355 S_MciCmdTable
[uTbl
].lpTable
= LockResource(hMem
);
358 MCI_DumpCommandTable(uTbl
);
361 /* create the verbs table */
362 /* get # of entries */
363 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
366 lmem
+= strlen(lmem
) + 1;
367 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
368 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
369 if (eid
== MCI_COMMAND_HEAD
)
371 } while (eid
!= MCI_END_COMMAND_LIST
);
373 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCSTR
));
374 S_MciCmdTable
[uTbl
].nVerbs
= count
;
376 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
380 lmem
+= strlen(lmem
) + 1;
381 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
382 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
383 if (eid
== MCI_COMMAND_HEAD
)
384 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
385 } while (eid
!= MCI_END_COMMAND_LIST
);
386 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
391 return MCI_NO_COMMAND_TABLE
;
394 /**************************************************************************
395 * MCI_DeleteCommandTable [internal]
397 static BOOL
MCI_DeleteCommandTable(UINT uTbl
)
399 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].hMem
)
402 FreeResource(S_MciCmdTable
[uTbl
].hMem
);
403 S_MciCmdTable
[uTbl
].hMem
= 0;
404 if (S_MciCmdTable
[uTbl
].aVerbs
) {
405 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTbl
].aVerbs
);
406 S_MciCmdTable
[uTbl
].aVerbs
= 0;
411 /**************************************************************************
412 * MCI_UnLoadMciDriver [internal]
414 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
416 LPWINE_MCIDRIVER
* tmp
;
421 CloseDriver(wmd
->hDriver
, 0, 0);
423 if (wmd
->dwPrivate
!= 0)
424 WARN("Unloading mci driver with non nul dwPrivate field\n");
426 EnterCriticalSection(&WINMM_IData
->cs
);
427 for (tmp
= &WINMM_IData
->lpMciDrvs
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
433 LeaveCriticalSection(&WINMM_IData
->cs
);
435 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
436 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
437 HeapFree(GetProcessHeap(), 0, wmd
->lpstrElementName
);
439 HeapFree(GetProcessHeap(), 0, wmd
);
443 /**************************************************************************
444 * MCI_OpenMciDriver [internal]
446 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCSTR drvTyp
, LPARAM lp
)
450 if (!DRIVER_GetLibName(drvTyp
, "mci", libName
, sizeof(libName
)))
454 /* First load driver */
455 if ((wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
))) {
457 } else if (WINMM_CheckForMMSystem() && pFnMciMapMsg32ATo16
) {
460 switch (res
= pFnMciMapMsg32ATo16(0, DRV_OPEN
, 0, &lp
)) {
461 case WINMM_MAP_MSGERROR
:
462 TRACE("Not handled yet (DRV_OPEN)\n");
464 case WINMM_MAP_NOMEM
:
465 TRACE("Problem mapping msg=DRV_OPEN from 32a to 16\n");
468 case WINMM_MAP_OKMEM
:
469 if ((wmd
->hDriver
= OpenDriverA(drvTyp
, "mci", lp
)))
471 if (res
== WINMM_MAP_OKMEM
)
472 pFnMciUnMapMsg32ATo16(0, DRV_OPEN
, 0, lp
);
476 return (wmd
->bIs32
== 0xFFFF) ? FALSE
: TRUE
;
479 /**************************************************************************
480 * MCI_LoadMciDriver [internal]
482 static DWORD
MCI_LoadMciDriver(LPCSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
484 LPSTR strDevTyp
= str_dup_upper(_strDevTyp
);
485 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
486 MCI_OPEN_DRIVER_PARMSA modp
;
489 if (!wmd
|| !strDevTyp
) {
490 dwRet
= MCIERR_OUT_OF_MEMORY
;
494 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
495 wmd
->dwYieldData
= VK_CANCEL
;
496 wmd
->CreatorThread
= GetCurrentThreadId();
498 EnterCriticalSection(&WINMM_IData
->cs
);
499 /* wmd must be inserted in list before sending opening the driver, coz' it
500 * may want to lookup at wDevID
502 wmd
->lpNext
= WINMM_IData
->lpMciDrvs
;
503 WINMM_IData
->lpMciDrvs
= wmd
;
505 for (modp
.wDeviceID
= MCI_MAGIC
;
506 MCI_GetDriver(modp
.wDeviceID
) != 0;
509 wmd
->wDeviceID
= modp
.wDeviceID
;
511 LeaveCriticalSection(&WINMM_IData
->cs
);
513 TRACE("wDevID=%04X \n", modp
.wDeviceID
);
515 modp
.lpstrParams
= NULL
;
517 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (LPARAM
)&modp
)) {
518 /* silence warning if all is used... some bogus program use commands like
521 if (strcasecmp(strDevTyp
, "all") != 0) {
522 dwRet
= MCIERR_CANNOT_USE_ALL
;
524 FIXME("Couldn't load driver for type %s.\n"
525 "If you don't have a windows installation accessible from Wine,\n"
526 "you perhaps forgot to create a [mci] section in system.ini\n",
528 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
533 /* FIXME: should also check that module's description is of the form
534 * MODULENAME:[MCI] comment
537 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
538 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
539 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
541 TRACE("Loaded driver %x (%s), type is %d, cmdTable=%08x\n",
542 wmd
->hDriver
, strDevTyp
, modp
.wType
, modp
.wCustomCommandTable
);
544 wmd
->lpstrDeviceType
= strDevTyp
;
545 wmd
->wType
= modp
.wType
;
547 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
548 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
552 MCI_UnLoadMciDriver(wmd
);
553 HeapFree(GetProcessHeap(), 0, strDevTyp
);
558 /**************************************************************************
559 * MCI_FinishOpen [internal]
561 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSA lpParms
,
564 if (dwParam
& MCI_OPEN_ELEMENT
)
566 wmd
->lpstrElementName
= HeapAlloc(GetProcessHeap(),0,strlen(lpParms
->lpstrElementName
)+1);
567 strcpy( wmd
->lpstrElementName
, lpParms
->lpstrElementName
);
569 if (dwParam
& MCI_OPEN_ALIAS
)
571 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, strlen(lpParms
->lpstrAlias
)+1);
572 strcpy( wmd
->lpstrAlias
, lpParms
->lpstrAlias
);
574 lpParms
->wDeviceID
= wmd
->wDeviceID
;
576 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
580 /**************************************************************************
581 * MCI_FindCommand [internal]
583 static LPCSTR
MCI_FindCommand(UINT uTbl
, LPCSTR verb
)
587 if (uTbl
>= MAX_MCICMDTABLE
|| S_MciCmdTable
[uTbl
].hMem
== 0)
590 /* another improvement would be to have the aVerbs array sorted,
591 * so that we could use a dichotomic search on it, rather than this dumb
594 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
595 if (strcmp(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
596 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
602 /**************************************************************************
603 * MCI_GetReturnType [internal]
605 static DWORD
MCI_GetReturnType(LPCSTR lpCmd
)
607 lpCmd
+= strlen(lpCmd
) + 1 + sizeof(DWORD
) + sizeof(WORD
);
608 if (*lpCmd
== '\0' && *(LPWORD
)(lpCmd
+ 1 + sizeof(DWORD
)) == MCI_RETURN
) {
609 return *(LPDWORD
)(lpCmd
+ 1);
614 /**************************************************************************
615 * MCI_GetMessage [internal]
617 static WORD
MCI_GetMessage(LPCSTR lpCmd
)
619 return (WORD
)*(LPDWORD
)(lpCmd
+ strlen(lpCmd
) + 1);
622 /**************************************************************************
623 * MCI_GetDWord [internal]
625 static BOOL
MCI_GetDWord(LPDWORD data
, LPSTR
* ptr
)
630 val
= strtoul(*ptr
, &ret
, 0);
634 case ' ': ret
++; break;
635 default: return FALSE
;
643 /**************************************************************************
644 * MCI_GetString [internal]
646 static DWORD
MCI_GetString(LPSTR
* str
, LPSTR
* args
)
650 /* see if we have a quoted string */
652 ptr
= strchr(*str
= ptr
+ 1, '"');
653 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
654 /* FIXME: shall we escape \" from string ?? */
655 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
656 *ptr
++ = '\0'; /* remove trailing " */
657 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
660 ptr
= strchr(ptr
, ' ');
665 ptr
= *args
+ strlen(*args
);
674 #define MCI_DATA_SIZE 16
676 /**************************************************************************
677 * MCI_ParseOptArgs [internal]
679 static DWORD
MCI_ParseOptArgs(LPDWORD data
, int _offset
, LPCSTR lpCmd
,
680 LPSTR args
, LPDWORD dwFlags
)
684 DWORD dwRet
, flg
, cflg
= 0;
688 /* loop on arguments */
691 found
= inCst
= FALSE
;
694 /* skip any leading white space(s) */
695 while (*args
== ' ') args
++;
696 TRACE("args='%s' offset=%d\n", args
, offset
);
698 do { /* loop on options for command table for the requested verb */
700 lmem
+= (len
= strlen(lmem
)) + 1;
701 flg
= *(LPDWORD
)lmem
;
702 eid
= *(LPWORD
)(lmem
+ sizeof(DWORD
));
703 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
704 /* EPP TRACE("\tcmd='%s' inCst=%c eid=%04x\n", str, inCst ? 'Y' : 'N', eid); */
708 inCst
= TRUE
; cflg
= flg
; break;
709 case MCI_END_CONSTANT
:
710 /* there may be additional integral values after flag in constant */
711 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
714 inCst
= FALSE
; cflg
= 0;
718 if (strncasecmp(args
, str
, len
) == 0 &&
719 (args
[len
] == 0 || args
[len
] == ' ')) {
720 /* store good values into data[] */
722 while (*args
== ' ') args
++;
726 case MCI_COMMAND_HEAD
:
728 case MCI_END_COMMAND
:
729 case MCI_END_COMMAND_LIST
:
730 case MCI_CONSTANT
: /* done above */
731 case MCI_END_CONSTANT
: /* done above */
743 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
744 return MCIERR_BAD_INTEGER
;
749 /* store rect in data (offset...offset+3) */
751 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
752 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
753 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
754 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
755 ERR("Bad rect '%s'\n", args
);
756 return MCIERR_BAD_INTEGER
;
761 if ((dwRet
= MCI_GetString((LPSTR
*)&data
[offset
], &args
)))
764 default: ERR("oops\n");
766 /* exit inside while loop, except if just entered in constant area definition */
767 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
769 /* have offset incremented if needed */
771 case MCI_COMMAND_HEAD
:
773 case MCI_END_COMMAND
:
774 case MCI_END_COMMAND_LIST
:
776 case MCI_FLAG
: break;
777 case MCI_INTEGER
: if (!inCst
) offset
++; break;
778 case MCI_END_CONSTANT
:
779 case MCI_STRING
: offset
++; break;
780 case MCI_RECT
: offset
+= 4; break;
781 default: ERR("oops\n");
784 } while (eid
!= MCI_END_COMMAND
);
786 WARN("Optarg '%s' not found\n", args
);
787 return MCIERR_UNRECOGNIZED_COMMAND
;
789 if (offset
== MCI_DATA_SIZE
) {
790 ERR("Internal data[] buffer overflow\n");
791 return MCIERR_PARSER_INTERNAL
;
797 /**************************************************************************
798 * MCI_HandleReturnValues [internal]
800 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
801 LPDWORD data
, LPSTR lpstrRet
, UINT uRetLen
)
805 case 0: /* nothing to return */
808 switch (dwRet
& 0xFFFF0000ul
) {
810 case MCI_INTEGER_RETURNED
:
811 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
813 case MCI_RESOURCE_RETURNED
:
814 /* return string which ID is HIWORD(data[1]),
815 * string is loaded from mmsystem.dll */
816 LoadStringA(WINMM_IData
->hWinMM32Instance
, HIWORD(data
[1]),
819 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
820 /* return string which ID is HIWORD(data[1]),
821 * string is loaded from driver */
822 /* FIXME: this is wrong for a 16 bit handle */
823 LoadStringA(GetDriverModuleHandle(wmd
->hDriver
),
824 HIWORD(data
[1]), lpstrRet
, uRetLen
);
826 case MCI_COLONIZED3_RETURN
:
827 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d",
828 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
829 LOBYTE(HIWORD(data
[1])));
831 case MCI_COLONIZED4_RETURN
:
832 snprintf(lpstrRet
, uRetLen
, "%d:%d:%d:%d",
833 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
834 LOBYTE(HIWORD(data
[1])), HIBYTE(HIWORD(data
[1])));
836 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
840 switch (dwRet
& 0xFFFF0000ul
) {
842 /* nothing to do data[1] == lpstrRet */
844 case MCI_INTEGER_RETURNED
:
845 data
[1] = *(LPDWORD
)lpstrRet
;
846 snprintf(lpstrRet
, uRetLen
, "%ld", data
[1]);
849 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
854 if (dwRet
& 0xFFFF0000ul
)
855 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
856 snprintf(lpstrRet
, uRetLen
, "%ld %ld %ld %ld",
857 data
[1], data
[2], data
[3], data
[4]);
859 default: ERR("oops\n");
862 return LOWORD(dwRet
);
865 /**************************************************************************
866 * mciSendStringA [WINMM.@]
868 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
869 UINT uRetLen
, HWND hwndCallback
)
871 LPSTR verb
, dev
, args
;
872 LPWINE_MCIDRIVER wmd
= 0;
873 DWORD dwFlags
= 0, dwRet
= 0;
875 DWORD data
[MCI_DATA_SIZE
];
878 LPSTR devAlias
= NULL
;
879 BOOL bAutoOpen
= FALSE
;
881 TRACE("('%s', %p, %d, %X)\n", lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
883 /* format is <command> <device> <optargs> */
884 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, strlen(lpstrCommand
)+1)))
885 return MCIERR_OUT_OF_MEMORY
;
886 strcpy( verb
, lpstrCommand
);
888 memset(data
, 0, sizeof(data
));
890 if (!(args
= strchr(verb
, ' '))) {
891 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
895 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
899 /* case dev == 'new' has to be handled */
900 if (!strcasecmp(dev
, "new")) {
901 FIXME("'new': NIY as device name\n");
902 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
906 /* otherwise, try to grab devType from open */
907 if (!strcmp(verb
, "open")) {
910 if ((devType
= strchr(dev
, '!')) != NULL
) {
912 tmp
= devType
; devType
= dev
; dev
= tmp
;
914 dwFlags
|= MCI_OPEN_TYPE
;
915 data
[2] = (DWORD
)devType
;
916 devType
= str_dup_upper(devType
);
917 dwFlags
|= MCI_OPEN_ELEMENT
;
918 data
[3] = (DWORD
)dev
;
919 } else if (strchr(dev
, '.') == NULL
) {
920 tmp
= strchr(dev
,' ');
921 if (tmp
) *tmp
= '\0';
922 data
[2] = (DWORD
)dev
;
923 devType
= str_dup_upper(dev
);
925 dwFlags
|= MCI_OPEN_TYPE
;
927 if ((devType
= strstr(args
, "type ")) != NULL
) {
929 tmp
= strchr(devType
, ' ');
930 if (tmp
) *tmp
= '\0';
931 devType
= str_dup_upper(devType
);
933 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
936 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
939 devType
= str_dup_upper(buf
);
941 dwFlags
|= MCI_OPEN_ELEMENT
;
942 data
[3] = (DWORD
)dev
;
944 if ((devAlias
= strstr(args
," alias "))) {
947 if (!(tmp
= strchr(devAlias
,' '))) tmp
= devAlias
+ strlen(devAlias
);
948 if (tmp
) *tmp
= '\0';
949 tmp2
= HeapAlloc(GetProcessHeap(), 0, tmp
- devAlias
+ 1 );
950 memcpy( tmp2
, devAlias
, tmp
- devAlias
);
951 tmp2
[tmp
- devAlias
] = 0;
952 data
[4] = (DWORD
)tmp2
;
953 /* should be done in regular options parsing */
954 /* dwFlags |= MCI_OPEN_ALIAS; */
957 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
958 HeapFree(GetProcessHeap(), 0, devType
);
960 MCI_UnLoadMciDriver(wmd
);
963 } else if (!(wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
)))) {
966 sprintf(buf
, "open %s wait", dev
);
968 if ((dwRet
= mciSendStringA(buf
, NULL
, 0, 0)) != 0)
971 wmd
= MCI_GetDriver(mciGetDeviceIDA(dev
));
973 /* FIXME: memory leak, MCI driver is not closed */
974 dwRet
= MCIERR_INVALID_DEVICE_ID
;
979 /* get the verb in the different command tables */
981 /* try the device specific command table */
982 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
984 /* try the type specific command table */
985 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
986 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
987 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
988 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
991 /* try core command table */
992 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
995 TRACE("Command '%s' not found!\n", verb
);
996 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1000 /* set up call back */
1001 if (hwndCallback
!= 0) {
1002 dwFlags
|= MCI_NOTIFY
;
1003 data
[0] = (DWORD
)hwndCallback
;
1006 /* set return information */
1007 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1008 case 0: offset
= 1; break;
1009 case MCI_INTEGER
: offset
= 2; break;
1010 case MCI_STRING
: data
[1] = (DWORD
)lpstrRet
; data
[2] = uRetLen
; offset
= 3; break;
1011 case MCI_RECT
: offset
= 5; break;
1012 default: ERR("oops\n");
1015 TRACE("verb='%s' on dev='%s'; offset=%d\n", verb
, dev
, offset
);
1017 if ((dwRet
= MCI_ParseOptArgs(data
, offset
, lpCmd
, args
, &dwFlags
)))
1020 if (bAutoOpen
&& (dwFlags
& MCI_NOTIFY
)) {
1021 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1024 /* FIXME: the command should get it's own notification window set up and
1025 * ask for device closing while processing the notification mechanism
1027 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1029 #define STR_OF(_x) (IsBadReadPtr((char*)_x,1)?"?":(char*)(_x))
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], STR_OF(data
[0]), data
[1], STR_OF(data
[1]),
1033 data
[2], STR_OF(data
[2]), data
[3], STR_OF(data
[3]),
1034 data
[4], STR_OF(data
[4]), data
[5], STR_OF(data
[5]));
1037 if (strcmp(verb
, "open") == 0) {
1038 if ((dwRet
= MCI_FinishOpen(wmd
, (LPMCI_OPEN_PARMSA
)data
, dwFlags
)))
1039 MCI_UnLoadMciDriver(wmd
);
1040 /* FIXME: notification is not properly shared across two opens */
1042 dwRet
= MCI_SendCommand(wmd
->wDeviceID
, MCI_GetMessage(lpCmd
), dwFlags
, (DWORD
)data
, TRUE
);
1044 TRACE("=> 1/ %lx (%s)\n", dwRet
, lpstrRet
);
1045 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, data
, lpstrRet
, uRetLen
);
1046 TRACE("=> 2/ %lx (%s)\n", dwRet
, lpstrRet
);
1049 HeapFree(GetProcessHeap(), 0, verb
);
1050 HeapFree(GetProcessHeap(), 0, devAlias
);
1054 /**************************************************************************
1055 * mciSendStringW [WINMM.@]
1057 DWORD WINAPI
mciSendStringW(LPCWSTR lpwstrCommand
, LPSTR lpstrRet
,
1058 UINT uRetLen
, HWND hwndCallback
)
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
);
1068 ret
= mciSendStringA(lpstrCommand
, lpstrRet
, uRetLen
, hwndCallback
);
1069 HeapFree(GetProcessHeap(), 0, lpstrCommand
);
1073 /**************************************************************************
1074 * mciExecute [WINMM.@]
1075 * mciExecute [MMSYSTEM.712]
1077 DWORD WINAPI
mciExecute(LPCSTR lpstrCommand
)
1082 TRACE("(%s)!\n", lpstrCommand
);
1084 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1086 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1087 sprintf(strRet
, "Unknown MCI error (%ld)", ret
);
1089 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1091 /* FIXME: what shall I return ? */
1095 /**************************************************************************
1096 * mciLoadCommandResource [WINMM.@]
1098 * Strangely, this function only exists as an UNICODE one.
1100 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1104 UINT16 ret
= MCI_NO_COMMAND_TABLE
;
1106 TRACE("(%04x, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1108 /* if a file named "resname.mci" exits, then load resource "resname" from it
1109 * otherwise directly from driver
1110 * We don't support it (who uses this feature ?), but we check anyway
1114 /* FIXME: we should put this back into order, but I never found a program
1115 * actually using this feature, so we not need it
1120 strcat(strcpy(buf
, resname
), ".mci");
1121 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1122 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1126 if (!(hRsrc
= FindResourceW(hInst
, resNameW
, (LPCWSTR
)RT_RCDATAA
))) {
1127 WARN("No command table found in resource\n");
1128 } else if ((hMem
= LoadResource(hInst
, hRsrc
))) {
1129 ret
= MCI_SetCommandTable(hMem
, type
);
1131 WARN("Couldn't load resource.\n");
1133 TRACE("=> %04x\n", ret
);
1137 /**************************************************************************
1138 * mciFreeCommandResource [WINMM.@]
1140 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1142 TRACE("(%08x)!\n", uTable
);
1144 return MCI_DeleteCommandTable(uTable
);
1147 /**************************************************************************
1148 * MCI_SendCommandFrom32 [internal]
1150 DWORD
MCI_SendCommandFrom32(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1152 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1153 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1157 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1158 } else if (pFnMciMapMsg32ATo16
) {
1161 switch (res
= pFnMciMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, &dwParam2
)) {
1162 case WINMM_MAP_MSGERROR
:
1163 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1164 dwRet
= MCIERR_DRIVER_INTERNAL
;
1166 case WINMM_MAP_NOMEM
:
1167 TRACE("Problem mapping msg=%s from 32a to 16\n", MCI_MessageToString(wMsg
));
1168 dwRet
= MCIERR_OUT_OF_MEMORY
;
1171 case WINMM_MAP_OKMEM
:
1172 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1173 if (res
== WINMM_MAP_OKMEM
)
1174 pFnMciUnMapMsg32ATo16(wmd
->wType
, wMsg
, dwParam1
, dwParam2
);
1182 /**************************************************************************
1183 * MCI_SendCommandFrom16 [internal]
1185 DWORD
MCI_SendCommandFrom16(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1187 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
1188 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
1191 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1193 if (wmd
->bIs32
&& pFnMciMapMsg16To32A
) {
1196 switch (res
= pFnMciMapMsg16To32A(wmd
->wType
, wMsg
, &dwParam2
)) {
1197 case WINMM_MAP_MSGERROR
:
1198 TRACE("Not handled yet (%s)\n", MCI_MessageToString(wMsg
));
1199 dwRet
= MCIERR_DRIVER_INTERNAL
;
1201 case WINMM_MAP_NOMEM
:
1202 TRACE("Problem mapping msg=%s from 16 to 32a\n", MCI_MessageToString(wMsg
));
1203 dwRet
= MCIERR_OUT_OF_MEMORY
;
1206 case WINMM_MAP_OKMEM
:
1207 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1208 if (res
== WINMM_MAP_OKMEM
)
1209 pFnMciUnMapMsg16To32A(wmd
->wType
, wMsg
, dwParam2
);
1213 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
1219 /**************************************************************************
1220 * MCI_Open [internal]
1222 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSA lpParms
)
1224 char strDevTyp
[128];
1226 LPWINE_MCIDRIVER wmd
= NULL
;
1228 TRACE("(%08lX, %p)\n", dwParam
, lpParms
);
1229 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1231 /* only two low bytes are generic, the other ones are dev type specific */
1232 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1233 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1234 MCI_NOTIFY|MCI_WAIT)
1235 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1236 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1238 #undef WINE_MCIDRIVER_SUPP
1242 if (dwParam
& MCI_OPEN_TYPE
) {
1243 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1244 WORD uDevType
= LOWORD((DWORD
)lpParms
->lpstrDeviceType
);
1246 if (uDevType
< MCI_DEVTYPE_FIRST
||
1247 uDevType
> MCI_DEVTYPE_LAST
||
1248 !LoadStringA(WINMM_IData
->hWinMM32Instance
, uDevType
, strDevTyp
, sizeof(strDevTyp
))) {
1249 dwRet
= MCIERR_BAD_INTEGER
;
1254 if (lpParms
->lpstrDeviceType
== NULL
) {
1255 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1258 strcpy(strDevTyp
, lpParms
->lpstrDeviceType
);
1259 ptr
= strchr(strDevTyp
, '!');
1261 /* this behavior is not documented in windows. However, since, in
1262 * some occasions, MCI_OPEN handling is translated by WinMM into
1263 * a call to mciSendString("open <type>"); this code shall be correct
1265 if (dwParam
& MCI_OPEN_ELEMENT
) {
1266 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1267 lpParms
->lpstrElementName
, strDevTyp
);
1268 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1271 dwParam
|= MCI_OPEN_ELEMENT
;
1273 /* FIXME: not a good idea to write in user supplied buffer */
1274 lpParms
->lpstrElementName
= ptr
;
1278 TRACE("devType='%s' !\n", strDevTyp
);
1281 if (dwParam
& MCI_OPEN_ELEMENT
) {
1282 TRACE("lpstrElementName='%s'\n", lpParms
->lpstrElementName
);
1284 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1285 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1286 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1290 if (!lpParms
->lpstrElementName
) {
1291 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1295 /* type, if given as a parameter, supersedes file extension */
1296 if (!strDevTyp
[0] &&
1297 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1298 strDevTyp
, sizeof(strDevTyp
))) {
1299 if (GetDriveTypeA(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1300 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1303 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1304 strcpy(strDevTyp
, "CDAUDIO");
1308 if (strDevTyp
[0] == 0) {
1309 FIXME("Couldn't load driver\n");
1310 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1314 if (dwParam
& MCI_OPEN_ALIAS
) {
1315 TRACE("Alias='%s' !\n", lpParms
->lpstrAlias
);
1316 if (!lpParms
->lpstrAlias
) {
1317 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1322 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1326 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1327 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet
);
1328 /* FIXME: is dwRet the correct ret code ? */
1332 /* only handled devices fall through */
1333 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1335 if (dwParam
& MCI_NOTIFY
)
1336 mciDriverNotify(lpParms
->dwCallback
, wmd
->wDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1340 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1342 if (dwParam
& MCI_NOTIFY
)
1343 mciDriverNotify(lpParms
->dwCallback
, 0, MCI_NOTIFY_FAILURE
);
1347 /**************************************************************************
1348 * MCI_Close [internal]
1350 static DWORD
MCI_Close(UINT16 wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1353 LPWINE_MCIDRIVER wmd
;
1355 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwParam
, lpParms
);
1357 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1358 LPWINE_MCIDRIVER next
;
1360 EnterCriticalSection(&WINMM_IData
->cs
);
1361 /* FIXME: shall I notify once after all is done, or for
1362 * each of the open drivers ? if the latest, which notif
1363 * to return when only one fails ?
1365 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; ) {
1367 MCI_Close(wmd
->wDeviceID
, dwParam
, lpParms
);
1370 LeaveCriticalSection(&WINMM_IData
->cs
);
1374 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1375 return MCIERR_INVALID_DEVICE_ID
;
1378 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD
)lpParms
);
1380 MCI_UnLoadMciDriver(wmd
);
1382 if (dwParam
& MCI_NOTIFY
)
1383 mciDriverNotify(lpParms
->dwCallback
, wDevID
,
1384 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1389 /**************************************************************************
1390 * MCI_WriteString [internal]
1392 DWORD
MCI_WriteString(LPSTR lpDstStr
, DWORD dstSize
, LPCSTR lpSrcStr
)
1397 if (dstSize
<= strlen(lpSrcStr
)) {
1398 lstrcpynA(lpDstStr
, lpSrcStr
, dstSize
- 1);
1399 ret
= MCIERR_PARAM_OVERFLOW
;
1401 strcpy(lpDstStr
, lpSrcStr
);
1409 /**************************************************************************
1410 * MCI_Sysinfo [internal]
1412 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSA lpParms
)
1414 DWORD ret
= MCIERR_INVALID_DEVICE_ID
;
1415 LPWINE_MCIDRIVER wmd
;
1417 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1419 TRACE("(%08x, %08lX, %08lX[num=%ld, wDevTyp=%u])\n",
1420 uDevID
, dwFlags
, (DWORD
)lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1422 switch (dwFlags
& ~MCI_SYSINFO_OPEN
) {
1423 case MCI_SYSINFO_QUANTITY
:
1427 if (lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
||
1428 lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
) {
1429 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1430 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1431 EnterCriticalSection(&WINMM_IData
->cs
);
1432 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1435 LeaveCriticalSection(&WINMM_IData
->cs
);
1437 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1438 cnt
= MCI_InstalledCount
;
1441 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1442 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n",
1443 lpParms
->wDeviceType
);
1444 EnterCriticalSection(&WINMM_IData
->cs
);
1445 for (wmd
= WINMM_IData
->lpMciDrvs
; wmd
; wmd
= wmd
->lpNext
) {
1446 if (wmd
->wType
== lpParms
->wDeviceType
)
1449 LeaveCriticalSection(&WINMM_IData
->cs
);
1451 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n",
1452 lpParms
->wDeviceType
);
1453 FIXME("Don't know how to get # of MCI devices of a given type\n");
1457 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1459 TRACE("(%ld) => '%ld'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1460 ret
= MCI_INTEGER_RETURNED
;
1462 case MCI_SYSINFO_INSTALLNAME
:
1463 TRACE("MCI_SYSINFO_INSTALLNAME \n");
1464 if ((wmd
= MCI_GetDriver(uDevID
))) {
1465 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1466 wmd
->lpstrDeviceType
);
1468 *lpParms
->lpstrReturn
= 0;
1469 ret
= MCIERR_INVALID_DEVICE_ID
;
1471 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1473 case MCI_SYSINFO_NAME
:
1474 TRACE("MCI_SYSINFO_NAME\n");
1475 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1476 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1477 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1478 } else if (lpParms
->dwNumber
> MCI_InstalledCount
) {
1479 ret
= MCIERR_OUTOFRANGE
;
1481 DWORD count
= lpParms
->dwNumber
;
1482 LPSTR ptr
= MCI_lpInstallNames
;
1484 while (--count
> 0) ptr
+= strlen(ptr
) + 1;
1485 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, ptr
);
1487 TRACE("(%ld) => '%s'\n", lpParms
->dwNumber
, lpParms
->lpstrReturn
);
1490 TRACE("Unsupported flag value=%08lx\n", dwFlags
);
1491 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1496 /**************************************************************************
1497 * MCI_Break [internal]
1499 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1503 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1505 if (dwFlags
& MCI_NOTIFY
)
1506 mciDriverNotify(lpParms
->dwCallback
, wDevID
,
1507 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1512 /**************************************************************************
1513 * MCI_SendCommand [internal]
1515 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD dwParam1
,
1516 DWORD dwParam2
, BOOL bFrom32
)
1518 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1523 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1524 } else if (pFnMciMapMsg16To32A
) {
1525 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1527 case WINMM_MAP_OKMEM
:
1528 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1529 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1531 default: break; /* so that gcc does not bark */
1537 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1538 } else if (pFnMciMapMsg16To32A
) {
1539 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1541 case WINMM_MAP_OKMEM
:
1542 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1543 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1545 default: break; /* so that gcc does not bark */
1551 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1552 } else if (pFnMciMapMsg16To32A
) {
1553 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1555 case WINMM_MAP_OKMEM
:
1556 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1557 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1559 default: break; /* so that gcc doesnot bark */
1565 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1566 } else if (pFnMciMapMsg16To32A
) {
1567 switch (pFnMciMapMsg16To32A(0, wMsg
, &dwParam2
)) {
1569 case WINMM_MAP_OKMEM
:
1570 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1571 pFnMciUnMapMsg16To32A(0, wMsg
, dwParam2
);
1573 default: break; /* so that gcc does not bark */
1578 /* FIXME: it seems that MCI_SOUND needs the same handling as MCI_BREAK
1579 * but I couldn't get any doc on this MCI message
1583 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1584 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1585 dwRet
= MCIERR_CANNOT_USE_ALL
;
1588 MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
) :
1589 MCI_SendCommandFrom16(wDevID
, wMsg
, dwParam1
, dwParam2
);
1596 /**************************************************************************
1597 * MCI_CleanUp [internal]
1599 * Some MCI commands need to be cleaned-up (when not called from
1600 * mciSendString), because MCI drivers return extra information for string
1601 * transformation. This function gets rid of them.
1603 LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD dwParam2
)
1606 return LOWORD(dwRet
);
1609 case MCI_GETDEVCAPS
:
1610 switch (dwRet
& 0xFFFF0000ul
) {
1612 case MCI_COLONIZED3_RETURN
:
1613 case MCI_COLONIZED4_RETURN
:
1614 case MCI_INTEGER_RETURNED
:
1617 case MCI_RESOURCE_RETURNED
:
1618 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1620 LPMCI_GETDEVCAPS_PARMS lmgp
;
1622 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)(void*)dwParam2
;
1623 TRACE("Changing %08lx to %08lx\n", lmgp
->dwReturn
, (DWORD
)LOWORD(lmgp
->dwReturn
));
1624 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
1628 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1629 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1633 switch (dwRet
& 0xFFFF0000ul
) {
1635 case MCI_COLONIZED3_RETURN
:
1636 case MCI_COLONIZED4_RETURN
:
1637 case MCI_INTEGER_RETURNED
:
1640 case MCI_RESOURCE_RETURNED
:
1641 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1643 LPMCI_STATUS_PARMS lsp
;
1645 lsp
= (LPMCI_STATUS_PARMS
)(void*)dwParam2
;
1646 TRACE("Changing %08lx to %08lx\n", lsp
->dwReturn
, (DWORD
)LOWORD(lsp
->dwReturn
));
1647 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
1651 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1652 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1656 switch (dwRet
& 0xFFFF0000ul
) {
1658 case MCI_INTEGER_RETURNED
:
1662 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
1666 if (HIWORD(dwRet
)) {
1667 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1668 dwRet
, MCI_MessageToString(wMsg
));
1672 return LOWORD(dwRet
);
1675 /**************************************************************************
1676 * MCI_Init [internal]
1678 * Initializes the MCI internal variables.
1690 MCI_InstalledCount
= 0;
1691 ptr1
= MCI_lpInstallNames
= HeapAlloc(GetProcessHeap(), 0, count
);
1693 if (!MCI_lpInstallNames
)
1696 /* FIXME: should do also some registry diving here ? */
1697 if (!(err
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config", &hWineConf
)) &&
1698 !(err
= RegOpenKeyA(hWineConf
, "options", &hkey
))) {
1699 err
= RegQueryValueExA(hkey
, "mci", 0, &type
, MCI_lpInstallNames
, &count
);
1704 TRACE("Wine => '%s' \n", ptr1
);
1705 while ((ptr2
= strchr(ptr1
, ':')) != 0) {
1707 TRACE("---> '%s' \n", ptr1
);
1708 MCI_InstalledCount
++;
1711 MCI_InstalledCount
++;
1712 TRACE("---> '%s' \n", ptr1
);
1713 ptr1
+= strlen(ptr1
) + 1;
1715 GetPrivateProfileStringA("mci", NULL
, "", MCI_lpInstallNames
, count
, "SYSTEM.INI");
1716 while (strlen(ptr1
) > 0) {
1717 TRACE("---> '%s' \n", ptr1
);
1718 ptr1
+= strlen(ptr1
) + 1;
1719 MCI_InstalledCount
++;
1722 RegCloseKey(hWineConf
);