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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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)
34 * - implement automatic open
35 * + only works on string interface, on regular devices (don't work on all
37 * - command table handling isn't thread safe
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
61 /* First MCI valid device ID (0 means error) */
62 #define MCI_MAGIC 0x0001
65 static const WCHAR wszHklmMci
[] = L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\MCI";
67 static WINE_MCIDRIVER
*MciDrivers
;
69 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
);
70 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
);
72 /* dup a string and uppercase it */
73 static inline LPWSTR
str_dup_upper( LPCWSTR str
)
75 WCHAR
*p
= wcsdup( str
);
76 if (p
) CharUpperW( p
);
80 /**************************************************************************
81 * MCI_GetDriver [internal]
83 static LPWINE_MCIDRIVER
MCI_GetDriver(UINT wDevID
)
85 LPWINE_MCIDRIVER wmd
= 0;
87 EnterCriticalSection(&WINMM_cs
);
88 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
89 if (wmd
->wDeviceID
== wDevID
)
92 LeaveCriticalSection(&WINMM_cs
);
96 /**************************************************************************
97 * MCI_GetDriverFromString [internal]
99 static UINT
MCI_GetDriverFromString(LPCWSTR lpstrName
)
101 LPWINE_MCIDRIVER wmd
;
107 if (!wcsicmp(lpstrName
, L
"ALL"))
108 return MCI_ALL_DEVICE_ID
;
110 EnterCriticalSection(&WINMM_cs
);
111 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
112 if (wmd
->lpstrAlias
&& wcsicmp(wmd
->lpstrAlias
, lpstrName
) == 0) {
113 ret
= wmd
->wDeviceID
;
117 LeaveCriticalSection(&WINMM_cs
);
122 /**************************************************************************
123 * MCI_MessageToString [internal]
125 static const char* MCI_MessageToString(UINT wMsg
)
127 #define CASE(s) case (s): return #s
137 CASE(DRV_QUERYCONFIGURE
);
140 CASE(DRV_EXITSESSION
);
141 CASE(DRV_EXITAPPLICATION
);
145 CASE(MCI_CLOSE_DRIVER
);
154 CASE(MCI_GETDEVCAPS
);
158 CASE(MCI_OPEN_DRIVER
);
177 /* constants for digital video */
191 return wine_dbg_sprintf("MCI_<<%04X>>", wMsg
);
195 static LPWSTR
MCI_strdupAtoW( LPCSTR str
)
200 if (!str
) return NULL
;
201 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
202 ret
= malloc( len
* sizeof(WCHAR
) );
203 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
207 static int MCI_MapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR
*dwParam2
)
209 if (msg
< DRV_RESERVED
) return 0;
244 { /* MCI_ANIM_OPEN_PARMS is the largest known MCI_OPEN_PARMS
245 * structure, larger than MCI_WAVE_OPEN_PARMS */
246 MCI_ANIM_OPEN_PARMSA
*mci_openA
= (MCI_ANIM_OPEN_PARMSA
*)*dwParam2
;
247 MCI_ANIM_OPEN_PARMSW
*mci_openW
;
250 ptr
= malloc(sizeof(DWORD_PTR
) + sizeof(*mci_openW
));
253 *ptr
++ = *dwParam2
; /* save the previous pointer */
254 *dwParam2
= (DWORD_PTR
)ptr
;
255 mci_openW
= (MCI_ANIM_OPEN_PARMSW
*)ptr
;
257 if (dwParam1
& MCI_NOTIFY
)
258 mci_openW
->dwCallback
= mci_openA
->dwCallback
;
260 if (dwParam1
& MCI_OPEN_TYPE
)
262 if (dwParam1
& MCI_OPEN_TYPE_ID
)
263 mci_openW
->lpstrDeviceType
= (LPCWSTR
)mci_openA
->lpstrDeviceType
;
265 mci_openW
->lpstrDeviceType
= MCI_strdupAtoW(mci_openA
->lpstrDeviceType
);
267 if (dwParam1
& MCI_OPEN_ELEMENT
)
269 if (dwParam1
& MCI_OPEN_ELEMENT_ID
)
270 mci_openW
->lpstrElementName
= (LPCWSTR
)mci_openA
->lpstrElementName
;
272 mci_openW
->lpstrElementName
= MCI_strdupAtoW(mci_openA
->lpstrElementName
);
274 if (dwParam1
& MCI_OPEN_ALIAS
)
275 mci_openW
->lpstrAlias
= MCI_strdupAtoW(mci_openA
->lpstrAlias
);
276 /* We don't know how many DWORD follow, as
277 * the structure depends on the device. */
278 if (HIWORD(dwParam1
))
279 memcpy(&mci_openW
->dwStyle
, &mci_openA
->dwStyle
, sizeof(MCI_ANIM_OPEN_PARMSW
) - sizeof(MCI_OPEN_PARMSW
));
284 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
286 MCI_ANIM_WINDOW_PARMSA
*mci_windowA
= (MCI_ANIM_WINDOW_PARMSA
*)*dwParam2
;
287 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
;
289 mci_windowW
= malloc(sizeof(*mci_windowW
));
290 if (!mci_windowW
) return -1;
292 *dwParam2
= (DWORD_PTR
)mci_windowW
;
294 mci_windowW
->lpstrText
= MCI_strdupAtoW(mci_windowA
->lpstrText
);
296 if (dwParam1
& MCI_NOTIFY
)
297 mci_windowW
->dwCallback
= mci_windowA
->dwCallback
;
298 if (dwParam1
& MCI_ANIM_WINDOW_HWND
)
299 mci_windowW
->hWnd
= mci_windowA
->hWnd
;
300 if (dwParam1
& MCI_ANIM_WINDOW_STATE
)
301 mci_windowW
->nCmdShow
= mci_windowA
->nCmdShow
;
308 if (dwParam1
& (MCI_SYSINFO_INSTALLNAME
| MCI_SYSINFO_NAME
))
310 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*dwParam2
;
311 MCI_SYSINFO_PARMSW
*mci_sysinfoW
;
314 ptr
= malloc(sizeof(*mci_sysinfoW
) + sizeof(DWORD_PTR
));
317 *ptr
++ = *dwParam2
; /* save the previous pointer */
318 *dwParam2
= (DWORD_PTR
)ptr
;
319 mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)ptr
;
321 if (dwParam1
& MCI_NOTIFY
)
322 mci_sysinfoW
->dwCallback
= mci_sysinfoA
->dwCallback
;
324 /* Size is measured in numbers of characters, despite what MSDN says. */
325 mci_sysinfoW
->dwRetSize
= mci_sysinfoA
->dwRetSize
;
326 mci_sysinfoW
->lpstrReturn
= malloc(mci_sysinfoW
->dwRetSize
* sizeof(WCHAR
));
327 mci_sysinfoW
->dwNumber
= mci_sysinfoA
->dwNumber
;
328 mci_sysinfoW
->wDeviceType
= mci_sysinfoA
->wDeviceType
;
334 MCI_DGV_INFO_PARMSA
*mci_infoA
= (MCI_DGV_INFO_PARMSA
*)*dwParam2
;
335 MCI_DGV_INFO_PARMSW
*mci_infoW
;
338 ptr
= malloc(sizeof(*mci_infoW
) + sizeof(DWORD_PTR
));
341 *ptr
++ = *dwParam2
; /* save the previous pointer */
342 *dwParam2
= (DWORD_PTR
)ptr
;
343 mci_infoW
= (MCI_DGV_INFO_PARMSW
*)ptr
;
345 if (dwParam1
& MCI_NOTIFY
)
346 mci_infoW
->dwCallback
= mci_infoA
->dwCallback
;
348 /* Size is measured in numbers of characters. */
349 mci_infoW
->dwRetSize
= mci_infoA
->dwRetSize
;
350 mci_infoW
->lpstrReturn
= malloc(mci_infoW
->dwRetSize
* sizeof(WCHAR
));
351 if (dwParam1
& MCI_DGV_INFO_ITEM
)
352 mci_infoW
->dwItem
= mci_infoA
->dwItem
;
359 { /* All these commands have the same layout: callback + string + optional rect */
360 MCI_OVLY_LOAD_PARMSA
*mci_loadA
= (MCI_OVLY_LOAD_PARMSA
*)*dwParam2
;
361 MCI_OVLY_LOAD_PARMSW
*mci_loadW
;
363 mci_loadW
= malloc(sizeof(*mci_loadW
));
364 if (!mci_loadW
) return -1;
366 *dwParam2
= (DWORD_PTR
)mci_loadW
;
367 if (dwParam1
& MCI_NOTIFY
)
368 mci_loadW
->dwCallback
= mci_loadA
->dwCallback
;
369 mci_loadW
->lpfilename
= MCI_strdupAtoW(mci_loadA
->lpfilename
);
370 if ((MCI_SAVE
== msg
&& dwParam1
& MCI_DGV_RECT
) ||
371 (MCI_LOAD
== msg
&& dwParam1
& MCI_OVLY_RECT
) ||
372 (MCI_CAPTURE
== msg
&& dwParam1
& MCI_DGV_CAPTURE_AT
) ||
373 (MCI_RESTORE
== msg
&& dwParam1
& MCI_DGV_RESTORE_AT
))
374 mci_loadW
->rc
= mci_loadA
->rc
;
379 { /* All these commands have the same layout: callback + string */
380 MCI_VD_ESCAPE_PARMSA
*mci_vd_escapeA
= (MCI_VD_ESCAPE_PARMSA
*)*dwParam2
;
381 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
;
383 mci_vd_escapeW
= malloc(sizeof(*mci_vd_escapeW
));
384 if (!mci_vd_escapeW
) return -1;
386 *dwParam2
= (DWORD_PTR
)mci_vd_escapeW
;
387 if (dwParam1
& MCI_NOTIFY
)
388 mci_vd_escapeW
->dwCallback
= mci_vd_escapeA
->dwCallback
;
389 mci_vd_escapeW
->lpstrCommand
= MCI_strdupAtoW(mci_vd_escapeA
->lpstrCommand
);
394 if (!(dwParam1
& (MCI_DGV_SETVIDEO_QUALITY
| MCI_DGV_SETVIDEO_ALG
395 | MCI_DGV_SETAUDIO_QUALITY
| MCI_DGV_SETAUDIO_ALG
)))
397 /* fall through to default */
402 FIXME("Message %s needs translation\n", MCI_MessageToString(msg
));
403 return 0; /* pass through untouched */
407 static void MCI_UnmapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
,
414 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
415 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*ptr
;
416 MCI_OPEN_PARMSW
*mci_openW
= (MCI_OPEN_PARMSW
*)dwParam2
;
418 mci_openA
->wDeviceID
= mci_openW
->wDeviceID
;
420 if (dwParam1
& MCI_OPEN_TYPE
)
422 if (!(dwParam1
& MCI_OPEN_TYPE_ID
))
423 free((WCHAR
*)mci_openW
->lpstrDeviceType
);
425 if (dwParam1
& MCI_OPEN_ELEMENT
)
427 if (!(dwParam1
& MCI_OPEN_ELEMENT_ID
))
428 free((WCHAR
*)mci_openW
->lpstrElementName
);
430 if (dwParam1
& MCI_OPEN_ALIAS
)
431 free((WCHAR
*)mci_openW
->lpstrAlias
);
436 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
438 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
= (MCI_ANIM_WINDOW_PARMSW
*)dwParam2
;
440 free((void *)mci_windowW
->lpstrText
);
446 if (dwParam1
& (MCI_SYSINFO_INSTALLNAME
| MCI_SYSINFO_NAME
))
448 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
449 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*ptr
;
450 MCI_SYSINFO_PARMSW
*mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)dwParam2
;
454 WideCharToMultiByte(CP_ACP
, 0,
455 mci_sysinfoW
->lpstrReturn
, -1,
456 mci_sysinfoA
->lpstrReturn
, mci_sysinfoA
->dwRetSize
,
460 free(mci_sysinfoW
->lpstrReturn
);
466 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
467 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*ptr
;
468 MCI_INFO_PARMSW
*mci_infoW
= (MCI_INFO_PARMSW
*)dwParam2
;
472 WideCharToMultiByte(CP_ACP
, 0,
473 mci_infoW
->lpstrReturn
, -1,
474 mci_infoA
->lpstrReturn
, mci_infoA
->dwRetSize
,
478 free(mci_infoW
->lpstrReturn
);
486 { /* All these commands have the same layout: callback + string + optional rect */
487 MCI_OVLY_LOAD_PARMSW
*mci_loadW
= (MCI_OVLY_LOAD_PARMSW
*)dwParam2
;
489 free((void *)mci_loadW
->lpfilename
);
495 { /* All these commands have the same layout: callback + string */
496 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
= (MCI_VD_ESCAPE_PARMSW
*)dwParam2
;
498 free((void *)mci_vd_escapeW
->lpstrCommand
);
499 free(mci_vd_escapeW
);
504 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg
));
509 /**************************************************************************
510 * MCI_GetDevTypeFromFileName [internal]
512 static DWORD
MCI_GetDevTypeFromFileName(LPCWSTR fileName
, LPWSTR buf
, UINT len
)
516 if ((tmp
= wcsrchr(fileName
, '.'))) {
517 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
518 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions",
519 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
521 LONG lRet
= RegQueryValueExW( hKey
, tmp
+ 1, 0, 0, (void*)buf
, &dwLen
);
523 if (lRet
== ERROR_SUCCESS
) return 0;
525 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp
));
527 return MCIERR_EXTENSION_NOT_FOUND
;
530 /**************************************************************************
531 * MCI_GetDevTypeFromResource [internal]
533 static UINT
MCI_GetDevTypeFromResource(LPCWSTR lpstrName
)
537 for (uDevType
= MCI_DEVTYPE_FIRST
; uDevType
<= MCI_DEVTYPE_LAST
; uDevType
++) {
538 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, ARRAY_SIZE(buf
))) {
539 /* FIXME: ignore digits suffix */
540 if (!wcsicmp(buf
, lpstrName
))
547 #define MAX_MCICMDTABLE 20
548 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
550 typedef struct tagWINE_MCICMDTABLE
{
554 UINT nVerbs
; /* number of verbs in command table */
555 LPCWSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
556 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
558 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
560 /**************************************************************************
561 * MCI_IsCommandTableValid [internal]
563 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
572 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
573 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
575 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
578 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
581 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
582 flg
= *(const DWORD
*)lmem
;
583 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
584 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
586 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
588 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
589 case MCI_STRING
: if (inCst
) return FALSE
; break;
590 case MCI_HWND
: /* Occurs inside MCI_CONSTANT as in "window handle default" */
593 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
594 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
595 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
596 case MCI_FLAG
: if (!*str
) return FALSE
; break;
597 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
598 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
599 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
600 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
601 default: return FALSE
;
603 } while (eid
!= MCI_END_COMMAND_LIST
);
607 /**************************************************************************
608 * MCI_DumpCommandTable [internal]
610 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
616 if (!MCI_IsCommandTableValid(uTbl
)) {
617 ERR("Ooops: %d is not valid\n", uTbl
);
621 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
626 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
627 /* flg = *(const DWORD*)lmem; */
628 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
629 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
630 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
631 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
632 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
633 } while (eid
!= MCI_END_COMMAND_LIST
);
638 /**************************************************************************
639 * MCI_GetCommandTable [internal]
641 static UINT
MCI_GetCommandTable(UINT uDevType
)
647 /* first look up existing for existing devType */
648 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
649 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
653 /* well try to load id */
654 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
655 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, ARRAY_SIZE(buf
))) {
658 } else if (uDevType
== 0) {
661 uTbl
= MCI_NO_COMMAND_TABLE
;
663 HRSRC hRsrc
= FindResourceW(hWinMM32Instance
, str
, (LPCWSTR
)RT_RCDATA
);
666 if (hRsrc
) hMem
= LoadResource(hWinMM32Instance
, hRsrc
);
668 uTbl
= MCI_SetCommandTable(hMem
, uDevType
);
670 WARN("No command table found in resource %p[%s]\n",
671 hWinMM32Instance
, debugstr_w(str
));
674 TRACE("=> %d\n", uTbl
);
678 /**************************************************************************
679 * MCI_SetCommandTable [internal]
681 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
)
684 static BOOL bInitDone
= FALSE
;
687 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
688 * can be called with 0 as a uDevType to retrieve it.
693 MCI_GetCommandTable(0);
695 TRACE("(%p, %u)\n", hMem
, uDevType
);
696 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
697 if (!S_MciCmdTable
[uTbl
].lpTable
) {
703 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
704 S_MciCmdTable
[uTbl
].lpTable
= LockResource(hMem
);
705 S_MciCmdTable
[uTbl
].hMem
= hMem
;
708 MCI_DumpCommandTable(uTbl
);
711 /* create the verbs table */
712 /* get # of entries */
713 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
717 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
718 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
719 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
720 if (eid
== MCI_COMMAND_HEAD
)
722 } while (eid
!= MCI_END_COMMAND_LIST
);
724 S_MciCmdTable
[uTbl
].aVerbs
= malloc(count
* sizeof(const WCHAR
*));
725 S_MciCmdTable
[uTbl
].nVerbs
= count
;
727 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
731 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
732 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
733 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
734 if (eid
== MCI_COMMAND_HEAD
)
735 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
736 } while (eid
!= MCI_END_COMMAND_LIST
);
737 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
742 return MCI_NO_COMMAND_TABLE
;
745 /**************************************************************************
746 * MCI_UnLoadMciDriver [internal]
748 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
750 LPWINE_MCIDRIVER
* tmp
;
755 CloseDriver(wmd
->hDriver
, 0, 0);
757 if (wmd
->dwPrivate
!= 0)
758 WARN("Unloading mci driver with non nul dwPrivate field\n");
760 EnterCriticalSection(&WINMM_cs
);
761 for (tmp
= &MciDrivers
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
767 LeaveCriticalSection(&WINMM_cs
);
769 free(wmd
->lpstrDeviceType
);
770 free(wmd
->lpstrAlias
);
776 /**************************************************************************
777 * MCI_OpenMciDriver [internal]
779 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCWSTR drvTyp
, DWORD_PTR lp
)
783 if (!DRIVER_GetLibName(drvTyp
, L
"MCI", libName
, sizeof(libName
)))
786 /* First load driver */
787 wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
);
788 return wmd
->hDriver
!= NULL
;
791 /**************************************************************************
792 * MCI_LoadMciDriver [internal]
794 static DWORD
MCI_LoadMciDriver(LPCWSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
796 LPWSTR strDevTyp
= str_dup_upper(_strDevTyp
);
797 WINE_MCIDRIVER
* wmd
= calloc(1, sizeof(*wmd
));
798 MCI_OPEN_DRIVER_PARMSW modp
;
801 if (!wmd
|| !strDevTyp
) {
802 dwRet
= MCIERR_OUT_OF_MEMORY
;
806 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
807 wmd
->dwYieldData
= VK_CANCEL
;
808 wmd
->CreatorThread
= GetCurrentThreadId();
810 EnterCriticalSection(&WINMM_cs
);
811 /* wmd must be inserted in list before sending opening the driver, because it
812 * may want to lookup at wDevID
814 wmd
->lpNext
= MciDrivers
;
817 for (modp
.wDeviceID
= MCI_MAGIC
;
818 MCI_GetDriver(modp
.wDeviceID
) != 0;
821 wmd
->wDeviceID
= modp
.wDeviceID
;
823 LeaveCriticalSection(&WINMM_cs
);
825 TRACE("wDevID=%04X\n", modp
.wDeviceID
);
827 modp
.lpstrParams
= NULL
;
829 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (DWORD_PTR
)&modp
)) {
830 /* silence warning if all is used... some bogus program use commands like
833 if (wcsicmp(strDevTyp
, L
"ALL") == 0) {
834 dwRet
= MCIERR_CANNOT_USE_ALL
;
836 FIXME("Couldn't load driver for type %s.\n",
837 debugstr_w(strDevTyp
));
838 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
843 /* FIXME: should also check that module's description is of the form
844 * MODULENAME:[MCI] comment
847 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
848 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
849 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
851 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
852 wmd
->hDriver
, debugstr_w(strDevTyp
), modp
.wType
, modp
.wCustomCommandTable
);
854 wmd
->lpstrDeviceType
= strDevTyp
;
855 wmd
->wType
= modp
.wType
;
857 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
858 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
862 MCI_UnLoadMciDriver(wmd
);
868 /**************************************************************************
869 * MCI_SendCommandFrom32 [internal]
871 static DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
873 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
874 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
877 if(wmd
->CreatorThread
!= GetCurrentThreadId())
878 return MCIERR_INVALID_DEVICE_NAME
;
880 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
885 /**************************************************************************
886 * MCI_FinishOpen [internal]
888 * Three modes of operation:
889 * 1 open foo.ext ... -> OPEN_ELEMENT with lpstrElementName=foo.ext
890 * open sequencer!foo.ext same with lpstrElementName=foo.ext
891 * 2 open new type waveaudio -> OPEN_ELEMENT with empty ("") lpstrElementName
892 * 3 open sequencer -> OPEN_ELEMENT unset, and
893 * capability sequencer (auto-open) likewise
895 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSW lpParms
,
898 LPCWSTR alias
= NULL
;
899 /* Open always defines an alias for further reference */
900 if (dwParam
& MCI_OPEN_ALIAS
) { /* open ... alias */
901 alias
= lpParms
->lpstrAlias
;
902 if (MCI_GetDriverFromString(alias
))
903 return MCIERR_DUPLICATE_ALIAS
;
905 if ((dwParam
& MCI_OPEN_ELEMENT
) /* open file.wav */
906 && !(dwParam
& MCI_OPEN_ELEMENT_ID
))
907 alias
= lpParms
->lpstrElementName
;
908 else if (dwParam
& MCI_OPEN_TYPE
) /* open cdaudio */
909 alias
= wmd
->lpstrDeviceType
;
910 if (alias
&& MCI_GetDriverFromString(alias
))
911 return MCIERR_DEVICE_OPEN
;
914 wmd
->lpstrAlias
= wcsdup(alias
);
915 if (!wmd
->lpstrAlias
) return MCIERR_OUT_OF_MEMORY
;
916 /* In most cases, natives adds MCI_OPEN_ALIAS to the flags passed to the driver.
917 * Don't. The drivers don't care about the winmm alias. */
919 lpParms
->wDeviceID
= wmd
->wDeviceID
;
921 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
925 /**************************************************************************
926 * MCI_FindCommand [internal]
928 static LPCWSTR
MCI_FindCommand(UINT uTbl
, LPCWSTR verb
)
932 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
935 /* another improvement would be to have the aVerbs array sorted,
936 * so that we could use a dichotomic search on it, rather than this dumb
939 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
940 if (wcsicmp(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
941 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
947 /**************************************************************************
948 * MCI_GetReturnType [internal]
950 static DWORD
MCI_GetReturnType(LPCWSTR lpCmd
)
952 lpCmd
= (LPCWSTR
)((const BYTE
*)(lpCmd
+ lstrlenW(lpCmd
) + 1) + sizeof(DWORD
) + sizeof(WORD
));
953 if (*lpCmd
== '\0' && *(const WORD
*)((const BYTE
*)(lpCmd
+ 1) + sizeof(DWORD
)) == MCI_RETURN
) {
954 return *(const DWORD
*)(lpCmd
+ 1);
959 /**************************************************************************
960 * MCI_GetMessage [internal]
962 static WORD
MCI_GetMessage(LPCWSTR lpCmd
)
964 return (WORD
)*(const DWORD
*)(lpCmd
+ lstrlenW(lpCmd
) + 1);
967 /**************************************************************************
968 * MCI_GetDWord [internal]
970 * Accept 0 -1 255 255:0 255:255:255:255 :::1 1::: 2::3 ::4: 12345678
971 * Refuse -1:0 0:-1 :: 256:0 1:256 0::::1
973 static BOOL
MCI_GetDWord(DWORD
* data
, LPWSTR
* ptr
)
976 DWORD total
= 0, shift
= 0;
977 BOOL sign
= FALSE
, digits
= FALSE
;
979 while (*ret
== ' ' || *ret
== '\t') ret
++;
986 while ('0' <= *ret
&& *ret
<= '9') {
987 val
= *ret
++ - '0' + 10 * val
;
993 case ' ': ret
++; break;
994 default: return FALSE
;
996 if ((val
>= 256) || (shift
>= 24)) return FALSE
;
997 total
|= val
<< shift
;
1003 if (!digits
) return FALSE
;
1004 if (shift
&& (val
>= 256 || sign
)) return FALSE
;
1005 total
|= val
<< shift
;
1006 *data
= sign
? -total
: total
;
1012 /**************************************************************************
1013 * MCI_GetString [internal]
1015 static DWORD
MCI_GetString(LPWSTR
* str
, LPWSTR
* args
)
1019 /* see if we have a quoted string */
1021 ptr
= wcschr(*str
= ptr
+ 1, '"');
1022 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
1023 /* FIXME: shall we escape \" from string ?? */
1024 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1025 *ptr
++ = '\0'; /* remove trailing " */
1026 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
1028 ptr
= wcschr(ptr
, ' ');
1033 ptr
= *args
+ lstrlenW(*args
);
1042 #define MCI_DATA_SIZE 16
1044 /**************************************************************************
1045 * MCI_ParseOptArgs [internal]
1047 static DWORD
MCI_ParseOptArgs(DWORD
* data
, int _offset
, LPCWSTR lpCmd
,
1048 LPWSTR args
, LPDWORD dwFlags
)
1053 DWORD dwRet
, flg
, cflg
= 0;
1057 /* loop on arguments */
1059 lmem
= (const char*)lpCmd
;
1060 found
= inCst
= FALSE
;
1063 /* skip any leading white space(s) */
1064 while (*args
== ' ') args
++;
1065 TRACE("args=%s\n", debugstr_w(args
));
1067 do { /* loop on options for command table for the requested verb */
1068 str
= (LPCWSTR
)lmem
;
1069 lmem
+= ((len
= lstrlenW(str
)) + 1) * sizeof(WCHAR
);
1070 flg
= *(const DWORD
*)lmem
;
1071 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
1072 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
1073 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1077 inCst
= TRUE
; cflg
= flg
; break;
1078 case MCI_END_CONSTANT
:
1079 /* there may be additional integral values after flag in constant */
1080 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
1083 inCst
= FALSE
; cflg
= 0;
1086 if (offset
!= _offset
) {
1087 FIXME("MCI_RETURN not in first position\n");
1088 return MCIERR_PARSER_INTERNAL
;
1092 if (wcsnicmp(args
, str
, len
) == 0 &&
1093 ((eid
== MCI_STRING
&& len
== 0) || args
[len
] == 0 || args
[len
] == ' ')) {
1094 /* store good values into data[] */
1096 while (*args
== ' ') args
++;
1100 case MCI_COMMAND_HEAD
:
1102 case MCI_END_COMMAND
:
1103 case MCI_END_COMMAND_LIST
:
1104 case MCI_CONSTANT
: /* done above */
1105 case MCI_END_CONSTANT
: /* done above */
1109 TRACE("flag=%08lx\n", flg
);
1116 data
[offset
] |= flg
;
1119 TRACE("flag=%08lx constant=%08lx\n", cflg
, flg
);
1122 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
1123 return MCIERR_BAD_INTEGER
;
1125 TRACE("flag=%08lx int=%ld\n", flg
, data
[offset
]);
1129 /* store rect in data (offset..offset+3) */
1131 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
1132 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
1133 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
1134 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
1135 return MCIERR_BAD_INTEGER
;
1137 TRACE("flag=%08lx for rectangle\n", flg
);
1141 if ((dwRet
= MCI_GetString((LPWSTR
*)&data
[offset
], &args
)))
1143 TRACE("flag=%08lx string=%s\n", flg
, debugstr_w(*(LPWSTR
*)&data
[offset
]));
1145 default: ERR("oops\n");
1147 /* exit inside while loop, except if just entered in constant area definition */
1148 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
1150 /* have offset incremented if needed */
1152 case MCI_COMMAND_HEAD
:
1154 case MCI_END_COMMAND
:
1155 case MCI_END_COMMAND_LIST
:
1157 case MCI_FLAG
: break;
1160 case MCI_HDC
: if (!inCst
) offset
+= sizeof(HANDLE
)/sizeof(DWORD
); break;
1161 case MCI_INTEGER
: if (!inCst
) offset
++; break;
1162 case MCI_END_CONSTANT
: offset
++; break;
1163 case MCI_STRING
: offset
+= sizeof(LPWSTR
)/sizeof(DWORD
); break;
1164 case MCI_RECT
: offset
+= 4; break;
1165 default: ERR("oops\n");
1168 } while (eid
!= MCI_END_COMMAND
);
1170 WARN("Optarg %s not found\n", debugstr_w(args
));
1171 return MCIERR_UNRECOGNIZED_COMMAND
;
1173 if (offset
== MCI_DATA_SIZE
) {
1174 FIXME("Internal data[] buffer overflow\n");
1175 return MCIERR_PARSER_INTERNAL
;
1181 /**************************************************************************
1182 * MCI_HandleReturnValues [internal]
1184 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
1185 MCI_GENERIC_PARMS
*params
, LPWSTR lpstrRet
, UINT uRetLen
)
1189 case 0: /* nothing to return */
1193 DWORD data
= *(DWORD
*)(params
+ 1);
1194 switch (dwRet
& 0xFFFF0000ul
) {
1196 case MCI_INTEGER_RETURNED
:
1197 swprintf(lpstrRet
, uRetLen
, L
"%d", data
);
1199 case MCI_RESOURCE_RETURNED
:
1200 /* return string which ID is HIWORD(data),
1201 * string is loaded from mmsystem.dll */
1202 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1204 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1205 /* return string which ID is HIWORD(data),
1206 * string is loaded from driver */
1207 /* FIXME: this is wrong for a 16 bit handle */
1208 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1209 HIWORD(data
), lpstrRet
, uRetLen
);
1211 case MCI_COLONIZED3_RETURN
:
1212 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d",
1213 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1214 LOBYTE(HIWORD(data
)));
1216 case MCI_COLONIZED4_RETURN
:
1217 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d:%02d",
1218 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1219 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1221 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1225 case 13: /* MCI_INTEGER64 */
1227 DWORD_PTR data
= *(DWORD_PTR
*)(params
+ 1);
1228 switch (dwRet
& 0xFFFF0000ul
) {
1230 case MCI_INTEGER_RETURNED
:
1231 swprintf(lpstrRet
, uRetLen
, L
"%ld", data
);
1233 case MCI_RESOURCE_RETURNED
:
1234 /* return string which ID is HIWORD(data),
1235 * string is loaded from mmsystem.dll */
1236 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1238 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1239 /* return string which ID is HIWORD(data),
1240 * string is loaded from driver */
1241 /* FIXME: this is wrong for a 16 bit handle */
1242 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1243 HIWORD(data
), lpstrRet
, uRetLen
);
1245 case MCI_COLONIZED3_RETURN
:
1246 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d",
1247 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1248 LOBYTE(HIWORD(data
)));
1250 case MCI_COLONIZED4_RETURN
:
1251 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d:%02d",
1252 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1253 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1255 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1260 switch (dwRet
& 0xFFFF0000ul
) {
1262 /* nothing to do data[0] == lpstrRet */
1264 case MCI_INTEGER_RETURNED
:
1266 DWORD
*data
= (DWORD
*)(params
+ 1);
1267 *data
= *(LPDWORD
)lpstrRet
;
1268 swprintf(lpstrRet
, uRetLen
, L
"%d", *data
);
1272 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1278 DWORD
*data
= (DWORD
*)(params
+ 1);
1279 if (dwRet
& 0xFFFF0000ul
)
1280 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1281 swprintf(lpstrRet
, uRetLen
, L
"%d %d %d %d", data
[0], data
[1], data
[2], data
[3]);
1284 default: FIXME("Unknown MCI return type %ld\n", retType
);
1287 return LOWORD(dwRet
);
1290 /**************************************************************************
1291 * mciSendStringW [WINMM.@]
1293 DWORD WINAPI
mciSendStringW(LPCWSTR lpstrCommand
, LPWSTR lpstrRet
,
1294 UINT uRetLen
, HWND hwndCallback
)
1296 LPWSTR verb
, dev
, args
, devType
= NULL
;
1297 LPWINE_MCIDRIVER wmd
= 0;
1298 MCIDEVICEID uDevID
, auto_open
= 0;
1299 DWORD dwFlags
= 0, dwRet
= 0;
1306 MCI_GENERIC_PARMS generic
;
1307 MCI_OPEN_PARMSW open
;
1308 MCI_SOUND_PARMSW sound
;
1309 MCI_SYSINFO_PARMSW sysinfo
;
1310 DWORD dw
[MCI_DATA_SIZE
];
1313 TRACE("(%s, %p, %d, %p)\n",
1314 debugstr_w(lpstrCommand
), lpstrRet
, uRetLen
, hwndCallback
);
1315 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1317 if (!lpstrCommand
[0])
1318 return MCIERR_MISSING_COMMAND_STRING
;
1320 /* format is <command> <device> <optargs> */
1321 if (!(verb
= wcsdup(lpstrCommand
)))
1322 return MCIERR_OUT_OF_MEMORY
;
1325 memset(&data
, 0, sizeof(data
));
1327 if (!(args
= wcschr(verb
, ' '))) {
1328 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1332 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
1335 uDevID
= wcsicmp(dev
, L
"ALL") ? 0 : MCI_ALL_DEVICE_ID
;
1337 /* Determine devType from open */
1338 if (!wcscmp(verb
, L
"open")) {
1342 /* case dev == 'new' has to be handled */
1343 if (!wcscmp(dev
, L
"new")) {
1345 if ((devType
= wcsstr(args
, L
"type ")) != NULL
) {
1347 tmp
= wcschr(devType
, ' ');
1348 if (tmp
) *tmp
= '\0';
1349 devType
= str_dup_upper(devType
);
1350 if (tmp
) *tmp
= ' ';
1351 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1353 WARN("open new requires device type\n");
1354 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1357 dwFlags
|= MCI_OPEN_ELEMENT
;
1358 data
.open
.lpstrElementName
= &L
""[0];
1359 } else if ((devType
= wcschr(dev
, '!')) != NULL
) {
1361 tmp
= devType
; devType
= dev
; dev
= tmp
;
1363 dwFlags
|= MCI_OPEN_TYPE
;
1364 data
.open
.lpstrDeviceType
= devType
;
1365 devType
= str_dup_upper(devType
);
1366 dwFlags
|= MCI_OPEN_ELEMENT
;
1367 data
.open
.lpstrElementName
= dev
;
1368 } else if (DRIVER_GetLibName(dev
, L
"MCI", buf
, sizeof(buf
))) {
1369 /* this is the name of a mci driver's type */
1370 tmp
= wcschr(dev
, ' ');
1371 if (tmp
) *tmp
= '\0';
1372 data
.open
.lpstrDeviceType
= dev
;
1373 devType
= str_dup_upper(dev
);
1374 if (tmp
) *tmp
= ' ';
1375 dwFlags
|= MCI_OPEN_TYPE
;
1377 if ((devType
= wcsstr(args
, L
"type ")) != NULL
) {
1379 tmp
= wcschr(devType
, ' ');
1380 if (tmp
) *tmp
= '\0';
1381 devType
= str_dup_upper(devType
);
1382 if (tmp
) *tmp
= ' ';
1383 /* dwFlags and lpstrDeviceType will be correctly set in ParseOpt loop */
1385 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
1388 devType
= str_dup_upper(buf
);
1390 dwFlags
|= MCI_OPEN_ELEMENT
;
1391 data
.open
.lpstrElementName
= dev
;
1393 if (MCI_ALL_DEVICE_ID
== uDevID
) {
1394 dwRet
= MCIERR_CANNOT_USE_ALL
;
1397 if (!wcsstr(args
, L
" alias ") && !dev
) {
1398 dwRet
= MCIERR_NEW_REQUIRES_ALIAS
;
1402 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
1403 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
1404 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1407 } else if ((MCI_ALL_DEVICE_ID
!= uDevID
) && !(wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
)))
1408 && (lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
))) {
1409 /* auto-open uses the core command table */
1410 switch (MCI_GetMessage(lpCmd
)) {
1411 case MCI_SOUND
: /* command does not use a device name */
1414 case MCI_CLOSE
: /* don't auto-open for close */
1415 case MCI_BREAK
: /* no auto-open for system commands */
1416 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1421 WCHAR buf
[138], retbuf
[6];
1422 swprintf(buf
, ARRAY_SIZE(buf
), L
"open %s wait", dev
);
1423 /* open via mciSendString handles quoting, dev!file syntax and alias creation */
1424 if ((dwRet
= mciSendStringW(buf
, retbuf
, ARRAY_SIZE(retbuf
), 0)) != 0)
1426 auto_open
= wcstoul(retbuf
, NULL
, 10);
1427 TRACE("auto-opened %u for %s\n", auto_open
, debugstr_w(dev
));
1429 /* FIXME: test for notify flag (how to preparse?) before opening */
1430 wmd
= MCI_GetDriver(auto_open
);
1432 ERR("No auto-open device %u\n", auto_open
);
1433 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1440 /* get the verb in the different command tables */
1442 /* try the device specific command table */
1443 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
1445 /* try the type specific command table */
1446 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1447 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1448 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1449 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1452 /* try core command table */
1453 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1456 TRACE("Command %s not found!\n", debugstr_w(verb
));
1457 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1460 wMsg
= MCI_GetMessage(lpCmd
);
1462 /* set return information */
1463 offset
= sizeof(data
.generic
);
1464 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1468 offset
+= sizeof(DWORD
);
1471 data
.sysinfo
.lpstrReturn
= lpstrRet
;
1472 data
.sysinfo
.dwRetSize
= uRetLen
;
1473 offset
= FIELD_OFFSET( MCI_SYSINFO_PARMSW
, dwNumber
);
1476 offset
+= 4 * sizeof(DWORD
);
1478 case 13: /* MCI_INTEGER64 */
1479 offset
+= sizeof(DWORD_PTR
);
1482 FIXME("Unknown MCI return type %ld\n", retType
);
1483 dwRet
= MCIERR_PARSER_INTERNAL
;
1487 TRACE("verb=%s on dev=%s; offset=%d\n",
1488 debugstr_w(verb
), debugstr_w(dev
), offset
);
1490 if ((dwRet
= MCI_ParseOptArgs(data
.dw
, offset
/ sizeof(DWORD
), lpCmd
, args
, &dwFlags
)))
1493 /* set up call back */
1495 if (dwFlags
& MCI_NOTIFY
) {
1496 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1499 /* FIXME: the command should get its own notification window set up and
1500 * ask for device closing while processing the notification mechanism.
1501 * hwndCallback = ...
1502 * dwFlags |= MCI_NOTIFY;
1503 * In the meantime special-case all commands but PLAY and RECORD below. */
1505 if (dwFlags
& MCI_NOTIFY
) {
1506 data
.generic
.dwCallback
= (DWORD_PTR
)hwndCallback
;
1511 if (wcscmp(verb
, L
"open")) {
1512 FIXME("Cannot open with command %s\n", debugstr_w(verb
));
1513 dwRet
= MCIERR_DRIVER_INTERNAL
;
1519 /* Requirements on dev depend on the flags:
1520 * alias with INSTALLNAME, name like "digitalvideo"
1521 * with QUANTITY and NAME. */
1523 data
.sysinfo
.wDeviceType
= MCI_ALL_DEVICE_ID
;
1524 if (uDevID
!= MCI_ALL_DEVICE_ID
) {
1525 if (dwFlags
& MCI_SYSINFO_INSTALLNAME
)
1526 wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
));
1527 else if (!(data
.sysinfo
.wDeviceType
= MCI_GetDevTypeFromResource(dev
))) {
1528 dwRet
= MCIERR_DEVICE_TYPE_REQUIRED
;
1535 /* FIXME: name is optional, "sound" is a valid command.
1536 * FIXME: Parse "sound notify" as flag, not as name. */
1537 data
.sound
.lpstrSoundName
= dev
;
1538 dwFlags
|= MCI_SOUND_NAME
;
1542 TRACE("[%d, %s, %08lx, %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx]\n",
1543 wmd
? wmd
->wDeviceID
: uDevID
, MCI_MessageToString(wMsg
), dwFlags
,
1544 data
.dw
[0], data
.dw
[1], data
.dw
[2], data
.dw
[3], data
.dw
[4],
1545 data
.dw
[5], data
.dw
[6], data
.dw
[7], data
.dw
[8], data
.dw
[9]);
1547 if (wMsg
== MCI_OPEN
) {
1548 if ((dwRet
= MCI_FinishOpen(wmd
, &data
.open
, dwFlags
)))
1550 /* FIXME: notification is not properly shared across two opens */
1552 dwRet
= MCI_SendCommand(wmd
? wmd
->wDeviceID
: uDevID
, wMsg
, dwFlags
, (DWORD_PTR
)&data
);
1554 if (!LOWORD(dwRet
)) {
1555 TRACE("=> 1/ %lx (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1556 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, &data
.generic
, lpstrRet
, uRetLen
);
1557 TRACE("=> 2/ %lx (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1559 TRACE("=> %lx\n", dwRet
);
1563 /* PLAY and RECORD are the only known non-immediate commands */
1564 if (LOWORD(dwRet
) || !(wMsg
== MCI_PLAY
|| wMsg
== MCI_RECORD
))
1565 MCI_SendCommand(auto_open
, MCI_CLOSE
, 0, 0);
1567 FIXME("leaking auto-open device %u\n", auto_open
);
1569 if (wMsg
== MCI_OPEN
&& LOWORD(dwRet
) && wmd
)
1570 MCI_UnLoadMciDriver(wmd
);
1576 /**************************************************************************
1577 * mciSendStringA [WINMM.@]
1579 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
1580 UINT uRetLen
, HWND hwndCallback
)
1582 LPWSTR lpwstrCommand
;
1583 LPWSTR lpwstrRet
= NULL
;
1587 /* FIXME: is there something to do with lpstrReturnString ? */
1588 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, NULL
, 0 );
1589 lpwstrCommand
= malloc( len
* sizeof(WCHAR
) );
1590 MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, lpwstrCommand
, len
);
1593 if (uRetLen
) *lpstrRet
= '\0'; /* NT-w2k3 use memset(lpstrRet, 0, uRetLen); */
1594 lpwstrRet
= malloc( uRetLen
* sizeof(WCHAR
) );
1596 free( lpwstrCommand
);
1597 return MCIERR_OUT_OF_MEMORY
;
1600 ret
= mciSendStringW(lpwstrCommand
, lpwstrRet
, uRetLen
, hwndCallback
);
1601 if (!ret
&& lpwstrRet
)
1602 WideCharToMultiByte( CP_ACP
, 0, lpwstrRet
, -1, lpstrRet
, uRetLen
, NULL
, NULL
);
1603 free(lpwstrCommand
);
1608 /**************************************************************************
1609 * mciExecute [WINMM.@]
1611 BOOL WINAPI
mciExecute(LPCSTR lpstrCommand
)
1616 TRACE("(%s)!\n", lpstrCommand
);
1618 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1620 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1621 sprintf(strRet
, "Unknown MCI error (%ld)", ret
);
1623 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1625 /* FIXME: what shall I return ? */
1629 /**************************************************************************
1630 * mciLoadCommandResource [WINMM.@]
1632 * Strangely, this function only exists as a UNICODE one.
1634 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1636 UINT ret
= MCI_NO_COMMAND_TABLE
;
1640 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1642 /* if a file named "resname.mci" exits, then load resource "resname" from it
1643 * otherwise directly from driver
1644 * We don't support it (who uses this feature ?), but we check anyway
1648 /* FIXME: we should put this back into order, but I never found a program
1649 * actually using this feature, so we may not need it
1654 strcat(strcpy(buf
, resname
), ".mci");
1655 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1656 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1660 if ((hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
)) &&
1661 (hMem
= LoadResource(hInst
, hRsrc
))) {
1662 ret
= MCI_SetCommandTable(hMem
, type
);
1665 else WARN("No command table found in module for %s\n", debugstr_w(resNameW
));
1667 TRACE("=> %04x\n", ret
);
1671 /**************************************************************************
1672 * mciFreeCommandResource [WINMM.@]
1674 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1676 TRACE("(%08x)!\n", uTable
);
1678 if (uTable
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTable
].lpTable
)
1681 FreeResource(S_MciCmdTable
[uTable
].hMem
);
1682 S_MciCmdTable
[uTable
].hMem
= NULL
;
1683 S_MciCmdTable
[uTable
].lpTable
= NULL
;
1684 free(S_MciCmdTable
[uTable
].aVerbs
);
1685 S_MciCmdTable
[uTable
].aVerbs
= 0;
1686 S_MciCmdTable
[uTable
].nVerbs
= 0;
1690 /**************************************************************************
1691 * MCI_Open [internal]
1693 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSW lpParms
)
1695 WCHAR strDevTyp
[128];
1697 LPWINE_MCIDRIVER wmd
= NULL
;
1699 TRACE("(%08lX, %p)\n", dwParam
, lpParms
);
1700 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1702 /* only two low bytes are generic, the other ones are dev type specific */
1703 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1704 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1705 MCI_NOTIFY|MCI_WAIT)
1706 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0)
1707 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
);
1708 #undef WINE_MCIDRIVER_SUPP
1712 if (dwParam
& MCI_OPEN_TYPE
) {
1713 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1714 WORD uDevType
= LOWORD(lpParms
->lpstrDeviceType
);
1716 if (uDevType
< MCI_DEVTYPE_FIRST
|| uDevType
> MCI_DEVTYPE_LAST
||
1717 !LoadStringW(hWinMM32Instance
, uDevType
, strDevTyp
, ARRAY_SIZE(strDevTyp
))) {
1718 dwRet
= MCIERR_BAD_INTEGER
;
1723 if (lpParms
->lpstrDeviceType
== NULL
) {
1724 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1727 lstrcpyW(strDevTyp
, lpParms
->lpstrDeviceType
);
1728 ptr
= wcschr(strDevTyp
, '!');
1730 /* this behavior is not documented in windows. However, since, in
1731 * some occasions, MCI_OPEN handling is translated by WinMM into
1732 * a call to mciSendString("open <type>"); this code shall be correct
1734 if (dwParam
& MCI_OPEN_ELEMENT
) {
1735 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1736 debugstr_w(lpParms
->lpstrElementName
),
1737 debugstr_w(strDevTyp
));
1738 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1741 dwParam
|= MCI_OPEN_ELEMENT
;
1743 /* FIXME: not a good idea to write in user supplied buffer */
1744 lpParms
->lpstrElementName
= ptr
;
1748 TRACE("devType=%s !\n", debugstr_w(strDevTyp
));
1751 if (dwParam
& MCI_OPEN_ELEMENT
) {
1752 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms
->lpstrElementName
));
1754 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1755 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1756 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1760 if (!lpParms
->lpstrElementName
) {
1761 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1765 /* type, if given as a parameter, supersedes file extension */
1766 if (!strDevTyp
[0] &&
1767 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1768 strDevTyp
, sizeof(strDevTyp
))) {
1769 if (GetDriveTypeW(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1770 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1773 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1774 lstrcpyW(strDevTyp
, L
"CDAUDIO");
1778 if (strDevTyp
[0] == 0) {
1779 FIXME("Couldn't load driver\n");
1780 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1784 if (dwParam
& MCI_OPEN_ALIAS
) {
1785 TRACE("Alias=%s !\n", debugstr_w(lpParms
->lpstrAlias
));
1786 if (!lpParms
->lpstrAlias
) {
1787 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1792 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1796 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1797 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08lx], closing\n", dwRet
);
1798 /* FIXME: is dwRet the correct ret code ? */
1802 /* only handled devices fall through */
1803 TRACE("wDevID=%04X wDeviceID=%d dwRet=%ld\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1807 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1811 /**************************************************************************
1812 * MCI_Close [internal]
1814 static DWORD
MCI_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1817 LPWINE_MCIDRIVER wmd
;
1819 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwParam
, lpParms
);
1821 /* Every device must handle MCI_NOTIFY on its own. */
1822 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
1823 while (MciDrivers
) {
1824 /* Retrieve the device ID under lock, but send the message without,
1825 * the driver might be calling some winmm functions from another
1826 * thread before being fully stopped.
1828 EnterCriticalSection(&WINMM_cs
);
1831 LeaveCriticalSection(&WINMM_cs
);
1834 wDevID
= MciDrivers
->wDeviceID
;
1835 LeaveCriticalSection(&WINMM_cs
);
1836 MCI_Close(wDevID
, dwParam
, lpParms
);
1841 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1842 return MCIERR_INVALID_DEVICE_ID
;
1845 if(wmd
->CreatorThread
!= GetCurrentThreadId())
1846 return MCIERR_INVALID_DEVICE_NAME
;
1848 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD_PTR
)lpParms
);
1850 MCI_UnLoadMciDriver(wmd
);
1855 /**************************************************************************
1856 * MCI_WriteString [internal]
1858 static DWORD
MCI_WriteString(LPWSTR lpDstStr
, DWORD dstSize
, LPCWSTR lpSrcStr
)
1863 if (dstSize
<= lstrlenW(lpSrcStr
)) {
1864 ret
= MCIERR_PARAM_OVERFLOW
;
1866 lstrcpyW(lpDstStr
, lpSrcStr
);
1874 /**************************************************************************
1875 * MCI_Sysinfo [internal]
1877 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSW lpParms
)
1879 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1880 WCHAR buf
[2048], *s
, *p
;
1881 LPWINE_MCIDRIVER wmd
;
1884 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1885 if (lpParms
->lpstrReturn
== NULL
) return MCIERR_PARAM_OVERFLOW
;
1887 TRACE("(%08x, %08lX, %p[num=%ld, wDevTyp=%u])\n",
1888 uDevID
, dwFlags
, lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1889 if ((WORD
)MCI_ALL_DEVICE_ID
== LOWORD(uDevID
))
1890 uDevID
= MCI_ALL_DEVICE_ID
; /* Be compatible with Win9x */
1892 switch (dwFlags
& ~(MCI_SYSINFO_OPEN
|MCI_NOTIFY
|MCI_WAIT
)) {
1893 case MCI_SYSINFO_QUANTITY
:
1894 if (lpParms
->dwRetSize
< sizeof(DWORD
))
1895 return MCIERR_PARAM_OVERFLOW
;
1896 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1897 if (uDevID
== MCI_ALL_DEVICE_ID
) {
1898 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1899 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1900 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1901 EnterCriticalSection(&WINMM_cs
);
1902 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1905 LeaveCriticalSection(&WINMM_cs
);
1907 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1908 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
,
1909 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1910 RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1911 RegCloseKey( hKey
);
1913 if (GetPrivateProfileStringW(L
"MCI", 0, L
"", buf
, ARRAY_SIZE(buf
), L
"system.ini"))
1914 for (s
= buf
; *s
; s
+= lstrlenW(s
) + 1) cnt
++;
1917 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1918 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms
->wDeviceType
);
1919 EnterCriticalSection(&WINMM_cs
);
1920 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1921 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1923 LeaveCriticalSection(&WINMM_cs
);
1925 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms
->wDeviceType
);
1926 FIXME("Don't know how to get # of MCI devices of a given type\n");
1927 /* name = LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType))
1928 * then lookup registry and/or system.ini for name, ignoring digits suffix */
1929 switch (LOWORD(lpParms
->wDeviceType
)) {
1930 case MCI_DEVTYPE_CD_AUDIO
:
1931 case MCI_DEVTYPE_WAVEFORM_AUDIO
:
1932 case MCI_DEVTYPE_SEQUENCER
:
1935 default: /* "digitalvideo" gets 0 because it's not in the registry */
1940 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1941 TRACE("(%ld) => '%ld'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1942 ret
= MCI_INTEGER_RETURNED
;
1943 /* return ret; Only Win9x sends a notification in this case. */
1945 case MCI_SYSINFO_INSTALLNAME
:
1946 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1947 if ((wmd
= MCI_GetDriver(uDevID
))) {
1948 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1949 wmd
->lpstrDeviceType
);
1951 ret
= (uDevID
== MCI_ALL_DEVICE_ID
)
1952 ? MCIERR_CANNOT_USE_ALL
: MCIERR_INVALID_DEVICE_NAME
;
1954 TRACE("(%ld) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1956 case MCI_SYSINFO_NAME
:
1958 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1959 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1960 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1961 uDevID
== MCI_ALL_DEVICE_ID
? MCI_ALL_DEVICE_ID
: lpParms
->wDeviceType
);
1962 EnterCriticalSection(&WINMM_cs
);
1963 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1964 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1965 if (uDevID
== MCI_ALL_DEVICE_ID
||
1966 lpParms
->wDeviceType
== wmd
->wType
) {
1968 if (cnt
== lpParms
->dwNumber
) {
1969 s
= wmd
->lpstrAlias
;
1974 LeaveCriticalSection(&WINMM_cs
);
1975 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
1976 } else if (MCI_ALL_DEVICE_ID
== uDevID
) {
1977 TRACE("MCI_SYSINFO_NAME: device #%ld\n", lpParms
->dwNumber
);
1978 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
, 0,
1979 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1980 if (RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
,
1981 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
&&
1982 lpParms
->dwNumber
<= cnt
) {
1983 DWORD bufLen
= ARRAY_SIZE(buf
);
1984 if (RegEnumKeyExW(hKey
, lpParms
->dwNumber
- 1,
1985 buf
, &bufLen
, 0, 0, 0, 0) == ERROR_SUCCESS
)
1988 RegCloseKey( hKey
);
1991 if (GetPrivateProfileStringW(L
"MCI", 0, L
"", buf
, ARRAY_SIZE(buf
), L
"system.ini")) {
1992 for (p
= buf
; *p
; p
+= lstrlenW(p
) + 1, cnt
++) {
1993 TRACE("%ld: %s\n", cnt
, debugstr_w(p
));
1994 if (cnt
== lpParms
->dwNumber
- 1) {
2001 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
2003 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms
->wDeviceType
);
2004 /* Cheating: what is asked for is the nth device from the registry. */
2005 if (1 != lpParms
->dwNumber
|| /* Handle only one of each kind. */
2006 lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
)
2007 ret
= MCIERR_OUTOFRANGE
;
2009 LoadStringW(hWinMM32Instance
, LOWORD(lpParms
->wDeviceType
),
2010 lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
2014 TRACE("(%ld) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
2017 TRACE("Unsupported flag value=%08lx\n", dwFlags
);
2018 ret
= MCIERR_UNRECOGNIZED_KEYWORD
;
2020 if ((dwFlags
& MCI_NOTIFY
) && HRESULT_CODE(ret
)==0)
2021 mciDriverNotify((HWND
)lpParms
->dwCallback
, uDevID
, MCI_NOTIFY_SUCCESSFUL
);
2025 /**************************************************************************
2026 * MCI_Break [internal]
2028 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
2032 if (lpParms
== NULL
)
2033 return MCIERR_NULL_PARAMETER_BLOCK
;
2035 TRACE("(%08x, %08lX, vkey %04X, hwnd %p)\n", wDevID
, dwFlags
,
2036 lpParms
->nVirtKey
, lpParms
->hwndBreak
);
2038 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_BREAK
, dwFlags
, (DWORD_PTR
)lpParms
);
2039 if (!dwRet
&& (dwFlags
& MCI_NOTIFY
))
2040 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2044 /**************************************************************************
2045 * MCI_Sound [internal]
2047 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMSW lpParms
)
2051 if (dwFlags
& MCI_SOUND_NAME
) {
2052 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
2053 else dwRet
= PlaySoundW(lpParms
->lpstrSoundName
, NULL
,
2054 SND_ALIAS
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2055 ? 0 : MCIERR_HARDWARE
;
2056 } else dwRet
= PlaySoundW((LPCWSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
,
2057 SND_ALIAS_ID
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2058 ? 0 : MCIERR_HARDWARE
;
2060 if (!dwRet
&& lpParms
&& (dwFlags
& MCI_NOTIFY
))
2061 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2065 /**************************************************************************
2066 * MCI_SendCommand [internal]
2068 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2070 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
2074 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
2077 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
2080 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSW
)dwParam2
);
2083 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
2086 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMSW
)dwParam2
);
2089 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
2090 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2091 dwRet
= MCIERR_CANNOT_USE_ALL
;
2093 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
2100 /**************************************************************************
2101 * MCI_CleanUp [internal]
2103 * Some MCI commands need to be cleaned-up (when not called from
2104 * mciSendString), because MCI drivers return extra information for string
2105 * transformation. This function gets rid of them.
2107 static LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD_PTR dwParam2
)
2110 return LOWORD(dwRet
);
2113 case MCI_GETDEVCAPS
:
2114 switch (dwRet
& 0xFFFF0000ul
) {
2116 case MCI_COLONIZED3_RETURN
:
2117 case MCI_COLONIZED4_RETURN
:
2118 case MCI_INTEGER_RETURNED
:
2121 case MCI_RESOURCE_RETURNED
:
2122 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2124 LPMCI_GETDEVCAPS_PARMS lmgp
;
2126 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)dwParam2
;
2127 TRACE("Changing %08lx to %08x\n", lmgp
->dwReturn
, LOWORD(lmgp
->dwReturn
));
2128 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
2132 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2133 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2137 switch (dwRet
& 0xFFFF0000ul
) {
2139 case MCI_COLONIZED3_RETURN
:
2140 case MCI_COLONIZED4_RETURN
:
2141 case MCI_INTEGER_RETURNED
:
2144 case MCI_RESOURCE_RETURNED
:
2145 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2147 LPMCI_STATUS_PARMS lsp
;
2149 lsp
= (LPMCI_STATUS_PARMS
)dwParam2
;
2150 TRACE("Changing %08Ix to %08x\n", lsp
->dwReturn
, LOWORD(lsp
->dwReturn
));
2151 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
2155 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2156 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2160 switch (dwRet
& 0xFFFF0000ul
) {
2162 case MCI_INTEGER_RETURNED
:
2166 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
2170 if (HIWORD(dwRet
)) {
2171 FIXME("Got non null hiword for dwRet=0x%08Ix for command %s\n",
2172 dwRet
, MCI_MessageToString(wMsg
));
2176 return LOWORD(dwRet
);
2179 /**************************************************************************
2180 * mciGetErrorStringW [WINMM.@]
2182 BOOL WINAPI
mciGetErrorStringW(MCIERROR wError
, LPWSTR lpstrBuffer
, UINT uLength
)
2186 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2187 wError
>= MCIERR_BASE
&& wError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2189 if (LoadStringW(hWinMM32Instance
, wError
, lpstrBuffer
, uLength
) > 0) {
2196 /**************************************************************************
2197 * mciGetErrorStringA [WINMM.@]
2199 BOOL WINAPI
mciGetErrorStringA(MCIERROR dwError
, LPSTR lpstrBuffer
, UINT uLength
)
2203 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2204 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2206 if (LoadStringA(hWinMM32Instance
, dwError
, lpstrBuffer
, uLength
) > 0) {
2213 /**************************************************************************
2214 * mciDriverNotify [WINMM.@]
2216 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, MCIDEVICEID wDevID
, UINT wStatus
)
2218 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
2220 return PostMessageW(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
2223 /**************************************************************************
2224 * mciGetDriverData [WINMM.@]
2226 DWORD_PTR WINAPI
mciGetDriverData(MCIDEVICEID uDeviceID
)
2228 LPWINE_MCIDRIVER wmd
;
2230 TRACE("(%04x)\n", uDeviceID
);
2232 wmd
= MCI_GetDriver(uDeviceID
);
2235 WARN("Bad uDeviceID\n");
2239 return wmd
->dwPrivate
;
2242 /**************************************************************************
2243 * mciSetDriverData [WINMM.@]
2245 BOOL WINAPI
mciSetDriverData(MCIDEVICEID uDeviceID
, DWORD_PTR data
)
2247 LPWINE_MCIDRIVER wmd
;
2249 TRACE("(%04x, %08Ix)\n", uDeviceID
, data
);
2251 wmd
= MCI_GetDriver(uDeviceID
);
2254 WARN("Bad uDeviceID\n");
2258 wmd
->dwPrivate
= data
;
2262 /**************************************************************************
2263 * mciSendCommandW [WINMM.@]
2266 DWORD WINAPI
mciSendCommandW(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2270 TRACE("(%08x, %s, %08Ix, %08Ix)\n",
2271 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2273 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
);
2274 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
2275 TRACE("=> %08lx\n", dwRet
);
2279 /**************************************************************************
2280 * mciSendCommandA [WINMM.@]
2282 DWORD WINAPI
mciSendCommandA(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2287 TRACE("(%08x, %s, %08Ix, %08Ix)\n",
2288 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2290 mapped
= MCI_MapMsgAtoW(wMsg
, dwParam1
, &dwParam2
);
2293 FIXME("message %04x mapping failed\n", wMsg
);
2294 return MCIERR_OUT_OF_MEMORY
;
2296 ret
= mciSendCommandW(wDevID
, wMsg
, dwParam1
, dwParam2
);
2298 MCI_UnmapMsgAtoW(wMsg
, dwParam1
, dwParam2
, ret
);
2302 /**************************************************************************
2303 * mciGetDeviceIDA [WINMM.@]
2305 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
2307 LPWSTR w
= MCI_strdupAtoW(lpstrName
);
2308 UINT ret
= MCIERR_OUT_OF_MEMORY
;
2312 ret
= mciGetDeviceIDW(w
);
2318 /**************************************************************************
2319 * mciGetDeviceIDW [WINMM.@]
2321 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2323 return MCI_GetDriverFromString(lpwstrName
);
2326 /**************************************************************************
2327 * MCI_DefYieldProc [internal]
2329 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
2334 TRACE("(0x%04x, 0x%08lx)\n", wDevID
, data
);
2336 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
2337 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2338 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2341 msg
.hwnd
= HWND_32(HIWORD(data
));
2342 while (!PeekMessageW(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2348 /**************************************************************************
2349 * mciSetYieldProc [WINMM.@]
2351 BOOL WINAPI
mciSetYieldProc(MCIDEVICEID uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2353 LPWINE_MCIDRIVER wmd
;
2355 TRACE("(%u, %p, %08lx)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2357 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2358 WARN("Bad uDeviceID\n");
2362 wmd
->lpfnYieldProc
= fpYieldProc
;
2363 wmd
->dwYieldData
= dwYieldData
;
2368 /**************************************************************************
2369 * mciGetDeviceIDFromElementIDA [WINMM.@]
2371 UINT WINAPI
mciGetDeviceIDFromElementIDA(DWORD dwElementID
, LPCSTR lpstrType
)
2373 LPWSTR w
= MCI_strdupAtoW(lpstrType
);
2378 ret
= mciGetDeviceIDFromElementIDW(dwElementID
, w
);
2384 /**************************************************************************
2385 * mciGetDeviceIDFromElementIDW [WINMM.@]
2387 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2389 /* FIXME: that's rather strange, there is no
2390 * mciGetDeviceIDFromElementID32A in winmm.spec
2392 FIXME("(%lu, %s) stub\n", dwElementID
, debugstr_w(lpstrType
));
2396 /**************************************************************************
2397 * mciGetYieldProc [WINMM.@]
2399 YIELDPROC WINAPI
mciGetYieldProc(MCIDEVICEID uDeviceID
, DWORD
* lpdwYieldData
)
2401 LPWINE_MCIDRIVER wmd
;
2403 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2405 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2406 WARN("Bad uDeviceID\n");
2409 if (!wmd
->lpfnYieldProc
) {
2410 WARN("No proc set\n");
2413 if (lpdwYieldData
) *lpdwYieldData
= wmd
->dwYieldData
;
2414 return wmd
->lpfnYieldProc
;
2417 /**************************************************************************
2418 * mciGetCreatorTask [WINMM.@]
2420 HTASK WINAPI
mciGetCreatorTask(MCIDEVICEID uDeviceID
)
2422 LPWINE_MCIDRIVER wmd
;
2425 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)(DWORD_PTR
)wmd
->CreatorThread
;
2427 TRACE("(%u) => %p\n", uDeviceID
, ret
);
2431 /**************************************************************************
2432 * mciDriverYield [WINMM.@]
2434 UINT WINAPI
mciDriverYield(MCIDEVICEID uDeviceID
)
2436 LPWINE_MCIDRIVER wmd
;
2439 TRACE("(%04x)\n", uDeviceID
);
2441 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
) {
2443 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2445 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);