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 case 13: /* MCI_INTEGER64 */
1233 DWORD_PTR data
= *(DWORD_PTR
*)(params
+ 1);
1234 switch (dwRet
& 0xFFFF0000ul
) {
1236 case MCI_INTEGER_RETURNED
:
1237 swprintf(lpstrRet
, uRetLen
, L
"%ld", data
);
1239 case MCI_RESOURCE_RETURNED
:
1240 /* return string which ID is HIWORD(data),
1241 * string is loaded from mmsystem.dll */
1242 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1244 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1245 /* return string which ID is HIWORD(data),
1246 * string is loaded from driver */
1247 /* FIXME: this is wrong for a 16 bit handle */
1248 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1249 HIWORD(data
), lpstrRet
, uRetLen
);
1251 case MCI_COLONIZED3_RETURN
:
1252 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d",
1253 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1254 LOBYTE(HIWORD(data
)));
1256 case MCI_COLONIZED4_RETURN
:
1257 swprintf(lpstrRet
, uRetLen
, L
"%02d:%02d:%02d:%02d",
1258 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1259 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1261 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1266 switch (dwRet
& 0xFFFF0000ul
) {
1268 /* nothing to do data[0] == lpstrRet */
1270 case MCI_INTEGER_RETURNED
:
1272 DWORD
*data
= (DWORD
*)(params
+ 1);
1273 *data
= *(LPDWORD
)lpstrRet
;
1274 swprintf(lpstrRet
, uRetLen
, L
"%d", *data
);
1278 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1284 DWORD
*data
= (DWORD
*)(params
+ 1);
1285 if (dwRet
& 0xFFFF0000ul
)
1286 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1287 swprintf(lpstrRet
, uRetLen
, L
"%d %d %d %d", data
[0], data
[1], data
[2], data
[3]);
1290 default: FIXME("Unknown MCI return type %d\n", retType
);
1293 return LOWORD(dwRet
);
1296 /**************************************************************************
1297 * mciSendStringW [WINMM.@]
1299 DWORD WINAPI
mciSendStringW(LPCWSTR lpstrCommand
, LPWSTR lpstrRet
,
1300 UINT uRetLen
, HWND hwndCallback
)
1302 LPWSTR verb
, dev
, args
, devType
= NULL
;
1303 LPWINE_MCIDRIVER wmd
= 0;
1304 MCIDEVICEID uDevID
, auto_open
= 0;
1305 DWORD dwFlags
= 0, dwRet
= 0;
1312 MCI_GENERIC_PARMS generic
;
1313 MCI_OPEN_PARMSW open
;
1314 MCI_SOUND_PARMSW sound
;
1315 MCI_SYSINFO_PARMSW sysinfo
;
1316 DWORD dw
[MCI_DATA_SIZE
];
1319 TRACE("(%s, %p, %d, %p)\n",
1320 debugstr_w(lpstrCommand
), lpstrRet
, uRetLen
, hwndCallback
);
1321 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1323 if (!lpstrCommand
[0])
1324 return MCIERR_MISSING_COMMAND_STRING
;
1326 /* format is <command> <device> <optargs> */
1327 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(lpstrCommand
)+1) * sizeof(WCHAR
))))
1328 return MCIERR_OUT_OF_MEMORY
;
1329 lstrcpyW( verb
, lpstrCommand
);
1332 memset(&data
, 0, sizeof(data
));
1334 if (!(args
= wcschr(verb
, ' '))) {
1335 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1339 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
1342 uDevID
= wcsicmp(dev
, L
"ALL") ? 0 : MCI_ALL_DEVICE_ID
;
1344 /* Determine devType from open */
1345 if (!wcscmp(verb
, L
"open")) {
1349 /* case dev == 'new' has to be handled */
1350 if (!wcscmp(dev
, L
"new")) {
1352 if ((devType
= wcsstr(args
, L
"type ")) != NULL
) {
1354 tmp
= wcschr(devType
, ' ');
1355 if (tmp
) *tmp
= '\0';
1356 devType
= str_dup_upper(devType
);
1357 if (tmp
) *tmp
= ' ';
1358 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1360 WARN("open new requires device type\n");
1361 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1364 dwFlags
|= MCI_OPEN_ELEMENT
;
1365 data
.open
.lpstrElementName
= &L
""[0];
1366 } else if ((devType
= wcschr(dev
, '!')) != NULL
) {
1368 tmp
= devType
; devType
= dev
; dev
= tmp
;
1370 dwFlags
|= MCI_OPEN_TYPE
;
1371 data
.open
.lpstrDeviceType
= devType
;
1372 devType
= str_dup_upper(devType
);
1373 dwFlags
|= MCI_OPEN_ELEMENT
;
1374 data
.open
.lpstrElementName
= dev
;
1375 } else if (DRIVER_GetLibName(dev
, L
"MCI", buf
, sizeof(buf
))) {
1376 /* this is the name of a mci driver's type */
1377 tmp
= wcschr(dev
, ' ');
1378 if (tmp
) *tmp
= '\0';
1379 data
.open
.lpstrDeviceType
= dev
;
1380 devType
= str_dup_upper(dev
);
1381 if (tmp
) *tmp
= ' ';
1382 dwFlags
|= MCI_OPEN_TYPE
;
1384 if ((devType
= wcsstr(args
, L
"type ")) != NULL
) {
1386 tmp
= wcschr(devType
, ' ');
1387 if (tmp
) *tmp
= '\0';
1388 devType
= str_dup_upper(devType
);
1389 if (tmp
) *tmp
= ' ';
1390 /* dwFlags and lpstrDeviceType will be correctly set in ParseOpt loop */
1392 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
1395 devType
= str_dup_upper(buf
);
1397 dwFlags
|= MCI_OPEN_ELEMENT
;
1398 data
.open
.lpstrElementName
= dev
;
1400 if (MCI_ALL_DEVICE_ID
== uDevID
) {
1401 dwRet
= MCIERR_CANNOT_USE_ALL
;
1404 if (!wcsstr(args
, L
" alias ") && !dev
) {
1405 dwRet
= MCIERR_NEW_REQUIRES_ALIAS
;
1409 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
1410 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
1411 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1414 } else if ((MCI_ALL_DEVICE_ID
!= uDevID
) && !(wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
)))
1415 && (lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
))) {
1416 /* auto-open uses the core command table */
1417 switch (MCI_GetMessage(lpCmd
)) {
1418 case MCI_SOUND
: /* command does not use a device name */
1421 case MCI_CLOSE
: /* don't auto-open for close */
1422 case MCI_BREAK
: /* no auto-open for system commands */
1423 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1428 WCHAR buf
[138], retbuf
[6];
1429 swprintf(buf
, ARRAY_SIZE(buf
), L
"open %s wait", dev
);
1430 /* open via mciSendString handles quoting, dev!file syntax and alias creation */
1431 if ((dwRet
= mciSendStringW(buf
, retbuf
, ARRAY_SIZE(retbuf
), 0)) != 0)
1433 auto_open
= wcstoul(retbuf
, NULL
, 10);
1434 TRACE("auto-opened %u for %s\n", auto_open
, debugstr_w(dev
));
1436 /* FIXME: test for notify flag (how to preparse?) before opening */
1437 wmd
= MCI_GetDriver(auto_open
);
1439 ERR("No auto-open device %u\n", auto_open
);
1440 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1447 /* get the verb in the different command tables */
1449 /* try the device specific command table */
1450 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
1452 /* try the type specific command table */
1453 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1454 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1455 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1456 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1459 /* try core command table */
1460 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1463 TRACE("Command %s not found!\n", debugstr_w(verb
));
1464 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1467 wMsg
= MCI_GetMessage(lpCmd
);
1469 /* set return information */
1470 offset
= sizeof(data
.generic
);
1471 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1475 offset
+= sizeof(DWORD
);
1478 data
.sysinfo
.lpstrReturn
= lpstrRet
;
1479 data
.sysinfo
.dwRetSize
= uRetLen
;
1480 offset
= FIELD_OFFSET( MCI_SYSINFO_PARMSW
, dwNumber
);
1483 offset
+= 4 * sizeof(DWORD
);
1485 case 13: /* MCI_INTEGER64 */
1486 offset
+= sizeof(DWORD_PTR
);
1489 FIXME("Unknown MCI return type %d\n", retType
);
1490 dwRet
= MCIERR_PARSER_INTERNAL
;
1494 TRACE("verb=%s on dev=%s; offset=%d\n",
1495 debugstr_w(verb
), debugstr_w(dev
), offset
);
1497 if ((dwRet
= MCI_ParseOptArgs(data
.dw
, offset
/ sizeof(DWORD
), lpCmd
, args
, &dwFlags
)))
1500 /* set up call back */
1502 if (dwFlags
& MCI_NOTIFY
) {
1503 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1506 /* FIXME: the command should get its own notification window set up and
1507 * ask for device closing while processing the notification mechanism.
1508 * hwndCallback = ...
1509 * dwFlags |= MCI_NOTIFY;
1510 * In the meantime special-case all commands but PLAY and RECORD below. */
1512 if (dwFlags
& MCI_NOTIFY
) {
1513 data
.generic
.dwCallback
= (DWORD_PTR
)hwndCallback
;
1518 if (wcscmp(verb
, L
"open")) {
1519 FIXME("Cannot open with command %s\n", debugstr_w(verb
));
1520 dwRet
= MCIERR_DRIVER_INTERNAL
;
1526 /* Requirements on dev depend on the flags:
1527 * alias with INSTALLNAME, name like "digitalvideo"
1528 * with QUANTITY and NAME. */
1530 data
.sysinfo
.wDeviceType
= MCI_ALL_DEVICE_ID
;
1531 if (uDevID
!= MCI_ALL_DEVICE_ID
) {
1532 if (dwFlags
& MCI_SYSINFO_INSTALLNAME
)
1533 wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
));
1534 else if (!(data
.sysinfo
.wDeviceType
= MCI_GetDevTypeFromResource(dev
))) {
1535 dwRet
= MCIERR_DEVICE_TYPE_REQUIRED
;
1542 /* FIXME: name is optional, "sound" is a valid command.
1543 * FIXME: Parse "sound notify" as flag, not as name. */
1544 data
.sound
.lpstrSoundName
= dev
;
1545 dwFlags
|= MCI_SOUND_NAME
;
1549 TRACE("[%d, %s, %08x, %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x]\n",
1550 wmd
? wmd
->wDeviceID
: uDevID
, MCI_MessageToString(wMsg
), dwFlags
,
1551 data
.dw
[0], data
.dw
[1], data
.dw
[2], data
.dw
[3], data
.dw
[4],
1552 data
.dw
[5], data
.dw
[6], data
.dw
[7], data
.dw
[8], data
.dw
[9]);
1554 if (wMsg
== MCI_OPEN
) {
1555 if ((dwRet
= MCI_FinishOpen(wmd
, &data
.open
, dwFlags
)))
1557 /* FIXME: notification is not properly shared across two opens */
1559 dwRet
= MCI_SendCommand(wmd
? wmd
->wDeviceID
: uDevID
, wMsg
, dwFlags
, (DWORD_PTR
)&data
);
1561 if (!LOWORD(dwRet
)) {
1562 TRACE("=> 1/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1563 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, &data
.generic
, lpstrRet
, uRetLen
);
1564 TRACE("=> 2/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1566 TRACE("=> %x\n", dwRet
);
1570 /* PLAY and RECORD are the only known non-immediate commands */
1571 if (LOWORD(dwRet
) || !(wMsg
== MCI_PLAY
|| wMsg
== MCI_RECORD
))
1572 MCI_SendCommand(auto_open
, MCI_CLOSE
, 0, 0);
1574 FIXME("leaking auto-open device %u\n", auto_open
);
1576 if (wMsg
== MCI_OPEN
&& LOWORD(dwRet
) && wmd
)
1577 MCI_UnLoadMciDriver(wmd
);
1578 HeapFree(GetProcessHeap(), 0, devType
);
1579 HeapFree(GetProcessHeap(), 0, verb
);
1583 /**************************************************************************
1584 * mciSendStringA [WINMM.@]
1586 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
1587 UINT uRetLen
, HWND hwndCallback
)
1589 LPWSTR lpwstrCommand
;
1590 LPWSTR lpwstrRet
= NULL
;
1594 /* FIXME: is there something to do with lpstrReturnString ? */
1595 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, NULL
, 0 );
1596 lpwstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1597 MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, lpwstrCommand
, len
);
1600 if (uRetLen
) *lpstrRet
= '\0'; /* NT-w2k3 use memset(lpstrRet, 0, uRetLen); */
1601 lpwstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1603 HeapFree( GetProcessHeap(), 0, lpwstrCommand
);
1604 return MCIERR_OUT_OF_MEMORY
;
1607 ret
= mciSendStringW(lpwstrCommand
, lpwstrRet
, uRetLen
, hwndCallback
);
1608 if (!ret
&& lpwstrRet
)
1609 WideCharToMultiByte( CP_ACP
, 0, lpwstrRet
, -1, lpstrRet
, uRetLen
, NULL
, NULL
);
1610 HeapFree(GetProcessHeap(), 0, lpwstrCommand
);
1611 HeapFree(GetProcessHeap(), 0, lpwstrRet
);
1615 /**************************************************************************
1616 * mciExecute [WINMM.@]
1618 BOOL WINAPI
mciExecute(LPCSTR lpstrCommand
)
1623 TRACE("(%s)!\n", lpstrCommand
);
1625 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1627 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1628 sprintf(strRet
, "Unknown MCI error (%d)", ret
);
1630 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1632 /* FIXME: what shall I return ? */
1636 /**************************************************************************
1637 * mciLoadCommandResource [WINMM.@]
1639 * Strangely, this function only exists as a UNICODE one.
1641 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1643 UINT ret
= MCI_NO_COMMAND_TABLE
;
1647 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1649 /* if a file named "resname.mci" exits, then load resource "resname" from it
1650 * otherwise directly from driver
1651 * We don't support it (who uses this feature ?), but we check anyway
1655 /* FIXME: we should put this back into order, but I never found a program
1656 * actually using this feature, so we may not need it
1661 strcat(strcpy(buf
, resname
), ".mci");
1662 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1663 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1667 if ((hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
)) &&
1668 (hMem
= LoadResource(hInst
, hRsrc
))) {
1669 ret
= MCI_SetCommandTable(hMem
, type
);
1672 else WARN("No command table found in module for %s\n", debugstr_w(resNameW
));
1674 TRACE("=> %04x\n", ret
);
1678 /**************************************************************************
1679 * mciFreeCommandResource [WINMM.@]
1681 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1683 TRACE("(%08x)!\n", uTable
);
1685 if (uTable
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTable
].lpTable
)
1688 FreeResource(S_MciCmdTable
[uTable
].hMem
);
1689 S_MciCmdTable
[uTable
].hMem
= NULL
;
1690 S_MciCmdTable
[uTable
].lpTable
= NULL
;
1691 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTable
].aVerbs
);
1692 S_MciCmdTable
[uTable
].aVerbs
= 0;
1693 S_MciCmdTable
[uTable
].nVerbs
= 0;
1697 /**************************************************************************
1698 * MCI_Open [internal]
1700 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSW lpParms
)
1702 WCHAR strDevTyp
[128];
1704 LPWINE_MCIDRIVER wmd
= NULL
;
1706 TRACE("(%08X, %p)\n", dwParam
, lpParms
);
1707 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1709 /* only two low bytes are generic, the other ones are dev type specific */
1710 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1711 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1712 MCI_NOTIFY|MCI_WAIT)
1713 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0)
1714 FIXME("Unsupported yet dwFlags=%08X\n", dwParam
);
1715 #undef WINE_MCIDRIVER_SUPP
1719 if (dwParam
& MCI_OPEN_TYPE
) {
1720 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1721 WORD uDevType
= LOWORD(lpParms
->lpstrDeviceType
);
1723 if (uDevType
< MCI_DEVTYPE_FIRST
|| uDevType
> MCI_DEVTYPE_LAST
||
1724 !LoadStringW(hWinMM32Instance
, uDevType
, strDevTyp
, ARRAY_SIZE(strDevTyp
))) {
1725 dwRet
= MCIERR_BAD_INTEGER
;
1730 if (lpParms
->lpstrDeviceType
== NULL
) {
1731 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1734 lstrcpyW(strDevTyp
, lpParms
->lpstrDeviceType
);
1735 ptr
= wcschr(strDevTyp
, '!');
1737 /* this behavior is not documented in windows. However, since, in
1738 * some occasions, MCI_OPEN handling is translated by WinMM into
1739 * a call to mciSendString("open <type>"); this code shall be correct
1741 if (dwParam
& MCI_OPEN_ELEMENT
) {
1742 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1743 debugstr_w(lpParms
->lpstrElementName
),
1744 debugstr_w(strDevTyp
));
1745 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1748 dwParam
|= MCI_OPEN_ELEMENT
;
1750 /* FIXME: not a good idea to write in user supplied buffer */
1751 lpParms
->lpstrElementName
= ptr
;
1755 TRACE("devType=%s !\n", debugstr_w(strDevTyp
));
1758 if (dwParam
& MCI_OPEN_ELEMENT
) {
1759 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms
->lpstrElementName
));
1761 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1762 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1763 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1767 if (!lpParms
->lpstrElementName
) {
1768 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1772 /* type, if given as a parameter, supersedes file extension */
1773 if (!strDevTyp
[0] &&
1774 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1775 strDevTyp
, sizeof(strDevTyp
))) {
1776 if (GetDriveTypeW(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1777 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1780 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1781 lstrcpyW(strDevTyp
, L
"CDAUDIO");
1785 if (strDevTyp
[0] == 0) {
1786 FIXME("Couldn't load driver\n");
1787 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1791 if (dwParam
& MCI_OPEN_ALIAS
) {
1792 TRACE("Alias=%s !\n", debugstr_w(lpParms
->lpstrAlias
));
1793 if (!lpParms
->lpstrAlias
) {
1794 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1799 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1803 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1804 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet
);
1805 /* FIXME: is dwRet the correct ret code ? */
1809 /* only handled devices fall through */
1810 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1814 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1818 /**************************************************************************
1819 * MCI_Close [internal]
1821 static DWORD
MCI_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1824 LPWINE_MCIDRIVER wmd
;
1826 TRACE("(%04x, %08X, %p)\n", wDevID
, dwParam
, lpParms
);
1828 /* Every device must handle MCI_NOTIFY on its own. */
1829 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
1830 while (MciDrivers
) {
1831 /* Retrieve the device ID under lock, but send the message without,
1832 * the driver might be calling some winmm functions from another
1833 * thread before being fully stopped.
1835 EnterCriticalSection(&WINMM_cs
);
1838 LeaveCriticalSection(&WINMM_cs
);
1841 wDevID
= MciDrivers
->wDeviceID
;
1842 LeaveCriticalSection(&WINMM_cs
);
1843 MCI_Close(wDevID
, dwParam
, lpParms
);
1848 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1849 return MCIERR_INVALID_DEVICE_ID
;
1852 if(wmd
->CreatorThread
!= GetCurrentThreadId())
1853 return MCIERR_INVALID_DEVICE_NAME
;
1855 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD_PTR
)lpParms
);
1857 MCI_UnLoadMciDriver(wmd
);
1862 /**************************************************************************
1863 * MCI_WriteString [internal]
1865 static DWORD
MCI_WriteString(LPWSTR lpDstStr
, DWORD dstSize
, LPCWSTR lpSrcStr
)
1870 if (dstSize
<= lstrlenW(lpSrcStr
)) {
1871 ret
= MCIERR_PARAM_OVERFLOW
;
1873 lstrcpyW(lpDstStr
, lpSrcStr
);
1881 /**************************************************************************
1882 * MCI_Sysinfo [internal]
1884 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSW lpParms
)
1886 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1887 WCHAR buf
[2048], *s
, *p
;
1888 LPWINE_MCIDRIVER wmd
;
1891 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1892 if (lpParms
->lpstrReturn
== NULL
) return MCIERR_PARAM_OVERFLOW
;
1894 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1895 uDevID
, dwFlags
, lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1896 if ((WORD
)MCI_ALL_DEVICE_ID
== LOWORD(uDevID
))
1897 uDevID
= MCI_ALL_DEVICE_ID
; /* Be compatible with Win9x */
1899 switch (dwFlags
& ~(MCI_SYSINFO_OPEN
|MCI_NOTIFY
|MCI_WAIT
)) {
1900 case MCI_SYSINFO_QUANTITY
:
1901 if (lpParms
->dwRetSize
< sizeof(DWORD
))
1902 return MCIERR_PARAM_OVERFLOW
;
1903 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1904 if (uDevID
== MCI_ALL_DEVICE_ID
) {
1905 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1906 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1907 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1908 EnterCriticalSection(&WINMM_cs
);
1909 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1912 LeaveCriticalSection(&WINMM_cs
);
1914 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1915 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
,
1916 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1917 RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1918 RegCloseKey( hKey
);
1920 if (GetPrivateProfileStringW(L
"MCI", 0, L
"", buf
, ARRAY_SIZE(buf
), L
"system.ini"))
1921 for (s
= buf
; *s
; s
+= lstrlenW(s
) + 1) cnt
++;
1924 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1925 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms
->wDeviceType
);
1926 EnterCriticalSection(&WINMM_cs
);
1927 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1928 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1930 LeaveCriticalSection(&WINMM_cs
);
1932 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms
->wDeviceType
);
1933 FIXME("Don't know how to get # of MCI devices of a given type\n");
1934 /* name = LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType))
1935 * then lookup registry and/or system.ini for name, ignoring digits suffix */
1936 switch (LOWORD(lpParms
->wDeviceType
)) {
1937 case MCI_DEVTYPE_CD_AUDIO
:
1938 case MCI_DEVTYPE_WAVEFORM_AUDIO
:
1939 case MCI_DEVTYPE_SEQUENCER
:
1942 default: /* "digitalvideo" gets 0 because it's not in the registry */
1947 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1948 TRACE("(%d) => '%d'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1949 ret
= MCI_INTEGER_RETURNED
;
1950 /* return ret; Only Win9x sends a notification in this case. */
1952 case MCI_SYSINFO_INSTALLNAME
:
1953 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1954 if ((wmd
= MCI_GetDriver(uDevID
))) {
1955 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1956 wmd
->lpstrDeviceType
);
1958 ret
= (uDevID
== MCI_ALL_DEVICE_ID
)
1959 ? MCIERR_CANNOT_USE_ALL
: MCIERR_INVALID_DEVICE_NAME
;
1961 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1963 case MCI_SYSINFO_NAME
:
1965 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1966 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1967 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1968 uDevID
== MCI_ALL_DEVICE_ID
? MCI_ALL_DEVICE_ID
: lpParms
->wDeviceType
);
1969 EnterCriticalSection(&WINMM_cs
);
1970 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1971 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1972 if (uDevID
== MCI_ALL_DEVICE_ID
||
1973 lpParms
->wDeviceType
== wmd
->wType
) {
1975 if (cnt
== lpParms
->dwNumber
) {
1976 s
= wmd
->lpstrAlias
;
1981 LeaveCriticalSection(&WINMM_cs
);
1982 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
1983 } else if (MCI_ALL_DEVICE_ID
== uDevID
) {
1984 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms
->dwNumber
);
1985 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
, 0,
1986 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1987 if (RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
,
1988 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
&&
1989 lpParms
->dwNumber
<= cnt
) {
1990 DWORD bufLen
= ARRAY_SIZE(buf
);
1991 if (RegEnumKeyExW(hKey
, lpParms
->dwNumber
- 1,
1992 buf
, &bufLen
, 0, 0, 0, 0) == ERROR_SUCCESS
)
1995 RegCloseKey( hKey
);
1998 if (GetPrivateProfileStringW(L
"MCI", 0, L
"", buf
, ARRAY_SIZE(buf
), L
"system.ini")) {
1999 for (p
= buf
; *p
; p
+= lstrlenW(p
) + 1, cnt
++) {
2000 TRACE("%d: %s\n", cnt
, debugstr_w(p
));
2001 if (cnt
== lpParms
->dwNumber
- 1) {
2008 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
2010 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms
->wDeviceType
);
2011 /* Cheating: what is asked for is the nth device from the registry. */
2012 if (1 != lpParms
->dwNumber
|| /* Handle only one of each kind. */
2013 lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
)
2014 ret
= MCIERR_OUTOFRANGE
;
2016 LoadStringW(hWinMM32Instance
, LOWORD(lpParms
->wDeviceType
),
2017 lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
2021 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
2024 TRACE("Unsupported flag value=%08x\n", dwFlags
);
2025 ret
= MCIERR_UNRECOGNIZED_KEYWORD
;
2027 if ((dwFlags
& MCI_NOTIFY
) && HRESULT_CODE(ret
)==0)
2028 mciDriverNotify((HWND
)lpParms
->dwCallback
, uDevID
, MCI_NOTIFY_SUCCESSFUL
);
2032 /**************************************************************************
2033 * MCI_Break [internal]
2035 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
2039 if (lpParms
== NULL
)
2040 return MCIERR_NULL_PARAMETER_BLOCK
;
2042 TRACE("(%08x, %08X, vkey %04X, hwnd %p)\n", wDevID
, dwFlags
,
2043 lpParms
->nVirtKey
, lpParms
->hwndBreak
);
2045 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_BREAK
, dwFlags
, (DWORD_PTR
)lpParms
);
2046 if (!dwRet
&& (dwFlags
& MCI_NOTIFY
))
2047 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2051 /**************************************************************************
2052 * MCI_Sound [internal]
2054 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMSW lpParms
)
2058 if (dwFlags
& MCI_SOUND_NAME
) {
2059 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
2060 else dwRet
= PlaySoundW(lpParms
->lpstrSoundName
, NULL
,
2061 SND_ALIAS
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2062 ? 0 : MCIERR_HARDWARE
;
2063 } else dwRet
= PlaySoundW((LPCWSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
,
2064 SND_ALIAS_ID
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2065 ? 0 : MCIERR_HARDWARE
;
2067 if (!dwRet
&& lpParms
&& (dwFlags
& MCI_NOTIFY
))
2068 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2072 /**************************************************************************
2073 * MCI_SendCommand [internal]
2075 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2077 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
2081 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
2084 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
2087 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSW
)dwParam2
);
2090 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
2093 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMSW
)dwParam2
);
2096 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
2097 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2098 dwRet
= MCIERR_CANNOT_USE_ALL
;
2100 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
2107 /**************************************************************************
2108 * MCI_CleanUp [internal]
2110 * Some MCI commands need to be cleaned-up (when not called from
2111 * mciSendString), because MCI drivers return extra information for string
2112 * transformation. This function gets rid of them.
2114 static LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD_PTR dwParam2
)
2117 return LOWORD(dwRet
);
2120 case MCI_GETDEVCAPS
:
2121 switch (dwRet
& 0xFFFF0000ul
) {
2123 case MCI_COLONIZED3_RETURN
:
2124 case MCI_COLONIZED4_RETURN
:
2125 case MCI_INTEGER_RETURNED
:
2128 case MCI_RESOURCE_RETURNED
:
2129 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2131 LPMCI_GETDEVCAPS_PARMS lmgp
;
2133 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)dwParam2
;
2134 TRACE("Changing %08x to %08x\n", lmgp
->dwReturn
, LOWORD(lmgp
->dwReturn
));
2135 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
2139 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2140 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2144 switch (dwRet
& 0xFFFF0000ul
) {
2146 case MCI_COLONIZED3_RETURN
:
2147 case MCI_COLONIZED4_RETURN
:
2148 case MCI_INTEGER_RETURNED
:
2151 case MCI_RESOURCE_RETURNED
:
2152 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2154 LPMCI_STATUS_PARMS lsp
;
2156 lsp
= (LPMCI_STATUS_PARMS
)dwParam2
;
2157 TRACE("Changing %08lx to %08x\n", lsp
->dwReturn
, LOWORD(lsp
->dwReturn
));
2158 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
2162 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2163 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2167 switch (dwRet
& 0xFFFF0000ul
) {
2169 case MCI_INTEGER_RETURNED
:
2173 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
2177 if (HIWORD(dwRet
)) {
2178 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2179 dwRet
, MCI_MessageToString(wMsg
));
2183 return LOWORD(dwRet
);
2186 /**************************************************************************
2187 * mciGetErrorStringW [WINMM.@]
2189 BOOL WINAPI
mciGetErrorStringW(MCIERROR wError
, LPWSTR lpstrBuffer
, UINT uLength
)
2193 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2194 wError
>= MCIERR_BASE
&& wError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2196 if (LoadStringW(hWinMM32Instance
, wError
, lpstrBuffer
, uLength
) > 0) {
2203 /**************************************************************************
2204 * mciGetErrorStringA [WINMM.@]
2206 BOOL WINAPI
mciGetErrorStringA(MCIERROR dwError
, LPSTR lpstrBuffer
, UINT uLength
)
2210 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2211 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2213 if (LoadStringA(hWinMM32Instance
, dwError
, lpstrBuffer
, uLength
) > 0) {
2220 /**************************************************************************
2221 * mciDriverNotify [WINMM.@]
2223 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, MCIDEVICEID wDevID
, UINT wStatus
)
2225 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
2227 return PostMessageW(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
2230 /**************************************************************************
2231 * mciGetDriverData [WINMM.@]
2233 DWORD_PTR WINAPI
mciGetDriverData(MCIDEVICEID uDeviceID
)
2235 LPWINE_MCIDRIVER wmd
;
2237 TRACE("(%04x)\n", uDeviceID
);
2239 wmd
= MCI_GetDriver(uDeviceID
);
2242 WARN("Bad uDeviceID\n");
2246 return wmd
->dwPrivate
;
2249 /**************************************************************************
2250 * mciSetDriverData [WINMM.@]
2252 BOOL WINAPI
mciSetDriverData(MCIDEVICEID uDeviceID
, DWORD_PTR data
)
2254 LPWINE_MCIDRIVER wmd
;
2256 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
2258 wmd
= MCI_GetDriver(uDeviceID
);
2261 WARN("Bad uDeviceID\n");
2265 wmd
->dwPrivate
= data
;
2269 /**************************************************************************
2270 * mciSendCommandW [WINMM.@]
2273 DWORD WINAPI
mciSendCommandW(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2277 TRACE("(%08x, %s, %08lx, %08lx)\n",
2278 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2280 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
);
2281 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
2282 TRACE("=> %08x\n", dwRet
);
2286 /**************************************************************************
2287 * mciSendCommandA [WINMM.@]
2289 DWORD WINAPI
mciSendCommandA(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2294 TRACE("(%08x, %s, %08lx, %08lx)\n",
2295 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2297 mapped
= MCI_MapMsgAtoW(wMsg
, dwParam1
, &dwParam2
);
2300 FIXME("message %04x mapping failed\n", wMsg
);
2301 return MCIERR_OUT_OF_MEMORY
;
2303 ret
= mciSendCommandW(wDevID
, wMsg
, dwParam1
, dwParam2
);
2305 MCI_UnmapMsgAtoW(wMsg
, dwParam1
, dwParam2
, ret
);
2309 /**************************************************************************
2310 * mciGetDeviceIDA [WINMM.@]
2312 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
2314 LPWSTR w
= MCI_strdupAtoW(lpstrName
);
2315 UINT ret
= MCIERR_OUT_OF_MEMORY
;
2319 ret
= mciGetDeviceIDW(w
);
2320 HeapFree(GetProcessHeap(), 0, w
);
2325 /**************************************************************************
2326 * mciGetDeviceIDW [WINMM.@]
2328 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2330 return MCI_GetDriverFromString(lpwstrName
);
2333 /**************************************************************************
2334 * MCI_DefYieldProc [internal]
2336 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
2341 TRACE("(0x%04x, 0x%08x)\n", wDevID
, data
);
2343 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
2344 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2345 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2348 msg
.hwnd
= HWND_32(HIWORD(data
));
2349 while (!PeekMessageW(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2355 /**************************************************************************
2356 * mciSetYieldProc [WINMM.@]
2358 BOOL WINAPI
mciSetYieldProc(MCIDEVICEID uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2360 LPWINE_MCIDRIVER wmd
;
2362 TRACE("(%u, %p, %08x)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2364 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2365 WARN("Bad uDeviceID\n");
2369 wmd
->lpfnYieldProc
= fpYieldProc
;
2370 wmd
->dwYieldData
= dwYieldData
;
2375 /**************************************************************************
2376 * mciGetDeviceIDFromElementIDA [WINMM.@]
2378 UINT WINAPI
mciGetDeviceIDFromElementIDA(DWORD dwElementID
, LPCSTR lpstrType
)
2380 LPWSTR w
= MCI_strdupAtoW(lpstrType
);
2385 ret
= mciGetDeviceIDFromElementIDW(dwElementID
, w
);
2386 HeapFree(GetProcessHeap(), 0, w
);
2391 /**************************************************************************
2392 * mciGetDeviceIDFromElementIDW [WINMM.@]
2394 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2396 /* FIXME: that's rather strange, there is no
2397 * mciGetDeviceIDFromElementID32A in winmm.spec
2399 FIXME("(%u, %s) stub\n", dwElementID
, debugstr_w(lpstrType
));
2403 /**************************************************************************
2404 * mciGetYieldProc [WINMM.@]
2406 YIELDPROC WINAPI
mciGetYieldProc(MCIDEVICEID uDeviceID
, DWORD
* lpdwYieldData
)
2408 LPWINE_MCIDRIVER wmd
;
2410 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2412 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2413 WARN("Bad uDeviceID\n");
2416 if (!wmd
->lpfnYieldProc
) {
2417 WARN("No proc set\n");
2420 if (lpdwYieldData
) *lpdwYieldData
= wmd
->dwYieldData
;
2421 return wmd
->lpfnYieldProc
;
2424 /**************************************************************************
2425 * mciGetCreatorTask [WINMM.@]
2427 HTASK WINAPI
mciGetCreatorTask(MCIDEVICEID uDeviceID
)
2429 LPWINE_MCIDRIVER wmd
;
2432 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)(DWORD_PTR
)wmd
->CreatorThread
;
2434 TRACE("(%u) => %p\n", uDeviceID
, ret
);
2438 /**************************************************************************
2439 * mciDriverYield [WINMM.@]
2441 UINT WINAPI
mciDriverYield(MCIDEVICEID uDeviceID
)
2443 LPWINE_MCIDRIVER wmd
;
2446 TRACE("(%04x)\n", uDeviceID
);
2448 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
) {
2450 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2452 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);