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 INT len
= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
76 LPWSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
79 memcpy( p
, str
, len
);
85 /**************************************************************************
86 * MCI_GetDriver [internal]
88 static LPWINE_MCIDRIVER
MCI_GetDriver(UINT wDevID
)
90 LPWINE_MCIDRIVER wmd
= 0;
92 EnterCriticalSection(&WINMM_cs
);
93 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
94 if (wmd
->wDeviceID
== wDevID
)
97 LeaveCriticalSection(&WINMM_cs
);
101 /**************************************************************************
102 * MCI_GetDriverFromString [internal]
104 static UINT
MCI_GetDriverFromString(LPCWSTR lpstrName
)
106 LPWINE_MCIDRIVER wmd
;
112 if (!wcsicmp(lpstrName
, L
"ALL"))
113 return MCI_ALL_DEVICE_ID
;
115 EnterCriticalSection(&WINMM_cs
);
116 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
117 if (wmd
->lpstrAlias
&& wcsicmp(wmd
->lpstrAlias
, lpstrName
) == 0) {
118 ret
= wmd
->wDeviceID
;
122 LeaveCriticalSection(&WINMM_cs
);
127 /**************************************************************************
128 * MCI_MessageToString [internal]
130 static const char* MCI_MessageToString(UINT wMsg
)
132 #define CASE(s) case (s): return #s
142 CASE(DRV_QUERYCONFIGURE
);
145 CASE(DRV_EXITSESSION
);
146 CASE(DRV_EXITAPPLICATION
);
150 CASE(MCI_CLOSE_DRIVER
);
159 CASE(MCI_GETDEVCAPS
);
163 CASE(MCI_OPEN_DRIVER
);
182 /* constants for digital video */
196 return wine_dbg_sprintf("MCI_<<%04X>>", wMsg
);
200 static LPWSTR
MCI_strdupAtoW( LPCSTR str
)
205 if (!str
) return NULL
;
206 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
207 ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
208 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
212 static int MCI_MapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR
*dwParam2
)
214 if (msg
< DRV_RESERVED
) return 0;
249 { /* MCI_ANIM_OPEN_PARMS is the largest known MCI_OPEN_PARMS
250 * structure, larger than MCI_WAVE_OPEN_PARMS */
251 MCI_ANIM_OPEN_PARMSA
*mci_openA
= (MCI_ANIM_OPEN_PARMSA
*)*dwParam2
;
252 MCI_ANIM_OPEN_PARMSW
*mci_openW
;
255 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR
) + sizeof(*mci_openW
));
258 *ptr
++ = *dwParam2
; /* save the previous pointer */
259 *dwParam2
= (DWORD_PTR
)ptr
;
260 mci_openW
= (MCI_ANIM_OPEN_PARMSW
*)ptr
;
262 if (dwParam1
& MCI_NOTIFY
)
263 mci_openW
->dwCallback
= mci_openA
->dwCallback
;
265 if (dwParam1
& MCI_OPEN_TYPE
)
267 if (dwParam1
& MCI_OPEN_TYPE_ID
)
268 mci_openW
->lpstrDeviceType
= (LPCWSTR
)mci_openA
->lpstrDeviceType
;
270 mci_openW
->lpstrDeviceType
= MCI_strdupAtoW(mci_openA
->lpstrDeviceType
);
272 if (dwParam1
& MCI_OPEN_ELEMENT
)
274 if (dwParam1
& MCI_OPEN_ELEMENT_ID
)
275 mci_openW
->lpstrElementName
= (LPCWSTR
)mci_openA
->lpstrElementName
;
277 mci_openW
->lpstrElementName
= MCI_strdupAtoW(mci_openA
->lpstrElementName
);
279 if (dwParam1
& MCI_OPEN_ALIAS
)
280 mci_openW
->lpstrAlias
= MCI_strdupAtoW(mci_openA
->lpstrAlias
);
281 /* We don't know how many DWORD follow, as
282 * the structure depends on the device. */
283 if (HIWORD(dwParam1
))
284 memcpy(&mci_openW
->dwStyle
, &mci_openA
->dwStyle
, sizeof(MCI_ANIM_OPEN_PARMSW
) - sizeof(MCI_OPEN_PARMSW
));
289 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
291 MCI_ANIM_WINDOW_PARMSA
*mci_windowA
= (MCI_ANIM_WINDOW_PARMSA
*)*dwParam2
;
292 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
;
294 mci_windowW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW
));
295 if (!mci_windowW
) return -1;
297 *dwParam2
= (DWORD_PTR
)mci_windowW
;
299 mci_windowW
->lpstrText
= MCI_strdupAtoW(mci_windowA
->lpstrText
);
301 if (dwParam1
& MCI_NOTIFY
)
302 mci_windowW
->dwCallback
= mci_windowA
->dwCallback
;
303 if (dwParam1
& MCI_ANIM_WINDOW_HWND
)
304 mci_windowW
->hWnd
= mci_windowA
->hWnd
;
305 if (dwParam1
& MCI_ANIM_WINDOW_STATE
)
306 mci_windowW
->nCmdShow
= mci_windowA
->nCmdShow
;
313 if (dwParam1
& (MCI_SYSINFO_INSTALLNAME
| MCI_SYSINFO_NAME
))
315 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*dwParam2
;
316 MCI_SYSINFO_PARMSW
*mci_sysinfoW
;
319 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW
) + sizeof(DWORD_PTR
));
322 *ptr
++ = *dwParam2
; /* save the previous pointer */
323 *dwParam2
= (DWORD_PTR
)ptr
;
324 mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)ptr
;
326 if (dwParam1
& MCI_NOTIFY
)
327 mci_sysinfoW
->dwCallback
= mci_sysinfoA
->dwCallback
;
329 /* Size is measured in numbers of characters, despite what MSDN says. */
330 mci_sysinfoW
->dwRetSize
= mci_sysinfoA
->dwRetSize
;
331 mci_sysinfoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW
->dwRetSize
* sizeof(WCHAR
));
332 mci_sysinfoW
->dwNumber
= mci_sysinfoA
->dwNumber
;
333 mci_sysinfoW
->wDeviceType
= mci_sysinfoA
->wDeviceType
;
339 MCI_DGV_INFO_PARMSA
*mci_infoA
= (MCI_DGV_INFO_PARMSA
*)*dwParam2
;
340 MCI_DGV_INFO_PARMSW
*mci_infoW
;
343 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW
) + sizeof(DWORD_PTR
));
346 *ptr
++ = *dwParam2
; /* save the previous pointer */
347 *dwParam2
= (DWORD_PTR
)ptr
;
348 mci_infoW
= (MCI_DGV_INFO_PARMSW
*)ptr
;
350 if (dwParam1
& MCI_NOTIFY
)
351 mci_infoW
->dwCallback
= mci_infoA
->dwCallback
;
353 /* Size is measured in numbers of characters. */
354 mci_infoW
->dwRetSize
= mci_infoA
->dwRetSize
;
355 mci_infoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_infoW
->dwRetSize
* sizeof(WCHAR
));
356 if (dwParam1
& MCI_DGV_INFO_ITEM
)
357 mci_infoW
->dwItem
= mci_infoA
->dwItem
;
364 { /* All these commands have the same layout: callback + string + optional rect */
365 MCI_OVLY_LOAD_PARMSA
*mci_loadA
= (MCI_OVLY_LOAD_PARMSA
*)*dwParam2
;
366 MCI_OVLY_LOAD_PARMSW
*mci_loadW
;
368 mci_loadW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW
));
369 if (!mci_loadW
) return -1;
371 *dwParam2
= (DWORD_PTR
)mci_loadW
;
372 if (dwParam1
& MCI_NOTIFY
)
373 mci_loadW
->dwCallback
= mci_loadA
->dwCallback
;
374 mci_loadW
->lpfilename
= MCI_strdupAtoW(mci_loadA
->lpfilename
);
375 if ((MCI_SAVE
== msg
&& dwParam1
& MCI_DGV_RECT
) ||
376 (MCI_LOAD
== msg
&& dwParam1
& MCI_OVLY_RECT
) ||
377 (MCI_CAPTURE
== msg
&& dwParam1
& MCI_DGV_CAPTURE_AT
) ||
378 (MCI_RESTORE
== msg
&& dwParam1
& MCI_DGV_RESTORE_AT
))
379 mci_loadW
->rc
= mci_loadA
->rc
;
384 { /* All these commands have the same layout: callback + string */
385 MCI_VD_ESCAPE_PARMSA
*mci_vd_escapeA
= (MCI_VD_ESCAPE_PARMSA
*)*dwParam2
;
386 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
;
388 mci_vd_escapeW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW
));
389 if (!mci_vd_escapeW
) return -1;
391 *dwParam2
= (DWORD_PTR
)mci_vd_escapeW
;
392 if (dwParam1
& MCI_NOTIFY
)
393 mci_vd_escapeW
->dwCallback
= mci_vd_escapeA
->dwCallback
;
394 mci_vd_escapeW
->lpstrCommand
= MCI_strdupAtoW(mci_vd_escapeA
->lpstrCommand
);
399 if (!(dwParam1
& (MCI_DGV_SETVIDEO_QUALITY
| MCI_DGV_SETVIDEO_ALG
400 | MCI_DGV_SETAUDIO_QUALITY
| MCI_DGV_SETAUDIO_ALG
)))
402 /* fall through to default */
407 FIXME("Message %s needs translation\n", MCI_MessageToString(msg
));
408 return 0; /* pass through untouched */
412 static void MCI_UnmapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
,
419 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
420 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*ptr
;
421 MCI_OPEN_PARMSW
*mci_openW
= (MCI_OPEN_PARMSW
*)dwParam2
;
423 mci_openA
->wDeviceID
= mci_openW
->wDeviceID
;
425 if (dwParam1
& MCI_OPEN_TYPE
)
427 if (!(dwParam1
& MCI_OPEN_TYPE_ID
))
428 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrDeviceType
);
430 if (dwParam1
& MCI_OPEN_ELEMENT
)
432 if (!(dwParam1
& MCI_OPEN_ELEMENT_ID
))
433 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrElementName
);
435 if (dwParam1
& MCI_OPEN_ALIAS
)
436 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrAlias
);
437 HeapFree(GetProcessHeap(), 0, ptr
);
441 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
443 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
= (MCI_ANIM_WINDOW_PARMSW
*)dwParam2
;
445 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW
->lpstrText
);
446 HeapFree(GetProcessHeap(), 0, mci_windowW
);
451 if (dwParam1
& (MCI_SYSINFO_INSTALLNAME
| MCI_SYSINFO_NAME
))
453 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
454 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*ptr
;
455 MCI_SYSINFO_PARMSW
*mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)dwParam2
;
459 WideCharToMultiByte(CP_ACP
, 0,
460 mci_sysinfoW
->lpstrReturn
, -1,
461 mci_sysinfoA
->lpstrReturn
, mci_sysinfoA
->dwRetSize
,
465 HeapFree(GetProcessHeap(), 0, mci_sysinfoW
->lpstrReturn
);
466 HeapFree(GetProcessHeap(), 0, ptr
);
471 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
472 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*ptr
;
473 MCI_INFO_PARMSW
*mci_infoW
= (MCI_INFO_PARMSW
*)dwParam2
;
477 WideCharToMultiByte(CP_ACP
, 0,
478 mci_infoW
->lpstrReturn
, -1,
479 mci_infoA
->lpstrReturn
, mci_infoA
->dwRetSize
,
483 HeapFree(GetProcessHeap(), 0, mci_infoW
->lpstrReturn
);
484 HeapFree(GetProcessHeap(), 0, ptr
);
491 { /* All these commands have the same layout: callback + string + optional rect */
492 MCI_OVLY_LOAD_PARMSW
*mci_loadW
= (MCI_OVLY_LOAD_PARMSW
*)dwParam2
;
494 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW
->lpfilename
);
495 HeapFree(GetProcessHeap(), 0, mci_loadW
);
500 { /* All these commands have the same layout: callback + string */
501 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
= (MCI_VD_ESCAPE_PARMSW
*)dwParam2
;
503 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW
->lpstrCommand
);
504 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW
);
509 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg
));
514 /**************************************************************************
515 * MCI_GetDevTypeFromFileName [internal]
517 static DWORD
MCI_GetDevTypeFromFileName(LPCWSTR fileName
, LPWSTR buf
, UINT len
)
521 if ((tmp
= wcsrchr(fileName
, '.'))) {
522 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
523 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions",
524 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
526 LONG lRet
= RegQueryValueExW( hKey
, tmp
+ 1, 0, 0, (void*)buf
, &dwLen
);
528 if (lRet
== ERROR_SUCCESS
) return 0;
530 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp
));
532 return MCIERR_EXTENSION_NOT_FOUND
;
535 /**************************************************************************
536 * MCI_GetDevTypeFromResource [internal]
538 static UINT
MCI_GetDevTypeFromResource(LPCWSTR lpstrName
)
542 for (uDevType
= MCI_DEVTYPE_FIRST
; uDevType
<= MCI_DEVTYPE_LAST
; uDevType
++) {
543 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, ARRAY_SIZE(buf
))) {
544 /* FIXME: ignore digits suffix */
545 if (!wcsicmp(buf
, lpstrName
))
552 #define MAX_MCICMDTABLE 20
553 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
555 typedef struct tagWINE_MCICMDTABLE
{
559 UINT nVerbs
; /* number of verbs in command table */
560 LPCWSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
561 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
563 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
565 /**************************************************************************
566 * MCI_IsCommandTableValid [internal]
568 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
577 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
578 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
580 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
583 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
586 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
587 flg
= *(const DWORD
*)lmem
;
588 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
589 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
591 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
593 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
594 case MCI_STRING
: if (inCst
) return FALSE
; break;
595 case MCI_HWND
: /* Occurs inside MCI_CONSTANT as in "window handle default" */
598 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
599 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
600 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
601 case MCI_FLAG
: if (!*str
) return FALSE
; break;
602 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
603 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
604 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
605 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
606 default: return FALSE
;
608 } while (eid
!= MCI_END_COMMAND_LIST
);
612 /**************************************************************************
613 * MCI_DumpCommandTable [internal]
615 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
621 if (!MCI_IsCommandTableValid(uTbl
)) {
622 ERR("Ooops: %d is not valid\n", uTbl
);
626 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
631 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
632 /* flg = *(const DWORD*)lmem; */
633 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
634 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
635 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
636 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
637 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
638 } while (eid
!= MCI_END_COMMAND_LIST
);
643 /**************************************************************************
644 * MCI_GetCommandTable [internal]
646 static UINT
MCI_GetCommandTable(UINT uDevType
)
652 /* first look up existing for existing devType */
653 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
654 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
658 /* well try to load id */
659 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
660 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, ARRAY_SIZE(buf
))) {
663 } else if (uDevType
== 0) {
666 uTbl
= MCI_NO_COMMAND_TABLE
;
668 HRSRC hRsrc
= FindResourceW(hWinMM32Instance
, str
, (LPCWSTR
)RT_RCDATA
);
671 if (hRsrc
) hMem
= LoadResource(hWinMM32Instance
, hRsrc
);
673 uTbl
= MCI_SetCommandTable(hMem
, uDevType
);
675 WARN("No command table found in resource %p[%s]\n",
676 hWinMM32Instance
, debugstr_w(str
));
679 TRACE("=> %d\n", uTbl
);
683 /**************************************************************************
684 * MCI_SetCommandTable [internal]
686 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
)
689 static BOOL bInitDone
= FALSE
;
692 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
693 * can be called with 0 as a uDevType to retrieve it.
698 MCI_GetCommandTable(0);
700 TRACE("(%p, %u)\n", hMem
, uDevType
);
701 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
702 if (!S_MciCmdTable
[uTbl
].lpTable
) {
708 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
709 S_MciCmdTable
[uTbl
].lpTable
= LockResource(hMem
);
710 S_MciCmdTable
[uTbl
].hMem
= hMem
;
713 MCI_DumpCommandTable(uTbl
);
716 /* create the verbs table */
717 /* get # of entries */
718 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
722 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
723 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
724 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
725 if (eid
== MCI_COMMAND_HEAD
)
727 } while (eid
!= MCI_END_COMMAND_LIST
);
729 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCWSTR
));
730 S_MciCmdTable
[uTbl
].nVerbs
= count
;
732 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
736 lmem
+= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
737 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
738 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
739 if (eid
== MCI_COMMAND_HEAD
)
740 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
741 } while (eid
!= MCI_END_COMMAND_LIST
);
742 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
747 return MCI_NO_COMMAND_TABLE
;
750 /**************************************************************************
751 * MCI_UnLoadMciDriver [internal]
753 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
755 LPWINE_MCIDRIVER
* tmp
;
760 CloseDriver(wmd
->hDriver
, 0, 0);
762 if (wmd
->dwPrivate
!= 0)
763 WARN("Unloading mci driver with non nul dwPrivate field\n");
765 EnterCriticalSection(&WINMM_cs
);
766 for (tmp
= &MciDrivers
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
772 LeaveCriticalSection(&WINMM_cs
);
774 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
775 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
777 HeapFree(GetProcessHeap(), 0, wmd
);
781 /**************************************************************************
782 * MCI_OpenMciDriver [internal]
784 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCWSTR drvTyp
, DWORD_PTR lp
)
788 if (!DRIVER_GetLibName(drvTyp
, L
"MCI", libName
, sizeof(libName
)))
791 /* First load driver */
792 wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
);
793 return wmd
->hDriver
!= NULL
;
796 /**************************************************************************
797 * MCI_LoadMciDriver [internal]
799 static DWORD
MCI_LoadMciDriver(LPCWSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
801 LPWSTR strDevTyp
= str_dup_upper(_strDevTyp
);
802 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
803 MCI_OPEN_DRIVER_PARMSW modp
;
806 if (!wmd
|| !strDevTyp
) {
807 dwRet
= MCIERR_OUT_OF_MEMORY
;
811 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
812 wmd
->dwYieldData
= VK_CANCEL
;
813 wmd
->CreatorThread
= GetCurrentThreadId();
815 EnterCriticalSection(&WINMM_cs
);
816 /* wmd must be inserted in list before sending opening the driver, because it
817 * may want to lookup at wDevID
819 wmd
->lpNext
= MciDrivers
;
822 for (modp
.wDeviceID
= MCI_MAGIC
;
823 MCI_GetDriver(modp
.wDeviceID
) != 0;
826 wmd
->wDeviceID
= modp
.wDeviceID
;
828 LeaveCriticalSection(&WINMM_cs
);
830 TRACE("wDevID=%04X\n", modp
.wDeviceID
);
832 modp
.lpstrParams
= NULL
;
834 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (DWORD_PTR
)&modp
)) {
835 /* silence warning if all is used... some bogus program use commands like
838 if (wcsicmp(strDevTyp
, L
"ALL") == 0) {
839 dwRet
= MCIERR_CANNOT_USE_ALL
;
841 FIXME("Couldn't load driver for type %s.\n",
842 debugstr_w(strDevTyp
));
843 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
848 /* FIXME: should also check that module's description is of the form
849 * MODULENAME:[MCI] comment
852 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
853 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
854 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
856 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
857 wmd
->hDriver
, debugstr_w(strDevTyp
), modp
.wType
, modp
.wCustomCommandTable
);
859 wmd
->lpstrDeviceType
= strDevTyp
;
860 wmd
->wType
= modp
.wType
;
862 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
863 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
867 MCI_UnLoadMciDriver(wmd
);
868 HeapFree(GetProcessHeap(), 0, strDevTyp
);
873 /**************************************************************************
874 * MCI_SendCommandFrom32 [internal]
876 static DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
878 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
879 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
882 if(wmd
->CreatorThread
!= GetCurrentThreadId())
883 return MCIERR_INVALID_DEVICE_NAME
;
885 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
890 /**************************************************************************
891 * MCI_FinishOpen [internal]
893 * Three modes of operation:
894 * 1 open foo.ext ... -> OPEN_ELEMENT with lpstrElementName=foo.ext
895 * open sequencer!foo.ext same with lpstrElementName=foo.ext
896 * 2 open new type waveaudio -> OPEN_ELEMENT with empty ("") lpstrElementName
897 * 3 open sequencer -> OPEN_ELEMENT unset, and
898 * capability sequencer (auto-open) likewise
900 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSW lpParms
,
903 LPCWSTR alias
= NULL
;
904 /* Open always defines an alias for further reference */
905 if (dwParam
& MCI_OPEN_ALIAS
) { /* open ... alias */
906 alias
= lpParms
->lpstrAlias
;
907 if (MCI_GetDriverFromString(alias
))
908 return MCIERR_DUPLICATE_ALIAS
;
910 if ((dwParam
& MCI_OPEN_ELEMENT
) /* open file.wav */
911 && !(dwParam
& MCI_OPEN_ELEMENT_ID
))
912 alias
= lpParms
->lpstrElementName
;
913 else if (dwParam
& MCI_OPEN_TYPE
) /* open cdaudio */
914 alias
= wmd
->lpstrDeviceType
;
915 if (alias
&& MCI_GetDriverFromString(alias
))
916 return MCIERR_DEVICE_OPEN
;
919 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(alias
)+1) * sizeof(WCHAR
));
920 if (!wmd
->lpstrAlias
) return MCIERR_OUT_OF_MEMORY
;
921 lstrcpyW( wmd
->lpstrAlias
, alias
);
922 /* In most cases, natives adds MCI_OPEN_ALIAS to the flags passed to the driver.
923 * Don't. The drivers don't care about the winmm alias. */
925 lpParms
->wDeviceID
= wmd
->wDeviceID
;
927 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
931 /**************************************************************************
932 * MCI_FindCommand [internal]
934 static LPCWSTR
MCI_FindCommand(UINT uTbl
, LPCWSTR verb
)
938 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
941 /* another improvement would be to have the aVerbs array sorted,
942 * so that we could use a dichotomic search on it, rather than this dumb
945 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
946 if (wcsicmp(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
947 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
953 /**************************************************************************
954 * MCI_GetReturnType [internal]
956 static DWORD
MCI_GetReturnType(LPCWSTR lpCmd
)
958 lpCmd
= (LPCWSTR
)((const BYTE
*)(lpCmd
+ lstrlenW(lpCmd
) + 1) + sizeof(DWORD
) + sizeof(WORD
));
959 if (*lpCmd
== '\0' && *(const WORD
*)((const BYTE
*)(lpCmd
+ 1) + sizeof(DWORD
)) == MCI_RETURN
) {
960 return *(const DWORD
*)(lpCmd
+ 1);
965 /**************************************************************************
966 * MCI_GetMessage [internal]
968 static WORD
MCI_GetMessage(LPCWSTR lpCmd
)
970 return (WORD
)*(const DWORD
*)(lpCmd
+ lstrlenW(lpCmd
) + 1);
973 /**************************************************************************
974 * MCI_GetDWord [internal]
976 * Accept 0 -1 255 255:0 255:255:255:255 :::1 1::: 2::3 ::4: 12345678
977 * Refuse -1:0 0:-1 :: 256:0 1:256 0::::1
979 static BOOL
MCI_GetDWord(DWORD
* data
, LPWSTR
* ptr
)
982 DWORD total
= 0, shift
= 0;
983 BOOL sign
= FALSE
, digits
= FALSE
;
985 while (*ret
== ' ' || *ret
== '\t') ret
++;
992 while ('0' <= *ret
&& *ret
<= '9') {
993 val
= *ret
++ - '0' + 10 * val
;
999 case ' ': ret
++; break;
1000 default: return FALSE
;
1002 if ((val
>= 256) || (shift
>= 24)) return FALSE
;
1003 total
|= val
<< shift
;
1009 if (!digits
) return FALSE
;
1010 if (shift
&& (val
>= 256 || sign
)) return FALSE
;
1011 total
|= val
<< shift
;
1012 *data
= sign
? -total
: total
;
1018 /**************************************************************************
1019 * MCI_GetString [internal]
1021 static DWORD
MCI_GetString(LPWSTR
* str
, LPWSTR
* args
)
1025 /* see if we have a quoted string */
1027 ptr
= wcschr(*str
= ptr
+ 1, '"');
1028 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
1029 /* FIXME: shall we escape \" from string ?? */
1030 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1031 *ptr
++ = '\0'; /* remove trailing " */
1032 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
1034 ptr
= wcschr(ptr
, ' ');
1039 ptr
= *args
+ lstrlenW(*args
);
1048 #define MCI_DATA_SIZE 16
1050 /**************************************************************************
1051 * MCI_ParseOptArgs [internal]
1053 static DWORD
MCI_ParseOptArgs(DWORD
* data
, int _offset
, LPCWSTR lpCmd
,
1054 LPWSTR args
, LPDWORD dwFlags
)
1059 DWORD dwRet
, flg
, cflg
= 0;
1063 /* loop on arguments */
1065 lmem
= (const char*)lpCmd
;
1066 found
= inCst
= FALSE
;
1069 /* skip any leading white space(s) */
1070 while (*args
== ' ') args
++;
1071 TRACE("args=%s\n", debugstr_w(args
));
1073 do { /* loop on options for command table for the requested verb */
1074 str
= (LPCWSTR
)lmem
;
1075 lmem
+= ((len
= lstrlenW(str
)) + 1) * sizeof(WCHAR
);
1076 flg
= *(const DWORD
*)lmem
;
1077 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
1078 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
1079 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1083 inCst
= TRUE
; cflg
= flg
; break;
1084 case MCI_END_CONSTANT
:
1085 /* there may be additional integral values after flag in constant */
1086 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
1089 inCst
= FALSE
; cflg
= 0;
1092 if (offset
!= _offset
) {
1093 FIXME("MCI_RETURN not in first position\n");
1094 return MCIERR_PARSER_INTERNAL
;
1098 if (wcsnicmp(args
, str
, len
) == 0 &&
1099 ((eid
== MCI_STRING
&& len
== 0) || args
[len
] == 0 || args
[len
] == ' ')) {
1100 /* store good values into data[] */
1102 while (*args
== ' ') args
++;
1106 case MCI_COMMAND_HEAD
:
1108 case MCI_END_COMMAND
:
1109 case MCI_END_COMMAND_LIST
:
1110 case MCI_CONSTANT
: /* done above */
1111 case MCI_END_CONSTANT
: /* done above */
1115 TRACE("flag=%08x\n", flg
);
1122 data
[offset
] |= flg
;
1125 TRACE("flag=%08x constant=%08x\n", cflg
, flg
);
1128 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
1129 return MCIERR_BAD_INTEGER
;
1131 TRACE("flag=%08x int=%d\n", flg
, data
[offset
]);
1135 /* store rect in data (offset..offset+3) */
1137 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
1138 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
1139 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
1140 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
1141 return MCIERR_BAD_INTEGER
;
1143 TRACE("flag=%08x for rectangle\n", flg
);
1147 if ((dwRet
= MCI_GetString((LPWSTR
*)&data
[offset
], &args
)))
1149 TRACE("flag=%08x string=%s\n", flg
, debugstr_w(*(LPWSTR
*)&data
[offset
]));
1151 default: ERR("oops\n");
1153 /* exit inside while loop, except if just entered in constant area definition */
1154 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
1156 /* have offset incremented if needed */
1158 case MCI_COMMAND_HEAD
:
1160 case MCI_END_COMMAND
:
1161 case MCI_END_COMMAND_LIST
:
1163 case MCI_FLAG
: break;
1166 case MCI_HDC
: if (!inCst
) offset
+= sizeof(HANDLE
)/sizeof(DWORD
); break;
1167 case MCI_INTEGER
: if (!inCst
) offset
++; break;
1168 case MCI_END_CONSTANT
: offset
++; break;
1169 case MCI_STRING
: offset
+= sizeof(LPWSTR
)/sizeof(DWORD
); break;
1170 case MCI_RECT
: offset
+= 4; break;
1171 default: ERR("oops\n");
1174 } while (eid
!= MCI_END_COMMAND
);
1176 WARN("Optarg %s not found\n", debugstr_w(args
));
1177 return MCIERR_UNRECOGNIZED_COMMAND
;
1179 if (offset
== MCI_DATA_SIZE
) {
1180 FIXME("Internal data[] buffer overflow\n");
1181 return MCIERR_PARSER_INTERNAL
;
1187 /**************************************************************************
1188 * MCI_HandleReturnValues [internal]
1190 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
1191 MCI_GENERIC_PARMS
*params
, LPWSTR lpstrRet
, UINT uRetLen
)
1195 case 0: /* nothing to return */
1199 DWORD data
= *(DWORD
*)(params
+ 1);
1200 switch (dwRet
& 0xFFFF0000ul
) {
1202 case MCI_INTEGER_RETURNED
:
1203 swprintf(lpstrRet
, uRetLen
, L
"%d", data
);
1205 case MCI_RESOURCE_RETURNED
:
1206 /* return string which ID is HIWORD(data),
1207 * string is loaded from mmsystem.dll */
1208 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1210 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1211 /* return string which ID is HIWORD(data),
1212 * string is loaded from driver */
1213 /* FIXME: this is wrong for a 16 bit handle */
1214 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1215 HIWORD(data
), lpstrRet
, uRetLen
);
1217 case MCI_COLONIZED3_RETURN
:
1218 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d",
1219 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1220 LOBYTE(HIWORD(data
)));
1222 case MCI_COLONIZED4_RETURN
:
1223 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d:%02d",
1224 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1225 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1227 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1231 #ifdef MCI_INTEGER64
1234 DWORD_PTR data
= *(DWORD_PTR
*)(params
+ 1);
1235 switch (dwRet
& 0xFFFF0000ul
) {
1237 case MCI_INTEGER_RETURNED
:
1238 swprintf(lpstrRet
, uRetLen
, L
"%ld", data
);
1240 case MCI_RESOURCE_RETURNED
:
1241 /* return string which ID is HIWORD(data),
1242 * string is loaded from mmsystem.dll */
1243 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1245 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1246 /* return string which ID is HIWORD(data),
1247 * string is loaded from driver */
1248 /* FIXME: this is wrong for a 16 bit handle */
1249 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1250 HIWORD(data
), lpstrRet
, uRetLen
);
1252 case MCI_COLONIZED3_RETURN
:
1253 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d",
1254 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1255 LOBYTE(HIWORD(data
)));
1257 case MCI_COLONIZED4_RETURN
:
1258 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d:%02d",
1259 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1260 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1262 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1268 switch (dwRet
& 0xFFFF0000ul
) {
1270 /* nothing to do data[0] == lpstrRet */
1272 case MCI_INTEGER_RETURNED
:
1274 DWORD
*data
= (DWORD
*)(params
+ 1);
1275 *data
= *(LPDWORD
)lpstrRet
;
1276 swprintf(lpstrRet
, uRetLen
, L
"%d", *data
);
1280 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1286 DWORD
*data
= (DWORD
*)(params
+ 1);
1287 if (dwRet
& 0xFFFF0000ul
)
1288 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1289 swprintf(lpstrRet
, uRetLen
, L
"%d %d %d %d", data
[0], data
[1], data
[2], data
[3]);
1292 default: FIXME("Unknown MCI return type %d\n", retType
);
1295 return LOWORD(dwRet
);
1298 /**************************************************************************
1299 * mciSendStringW [WINMM.@]
1301 DWORD WINAPI
mciSendStringW(LPCWSTR lpstrCommand
, LPWSTR lpstrRet
,
1302 UINT uRetLen
, HWND hwndCallback
)
1304 LPWSTR verb
, dev
, args
, devType
= NULL
;
1305 LPWINE_MCIDRIVER wmd
= 0;
1306 MCIDEVICEID uDevID
, auto_open
= 0;
1307 DWORD dwFlags
= 0, dwRet
= 0;
1314 MCI_GENERIC_PARMS generic
;
1315 MCI_OPEN_PARMSW open
;
1316 MCI_SOUND_PARMSW sound
;
1317 MCI_SYSINFO_PARMSW sysinfo
;
1318 DWORD dw
[MCI_DATA_SIZE
];
1321 TRACE("(%s, %p, %d, %p)\n",
1322 debugstr_w(lpstrCommand
), lpstrRet
, uRetLen
, hwndCallback
);
1323 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1325 if (!lpstrCommand
[0])
1326 return MCIERR_MISSING_COMMAND_STRING
;
1328 /* format is <command> <device> <optargs> */
1329 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(lpstrCommand
)+1) * sizeof(WCHAR
))))
1330 return MCIERR_OUT_OF_MEMORY
;
1331 lstrcpyW( verb
, lpstrCommand
);
1334 memset(&data
, 0, sizeof(data
));
1336 if (!(args
= wcschr(verb
, ' '))) {
1337 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1341 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
1344 uDevID
= wcsicmp(dev
, L
"ALL") ? 0 : MCI_ALL_DEVICE_ID
;
1346 /* Determine devType from open */
1347 if (!wcscmp(verb
, L
"open")) {
1351 /* case dev == 'new' has to be handled */
1352 if (!wcscmp(dev
, L
"new")) {
1354 if ((devType
= wcsstr(args
, L
"type ")) != NULL
) {
1356 tmp
= wcschr(devType
, ' ');
1357 if (tmp
) *tmp
= '\0';
1358 devType
= str_dup_upper(devType
);
1359 if (tmp
) *tmp
= ' ';
1360 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1362 WARN("open new requires device type\n");
1363 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1366 dwFlags
|= MCI_OPEN_ELEMENT
;
1367 data
.open
.lpstrElementName
= &L
""[0];
1368 } else if ((devType
= wcschr(dev
, '!')) != NULL
) {
1370 tmp
= devType
; devType
= dev
; dev
= tmp
;
1372 dwFlags
|= MCI_OPEN_TYPE
;
1373 data
.open
.lpstrDeviceType
= devType
;
1374 devType
= str_dup_upper(devType
);
1375 dwFlags
|= MCI_OPEN_ELEMENT
;
1376 data
.open
.lpstrElementName
= dev
;
1377 } else if (DRIVER_GetLibName(dev
, L
"MCI", buf
, sizeof(buf
))) {
1378 /* this is the name of a mci driver's type */
1379 tmp
= wcschr(dev
, ' ');
1380 if (tmp
) *tmp
= '\0';
1381 data
.open
.lpstrDeviceType
= dev
;
1382 devType
= str_dup_upper(dev
);
1383 if (tmp
) *tmp
= ' ';
1384 dwFlags
|= MCI_OPEN_TYPE
;
1386 if ((devType
= wcsstr(args
, L
"type ")) != NULL
) {
1388 tmp
= wcschr(devType
, ' ');
1389 if (tmp
) *tmp
= '\0';
1390 devType
= str_dup_upper(devType
);
1391 if (tmp
) *tmp
= ' ';
1392 /* dwFlags and lpstrDeviceType will be correctly set in ParseOpt loop */
1394 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
1397 devType
= str_dup_upper(buf
);
1399 dwFlags
|= MCI_OPEN_ELEMENT
;
1400 data
.open
.lpstrElementName
= dev
;
1402 if (MCI_ALL_DEVICE_ID
== uDevID
) {
1403 dwRet
= MCIERR_CANNOT_USE_ALL
;
1406 if (!wcsstr(args
, L
" alias ") && !dev
) {
1407 dwRet
= MCIERR_NEW_REQUIRES_ALIAS
;
1411 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
1412 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
1413 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1416 } else if ((MCI_ALL_DEVICE_ID
!= uDevID
) && !(wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
)))
1417 && (lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
))) {
1418 /* auto-open uses the core command table */
1419 switch (MCI_GetMessage(lpCmd
)) {
1420 case MCI_SOUND
: /* command does not use a device name */
1423 case MCI_CLOSE
: /* don't auto-open for close */
1424 case MCI_BREAK
: /* no auto-open for system commands */
1425 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1430 WCHAR buf
[138], retbuf
[6];
1431 swprintf(buf
, ARRAY_SIZE(buf
), L
"open %s wait", dev
);
1432 /* open via mciSendString handles quoting, dev!file syntax and alias creation */
1433 if ((dwRet
= mciSendStringW(buf
, retbuf
, ARRAY_SIZE(retbuf
), 0)) != 0)
1435 auto_open
= wcstoul(retbuf
, NULL
, 10);
1436 TRACE("auto-opened %u for %s\n", auto_open
, debugstr_w(dev
));
1438 /* FIXME: test for notify flag (how to preparse?) before opening */
1439 wmd
= MCI_GetDriver(auto_open
);
1441 ERR("No auto-open device %u\n", auto_open
);
1442 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1449 /* get the verb in the different command tables */
1451 /* try the device specific command table */
1452 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
1454 /* try the type specific command table */
1455 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1456 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1457 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1458 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1461 /* try core command table */
1462 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1465 TRACE("Command %s not found!\n", debugstr_w(verb
));
1466 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1469 wMsg
= MCI_GetMessage(lpCmd
);
1471 /* set return information */
1472 offset
= sizeof(data
.generic
);
1473 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1477 offset
+= sizeof(DWORD
);
1480 data
.sysinfo
.lpstrReturn
= lpstrRet
;
1481 data
.sysinfo
.dwRetSize
= uRetLen
;
1482 offset
= FIELD_OFFSET( MCI_SYSINFO_PARMSW
, dwNumber
);
1485 offset
+= 4 * sizeof(DWORD
);
1487 #ifdef MCI_INTEGER64
1489 offset
+= sizeof(DWORD_PTR
);
1493 FIXME("Unknown MCI return type %d\n", retType
);
1494 dwRet
= MCIERR_PARSER_INTERNAL
;
1498 TRACE("verb=%s on dev=%s; offset=%d\n",
1499 debugstr_w(verb
), debugstr_w(dev
), offset
);
1501 if ((dwRet
= MCI_ParseOptArgs(data
.dw
, offset
/ sizeof(DWORD
), lpCmd
, args
, &dwFlags
)))
1504 /* set up call back */
1506 if (dwFlags
& MCI_NOTIFY
) {
1507 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1510 /* FIXME: the command should get its own notification window set up and
1511 * ask for device closing while processing the notification mechanism.
1512 * hwndCallback = ...
1513 * dwFlags |= MCI_NOTIFY;
1514 * In the meantime special-case all commands but PLAY and RECORD below. */
1516 if (dwFlags
& MCI_NOTIFY
) {
1517 data
.generic
.dwCallback
= (DWORD_PTR
)hwndCallback
;
1522 if (wcscmp(verb
, L
"open")) {
1523 FIXME("Cannot open with command %s\n", debugstr_w(verb
));
1524 dwRet
= MCIERR_DRIVER_INTERNAL
;
1530 /* Requirements on dev depend on the flags:
1531 * alias with INSTALLNAME, name like "digitalvideo"
1532 * with QUANTITY and NAME. */
1534 data
.sysinfo
.wDeviceType
= MCI_ALL_DEVICE_ID
;
1535 if (uDevID
!= MCI_ALL_DEVICE_ID
) {
1536 if (dwFlags
& MCI_SYSINFO_INSTALLNAME
)
1537 wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
));
1538 else if (!(data
.sysinfo
.wDeviceType
= MCI_GetDevTypeFromResource(dev
))) {
1539 dwRet
= MCIERR_DEVICE_TYPE_REQUIRED
;
1546 /* FIXME: name is optional, "sound" is a valid command.
1547 * FIXME: Parse "sound notify" as flag, not as name. */
1548 data
.sound
.lpstrSoundName
= dev
;
1549 dwFlags
|= MCI_SOUND_NAME
;
1553 TRACE("[%d, %s, %08x, %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x]\n",
1554 wmd
? wmd
->wDeviceID
: uDevID
, MCI_MessageToString(wMsg
), dwFlags
,
1555 data
.dw
[0], data
.dw
[1], data
.dw
[2], data
.dw
[3], data
.dw
[4],
1556 data
.dw
[5], data
.dw
[6], data
.dw
[7], data
.dw
[8], data
.dw
[9]);
1558 if (wMsg
== MCI_OPEN
) {
1559 if ((dwRet
= MCI_FinishOpen(wmd
, &data
.open
, dwFlags
)))
1561 /* FIXME: notification is not properly shared across two opens */
1563 dwRet
= MCI_SendCommand(wmd
? wmd
->wDeviceID
: uDevID
, wMsg
, dwFlags
, (DWORD_PTR
)&data
);
1565 if (!LOWORD(dwRet
)) {
1566 TRACE("=> 1/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1567 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, &data
.generic
, lpstrRet
, uRetLen
);
1568 TRACE("=> 2/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1570 TRACE("=> %x\n", dwRet
);
1574 /* PLAY and RECORD are the only known non-immediate commands */
1575 if (LOWORD(dwRet
) || !(wMsg
== MCI_PLAY
|| wMsg
== MCI_RECORD
))
1576 MCI_SendCommand(auto_open
, MCI_CLOSE
, 0, 0);
1578 FIXME("leaking auto-open device %u\n", auto_open
);
1580 if (wMsg
== MCI_OPEN
&& LOWORD(dwRet
) && wmd
)
1581 MCI_UnLoadMciDriver(wmd
);
1582 HeapFree(GetProcessHeap(), 0, devType
);
1583 HeapFree(GetProcessHeap(), 0, verb
);
1587 /**************************************************************************
1588 * mciSendStringA [WINMM.@]
1590 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
1591 UINT uRetLen
, HWND hwndCallback
)
1593 LPWSTR lpwstrCommand
;
1594 LPWSTR lpwstrRet
= NULL
;
1598 /* FIXME: is there something to do with lpstrReturnString ? */
1599 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, NULL
, 0 );
1600 lpwstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1601 MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, lpwstrCommand
, len
);
1604 if (uRetLen
) *lpstrRet
= '\0'; /* NT-w2k3 use memset(lpstrRet, 0, uRetLen); */
1605 lpwstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1607 HeapFree( GetProcessHeap(), 0, lpwstrCommand
);
1608 return MCIERR_OUT_OF_MEMORY
;
1611 ret
= mciSendStringW(lpwstrCommand
, lpwstrRet
, uRetLen
, hwndCallback
);
1612 if (!ret
&& lpwstrRet
)
1613 WideCharToMultiByte( CP_ACP
, 0, lpwstrRet
, -1, lpstrRet
, uRetLen
, NULL
, NULL
);
1614 HeapFree(GetProcessHeap(), 0, lpwstrCommand
);
1615 HeapFree(GetProcessHeap(), 0, lpwstrRet
);
1619 /**************************************************************************
1620 * mciExecute [WINMM.@]
1622 BOOL WINAPI
mciExecute(LPCSTR lpstrCommand
)
1627 TRACE("(%s)!\n", lpstrCommand
);
1629 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1631 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1632 sprintf(strRet
, "Unknown MCI error (%d)", ret
);
1634 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1636 /* FIXME: what shall I return ? */
1640 /**************************************************************************
1641 * mciLoadCommandResource [WINMM.@]
1643 * Strangely, this function only exists as a UNICODE one.
1645 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1647 UINT ret
= MCI_NO_COMMAND_TABLE
;
1651 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1653 /* if a file named "resname.mci" exits, then load resource "resname" from it
1654 * otherwise directly from driver
1655 * We don't support it (who uses this feature ?), but we check anyway
1659 /* FIXME: we should put this back into order, but I never found a program
1660 * actually using this feature, so we may not need it
1665 strcat(strcpy(buf
, resname
), ".mci");
1666 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1667 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1671 if ((hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
)) &&
1672 (hMem
= LoadResource(hInst
, hRsrc
))) {
1673 ret
= MCI_SetCommandTable(hMem
, type
);
1676 else WARN("No command table found in module for %s\n", debugstr_w(resNameW
));
1678 TRACE("=> %04x\n", ret
);
1682 /**************************************************************************
1683 * mciFreeCommandResource [WINMM.@]
1685 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1687 TRACE("(%08x)!\n", uTable
);
1689 if (uTable
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTable
].lpTable
)
1692 FreeResource(S_MciCmdTable
[uTable
].hMem
);
1693 S_MciCmdTable
[uTable
].hMem
= NULL
;
1694 S_MciCmdTable
[uTable
].lpTable
= NULL
;
1695 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTable
].aVerbs
);
1696 S_MciCmdTable
[uTable
].aVerbs
= 0;
1697 S_MciCmdTable
[uTable
].nVerbs
= 0;
1701 /**************************************************************************
1702 * MCI_Open [internal]
1704 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSW lpParms
)
1706 WCHAR strDevTyp
[128];
1708 LPWINE_MCIDRIVER wmd
= NULL
;
1710 TRACE("(%08X, %p)\n", dwParam
, lpParms
);
1711 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1713 /* only two low bytes are generic, the other ones are dev type specific */
1714 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1715 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1716 MCI_NOTIFY|MCI_WAIT)
1717 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0)
1718 FIXME("Unsupported yet dwFlags=%08X\n", dwParam
);
1719 #undef WINE_MCIDRIVER_SUPP
1723 if (dwParam
& MCI_OPEN_TYPE
) {
1724 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1725 WORD uDevType
= LOWORD(lpParms
->lpstrDeviceType
);
1727 if (uDevType
< MCI_DEVTYPE_FIRST
|| uDevType
> MCI_DEVTYPE_LAST
||
1728 !LoadStringW(hWinMM32Instance
, uDevType
, strDevTyp
, ARRAY_SIZE(strDevTyp
))) {
1729 dwRet
= MCIERR_BAD_INTEGER
;
1734 if (lpParms
->lpstrDeviceType
== NULL
) {
1735 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1738 lstrcpyW(strDevTyp
, lpParms
->lpstrDeviceType
);
1739 ptr
= wcschr(strDevTyp
, '!');
1741 /* this behavior is not documented in windows. However, since, in
1742 * some occasions, MCI_OPEN handling is translated by WinMM into
1743 * a call to mciSendString("open <type>"); this code shall be correct
1745 if (dwParam
& MCI_OPEN_ELEMENT
) {
1746 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1747 debugstr_w(lpParms
->lpstrElementName
),
1748 debugstr_w(strDevTyp
));
1749 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1752 dwParam
|= MCI_OPEN_ELEMENT
;
1754 /* FIXME: not a good idea to write in user supplied buffer */
1755 lpParms
->lpstrElementName
= ptr
;
1759 TRACE("devType=%s !\n", debugstr_w(strDevTyp
));
1762 if (dwParam
& MCI_OPEN_ELEMENT
) {
1763 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms
->lpstrElementName
));
1765 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1766 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1767 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1771 if (!lpParms
->lpstrElementName
) {
1772 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1776 /* type, if given as a parameter, supersedes file extension */
1777 if (!strDevTyp
[0] &&
1778 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1779 strDevTyp
, sizeof(strDevTyp
))) {
1780 if (GetDriveTypeW(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1781 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1784 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1785 lstrcpyW(strDevTyp
, L
"CDAUDIO");
1789 if (strDevTyp
[0] == 0) {
1790 FIXME("Couldn't load driver\n");
1791 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1795 if (dwParam
& MCI_OPEN_ALIAS
) {
1796 TRACE("Alias=%s !\n", debugstr_w(lpParms
->lpstrAlias
));
1797 if (!lpParms
->lpstrAlias
) {
1798 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1803 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1807 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1808 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet
);
1809 /* FIXME: is dwRet the correct ret code ? */
1813 /* only handled devices fall through */
1814 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1818 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1822 /**************************************************************************
1823 * MCI_Close [internal]
1825 static DWORD
MCI_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1828 LPWINE_MCIDRIVER wmd
;
1830 TRACE("(%04x, %08X, %p)\n", wDevID
, dwParam
, lpParms
);
1832 /* Every device must handle MCI_NOTIFY on its own. */
1833 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
1834 while (MciDrivers
) {
1835 /* Retrieve the device ID under lock, but send the message without,
1836 * the driver might be calling some winmm functions from another
1837 * thread before being fully stopped.
1839 EnterCriticalSection(&WINMM_cs
);
1842 LeaveCriticalSection(&WINMM_cs
);
1845 wDevID
= MciDrivers
->wDeviceID
;
1846 LeaveCriticalSection(&WINMM_cs
);
1847 MCI_Close(wDevID
, dwParam
, lpParms
);
1852 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1853 return MCIERR_INVALID_DEVICE_ID
;
1856 if(wmd
->CreatorThread
!= GetCurrentThreadId())
1857 return MCIERR_INVALID_DEVICE_NAME
;
1859 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD_PTR
)lpParms
);
1861 MCI_UnLoadMciDriver(wmd
);
1866 /**************************************************************************
1867 * MCI_WriteString [internal]
1869 static DWORD
MCI_WriteString(LPWSTR lpDstStr
, DWORD dstSize
, LPCWSTR lpSrcStr
)
1874 if (dstSize
<= lstrlenW(lpSrcStr
)) {
1875 ret
= MCIERR_PARAM_OVERFLOW
;
1877 lstrcpyW(lpDstStr
, lpSrcStr
);
1885 /**************************************************************************
1886 * MCI_Sysinfo [internal]
1888 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSW lpParms
)
1890 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1891 WCHAR buf
[2048], *s
, *p
;
1892 LPWINE_MCIDRIVER wmd
;
1895 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1896 if (lpParms
->lpstrReturn
== NULL
) return MCIERR_PARAM_OVERFLOW
;
1898 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1899 uDevID
, dwFlags
, lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1900 if ((WORD
)MCI_ALL_DEVICE_ID
== LOWORD(uDevID
))
1901 uDevID
= MCI_ALL_DEVICE_ID
; /* Be compatible with Win9x */
1903 switch (dwFlags
& ~(MCI_SYSINFO_OPEN
|MCI_NOTIFY
|MCI_WAIT
)) {
1904 case MCI_SYSINFO_QUANTITY
:
1905 if (lpParms
->dwRetSize
< sizeof(DWORD
))
1906 return MCIERR_PARAM_OVERFLOW
;
1907 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1908 if (uDevID
== MCI_ALL_DEVICE_ID
) {
1909 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1910 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1911 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1912 EnterCriticalSection(&WINMM_cs
);
1913 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1916 LeaveCriticalSection(&WINMM_cs
);
1918 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1919 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
,
1920 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1921 RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1922 RegCloseKey( hKey
);
1924 if (GetPrivateProfileStringW(L
"MCI", 0, L
"", buf
, ARRAY_SIZE(buf
), L
"system.ini"))
1925 for (s
= buf
; *s
; s
+= lstrlenW(s
) + 1) cnt
++;
1928 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1929 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms
->wDeviceType
);
1930 EnterCriticalSection(&WINMM_cs
);
1931 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1932 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1934 LeaveCriticalSection(&WINMM_cs
);
1936 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms
->wDeviceType
);
1937 FIXME("Don't know how to get # of MCI devices of a given type\n");
1938 /* name = LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType))
1939 * then lookup registry and/or system.ini for name, ignoring digits suffix */
1940 switch (LOWORD(lpParms
->wDeviceType
)) {
1941 case MCI_DEVTYPE_CD_AUDIO
:
1942 case MCI_DEVTYPE_WAVEFORM_AUDIO
:
1943 case MCI_DEVTYPE_SEQUENCER
:
1946 default: /* "digitalvideo" gets 0 because it's not in the registry */
1951 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1952 TRACE("(%d) => '%d'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1953 ret
= MCI_INTEGER_RETURNED
;
1954 /* return ret; Only Win9x sends a notification in this case. */
1956 case MCI_SYSINFO_INSTALLNAME
:
1957 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1958 if ((wmd
= MCI_GetDriver(uDevID
))) {
1959 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1960 wmd
->lpstrDeviceType
);
1962 ret
= (uDevID
== MCI_ALL_DEVICE_ID
)
1963 ? MCIERR_CANNOT_USE_ALL
: MCIERR_INVALID_DEVICE_NAME
;
1965 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1967 case MCI_SYSINFO_NAME
:
1969 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1970 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1971 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1972 uDevID
== MCI_ALL_DEVICE_ID
? MCI_ALL_DEVICE_ID
: lpParms
->wDeviceType
);
1973 EnterCriticalSection(&WINMM_cs
);
1974 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1975 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1976 if (uDevID
== MCI_ALL_DEVICE_ID
||
1977 lpParms
->wDeviceType
== wmd
->wType
) {
1979 if (cnt
== lpParms
->dwNumber
) {
1980 s
= wmd
->lpstrAlias
;
1985 LeaveCriticalSection(&WINMM_cs
);
1986 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
1987 } else if (MCI_ALL_DEVICE_ID
== uDevID
) {
1988 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms
->dwNumber
);
1989 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
, 0,
1990 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1991 if (RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
,
1992 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
&&
1993 lpParms
->dwNumber
<= cnt
) {
1994 DWORD bufLen
= ARRAY_SIZE(buf
);
1995 if (RegEnumKeyExW(hKey
, lpParms
->dwNumber
- 1,
1996 buf
, &bufLen
, 0, 0, 0, 0) == ERROR_SUCCESS
)
1999 RegCloseKey( hKey
);
2002 if (GetPrivateProfileStringW(L
"MCI", 0, L
"", buf
, ARRAY_SIZE(buf
), L
"system.ini")) {
2003 for (p
= buf
; *p
; p
+= lstrlenW(p
) + 1, cnt
++) {
2004 TRACE("%d: %s\n", cnt
, debugstr_w(p
));
2005 if (cnt
== lpParms
->dwNumber
- 1) {
2012 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
2014 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms
->wDeviceType
);
2015 /* Cheating: what is asked for is the nth device from the registry. */
2016 if (1 != lpParms
->dwNumber
|| /* Handle only one of each kind. */
2017 lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
)
2018 ret
= MCIERR_OUTOFRANGE
;
2020 LoadStringW(hWinMM32Instance
, LOWORD(lpParms
->wDeviceType
),
2021 lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
2025 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
2028 TRACE("Unsupported flag value=%08x\n", dwFlags
);
2029 ret
= MCIERR_UNRECOGNIZED_KEYWORD
;
2031 if ((dwFlags
& MCI_NOTIFY
) && HRESULT_CODE(ret
)==0)
2032 mciDriverNotify((HWND
)lpParms
->dwCallback
, uDevID
, MCI_NOTIFY_SUCCESSFUL
);
2036 /**************************************************************************
2037 * MCI_Break [internal]
2039 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
2043 if (lpParms
== NULL
)
2044 return MCIERR_NULL_PARAMETER_BLOCK
;
2046 TRACE("(%08x, %08X, vkey %04X, hwnd %p)\n", wDevID
, dwFlags
,
2047 lpParms
->nVirtKey
, lpParms
->hwndBreak
);
2049 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_BREAK
, dwFlags
, (DWORD_PTR
)lpParms
);
2050 if (!dwRet
&& (dwFlags
& MCI_NOTIFY
))
2051 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2055 /**************************************************************************
2056 * MCI_Sound [internal]
2058 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMSW lpParms
)
2062 if (dwFlags
& MCI_SOUND_NAME
) {
2063 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
2064 else dwRet
= PlaySoundW(lpParms
->lpstrSoundName
, NULL
,
2065 SND_ALIAS
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2066 ? 0 : MCIERR_HARDWARE
;
2067 } else dwRet
= PlaySoundW((LPCWSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
,
2068 SND_ALIAS_ID
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2069 ? 0 : MCIERR_HARDWARE
;
2071 if (!dwRet
&& lpParms
&& (dwFlags
& MCI_NOTIFY
))
2072 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2076 /**************************************************************************
2077 * MCI_SendCommand [internal]
2079 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2081 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
2085 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
2088 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
2091 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSW
)dwParam2
);
2094 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
2097 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMSW
)dwParam2
);
2100 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
2101 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2102 dwRet
= MCIERR_CANNOT_USE_ALL
;
2104 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
2111 /**************************************************************************
2112 * MCI_CleanUp [internal]
2114 * Some MCI commands need to be cleaned-up (when not called from
2115 * mciSendString), because MCI drivers return extra information for string
2116 * transformation. This function gets rid of them.
2118 static LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD_PTR dwParam2
)
2121 return LOWORD(dwRet
);
2124 case MCI_GETDEVCAPS
:
2125 switch (dwRet
& 0xFFFF0000ul
) {
2127 case MCI_COLONIZED3_RETURN
:
2128 case MCI_COLONIZED4_RETURN
:
2129 case MCI_INTEGER_RETURNED
:
2132 case MCI_RESOURCE_RETURNED
:
2133 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2135 LPMCI_GETDEVCAPS_PARMS lmgp
;
2137 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)dwParam2
;
2138 TRACE("Changing %08x to %08x\n", lmgp
->dwReturn
, LOWORD(lmgp
->dwReturn
));
2139 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
2143 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2144 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2148 switch (dwRet
& 0xFFFF0000ul
) {
2150 case MCI_COLONIZED3_RETURN
:
2151 case MCI_COLONIZED4_RETURN
:
2152 case MCI_INTEGER_RETURNED
:
2155 case MCI_RESOURCE_RETURNED
:
2156 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2158 LPMCI_STATUS_PARMS lsp
;
2160 lsp
= (LPMCI_STATUS_PARMS
)dwParam2
;
2161 TRACE("Changing %08lx to %08x\n", lsp
->dwReturn
, LOWORD(lsp
->dwReturn
));
2162 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
2166 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2167 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2171 switch (dwRet
& 0xFFFF0000ul
) {
2173 case MCI_INTEGER_RETURNED
:
2177 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
2181 if (HIWORD(dwRet
)) {
2182 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2183 dwRet
, MCI_MessageToString(wMsg
));
2187 return LOWORD(dwRet
);
2190 /**************************************************************************
2191 * mciGetErrorStringW [WINMM.@]
2193 BOOL WINAPI
mciGetErrorStringW(MCIERROR wError
, LPWSTR lpstrBuffer
, UINT uLength
)
2197 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2198 wError
>= MCIERR_BASE
&& wError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2200 if (LoadStringW(hWinMM32Instance
, wError
, lpstrBuffer
, uLength
) > 0) {
2207 /**************************************************************************
2208 * mciGetErrorStringA [WINMM.@]
2210 BOOL WINAPI
mciGetErrorStringA(MCIERROR dwError
, LPSTR lpstrBuffer
, UINT uLength
)
2214 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2215 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2217 if (LoadStringA(hWinMM32Instance
, dwError
, lpstrBuffer
, uLength
) > 0) {
2224 /**************************************************************************
2225 * mciDriverNotify [WINMM.@]
2227 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, MCIDEVICEID wDevID
, UINT wStatus
)
2229 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
2231 return PostMessageW(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
2234 /**************************************************************************
2235 * mciGetDriverData [WINMM.@]
2237 DWORD_PTR WINAPI
mciGetDriverData(MCIDEVICEID uDeviceID
)
2239 LPWINE_MCIDRIVER wmd
;
2241 TRACE("(%04x)\n", uDeviceID
);
2243 wmd
= MCI_GetDriver(uDeviceID
);
2246 WARN("Bad uDeviceID\n");
2250 return wmd
->dwPrivate
;
2253 /**************************************************************************
2254 * mciSetDriverData [WINMM.@]
2256 BOOL WINAPI
mciSetDriverData(MCIDEVICEID uDeviceID
, DWORD_PTR data
)
2258 LPWINE_MCIDRIVER wmd
;
2260 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
2262 wmd
= MCI_GetDriver(uDeviceID
);
2265 WARN("Bad uDeviceID\n");
2269 wmd
->dwPrivate
= data
;
2273 /**************************************************************************
2274 * mciSendCommandW [WINMM.@]
2277 DWORD WINAPI
mciSendCommandW(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2281 TRACE("(%08x, %s, %08lx, %08lx)\n",
2282 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2284 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
);
2285 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
2286 TRACE("=> %08x\n", dwRet
);
2290 /**************************************************************************
2291 * mciSendCommandA [WINMM.@]
2293 DWORD WINAPI
mciSendCommandA(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2298 TRACE("(%08x, %s, %08lx, %08lx)\n",
2299 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2301 mapped
= MCI_MapMsgAtoW(wMsg
, dwParam1
, &dwParam2
);
2304 FIXME("message %04x mapping failed\n", wMsg
);
2305 return MCIERR_OUT_OF_MEMORY
;
2307 ret
= mciSendCommandW(wDevID
, wMsg
, dwParam1
, dwParam2
);
2309 MCI_UnmapMsgAtoW(wMsg
, dwParam1
, dwParam2
, ret
);
2313 /**************************************************************************
2314 * mciGetDeviceIDA [WINMM.@]
2316 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
2318 LPWSTR w
= MCI_strdupAtoW(lpstrName
);
2319 UINT ret
= MCIERR_OUT_OF_MEMORY
;
2323 ret
= mciGetDeviceIDW(w
);
2324 HeapFree(GetProcessHeap(), 0, w
);
2329 /**************************************************************************
2330 * mciGetDeviceIDW [WINMM.@]
2332 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2334 return MCI_GetDriverFromString(lpwstrName
);
2337 /**************************************************************************
2338 * MCI_DefYieldProc [internal]
2340 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
2345 TRACE("(0x%04x, 0x%08x)\n", wDevID
, data
);
2347 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
2348 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2349 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2352 msg
.hwnd
= HWND_32(HIWORD(data
));
2353 while (!PeekMessageW(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2359 /**************************************************************************
2360 * mciSetYieldProc [WINMM.@]
2362 BOOL WINAPI
mciSetYieldProc(MCIDEVICEID uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2364 LPWINE_MCIDRIVER wmd
;
2366 TRACE("(%u, %p, %08x)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2368 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2369 WARN("Bad uDeviceID\n");
2373 wmd
->lpfnYieldProc
= fpYieldProc
;
2374 wmd
->dwYieldData
= dwYieldData
;
2379 /**************************************************************************
2380 * mciGetDeviceIDFromElementIDA [WINMM.@]
2382 UINT WINAPI
mciGetDeviceIDFromElementIDA(DWORD dwElementID
, LPCSTR lpstrType
)
2384 LPWSTR w
= MCI_strdupAtoW(lpstrType
);
2389 ret
= mciGetDeviceIDFromElementIDW(dwElementID
, w
);
2390 HeapFree(GetProcessHeap(), 0, w
);
2395 /**************************************************************************
2396 * mciGetDeviceIDFromElementIDW [WINMM.@]
2398 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2400 /* FIXME: that's rather strange, there is no
2401 * mciGetDeviceIDFromElementID32A in winmm.spec
2403 FIXME("(%u, %s) stub\n", dwElementID
, debugstr_w(lpstrType
));
2407 /**************************************************************************
2408 * mciGetYieldProc [WINMM.@]
2410 YIELDPROC WINAPI
mciGetYieldProc(MCIDEVICEID uDeviceID
, DWORD
* lpdwYieldData
)
2412 LPWINE_MCIDRIVER wmd
;
2414 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2416 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2417 WARN("Bad uDeviceID\n");
2420 if (!wmd
->lpfnYieldProc
) {
2421 WARN("No proc set\n");
2424 if (lpdwYieldData
) *lpdwYieldData
= wmd
->dwYieldData
;
2425 return wmd
->lpfnYieldProc
;
2428 /**************************************************************************
2429 * mciGetCreatorTask [WINMM.@]
2431 HTASK WINAPI
mciGetCreatorTask(MCIDEVICEID uDeviceID
)
2433 LPWINE_MCIDRIVER wmd
;
2436 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)(DWORD_PTR
)wmd
->CreatorThread
;
2438 TRACE("(%u) => %p\n", uDeviceID
, ret
);
2442 /**************************************************************************
2443 * mciDriverYield [WINMM.@]
2445 UINT WINAPI
mciDriverYield(MCIDEVICEID uDeviceID
)
2447 LPWINE_MCIDRIVER wmd
;
2450 TRACE("(%04x)\n", uDeviceID
);
2452 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
) {
2454 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2456 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);