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
41 #include "wine/port.h"
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
65 /* First MCI valid device ID (0 means error) */
66 #define MCI_MAGIC 0x0001
69 static const WCHAR wszHklmMci
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','M','C','I',0};
70 static const WCHAR wszNull
[] = {0};
71 static const WCHAR wszAll
[] = {'A','L','L',0};
72 static const WCHAR wszMci
[] = {'M','C','I',0};
73 static const WCHAR wszOpen
[] = {'o','p','e','n',0};
74 static const WCHAR wszSystemIni
[] = {'s','y','s','t','e','m','.','i','n','i',0};
76 static WINE_MCIDRIVER
*MciDrivers
;
78 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
);
79 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
);
81 /* dup a string and uppercase it */
82 static inline LPWSTR
str_dup_upper( LPCWSTR str
)
84 INT len
= (strlenW(str
) + 1) * sizeof(WCHAR
);
85 LPWSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
88 memcpy( p
, str
, len
);
94 /**************************************************************************
95 * MCI_GetDriver [internal]
97 static LPWINE_MCIDRIVER
MCI_GetDriver(UINT wDevID
)
99 LPWINE_MCIDRIVER wmd
= 0;
101 EnterCriticalSection(&WINMM_cs
);
102 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
103 if (wmd
->wDeviceID
== wDevID
)
106 LeaveCriticalSection(&WINMM_cs
);
110 /**************************************************************************
111 * MCI_GetDriverFromString [internal]
113 static UINT
MCI_GetDriverFromString(LPCWSTR lpstrName
)
115 LPWINE_MCIDRIVER wmd
;
121 if (!strcmpiW(lpstrName
, wszAll
))
122 return MCI_ALL_DEVICE_ID
;
124 EnterCriticalSection(&WINMM_cs
);
125 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
126 if (wmd
->lpstrAlias
&& strcmpiW(wmd
->lpstrAlias
, lpstrName
) == 0) {
127 ret
= wmd
->wDeviceID
;
131 LeaveCriticalSection(&WINMM_cs
);
136 /**************************************************************************
137 * MCI_MessageToString [internal]
139 static const char* MCI_MessageToString(UINT wMsg
)
141 #define CASE(s) case (s): return #s
151 CASE(DRV_QUERYCONFIGURE
);
154 CASE(DRV_EXITSESSION
);
155 CASE(DRV_EXITAPPLICATION
);
159 CASE(MCI_CLOSE_DRIVER
);
168 CASE(MCI_GETDEVCAPS
);
172 CASE(MCI_OPEN_DRIVER
);
191 /* constants for digital video */
205 return wine_dbg_sprintf("MCI_<<%04X>>", wMsg
);
209 static LPWSTR
MCI_strdupAtoW( LPCSTR str
)
214 if (!str
) return NULL
;
215 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
216 ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
217 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
221 static int MCI_MapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR
*dwParam2
)
223 if (msg
< DRV_RESERVED
) return 0;
258 { /* MCI_ANIM_OPEN_PARMS is the largest known MCI_OPEN_PARMS
259 * structure, larger than MCI_WAVE_OPEN_PARMS */
260 MCI_ANIM_OPEN_PARMSA
*mci_openA
= (MCI_ANIM_OPEN_PARMSA
*)*dwParam2
;
261 MCI_ANIM_OPEN_PARMSW
*mci_openW
;
264 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR
) + sizeof(*mci_openW
));
267 *ptr
++ = *dwParam2
; /* save the previous pointer */
268 *dwParam2
= (DWORD_PTR
)ptr
;
269 mci_openW
= (MCI_ANIM_OPEN_PARMSW
*)ptr
;
271 if (dwParam1
& MCI_NOTIFY
)
272 mci_openW
->dwCallback
= mci_openA
->dwCallback
;
274 if (dwParam1
& MCI_OPEN_TYPE
)
276 if (dwParam1
& MCI_OPEN_TYPE_ID
)
277 mci_openW
->lpstrDeviceType
= (LPCWSTR
)mci_openA
->lpstrDeviceType
;
279 mci_openW
->lpstrDeviceType
= MCI_strdupAtoW(mci_openA
->lpstrDeviceType
);
281 if (dwParam1
& MCI_OPEN_ELEMENT
)
283 if (dwParam1
& MCI_OPEN_ELEMENT_ID
)
284 mci_openW
->lpstrElementName
= (LPCWSTR
)mci_openA
->lpstrElementName
;
286 mci_openW
->lpstrElementName
= MCI_strdupAtoW(mci_openA
->lpstrElementName
);
288 if (dwParam1
& MCI_OPEN_ALIAS
)
289 mci_openW
->lpstrAlias
= MCI_strdupAtoW(mci_openA
->lpstrAlias
);
290 /* We don't know how many DWORD follow, as
291 * the structure depends on the device. */
292 if (HIWORD(dwParam1
))
293 memcpy(&mci_openW
->dwStyle
, &mci_openA
->dwStyle
, sizeof(MCI_ANIM_OPEN_PARMSW
) - sizeof(MCI_OPEN_PARMSW
));
298 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
300 MCI_ANIM_WINDOW_PARMSA
*mci_windowA
= (MCI_ANIM_WINDOW_PARMSA
*)*dwParam2
;
301 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
;
303 mci_windowW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW
));
304 if (!mci_windowW
) return -1;
306 *dwParam2
= (DWORD_PTR
)mci_windowW
;
308 mci_windowW
->lpstrText
= MCI_strdupAtoW(mci_windowA
->lpstrText
);
310 if (dwParam1
& MCI_NOTIFY
)
311 mci_windowW
->dwCallback
= mci_windowA
->dwCallback
;
312 if (dwParam1
& MCI_ANIM_WINDOW_HWND
)
313 mci_windowW
->hWnd
= mci_windowA
->hWnd
;
314 if (dwParam1
& MCI_ANIM_WINDOW_STATE
)
315 mci_windowW
->nCmdShow
= mci_windowA
->nCmdShow
;
322 if (dwParam1
& (MCI_SYSINFO_INSTALLNAME
| MCI_SYSINFO_NAME
))
324 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*dwParam2
;
325 MCI_SYSINFO_PARMSW
*mci_sysinfoW
;
328 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW
) + sizeof(DWORD_PTR
));
331 *ptr
++ = *dwParam2
; /* save the previous pointer */
332 *dwParam2
= (DWORD_PTR
)ptr
;
333 mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)ptr
;
335 if (dwParam1
& MCI_NOTIFY
)
336 mci_sysinfoW
->dwCallback
= mci_sysinfoA
->dwCallback
;
338 /* Size is measured in numbers of characters, despite what MSDN says. */
339 mci_sysinfoW
->dwRetSize
= mci_sysinfoA
->dwRetSize
;
340 mci_sysinfoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW
->dwRetSize
* sizeof(WCHAR
));
341 mci_sysinfoW
->dwNumber
= mci_sysinfoA
->dwNumber
;
342 mci_sysinfoW
->wDeviceType
= mci_sysinfoA
->wDeviceType
;
348 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*dwParam2
;
349 MCI_INFO_PARMSW
*mci_infoW
;
352 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW
) + sizeof(DWORD_PTR
));
355 *ptr
++ = *dwParam2
; /* save the previous pointer */
356 *dwParam2
= (DWORD_PTR
)ptr
;
357 mci_infoW
= (MCI_INFO_PARMSW
*)ptr
;
359 if (dwParam1
& MCI_NOTIFY
)
360 mci_infoW
->dwCallback
= mci_infoA
->dwCallback
;
362 /* Size is measured in numbers of characters. */
363 mci_infoW
->dwRetSize
= mci_infoA
->dwRetSize
;
364 mci_infoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_infoW
->dwRetSize
* sizeof(WCHAR
));
371 { /* All these commands have the same layout: callback + string + optional rect */
372 MCI_OVLY_LOAD_PARMSA
*mci_loadA
= (MCI_OVLY_LOAD_PARMSA
*)*dwParam2
;
373 MCI_OVLY_LOAD_PARMSW
*mci_loadW
;
375 mci_loadW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW
));
376 if (!mci_loadW
) return -1;
378 *dwParam2
= (DWORD_PTR
)mci_loadW
;
379 if (dwParam1
& MCI_NOTIFY
)
380 mci_loadW
->dwCallback
= mci_loadA
->dwCallback
;
381 mci_loadW
->lpfilename
= MCI_strdupAtoW(mci_loadA
->lpfilename
);
382 if ((MCI_SAVE
== msg
&& dwParam1
& MCI_DGV_RECT
) ||
383 (MCI_LOAD
== msg
&& dwParam1
& MCI_OVLY_RECT
) ||
384 (MCI_CAPTURE
== msg
&& dwParam1
& MCI_DGV_CAPTURE_AT
) ||
385 (MCI_RESTORE
== msg
&& dwParam1
& MCI_DGV_RESTORE_AT
))
386 mci_loadW
->rc
= mci_loadA
->rc
;
391 { /* All these commands have the same layout: callback + string */
392 MCI_VD_ESCAPE_PARMSA
*mci_vd_escapeA
= (MCI_VD_ESCAPE_PARMSA
*)*dwParam2
;
393 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
;
395 mci_vd_escapeW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW
));
396 if (!mci_vd_escapeW
) return -1;
398 *dwParam2
= (DWORD_PTR
)mci_vd_escapeW
;
399 if (dwParam1
& MCI_NOTIFY
)
400 mci_vd_escapeW
->dwCallback
= mci_vd_escapeA
->dwCallback
;
401 mci_vd_escapeW
->lpstrCommand
= MCI_strdupAtoW(mci_vd_escapeA
->lpstrCommand
);
406 if (!(dwParam1
& (MCI_DGV_SETVIDEO_QUALITY
| MCI_DGV_SETVIDEO_ALG
407 | MCI_DGV_SETAUDIO_QUALITY
| MCI_DGV_SETAUDIO_ALG
)))
409 /* fall through to default */
414 FIXME("Message %s needs translation\n", MCI_MessageToString(msg
));
415 return 0; /* pass through untouched */
419 static void MCI_UnmapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
,
426 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
427 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*ptr
;
428 MCI_OPEN_PARMSW
*mci_openW
= (MCI_OPEN_PARMSW
*)dwParam2
;
430 mci_openA
->wDeviceID
= mci_openW
->wDeviceID
;
432 if (dwParam1
& MCI_OPEN_TYPE
)
434 if (!(dwParam1
& MCI_OPEN_TYPE_ID
))
435 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrDeviceType
);
437 if (dwParam1
& MCI_OPEN_ELEMENT
)
439 if (!(dwParam1
& MCI_OPEN_ELEMENT_ID
))
440 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrElementName
);
442 if (dwParam1
& MCI_OPEN_ALIAS
)
443 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrAlias
);
444 HeapFree(GetProcessHeap(), 0, ptr
);
448 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
450 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
= (MCI_ANIM_WINDOW_PARMSW
*)dwParam2
;
452 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW
->lpstrText
);
453 HeapFree(GetProcessHeap(), 0, mci_windowW
);
458 if (dwParam1
& (MCI_SYSINFO_INSTALLNAME
| MCI_SYSINFO_NAME
))
460 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
461 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*ptr
;
462 MCI_SYSINFO_PARMSW
*mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)dwParam2
;
466 WideCharToMultiByte(CP_ACP
, 0,
467 mci_sysinfoW
->lpstrReturn
, mci_sysinfoW
->dwRetSize
,
468 mci_sysinfoA
->lpstrReturn
, mci_sysinfoA
->dwRetSize
,
472 HeapFree(GetProcessHeap(), 0, mci_sysinfoW
->lpstrReturn
);
473 HeapFree(GetProcessHeap(), 0, ptr
);
478 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
479 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*ptr
;
480 MCI_INFO_PARMSW
*mci_infoW
= (MCI_INFO_PARMSW
*)dwParam2
;
484 WideCharToMultiByte(CP_ACP
, 0,
485 mci_infoW
->lpstrReturn
, mci_infoW
->dwRetSize
,
486 mci_infoA
->lpstrReturn
, mci_infoA
->dwRetSize
,
490 HeapFree(GetProcessHeap(), 0, mci_infoW
->lpstrReturn
);
491 HeapFree(GetProcessHeap(), 0, ptr
);
498 { /* All these commands have the same layout: callback + string + optional rect */
499 MCI_OVLY_LOAD_PARMSW
*mci_loadW
= (MCI_OVLY_LOAD_PARMSW
*)dwParam2
;
501 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW
->lpfilename
);
502 HeapFree(GetProcessHeap(), 0, mci_loadW
);
507 { /* All these commands have the same layout: callback + string */
508 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
= (MCI_VD_ESCAPE_PARMSW
*)dwParam2
;
510 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW
->lpstrCommand
);
511 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW
);
516 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg
));
521 /**************************************************************************
522 * MCI_GetDevTypeFromFileName [internal]
524 static DWORD
MCI_GetDevTypeFromFileName(LPCWSTR fileName
, LPWSTR buf
, UINT len
)
528 static const WCHAR keyW
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
529 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
530 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
531 if ((tmp
= strrchrW(fileName
, '.'))) {
532 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, keyW
,
533 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
535 LONG lRet
= RegQueryValueExW( hKey
, tmp
+ 1, 0, 0, (void*)buf
, &dwLen
);
537 if (lRet
== ERROR_SUCCESS
) return 0;
539 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp
));
541 return MCIERR_EXTENSION_NOT_FOUND
;
544 /**************************************************************************
545 * MCI_GetDevTypeFromResource [internal]
547 static UINT
MCI_GetDevTypeFromResource(LPCWSTR lpstrName
)
551 for (uDevType
= MCI_DEVTYPE_FIRST
; uDevType
<= MCI_DEVTYPE_LAST
; uDevType
++) {
552 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, sizeof(buf
) / sizeof(WCHAR
))) {
553 /* FIXME: ignore digits suffix */
554 if (!strcmpiW(buf
, lpstrName
))
561 #define MAX_MCICMDTABLE 20
562 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
564 typedef struct tagWINE_MCICMDTABLE
{
568 UINT nVerbs
; /* number of verbs in command table */
569 LPCWSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
570 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
572 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
574 /**************************************************************************
575 * MCI_IsCommandTableValid [internal]
577 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
586 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
587 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
589 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
592 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
595 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
596 flg
= *(const DWORD
*)lmem
;
597 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
598 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
600 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
602 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
603 case MCI_STRING
: if (inCst
) return FALSE
; break;
604 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
605 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
606 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
607 case MCI_FLAG
: if (!*str
) return FALSE
; break;
608 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
609 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
610 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
611 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
612 default: return FALSE
;
614 } while (eid
!= MCI_END_COMMAND_LIST
);
618 /**************************************************************************
619 * MCI_DumpCommandTable [internal]
621 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
628 if (!MCI_IsCommandTableValid(uTbl
)) {
629 ERR("Ooops: %d is not valid\n", uTbl
);
633 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
637 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
638 flg
= *(const DWORD
*)lmem
;
639 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
640 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
641 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
642 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
643 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
644 } while (eid
!= MCI_END_COMMAND_LIST
);
649 /**************************************************************************
650 * MCI_GetCommandTable [internal]
652 static UINT
MCI_GetCommandTable(UINT uDevType
)
658 /* first look up existing for existing devType */
659 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
660 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
664 /* well try to load id */
665 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
666 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, sizeof(buf
) / sizeof(WCHAR
))) {
669 } else if (uDevType
== 0) {
670 static const WCHAR wszCore
[] = {'C','O','R','E',0};
673 uTbl
= MCI_NO_COMMAND_TABLE
;
675 HRSRC hRsrc
= FindResourceW(hWinMM32Instance
, str
, (LPCWSTR
)RT_RCDATA
);
678 if (hRsrc
) hMem
= LoadResource(hWinMM32Instance
, hRsrc
);
680 uTbl
= MCI_SetCommandTable(hMem
, uDevType
);
682 WARN("No command table found in resource %p[%s]\n",
683 hWinMM32Instance
, debugstr_w(str
));
686 TRACE("=> %d\n", uTbl
);
690 /**************************************************************************
691 * MCI_SetCommandTable [internal]
693 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
)
696 static BOOL bInitDone
= FALSE
;
699 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
700 * can be called with 0 as a uDevType to retrieve it.
705 MCI_GetCommandTable(0);
707 TRACE("(%p, %u)\n", hMem
, uDevType
);
708 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
709 if (!S_MciCmdTable
[uTbl
].lpTable
) {
715 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
716 S_MciCmdTable
[uTbl
].lpTable
= LockResource(hMem
);
717 S_MciCmdTable
[uTbl
].hMem
= hMem
;
720 MCI_DumpCommandTable(uTbl
);
723 /* create the verbs table */
724 /* get # of entries */
725 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
729 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
730 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
731 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
732 if (eid
== MCI_COMMAND_HEAD
)
734 } while (eid
!= MCI_END_COMMAND_LIST
);
736 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCWSTR
));
737 S_MciCmdTable
[uTbl
].nVerbs
= count
;
739 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
743 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
744 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
745 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
746 if (eid
== MCI_COMMAND_HEAD
)
747 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
748 } while (eid
!= MCI_END_COMMAND_LIST
);
749 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
754 return MCI_NO_COMMAND_TABLE
;
757 /**************************************************************************
758 * MCI_UnLoadMciDriver [internal]
760 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
762 LPWINE_MCIDRIVER
* tmp
;
767 CloseDriver(wmd
->hDriver
, 0, 0);
769 if (wmd
->dwPrivate
!= 0)
770 WARN("Unloading mci driver with non nul dwPrivate field\n");
772 EnterCriticalSection(&WINMM_cs
);
773 for (tmp
= &MciDrivers
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
779 LeaveCriticalSection(&WINMM_cs
);
781 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
782 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
784 HeapFree(GetProcessHeap(), 0, wmd
);
788 /**************************************************************************
789 * MCI_OpenMciDriver [internal]
791 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCWSTR drvTyp
, DWORD_PTR lp
)
795 if (!DRIVER_GetLibName(drvTyp
, wszMci
, libName
, sizeof(libName
)))
798 /* First load driver */
799 wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
);
800 return wmd
->hDriver
!= NULL
;
803 /**************************************************************************
804 * MCI_LoadMciDriver [internal]
806 static DWORD
MCI_LoadMciDriver(LPCWSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
808 LPWSTR strDevTyp
= str_dup_upper(_strDevTyp
);
809 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
810 MCI_OPEN_DRIVER_PARMSW modp
;
813 if (!wmd
|| !strDevTyp
) {
814 dwRet
= MCIERR_OUT_OF_MEMORY
;
818 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
819 wmd
->dwYieldData
= VK_CANCEL
;
820 wmd
->CreatorThread
= GetCurrentThreadId();
822 EnterCriticalSection(&WINMM_cs
);
823 /* wmd must be inserted in list before sending opening the driver, because it
824 * may want to lookup at wDevID
826 wmd
->lpNext
= MciDrivers
;
829 for (modp
.wDeviceID
= MCI_MAGIC
;
830 MCI_GetDriver(modp
.wDeviceID
) != 0;
833 wmd
->wDeviceID
= modp
.wDeviceID
;
835 LeaveCriticalSection(&WINMM_cs
);
837 TRACE("wDevID=%04X\n", modp
.wDeviceID
);
839 modp
.lpstrParams
= NULL
;
841 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (DWORD_PTR
)&modp
)) {
842 /* silence warning if all is used... some bogus program use commands like
845 if (strcmpiW(strDevTyp
, wszAll
) == 0) {
846 dwRet
= MCIERR_CANNOT_USE_ALL
;
848 FIXME("Couldn't load driver for type %s.\n",
849 debugstr_w(strDevTyp
));
850 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
855 /* FIXME: should also check that module's description is of the form
856 * MODULENAME:[MCI] comment
859 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
860 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
861 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
863 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
864 wmd
->hDriver
, debugstr_w(strDevTyp
), modp
.wType
, modp
.wCustomCommandTable
);
866 wmd
->lpstrDeviceType
= strDevTyp
;
867 wmd
->wType
= modp
.wType
;
869 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
870 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
874 MCI_UnLoadMciDriver(wmd
);
875 HeapFree(GetProcessHeap(), 0, strDevTyp
);
880 /**************************************************************************
881 * MCI_SendCommandFrom32 [internal]
883 static DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
885 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
886 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
889 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
894 /**************************************************************************
895 * MCI_FinishOpen [internal]
897 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSW lpParms
,
900 LPCWSTR alias
= NULL
;
901 /* Open always defines an alias for further reference */
902 if (dwParam
& MCI_OPEN_ALIAS
) { /* open ... alias */
903 alias
= lpParms
->lpstrAlias
;
904 if (MCI_GetDriverFromString(alias
))
905 return MCIERR_DUPLICATE_ALIAS
;
907 if ((dwParam
& MCI_OPEN_ELEMENT
) /* open file.wav */
908 && !(dwParam
& MCI_OPEN_ELEMENT_ID
))
909 alias
= lpParms
->lpstrElementName
;
910 else if (dwParam
& MCI_OPEN_TYPE
) /* open cdaudio */
911 alias
= wmd
->lpstrDeviceType
;
912 if (alias
&& MCI_GetDriverFromString(alias
))
913 return MCIERR_DEVICE_OPEN
;
916 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, (strlenW(alias
)+1) * sizeof(WCHAR
));
917 if (!wmd
->lpstrAlias
) return MCIERR_OUT_OF_MEMORY
;
918 strcpyW( wmd
->lpstrAlias
, alias
);
919 /* In most cases, natives adds MCI_OPEN_ALIAS to the flags passed to the driver.
920 * Don't. The drivers don't care about the winmm alias. */
922 lpParms
->wDeviceID
= wmd
->wDeviceID
;
924 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
928 /**************************************************************************
929 * MCI_FindCommand [internal]
931 static LPCWSTR
MCI_FindCommand(UINT uTbl
, LPCWSTR verb
)
935 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
938 /* another improvement would be to have the aVerbs array sorted,
939 * so that we could use a dichotomic search on it, rather than this dumb
942 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
943 if (strcmpiW(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
944 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
950 /**************************************************************************
951 * MCI_GetReturnType [internal]
953 static DWORD
MCI_GetReturnType(LPCWSTR lpCmd
)
955 lpCmd
= (LPCWSTR
)((const BYTE
*)(lpCmd
+ strlenW(lpCmd
) + 1) + sizeof(DWORD
) + sizeof(WORD
));
956 if (*lpCmd
== '\0' && *(const WORD
*)((const BYTE
*)(lpCmd
+ 1) + sizeof(DWORD
)) == MCI_RETURN
) {
957 return *(const DWORD
*)(lpCmd
+ 1);
962 /**************************************************************************
963 * MCI_GetMessage [internal]
965 static WORD
MCI_GetMessage(LPCWSTR lpCmd
)
967 return (WORD
)*(const DWORD
*)(lpCmd
+ strlenW(lpCmd
) + 1);
970 /**************************************************************************
971 * MCI_GetDWord [internal]
973 static BOOL
MCI_GetDWord(DWORD
* data
, LPWSTR
* ptr
)
978 val
= strtoulW(*ptr
, &ret
, 0);
982 case ' ': ret
++; break;
983 default: return FALSE
;
991 /**************************************************************************
992 * MCI_GetString [internal]
994 static DWORD
MCI_GetString(LPWSTR
* str
, LPWSTR
* args
)
998 /* see if we have a quoted string */
1000 ptr
= strchrW(*str
= ptr
+ 1, '"');
1001 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
1002 /* FIXME: shall we escape \" from string ?? */
1003 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1004 *ptr
++ = '\0'; /* remove trailing " */
1005 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
1007 ptr
= strchrW(ptr
, ' ');
1012 ptr
= *args
+ strlenW(*args
);
1021 #define MCI_DATA_SIZE 16
1023 /**************************************************************************
1024 * MCI_ParseOptArgs [internal]
1026 static DWORD
MCI_ParseOptArgs(DWORD
* data
, int _offset
, LPCWSTR lpCmd
,
1027 LPWSTR args
, LPDWORD dwFlags
)
1032 DWORD dwRet
, flg
, cflg
= 0;
1036 /* loop on arguments */
1038 lmem
= (const char*)lpCmd
;
1039 found
= inCst
= FALSE
;
1042 /* skip any leading white space(s) */
1043 while (*args
== ' ') args
++;
1044 TRACE("args=%s\n", debugstr_w(args
));
1046 do { /* loop on options for command table for the requested verb */
1047 str
= (LPCWSTR
)lmem
;
1048 lmem
+= ((len
= strlenW(str
)) + 1) * sizeof(WCHAR
);
1049 flg
= *(const DWORD
*)lmem
;
1050 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
1051 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
1052 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1056 inCst
= TRUE
; cflg
= flg
; break;
1057 case MCI_END_CONSTANT
:
1058 /* there may be additional integral values after flag in constant */
1059 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
1062 inCst
= FALSE
; cflg
= 0;
1065 if (offset
!= _offset
) {
1066 ERR("MCI_RETURN not in first position\n");
1067 return MCIERR_PARSER_INTERNAL
;
1071 if (strncmpiW(args
, str
, len
) == 0 &&
1072 ((eid
== MCI_STRING
&& len
== 0) || args
[len
] == 0 || args
[len
] == ' ')) {
1073 /* store good values into data[] */
1075 while (*args
== ' ') args
++;
1079 case MCI_COMMAND_HEAD
:
1081 case MCI_END_COMMAND
:
1082 case MCI_END_COMMAND_LIST
:
1083 case MCI_CONSTANT
: /* done above */
1084 case MCI_END_CONSTANT
: /* done above */
1088 TRACE("flag=%08x\n", flg
);
1092 data
[offset
] |= flg
;
1095 TRACE("flag=%08x constant=%08x\n", cflg
, flg
);
1098 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
1099 return MCIERR_BAD_INTEGER
;
1101 TRACE("flag=%08x int=%d\n", flg
, data
[offset
]);
1105 /* store rect in data (offset..offset+3) */
1107 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
1108 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
1109 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
1110 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
1111 ERR("Bad rect %s\n", debugstr_w(args
));
1112 return MCIERR_BAD_INTEGER
;
1114 TRACE("flag=%08x for rectangle\n", flg
);
1118 if ((dwRet
= MCI_GetString((LPWSTR
*)&data
[offset
], &args
)))
1120 TRACE("flag=%08x string=%s\n", flg
, debugstr_w(*(LPWSTR
*)&data
[offset
]));
1122 default: ERR("oops\n");
1124 /* exit inside while loop, except if just entered in constant area definition */
1125 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
1127 /* have offset incremented if needed */
1129 case MCI_COMMAND_HEAD
:
1131 case MCI_END_COMMAND
:
1132 case MCI_END_COMMAND_LIST
:
1134 case MCI_FLAG
: break;
1135 case MCI_INTEGER
: if (!inCst
) offset
++; break;
1136 case MCI_END_CONSTANT
: offset
++; break;
1137 case MCI_STRING
: offset
+= sizeof(LPWSTR
)/sizeof(DWORD
); break;
1138 case MCI_RECT
: offset
+= 4; break;
1139 default: ERR("oops\n");
1142 } while (eid
!= MCI_END_COMMAND
);
1144 WARN("Optarg %s not found\n", debugstr_w(args
));
1145 return MCIERR_UNRECOGNIZED_COMMAND
;
1147 if (offset
== MCI_DATA_SIZE
) {
1148 ERR("Internal data[] buffer overflow\n");
1149 return MCIERR_PARSER_INTERNAL
;
1155 /**************************************************************************
1156 * MCI_HandleReturnValues [internal]
1158 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
1159 MCI_GENERIC_PARMS
*params
, LPWSTR lpstrRet
, UINT uRetLen
)
1161 static const WCHAR fmt_d
[] = {'%','d',0};
1162 static const WCHAR fmt_d4
[] = {'%','d',' ','%','d',' ','%','d',' ','%','d',0};
1163 static const WCHAR wszCol3
[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1164 static const WCHAR wszCol4
[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1168 case 0: /* nothing to return */
1172 DWORD data
= *(DWORD
*)(params
+ 1);
1173 switch (dwRet
& 0xFFFF0000ul
) {
1175 case MCI_INTEGER_RETURNED
:
1176 snprintfW(lpstrRet
, uRetLen
, fmt_d
, data
);
1178 case MCI_RESOURCE_RETURNED
:
1179 /* return string which ID is HIWORD(data),
1180 * string is loaded from mmsystem.dll */
1181 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1183 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1184 /* return string which ID is HIWORD(data),
1185 * string is loaded from driver */
1186 /* FIXME: this is wrong for a 16 bit handle */
1187 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1188 HIWORD(data
), lpstrRet
, uRetLen
);
1190 case MCI_COLONIZED3_RETURN
:
1191 snprintfW(lpstrRet
, uRetLen
, wszCol3
,
1192 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1193 LOBYTE(HIWORD(data
)));
1195 case MCI_COLONIZED4_RETURN
:
1196 snprintfW(lpstrRet
, uRetLen
, wszCol4
,
1197 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1198 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1200 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1205 switch (dwRet
& 0xFFFF0000ul
) {
1207 /* nothing to do data[0] == lpstrRet */
1209 case MCI_INTEGER_RETURNED
:
1211 DWORD
*data
= (DWORD
*)(params
+ 1);
1212 *data
= *(LPDWORD
)lpstrRet
;
1213 snprintfW(lpstrRet
, uRetLen
, fmt_d
, *data
);
1217 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1223 DWORD
*data
= (DWORD
*)(params
+ 1);
1224 if (dwRet
& 0xFFFF0000ul
)
1225 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1226 snprintfW(lpstrRet
, uRetLen
, fmt_d4
, data
[0], data
[1], data
[2], data
[3]);
1229 default: ERR("oops\n");
1232 return LOWORD(dwRet
);
1235 /**************************************************************************
1236 * mciSendStringW [WINMM.@]
1238 DWORD WINAPI
mciSendStringW(LPCWSTR lpstrCommand
, LPWSTR lpstrRet
,
1239 UINT uRetLen
, HWND hwndCallback
)
1241 LPWSTR verb
, dev
, args
;
1242 LPWINE_MCIDRIVER wmd
= 0;
1243 MCIDEVICEID uDevID
, auto_open
= 0;
1244 DWORD dwFlags
= 0, dwRet
= 0;
1249 static const WCHAR wszNew
[] = {'n','e','w',0};
1250 static const WCHAR wszSAliasS
[] = {' ','a','l','i','a','s',' ',0};
1251 static const WCHAR wszTypeS
[] = {'t','y','p','e',' ',0};
1254 MCI_GENERIC_PARMS generic
;
1255 MCI_OPEN_PARMSW open
;
1256 MCI_SOUND_PARMSW sound
;
1257 MCI_SYSINFO_PARMSW sysinfo
;
1258 DWORD dw
[MCI_DATA_SIZE
];
1261 TRACE("(%s, %p, %d, %p)\n",
1262 debugstr_w(lpstrCommand
), lpstrRet
, uRetLen
, hwndCallback
);
1263 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1265 /* format is <command> <device> <optargs> */
1266 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand
)+1) * sizeof(WCHAR
))))
1267 return MCIERR_OUT_OF_MEMORY
;
1268 strcpyW( verb
, lpstrCommand
);
1271 memset(&data
, 0, sizeof(data
));
1273 if (!(args
= strchrW(verb
, ' '))) {
1274 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1278 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
1281 uDevID
= strcmpiW(dev
, wszAll
) ? 0 : MCI_ALL_DEVICE_ID
;
1283 /* Determine devType from open */
1284 if (!strcmpW(verb
, wszOpen
)) {
1285 LPWSTR devType
, tmp
;
1288 /* case dev == 'new' has to be handled */
1289 if (!strcmpW(dev
, wszNew
)) {
1291 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1293 tmp
= strchrW(devType
, ' ');
1294 if (tmp
) *tmp
= '\0';
1295 devType
= str_dup_upper(devType
);
1296 if (tmp
) *tmp
= ' ';
1297 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1299 WARN("open new requires device type\n");
1300 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1303 } else if ((devType
= strchrW(dev
, '!')) != NULL
) {
1305 tmp
= devType
; devType
= dev
; dev
= tmp
;
1307 dwFlags
|= MCI_OPEN_TYPE
;
1308 data
.open
.lpstrDeviceType
= devType
;
1309 devType
= str_dup_upper(devType
);
1310 dwFlags
|= MCI_OPEN_ELEMENT
;
1311 data
.open
.lpstrElementName
= dev
;
1312 } else if (DRIVER_GetLibName(dev
, wszMci
, buf
, sizeof(buf
))) {
1313 /* this is the name of a mci driver's type */
1314 tmp
= strchrW(dev
, ' ');
1315 if (tmp
) *tmp
= '\0';
1316 data
.open
.lpstrDeviceType
= dev
;
1317 devType
= str_dup_upper(dev
);
1318 if (tmp
) *tmp
= ' ';
1319 dwFlags
|= MCI_OPEN_TYPE
;
1321 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1323 tmp
= strchrW(devType
, ' ');
1324 if (tmp
) *tmp
= '\0';
1325 devType
= str_dup_upper(devType
);
1326 if (tmp
) *tmp
= ' ';
1327 /* dwFlags and lpstrDeviceType will be correctly set in ParseOpt loop */
1329 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
1332 devType
= str_dup_upper(buf
);
1334 dwFlags
|= MCI_OPEN_ELEMENT
;
1335 data
.open
.lpstrElementName
= dev
;
1337 if (MCI_ALL_DEVICE_ID
== uDevID
) {
1338 dwRet
= MCIERR_CANNOT_USE_ALL
;
1341 if (!strstrW(args
, wszSAliasS
) && !dev
) {
1342 dwRet
= MCIERR_NEW_REQUIRES_ALIAS
;
1346 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
1347 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
1348 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1349 HeapFree(GetProcessHeap(), 0, devType
);
1352 } else if ((MCI_ALL_DEVICE_ID
!= uDevID
) && !(wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
)))
1353 && (lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
))) {
1354 /* auto-open uses the core command table */
1355 switch (MCI_GetMessage(lpCmd
)) {
1356 case MCI_SOUND
: /* command does not use a device name */
1359 case MCI_CLOSE
: /* don't auto-open for close */
1360 case MCI_BREAK
: /* no auto-open for system commands */
1361 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1366 static const WCHAR wszOpenWait
[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1367 WCHAR buf
[138], retbuf
[6];
1368 snprintfW(buf
, sizeof(buf
)/sizeof(WCHAR
), wszOpenWait
, dev
);
1369 /* open via mciSendString handles quoting, dev!file syntax and alias creation */
1370 if ((dwRet
= mciSendStringW(buf
, retbuf
, sizeof(retbuf
)/sizeof(WCHAR
), 0)) != 0)
1372 auto_open
= strtoulW(retbuf
, NULL
, 10);
1373 TRACE("auto-opened %u for %s\n", auto_open
, debugstr_w(dev
));
1375 /* FIXME: test for notify flag (how to preparse?) before opening */
1376 wmd
= MCI_GetDriver(auto_open
);
1378 ERR("No auto-open device %u\n", auto_open
);
1379 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1386 /* get the verb in the different command tables */
1388 /* try the device specific command table */
1389 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
1391 /* try the type specific command table */
1392 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1393 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1394 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1395 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1398 /* try core command table */
1399 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1402 TRACE("Command %s not found!\n", debugstr_w(verb
));
1403 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1406 wMsg
= MCI_GetMessage(lpCmd
);
1408 /* set return information */
1409 offset
= sizeof(data
.generic
);
1410 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1414 offset
+= sizeof(DWORD
);
1417 data
.sysinfo
.lpstrReturn
= lpstrRet
;
1418 data
.sysinfo
.dwRetSize
= uRetLen
;
1419 offset
= FIELD_OFFSET( MCI_SYSINFO_PARMSW
, dwNumber
);
1422 offset
+= 4 * sizeof(DWORD
);
1428 TRACE("verb=%s on dev=%s; offset=%d\n",
1429 debugstr_w(verb
), debugstr_w(dev
), offset
);
1431 if ((dwRet
= MCI_ParseOptArgs(data
.dw
, offset
/ sizeof(DWORD
), lpCmd
, args
, &dwFlags
)))
1434 /* set up call back */
1436 if (dwFlags
& MCI_NOTIFY
) {
1437 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1440 /* FIXME: the command should get its own notification window set up and
1441 * ask for device closing while processing the notification mechanism.
1442 * hwndCallback = ...
1443 * dwFlags |= MCI_NOTIFY;
1444 * In the meantime special-case all commands but PLAY and RECORD below. */
1446 if (dwFlags
& MCI_NOTIFY
) {
1447 data
.generic
.dwCallback
= (DWORD_PTR
)hwndCallback
;
1452 if (strcmpW(verb
, wszOpen
)) {
1453 FIXME("Cannot open with command %s\n", debugstr_w(verb
));
1454 dwRet
= MCIERR_INTERNAL
;
1460 /* Requirements on dev depend on the flags:
1461 * alias with INSTALLNAME, name like "digitalvideo"
1462 * with QUANTITY and NAME. */
1464 data
.sysinfo
.wDeviceType
= MCI_ALL_DEVICE_ID
;
1465 if (uDevID
!= MCI_ALL_DEVICE_ID
) {
1466 if (dwFlags
& MCI_SYSINFO_INSTALLNAME
)
1467 wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
));
1468 else if (!(data
.sysinfo
.wDeviceType
= MCI_GetDevTypeFromResource(dev
))) {
1469 dwRet
= MCIERR_DEVICE_TYPE_REQUIRED
;
1476 /* FIXME: name is optional, "sound" is a valid command.
1477 * FIXME: Parse "sound notify" as flag, not as name. */
1478 data
.sound
.lpstrSoundName
= dev
;
1479 dwFlags
|= MCI_SOUND_NAME
;
1483 TRACE("[%d, %s, %08x, %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x]\n",
1484 wmd
? wmd
->wDeviceID
: uDevID
, MCI_MessageToString(wMsg
), dwFlags
,
1485 data
.dw
[0], data
.dw
[1], data
.dw
[2], data
.dw
[3], data
.dw
[4],
1486 data
.dw
[5], data
.dw
[6], data
.dw
[7], data
.dw
[8], data
.dw
[9]);
1488 if (wMsg
== MCI_OPEN
) {
1489 if ((dwRet
= MCI_FinishOpen(wmd
, &data
.open
, dwFlags
)))
1491 /* FIXME: notification is not properly shared across two opens */
1493 dwRet
= MCI_SendCommand(wmd
? wmd
->wDeviceID
: uDevID
, wMsg
, dwFlags
, (DWORD_PTR
)&data
);
1495 TRACE("=> 1/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1496 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, &data
.generic
, lpstrRet
, uRetLen
);
1497 TRACE("=> 2/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1501 /* PLAY and RECORD are the only known non-immediate commands */
1502 if (LOWORD(dwRet
) || !(wMsg
== MCI_PLAY
|| wMsg
== MCI_RECORD
))
1503 MCI_SendCommand(auto_open
, MCI_CLOSE
, 0, 0);
1505 FIXME("leaking auto-open device %u\n", auto_open
);
1507 if (wMsg
== MCI_OPEN
&& LOWORD(dwRet
) && wmd
)
1508 MCI_UnLoadMciDriver(wmd
);
1509 HeapFree(GetProcessHeap(), 0, verb
);
1513 /**************************************************************************
1514 * mciSendStringA [WINMM.@]
1516 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
1517 UINT uRetLen
, HWND hwndCallback
)
1519 LPWSTR lpwstrCommand
;
1520 LPWSTR lpwstrRet
= NULL
;
1524 /* FIXME: is there something to do with lpstrReturnString ? */
1525 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, NULL
, 0 );
1526 lpwstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1527 MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, lpwstrCommand
, len
);
1530 lpwstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1532 WARN("no memory\n");
1533 HeapFree( GetProcessHeap(), 0, lpwstrCommand
);
1534 return MCIERR_OUT_OF_MEMORY
;
1537 ret
= mciSendStringW(lpwstrCommand
, lpwstrRet
, uRetLen
, hwndCallback
);
1538 if (!ret
&& lpwstrRet
)
1539 WideCharToMultiByte( CP_ACP
, 0, lpwstrRet
, -1, lpstrRet
, uRetLen
, NULL
, NULL
);
1540 HeapFree(GetProcessHeap(), 0, lpwstrCommand
);
1541 HeapFree(GetProcessHeap(), 0, lpwstrRet
);
1545 /**************************************************************************
1546 * mciExecute [WINMM.@]
1548 BOOL WINAPI
mciExecute(LPCSTR lpstrCommand
)
1553 TRACE("(%s)!\n", lpstrCommand
);
1555 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1557 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1558 sprintf(strRet
, "Unknown MCI error (%d)", ret
);
1560 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1562 /* FIXME: what shall I return ? */
1566 /**************************************************************************
1567 * mciLoadCommandResource [WINMM.@]
1569 * Strangely, this function only exists as a UNICODE one.
1571 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1573 UINT ret
= MCI_NO_COMMAND_TABLE
;
1577 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1579 /* if a file named "resname.mci" exits, then load resource "resname" from it
1580 * otherwise directly from driver
1581 * We don't support it (who uses this feature ?), but we check anyway
1585 /* FIXME: we should put this back into order, but I never found a program
1586 * actually using this feature, so we may not need it
1591 strcat(strcpy(buf
, resname
), ".mci");
1592 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1593 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1597 if ((hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
)) &&
1598 (hMem
= LoadResource(hInst
, hRsrc
))) {
1599 ret
= MCI_SetCommandTable(hMem
, type
);
1602 else WARN("No command table found in module for %s\n", debugstr_w(resNameW
));
1604 TRACE("=> %04x\n", ret
);
1608 /**************************************************************************
1609 * mciFreeCommandResource [WINMM.@]
1611 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1613 TRACE("(%08x)!\n", uTable
);
1615 if (uTable
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTable
].lpTable
)
1618 FreeResource(S_MciCmdTable
[uTable
].hMem
);
1619 S_MciCmdTable
[uTable
].hMem
= NULL
;
1620 S_MciCmdTable
[uTable
].lpTable
= NULL
;
1621 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTable
].aVerbs
);
1622 S_MciCmdTable
[uTable
].aVerbs
= 0;
1623 S_MciCmdTable
[uTable
].nVerbs
= 0;
1627 /**************************************************************************
1628 * MCI_Open [internal]
1630 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSW lpParms
)
1632 WCHAR strDevTyp
[128];
1634 LPWINE_MCIDRIVER wmd
= NULL
;
1636 TRACE("(%08X, %p)\n", dwParam
, lpParms
);
1637 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1639 /* only two low bytes are generic, the other ones are dev type specific */
1640 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1641 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1642 MCI_NOTIFY|MCI_WAIT)
1643 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1644 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1646 #undef WINE_MCIDRIVER_SUPP
1650 if (dwParam
& MCI_OPEN_TYPE
) {
1651 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1652 WORD uDevType
= LOWORD(lpParms
->lpstrDeviceType
);
1654 if (uDevType
< MCI_DEVTYPE_FIRST
||
1655 uDevType
> MCI_DEVTYPE_LAST
||
1656 !LoadStringW(hWinMM32Instance
, uDevType
,
1657 strDevTyp
, sizeof(strDevTyp
) / sizeof(WCHAR
))) {
1658 dwRet
= MCIERR_BAD_INTEGER
;
1663 if (lpParms
->lpstrDeviceType
== NULL
) {
1664 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1667 strcpyW(strDevTyp
, lpParms
->lpstrDeviceType
);
1668 ptr
= strchrW(strDevTyp
, '!');
1670 /* this behavior is not documented in windows. However, since, in
1671 * some occasions, MCI_OPEN handling is translated by WinMM into
1672 * a call to mciSendString("open <type>"); this code shall be correct
1674 if (dwParam
& MCI_OPEN_ELEMENT
) {
1675 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1676 debugstr_w(lpParms
->lpstrElementName
),
1677 debugstr_w(strDevTyp
));
1678 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1681 dwParam
|= MCI_OPEN_ELEMENT
;
1683 /* FIXME: not a good idea to write in user supplied buffer */
1684 lpParms
->lpstrElementName
= ptr
;
1688 TRACE("devType=%s !\n", debugstr_w(strDevTyp
));
1691 if (dwParam
& MCI_OPEN_ELEMENT
) {
1692 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms
->lpstrElementName
));
1694 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1695 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1696 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1700 if (!lpParms
->lpstrElementName
) {
1701 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1705 /* type, if given as a parameter, supersedes file extension */
1706 if (!strDevTyp
[0] &&
1707 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1708 strDevTyp
, sizeof(strDevTyp
))) {
1709 static const WCHAR wszCdAudio
[] = {'C','D','A','U','D','I','O',0};
1710 if (GetDriveTypeW(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1711 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1714 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1715 strcpyW(strDevTyp
, wszCdAudio
);
1719 if (strDevTyp
[0] == 0) {
1720 FIXME("Couldn't load driver\n");
1721 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1725 if (dwParam
& MCI_OPEN_ALIAS
) {
1726 TRACE("Alias=%s !\n", debugstr_w(lpParms
->lpstrAlias
));
1727 if (!lpParms
->lpstrAlias
) {
1728 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1733 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1737 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1738 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet
);
1739 /* FIXME: is dwRet the correct ret code ? */
1743 /* only handled devices fall through */
1744 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1748 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1752 /**************************************************************************
1753 * MCI_Close [internal]
1755 static DWORD
MCI_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1758 LPWINE_MCIDRIVER wmd
;
1760 TRACE("(%04x, %08X, %p)\n", wDevID
, dwParam
, lpParms
);
1762 /* Every device must handle MCI_NOTIFY on its own. */
1763 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
1764 while (MciDrivers
) {
1765 /* Retrieve the device ID under lock, but send the message without,
1766 * the driver might be calling some winmm functions from another
1767 * thread before being fully stopped.
1769 EnterCriticalSection(&WINMM_cs
);
1772 LeaveCriticalSection(&WINMM_cs
);
1775 wDevID
= MciDrivers
->wDeviceID
;
1776 LeaveCriticalSection(&WINMM_cs
);
1777 MCI_Close(wDevID
, dwParam
, lpParms
);
1782 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1783 return MCIERR_INVALID_DEVICE_ID
;
1786 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD_PTR
)lpParms
);
1788 MCI_UnLoadMciDriver(wmd
);
1793 /**************************************************************************
1794 * MCI_WriteString [internal]
1796 static DWORD
MCI_WriteString(LPWSTR lpDstStr
, DWORD dstSize
, LPCWSTR lpSrcStr
)
1801 if (dstSize
<= strlenW(lpSrcStr
)) {
1802 lstrcpynW(lpDstStr
, lpSrcStr
, dstSize
- 1);
1803 ret
= MCIERR_PARAM_OVERFLOW
;
1805 strcpyW(lpDstStr
, lpSrcStr
);
1813 /**************************************************************************
1814 * MCI_Sysinfo [internal]
1816 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSW lpParms
)
1818 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1819 WCHAR buf
[2048], *s
= buf
, *p
;
1820 LPWINE_MCIDRIVER wmd
;
1823 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1824 if (lpParms
->lpstrReturn
== NULL
) return MCIERR_PARAM_OVERFLOW
;
1826 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1827 uDevID
, dwFlags
, lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1828 if ((WORD
)MCI_ALL_DEVICE_ID
== LOWORD(uDevID
))
1829 uDevID
= MCI_ALL_DEVICE_ID
; /* Be compatible with Win9x */
1831 switch (dwFlags
& ~(MCI_SYSINFO_OPEN
|MCI_NOTIFY
|MCI_WAIT
)) {
1832 case MCI_SYSINFO_QUANTITY
:
1833 if (lpParms
->dwRetSize
< sizeof(DWORD
))
1834 return MCIERR_PARAM_OVERFLOW
;
1835 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1836 if (uDevID
== MCI_ALL_DEVICE_ID
) {
1837 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1838 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1839 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1840 EnterCriticalSection(&WINMM_cs
);
1841 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1844 LeaveCriticalSection(&WINMM_cs
);
1846 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1847 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
,
1848 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1849 RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1850 RegCloseKey( hKey
);
1852 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
))
1853 for (s
= buf
; *s
; s
+= strlenW(s
) + 1) cnt
++;
1856 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1857 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms
->wDeviceType
);
1858 EnterCriticalSection(&WINMM_cs
);
1859 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1860 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1862 LeaveCriticalSection(&WINMM_cs
);
1864 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms
->wDeviceType
);
1865 FIXME("Don't know how to get # of MCI devices of a given type\n");
1866 /* name = LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType))
1867 * then lookup registry and/or system.ini for name, ignoring digits suffix */
1868 switch (LOWORD(lpParms
->wDeviceType
)) {
1869 case MCI_DEVTYPE_CD_AUDIO
:
1870 case MCI_DEVTYPE_WAVEFORM_AUDIO
:
1871 case MCI_DEVTYPE_SEQUENCER
:
1874 default: /* "digitalvideo" gets 0 because it's not in the registry */
1879 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1880 TRACE("(%d) => '%d'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1881 ret
= MCI_INTEGER_RETURNED
;
1882 /* return ret; Only Win9x sends a notification in this case. */
1884 case MCI_SYSINFO_INSTALLNAME
:
1885 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1886 if ((wmd
= MCI_GetDriver(uDevID
))) {
1887 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1888 wmd
->lpstrDeviceType
);
1890 *lpParms
->lpstrReturn
= 0;
1891 ret
= (uDevID
== MCI_ALL_DEVICE_ID
)
1892 ? MCIERR_CANNOT_USE_ALL
: MCIERR_INVALID_DEVICE_NAME
;
1894 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1896 case MCI_SYSINFO_NAME
:
1898 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1899 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1900 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1901 uDevID
== MCI_ALL_DEVICE_ID
? MCI_ALL_DEVICE_ID
: lpParms
->wDeviceType
);
1902 EnterCriticalSection(&WINMM_cs
);
1903 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1904 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1905 if (uDevID
== MCI_ALL_DEVICE_ID
||
1906 lpParms
->wDeviceType
== wmd
->wType
) {
1908 if (cnt
== lpParms
->dwNumber
) {
1909 s
= wmd
->lpstrAlias
;
1914 LeaveCriticalSection(&WINMM_cs
);
1915 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
1916 } else if (MCI_ALL_DEVICE_ID
== uDevID
) {
1917 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms
->dwNumber
);
1918 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
, 0,
1919 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1920 if (RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
,
1921 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
&&
1922 lpParms
->dwNumber
<= cnt
) {
1923 DWORD bufLen
= sizeof(buf
)/sizeof(buf
[0]);
1924 if (RegEnumKeyExW(hKey
, lpParms
->dwNumber
- 1,
1925 buf
, &bufLen
, 0, 0, 0, 0) == ERROR_SUCCESS
)
1928 RegCloseKey( hKey
);
1931 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
)) {
1932 for (p
= buf
; *p
; p
+= strlenW(p
) + 1, cnt
++) {
1933 TRACE("%d: %s\n", cnt
, debugstr_w(p
));
1934 if (cnt
== lpParms
->dwNumber
- 1) {
1941 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
1943 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms
->wDeviceType
);
1944 /* Cheating: what is asked for is the nth device from the registry. */
1945 if (1 != lpParms
->dwNumber
|| /* Handle only one of each kind. */
1946 lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
)
1947 ret
= MCIERR_OUTOFRANGE
;
1949 LoadStringW(hWinMM32Instance
, LOWORD(lpParms
->wDeviceType
),
1950 lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
1954 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1957 TRACE("Unsupported flag value=%08x\n", dwFlags
);
1958 ret
= MCIERR_UNRECOGNIZED_KEYWORD
;
1960 if ((dwFlags
& MCI_NOTIFY
) && HRESULT_CODE(ret
)==0)
1961 mciDriverNotify((HWND
)lpParms
->dwCallback
, uDevID
, MCI_NOTIFY_SUCCESSFUL
);
1965 /**************************************************************************
1966 * MCI_Break [internal]
1968 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1972 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1973 FIXME("(%04x) vkey %04X stub\n", dwFlags
, lpParms
->nVirtKey
);
1975 if (MMSYSERR_NOERROR
==dwRet
&& (dwFlags
& MCI_NOTIFY
))
1976 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
1980 /**************************************************************************
1981 * MCI_Sound [internal]
1983 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMSW lpParms
)
1987 if (dwFlags
& MCI_SOUND_NAME
) {
1988 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1989 else dwRet
= PlaySoundW(lpParms
->lpstrSoundName
, NULL
,
1990 SND_ALIAS
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
1991 ? 0 : MCIERR_HARDWARE
;
1992 } else dwRet
= PlaySoundW((LPCWSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
,
1993 SND_ALIAS_ID
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
1994 ? 0 : MCIERR_HARDWARE
;
1996 if (!dwRet
&& lpParms
&& (dwFlags
& MCI_NOTIFY
))
1997 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2001 /**************************************************************************
2002 * MCI_SendCommand [internal]
2004 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2006 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
2010 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
2013 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
2016 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSW
)dwParam2
);
2019 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
2022 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMSW
)dwParam2
);
2025 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
2026 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2027 dwRet
= MCIERR_CANNOT_USE_ALL
;
2029 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
2036 /**************************************************************************
2037 * MCI_CleanUp [internal]
2039 * Some MCI commands need to be cleaned-up (when not called from
2040 * mciSendString), because MCI drivers return extra information for string
2041 * transformation. This function gets rid of them.
2043 static LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD_PTR dwParam2
)
2046 return LOWORD(dwRet
);
2049 case MCI_GETDEVCAPS
:
2050 switch (dwRet
& 0xFFFF0000ul
) {
2052 case MCI_COLONIZED3_RETURN
:
2053 case MCI_COLONIZED4_RETURN
:
2054 case MCI_INTEGER_RETURNED
:
2057 case MCI_RESOURCE_RETURNED
:
2058 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2060 LPMCI_GETDEVCAPS_PARMS lmgp
;
2062 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)dwParam2
;
2063 TRACE("Changing %08x to %08x\n", lmgp
->dwReturn
, LOWORD(lmgp
->dwReturn
));
2064 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
2068 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2069 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2073 switch (dwRet
& 0xFFFF0000ul
) {
2075 case MCI_COLONIZED3_RETURN
:
2076 case MCI_COLONIZED4_RETURN
:
2077 case MCI_INTEGER_RETURNED
:
2080 case MCI_RESOURCE_RETURNED
:
2081 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2083 LPMCI_STATUS_PARMS lsp
;
2085 lsp
= (LPMCI_STATUS_PARMS
)dwParam2
;
2086 TRACE("Changing %08lx to %08x\n", lsp
->dwReturn
, LOWORD(lsp
->dwReturn
));
2087 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
2091 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2092 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2096 switch (dwRet
& 0xFFFF0000ul
) {
2098 case MCI_INTEGER_RETURNED
:
2102 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
2106 if (HIWORD(dwRet
)) {
2107 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2108 dwRet
, MCI_MessageToString(wMsg
));
2112 return LOWORD(dwRet
);
2115 /**************************************************************************
2116 * mciGetErrorStringW [WINMM.@]
2118 BOOL WINAPI
mciGetErrorStringW(MCIERROR wError
, LPWSTR lpstrBuffer
, UINT uLength
)
2122 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2123 wError
>= MCIERR_BASE
&& wError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2125 if (LoadStringW(hWinMM32Instance
, wError
, lpstrBuffer
, uLength
) > 0) {
2132 /**************************************************************************
2133 * mciGetErrorStringA [WINMM.@]
2135 BOOL WINAPI
mciGetErrorStringA(MCIERROR dwError
, LPSTR lpstrBuffer
, UINT uLength
)
2139 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2140 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2142 if (LoadStringA(hWinMM32Instance
, dwError
, lpstrBuffer
, uLength
) > 0) {
2149 /**************************************************************************
2150 * mciDriverNotify [WINMM.@]
2152 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, MCIDEVICEID wDevID
, UINT wStatus
)
2154 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
2156 return PostMessageW(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
2159 /**************************************************************************
2160 * mciGetDriverData [WINMM.@]
2162 DWORD_PTR WINAPI
mciGetDriverData(MCIDEVICEID uDeviceID
)
2164 LPWINE_MCIDRIVER wmd
;
2166 TRACE("(%04x)\n", uDeviceID
);
2168 wmd
= MCI_GetDriver(uDeviceID
);
2171 WARN("Bad uDeviceID\n");
2175 return wmd
->dwPrivate
;
2178 /**************************************************************************
2179 * mciSetDriverData [WINMM.@]
2181 BOOL WINAPI
mciSetDriverData(MCIDEVICEID uDeviceID
, DWORD_PTR data
)
2183 LPWINE_MCIDRIVER wmd
;
2185 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
2187 wmd
= MCI_GetDriver(uDeviceID
);
2190 WARN("Bad uDeviceID\n");
2194 wmd
->dwPrivate
= data
;
2198 /**************************************************************************
2199 * mciSendCommandW [WINMM.@]
2202 DWORD WINAPI
mciSendCommandW(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2206 TRACE("(%08x, %s, %08lx, %08lx)\n",
2207 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2209 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
);
2210 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
2211 TRACE("=> %08x\n", dwRet
);
2215 /**************************************************************************
2216 * mciSendCommandA [WINMM.@]
2218 DWORD WINAPI
mciSendCommandA(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2223 TRACE("(%08x, %s, %08lx, %08lx)\n",
2224 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2226 mapped
= MCI_MapMsgAtoW(wMsg
, dwParam1
, &dwParam2
);
2229 FIXME("message %04x mapping failed\n", wMsg
);
2230 return MCIERR_OUT_OF_MEMORY
;
2232 ret
= mciSendCommandW(wDevID
, wMsg
, dwParam1
, dwParam2
);
2234 MCI_UnmapMsgAtoW(wMsg
, dwParam1
, dwParam2
, ret
);
2238 /**************************************************************************
2239 * mciGetDeviceIDA [WINMM.@]
2241 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
2243 LPWSTR w
= MCI_strdupAtoW(lpstrName
);
2244 UINT ret
= MCIERR_OUT_OF_MEMORY
;
2248 ret
= mciGetDeviceIDW(w
);
2249 HeapFree(GetProcessHeap(), 0, w
);
2254 /**************************************************************************
2255 * mciGetDeviceIDW [WINMM.@]
2257 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2259 return MCI_GetDriverFromString(lpwstrName
);
2262 /**************************************************************************
2263 * MCI_DefYieldProc [internal]
2265 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
2270 TRACE("(0x%04x, 0x%08x)\n", wDevID
, data
);
2272 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
2273 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2274 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2277 msg
.hwnd
= HWND_32(HIWORD(data
));
2278 while (!PeekMessageW(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2284 /**************************************************************************
2285 * mciSetYieldProc [WINMM.@]
2287 BOOL WINAPI
mciSetYieldProc(MCIDEVICEID uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2289 LPWINE_MCIDRIVER wmd
;
2291 TRACE("(%u, %p, %08x)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2293 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2294 WARN("Bad uDeviceID\n");
2298 wmd
->lpfnYieldProc
= fpYieldProc
;
2299 wmd
->dwYieldData
= dwYieldData
;
2304 /**************************************************************************
2305 * mciGetDeviceIDFromElementIDA [WINMM.@]
2307 UINT WINAPI
mciGetDeviceIDFromElementIDA(DWORD dwElementID
, LPCSTR lpstrType
)
2309 LPWSTR w
= MCI_strdupAtoW(lpstrType
);
2314 ret
= mciGetDeviceIDFromElementIDW(dwElementID
, w
);
2315 HeapFree(GetProcessHeap(), 0, w
);
2320 /**************************************************************************
2321 * mciGetDeviceIDFromElementIDW [WINMM.@]
2323 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2325 /* FIXME: that's rather strange, there is no
2326 * mciGetDeviceIDFromElementID32A in winmm.spec
2328 FIXME("(%u, %s) stub\n", dwElementID
, debugstr_w(lpstrType
));
2332 /**************************************************************************
2333 * mciGetYieldProc [WINMM.@]
2335 YIELDPROC WINAPI
mciGetYieldProc(MCIDEVICEID uDeviceID
, DWORD
* lpdwYieldData
)
2337 LPWINE_MCIDRIVER wmd
;
2339 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2341 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2342 WARN("Bad uDeviceID\n");
2345 if (!wmd
->lpfnYieldProc
) {
2346 WARN("No proc set\n");
2349 if (lpdwYieldData
) *lpdwYieldData
= wmd
->dwYieldData
;
2350 return wmd
->lpfnYieldProc
;
2353 /**************************************************************************
2354 * mciGetCreatorTask [WINMM.@]
2356 HTASK WINAPI
mciGetCreatorTask(MCIDEVICEID uDeviceID
)
2358 LPWINE_MCIDRIVER wmd
;
2361 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)(DWORD_PTR
)wmd
->CreatorThread
;
2363 TRACE("(%u) => %p\n", uDeviceID
, ret
);
2367 /**************************************************************************
2368 * mciDriverYield [WINMM.@]
2370 UINT WINAPI
mciDriverYield(MCIDEVICEID uDeviceID
)
2372 LPWINE_MCIDRIVER wmd
;
2375 TRACE("(%04x)\n", uDeviceID
);
2377 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
) {
2379 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2381 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);