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_DGV_INFO_PARMSA
*mci_infoA
= (MCI_DGV_INFO_PARMSA
*)*dwParam2
;
349 MCI_DGV_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_DGV_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
));
365 if (dwParam1
& MCI_DGV_INFO_ITEM
)
366 mci_infoW
->dwItem
= mci_infoA
->dwItem
;
373 { /* All these commands have the same layout: callback + string + optional rect */
374 MCI_OVLY_LOAD_PARMSA
*mci_loadA
= (MCI_OVLY_LOAD_PARMSA
*)*dwParam2
;
375 MCI_OVLY_LOAD_PARMSW
*mci_loadW
;
377 mci_loadW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW
));
378 if (!mci_loadW
) return -1;
380 *dwParam2
= (DWORD_PTR
)mci_loadW
;
381 if (dwParam1
& MCI_NOTIFY
)
382 mci_loadW
->dwCallback
= mci_loadA
->dwCallback
;
383 mci_loadW
->lpfilename
= MCI_strdupAtoW(mci_loadA
->lpfilename
);
384 if ((MCI_SAVE
== msg
&& dwParam1
& MCI_DGV_RECT
) ||
385 (MCI_LOAD
== msg
&& dwParam1
& MCI_OVLY_RECT
) ||
386 (MCI_CAPTURE
== msg
&& dwParam1
& MCI_DGV_CAPTURE_AT
) ||
387 (MCI_RESTORE
== msg
&& dwParam1
& MCI_DGV_RESTORE_AT
))
388 mci_loadW
->rc
= mci_loadA
->rc
;
393 { /* All these commands have the same layout: callback + string */
394 MCI_VD_ESCAPE_PARMSA
*mci_vd_escapeA
= (MCI_VD_ESCAPE_PARMSA
*)*dwParam2
;
395 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
;
397 mci_vd_escapeW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW
));
398 if (!mci_vd_escapeW
) return -1;
400 *dwParam2
= (DWORD_PTR
)mci_vd_escapeW
;
401 if (dwParam1
& MCI_NOTIFY
)
402 mci_vd_escapeW
->dwCallback
= mci_vd_escapeA
->dwCallback
;
403 mci_vd_escapeW
->lpstrCommand
= MCI_strdupAtoW(mci_vd_escapeA
->lpstrCommand
);
408 if (!(dwParam1
& (MCI_DGV_SETVIDEO_QUALITY
| MCI_DGV_SETVIDEO_ALG
409 | MCI_DGV_SETAUDIO_QUALITY
| MCI_DGV_SETAUDIO_ALG
)))
411 /* fall through to default */
416 FIXME("Message %s needs translation\n", MCI_MessageToString(msg
));
417 return 0; /* pass through untouched */
421 static void MCI_UnmapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
,
428 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
429 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*ptr
;
430 MCI_OPEN_PARMSW
*mci_openW
= (MCI_OPEN_PARMSW
*)dwParam2
;
432 mci_openA
->wDeviceID
= mci_openW
->wDeviceID
;
434 if (dwParam1
& MCI_OPEN_TYPE
)
436 if (!(dwParam1
& MCI_OPEN_TYPE_ID
))
437 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrDeviceType
);
439 if (dwParam1
& MCI_OPEN_ELEMENT
)
441 if (!(dwParam1
& MCI_OPEN_ELEMENT_ID
))
442 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrElementName
);
444 if (dwParam1
& MCI_OPEN_ALIAS
)
445 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrAlias
);
446 HeapFree(GetProcessHeap(), 0, ptr
);
450 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
452 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
= (MCI_ANIM_WINDOW_PARMSW
*)dwParam2
;
454 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW
->lpstrText
);
455 HeapFree(GetProcessHeap(), 0, mci_windowW
);
460 if (dwParam1
& (MCI_SYSINFO_INSTALLNAME
| MCI_SYSINFO_NAME
))
462 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
463 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*ptr
;
464 MCI_SYSINFO_PARMSW
*mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)dwParam2
;
468 WideCharToMultiByte(CP_ACP
, 0,
469 mci_sysinfoW
->lpstrReturn
, -1,
470 mci_sysinfoA
->lpstrReturn
, mci_sysinfoA
->dwRetSize
,
474 HeapFree(GetProcessHeap(), 0, mci_sysinfoW
->lpstrReturn
);
475 HeapFree(GetProcessHeap(), 0, ptr
);
480 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
481 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*ptr
;
482 MCI_INFO_PARMSW
*mci_infoW
= (MCI_INFO_PARMSW
*)dwParam2
;
486 WideCharToMultiByte(CP_ACP
, 0,
487 mci_infoW
->lpstrReturn
, -1,
488 mci_infoA
->lpstrReturn
, mci_infoA
->dwRetSize
,
492 HeapFree(GetProcessHeap(), 0, mci_infoW
->lpstrReturn
);
493 HeapFree(GetProcessHeap(), 0, ptr
);
500 { /* All these commands have the same layout: callback + string + optional rect */
501 MCI_OVLY_LOAD_PARMSW
*mci_loadW
= (MCI_OVLY_LOAD_PARMSW
*)dwParam2
;
503 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW
->lpfilename
);
504 HeapFree(GetProcessHeap(), 0, mci_loadW
);
509 { /* All these commands have the same layout: callback + string */
510 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
= (MCI_VD_ESCAPE_PARMSW
*)dwParam2
;
512 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW
->lpstrCommand
);
513 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW
);
518 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg
));
523 /**************************************************************************
524 * MCI_GetDevTypeFromFileName [internal]
526 static DWORD
MCI_GetDevTypeFromFileName(LPCWSTR fileName
, LPWSTR buf
, UINT len
)
530 static const WCHAR keyW
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
531 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
532 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
533 if ((tmp
= strrchrW(fileName
, '.'))) {
534 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, keyW
,
535 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
537 LONG lRet
= RegQueryValueExW( hKey
, tmp
+ 1, 0, 0, (void*)buf
, &dwLen
);
539 if (lRet
== ERROR_SUCCESS
) return 0;
541 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp
));
543 return MCIERR_EXTENSION_NOT_FOUND
;
546 /**************************************************************************
547 * MCI_GetDevTypeFromResource [internal]
549 static UINT
MCI_GetDevTypeFromResource(LPCWSTR lpstrName
)
553 for (uDevType
= MCI_DEVTYPE_FIRST
; uDevType
<= MCI_DEVTYPE_LAST
; uDevType
++) {
554 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, sizeof(buf
) / sizeof(WCHAR
))) {
555 /* FIXME: ignore digits suffix */
556 if (!strcmpiW(buf
, lpstrName
))
563 #define MAX_MCICMDTABLE 20
564 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
566 typedef struct tagWINE_MCICMDTABLE
{
570 UINT nVerbs
; /* number of verbs in command table */
571 LPCWSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
572 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
574 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
576 /**************************************************************************
577 * MCI_IsCommandTableValid [internal]
579 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
588 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
589 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
591 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
594 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
597 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
598 flg
= *(const DWORD
*)lmem
;
599 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
600 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
602 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
604 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
605 case MCI_STRING
: if (inCst
) return FALSE
; break;
606 case MCI_HWND
: /* Occurs inside MCI_CONSTANT as in "window handle default" */
609 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
610 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
611 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
612 case MCI_FLAG
: if (!*str
) return FALSE
; break;
613 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
614 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
615 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
616 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
617 default: return FALSE
;
619 } while (eid
!= MCI_END_COMMAND_LIST
);
623 /**************************************************************************
624 * MCI_DumpCommandTable [internal]
626 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
632 if (!MCI_IsCommandTableValid(uTbl
)) {
633 ERR("Ooops: %d is not valid\n", uTbl
);
637 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
642 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
643 /* flg = *(const DWORD*)lmem; */
644 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
645 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
646 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
647 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
648 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
649 } while (eid
!= MCI_END_COMMAND_LIST
);
654 /**************************************************************************
655 * MCI_GetCommandTable [internal]
657 static UINT
MCI_GetCommandTable(UINT uDevType
)
663 /* first look up existing for existing devType */
664 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
665 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
669 /* well try to load id */
670 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
671 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, sizeof(buf
) / sizeof(WCHAR
))) {
674 } else if (uDevType
== 0) {
675 static const WCHAR wszCore
[] = {'C','O','R','E',0};
678 uTbl
= MCI_NO_COMMAND_TABLE
;
680 HRSRC hRsrc
= FindResourceW(hWinMM32Instance
, str
, (LPCWSTR
)RT_RCDATA
);
683 if (hRsrc
) hMem
= LoadResource(hWinMM32Instance
, hRsrc
);
685 uTbl
= MCI_SetCommandTable(hMem
, uDevType
);
687 WARN("No command table found in resource %p[%s]\n",
688 hWinMM32Instance
, debugstr_w(str
));
691 TRACE("=> %d\n", uTbl
);
695 /**************************************************************************
696 * MCI_SetCommandTable [internal]
698 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
)
701 static BOOL bInitDone
= FALSE
;
704 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
705 * can be called with 0 as a uDevType to retrieve it.
710 MCI_GetCommandTable(0);
712 TRACE("(%p, %u)\n", hMem
, uDevType
);
713 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
714 if (!S_MciCmdTable
[uTbl
].lpTable
) {
720 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
721 S_MciCmdTable
[uTbl
].lpTable
= LockResource(hMem
);
722 S_MciCmdTable
[uTbl
].hMem
= hMem
;
725 MCI_DumpCommandTable(uTbl
);
728 /* create the verbs table */
729 /* get # of entries */
730 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
734 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
735 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
736 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
737 if (eid
== MCI_COMMAND_HEAD
)
739 } while (eid
!= MCI_END_COMMAND_LIST
);
741 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCWSTR
));
742 S_MciCmdTable
[uTbl
].nVerbs
= count
;
744 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
748 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
749 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
750 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
751 if (eid
== MCI_COMMAND_HEAD
)
752 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
753 } while (eid
!= MCI_END_COMMAND_LIST
);
754 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
759 return MCI_NO_COMMAND_TABLE
;
762 /**************************************************************************
763 * MCI_UnLoadMciDriver [internal]
765 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
767 LPWINE_MCIDRIVER
* tmp
;
772 CloseDriver(wmd
->hDriver
, 0, 0);
774 if (wmd
->dwPrivate
!= 0)
775 WARN("Unloading mci driver with non nul dwPrivate field\n");
777 EnterCriticalSection(&WINMM_cs
);
778 for (tmp
= &MciDrivers
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
784 LeaveCriticalSection(&WINMM_cs
);
786 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
787 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
789 HeapFree(GetProcessHeap(), 0, wmd
);
793 /**************************************************************************
794 * MCI_OpenMciDriver [internal]
796 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCWSTR drvTyp
, DWORD_PTR lp
)
800 if (!DRIVER_GetLibName(drvTyp
, wszMci
, libName
, sizeof(libName
)))
803 /* First load driver */
804 wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
);
805 return wmd
->hDriver
!= NULL
;
808 /**************************************************************************
809 * MCI_LoadMciDriver [internal]
811 static DWORD
MCI_LoadMciDriver(LPCWSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
813 LPWSTR strDevTyp
= str_dup_upper(_strDevTyp
);
814 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
815 MCI_OPEN_DRIVER_PARMSW modp
;
818 if (!wmd
|| !strDevTyp
) {
819 dwRet
= MCIERR_OUT_OF_MEMORY
;
823 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
824 wmd
->dwYieldData
= VK_CANCEL
;
825 wmd
->CreatorThread
= GetCurrentThreadId();
827 EnterCriticalSection(&WINMM_cs
);
828 /* wmd must be inserted in list before sending opening the driver, because it
829 * may want to lookup at wDevID
831 wmd
->lpNext
= MciDrivers
;
834 for (modp
.wDeviceID
= MCI_MAGIC
;
835 MCI_GetDriver(modp
.wDeviceID
) != 0;
838 wmd
->wDeviceID
= modp
.wDeviceID
;
840 LeaveCriticalSection(&WINMM_cs
);
842 TRACE("wDevID=%04X\n", modp
.wDeviceID
);
844 modp
.lpstrParams
= NULL
;
846 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (DWORD_PTR
)&modp
)) {
847 /* silence warning if all is used... some bogus program use commands like
850 if (strcmpiW(strDevTyp
, wszAll
) == 0) {
851 dwRet
= MCIERR_CANNOT_USE_ALL
;
853 FIXME("Couldn't load driver for type %s.\n",
854 debugstr_w(strDevTyp
));
855 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
860 /* FIXME: should also check that module's description is of the form
861 * MODULENAME:[MCI] comment
864 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
865 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
866 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
868 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
869 wmd
->hDriver
, debugstr_w(strDevTyp
), modp
.wType
, modp
.wCustomCommandTable
);
871 wmd
->lpstrDeviceType
= strDevTyp
;
872 wmd
->wType
= modp
.wType
;
874 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
875 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
879 MCI_UnLoadMciDriver(wmd
);
880 HeapFree(GetProcessHeap(), 0, strDevTyp
);
885 /**************************************************************************
886 * MCI_SendCommandFrom32 [internal]
888 static DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
890 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
891 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
894 if(wmd
->CreatorThread
!= GetCurrentThreadId())
895 return MCIERR_INVALID_DEVICE_NAME
;
897 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
902 /**************************************************************************
903 * MCI_FinishOpen [internal]
905 * Three modes of operation:
906 * 1 open foo.ext ... -> OPEN_ELEMENT with lpstrElementName=foo.ext
907 * open sequencer!foo.ext same with lpstrElementName=foo.ext
908 * 2 open new type waveaudio -> OPEN_ELEMENT with empty ("") lpstrElementName
909 * 3 open sequencer -> OPEN_ELEMENT unset, and
910 * capability sequencer (auto-open) likewise
912 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSW lpParms
,
915 LPCWSTR alias
= NULL
;
916 /* Open always defines an alias for further reference */
917 if (dwParam
& MCI_OPEN_ALIAS
) { /* open ... alias */
918 alias
= lpParms
->lpstrAlias
;
919 if (MCI_GetDriverFromString(alias
))
920 return MCIERR_DUPLICATE_ALIAS
;
922 if ((dwParam
& MCI_OPEN_ELEMENT
) /* open file.wav */
923 && !(dwParam
& MCI_OPEN_ELEMENT_ID
))
924 alias
= lpParms
->lpstrElementName
;
925 else if (dwParam
& MCI_OPEN_TYPE
) /* open cdaudio */
926 alias
= wmd
->lpstrDeviceType
;
927 if (alias
&& MCI_GetDriverFromString(alias
))
928 return MCIERR_DEVICE_OPEN
;
931 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, (strlenW(alias
)+1) * sizeof(WCHAR
));
932 if (!wmd
->lpstrAlias
) return MCIERR_OUT_OF_MEMORY
;
933 strcpyW( wmd
->lpstrAlias
, alias
);
934 /* In most cases, natives adds MCI_OPEN_ALIAS to the flags passed to the driver.
935 * Don't. The drivers don't care about the winmm alias. */
937 lpParms
->wDeviceID
= wmd
->wDeviceID
;
939 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
943 /**************************************************************************
944 * MCI_FindCommand [internal]
946 static LPCWSTR
MCI_FindCommand(UINT uTbl
, LPCWSTR verb
)
950 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
953 /* another improvement would be to have the aVerbs array sorted,
954 * so that we could use a dichotomic search on it, rather than this dumb
957 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
958 if (strcmpiW(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
959 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
965 /**************************************************************************
966 * MCI_GetReturnType [internal]
968 static DWORD
MCI_GetReturnType(LPCWSTR lpCmd
)
970 lpCmd
= (LPCWSTR
)((const BYTE
*)(lpCmd
+ strlenW(lpCmd
) + 1) + sizeof(DWORD
) + sizeof(WORD
));
971 if (*lpCmd
== '\0' && *(const WORD
*)((const BYTE
*)(lpCmd
+ 1) + sizeof(DWORD
)) == MCI_RETURN
) {
972 return *(const DWORD
*)(lpCmd
+ 1);
977 /**************************************************************************
978 * MCI_GetMessage [internal]
980 static WORD
MCI_GetMessage(LPCWSTR lpCmd
)
982 return (WORD
)*(const DWORD
*)(lpCmd
+ strlenW(lpCmd
) + 1);
985 /**************************************************************************
986 * MCI_GetDWord [internal]
988 * Accept 0 -1 255 255:0 255:255:255:255 :::1 1::: 2::3 ::4: 12345678
989 * Refuse -1:0 0:-1 :: 256:0 1:256 0::::1
991 static BOOL
MCI_GetDWord(DWORD
* data
, LPWSTR
* ptr
)
994 DWORD total
= 0, shift
= 0;
995 BOOL sign
= FALSE
, digits
= FALSE
;
997 while (*ret
== ' ' || *ret
== '\t') ret
++;
1004 while ('0' <= *ret
&& *ret
<= '9') {
1005 val
= *ret
++ - '0' + 10 * val
;
1011 case ' ': ret
++; break;
1012 default: return FALSE
;
1014 if ((val
>= 256) || (shift
>= 24)) return FALSE
;
1015 total
|= val
<< shift
;
1021 if (!digits
) return FALSE
;
1022 if (shift
&& (val
>= 256 || sign
)) return FALSE
;
1023 total
|= val
<< shift
;
1024 *data
= sign
? -total
: total
;
1030 /**************************************************************************
1031 * MCI_GetString [internal]
1033 static DWORD
MCI_GetString(LPWSTR
* str
, LPWSTR
* args
)
1037 /* see if we have a quoted string */
1039 ptr
= strchrW(*str
= ptr
+ 1, '"');
1040 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
1041 /* FIXME: shall we escape \" from string ?? */
1042 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1043 *ptr
++ = '\0'; /* remove trailing " */
1044 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
1046 ptr
= strchrW(ptr
, ' ');
1051 ptr
= *args
+ strlenW(*args
);
1060 #define MCI_DATA_SIZE 16
1062 /**************************************************************************
1063 * MCI_ParseOptArgs [internal]
1065 static DWORD
MCI_ParseOptArgs(DWORD
* data
, int _offset
, LPCWSTR lpCmd
,
1066 LPWSTR args
, LPDWORD dwFlags
)
1071 DWORD dwRet
, flg
, cflg
= 0;
1075 /* loop on arguments */
1077 lmem
= (const char*)lpCmd
;
1078 found
= inCst
= FALSE
;
1081 /* skip any leading white space(s) */
1082 while (*args
== ' ') args
++;
1083 TRACE("args=%s\n", debugstr_w(args
));
1085 do { /* loop on options for command table for the requested verb */
1086 str
= (LPCWSTR
)lmem
;
1087 lmem
+= ((len
= strlenW(str
)) + 1) * sizeof(WCHAR
);
1088 flg
= *(const DWORD
*)lmem
;
1089 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
1090 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
1091 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1095 inCst
= TRUE
; cflg
= flg
; break;
1096 case MCI_END_CONSTANT
:
1097 /* there may be additional integral values after flag in constant */
1098 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
1101 inCst
= FALSE
; cflg
= 0;
1104 if (offset
!= _offset
) {
1105 FIXME("MCI_RETURN not in first position\n");
1106 return MCIERR_PARSER_INTERNAL
;
1110 if (strncmpiW(args
, str
, len
) == 0 &&
1111 ((eid
== MCI_STRING
&& len
== 0) || args
[len
] == 0 || args
[len
] == ' ')) {
1112 /* store good values into data[] */
1114 while (*args
== ' ') args
++;
1118 case MCI_COMMAND_HEAD
:
1120 case MCI_END_COMMAND
:
1121 case MCI_END_COMMAND_LIST
:
1122 case MCI_CONSTANT
: /* done above */
1123 case MCI_END_CONSTANT
: /* done above */
1127 TRACE("flag=%08x\n", flg
);
1134 data
[offset
] |= flg
;
1137 TRACE("flag=%08x constant=%08x\n", cflg
, flg
);
1140 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
1141 return MCIERR_BAD_INTEGER
;
1143 TRACE("flag=%08x int=%d\n", flg
, data
[offset
]);
1147 /* store rect in data (offset..offset+3) */
1149 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
1150 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
1151 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
1152 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
1153 return MCIERR_BAD_INTEGER
;
1155 TRACE("flag=%08x for rectangle\n", flg
);
1159 if ((dwRet
= MCI_GetString((LPWSTR
*)&data
[offset
], &args
)))
1161 TRACE("flag=%08x string=%s\n", flg
, debugstr_w(*(LPWSTR
*)&data
[offset
]));
1163 default: ERR("oops\n");
1165 /* exit inside while loop, except if just entered in constant area definition */
1166 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
1168 /* have offset incremented if needed */
1170 case MCI_COMMAND_HEAD
:
1172 case MCI_END_COMMAND
:
1173 case MCI_END_COMMAND_LIST
:
1175 case MCI_FLAG
: break;
1178 case MCI_HDC
: if (!inCst
) offset
+= sizeof(HANDLE
)/sizeof(DWORD
); break;
1179 case MCI_INTEGER
: if (!inCst
) offset
++; break;
1180 case MCI_END_CONSTANT
: offset
++; break;
1181 case MCI_STRING
: offset
+= sizeof(LPWSTR
)/sizeof(DWORD
); break;
1182 case MCI_RECT
: offset
+= 4; break;
1183 default: ERR("oops\n");
1186 } while (eid
!= MCI_END_COMMAND
);
1188 WARN("Optarg %s not found\n", debugstr_w(args
));
1189 return MCIERR_UNRECOGNIZED_COMMAND
;
1191 if (offset
== MCI_DATA_SIZE
) {
1192 FIXME("Internal data[] buffer overflow\n");
1193 return MCIERR_PARSER_INTERNAL
;
1199 /**************************************************************************
1200 * MCI_HandleReturnValues [internal]
1202 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
1203 MCI_GENERIC_PARMS
*params
, LPWSTR lpstrRet
, UINT uRetLen
)
1205 static const WCHAR fmt_d
[] = {'%','d',0};
1206 static const WCHAR fmt_d4
[] = {'%','d',' ','%','d',' ','%','d',' ','%','d',0};
1207 static const WCHAR wszCol3
[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1208 static const WCHAR wszCol4
[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1212 case 0: /* nothing to return */
1216 DWORD data
= *(DWORD
*)(params
+ 1);
1217 switch (dwRet
& 0xFFFF0000ul
) {
1219 case MCI_INTEGER_RETURNED
:
1220 snprintfW(lpstrRet
, uRetLen
, fmt_d
, data
);
1222 case MCI_RESOURCE_RETURNED
:
1223 /* return string which ID is HIWORD(data),
1224 * string is loaded from mmsystem.dll */
1225 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1227 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1228 /* return string which ID is HIWORD(data),
1229 * string is loaded from driver */
1230 /* FIXME: this is wrong for a 16 bit handle */
1231 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1232 HIWORD(data
), lpstrRet
, uRetLen
);
1234 case MCI_COLONIZED3_RETURN
:
1235 snprintfW(lpstrRet
, uRetLen
, wszCol3
,
1236 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1237 LOBYTE(HIWORD(data
)));
1239 case MCI_COLONIZED4_RETURN
:
1240 snprintfW(lpstrRet
, uRetLen
, wszCol4
,
1241 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1242 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1244 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1248 #ifdef MCI_INTEGER64
1251 static const WCHAR fmt_ld
[] = {'%','l','d',0};
1252 DWORD_PTR data
= *(DWORD_PTR
*)(params
+ 1);
1253 switch (dwRet
& 0xFFFF0000ul
) {
1255 case MCI_INTEGER_RETURNED
:
1256 snprintfW(lpstrRet
, uRetLen
, fmt_ld
, data
);
1258 case MCI_RESOURCE_RETURNED
:
1259 /* return string which ID is HIWORD(data),
1260 * string is loaded from mmsystem.dll */
1261 LoadStringW(hWinMM32Instance
, HIWORD(data
), lpstrRet
, uRetLen
);
1263 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1264 /* return string which ID is HIWORD(data),
1265 * string is loaded from driver */
1266 /* FIXME: this is wrong for a 16 bit handle */
1267 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1268 HIWORD(data
), lpstrRet
, uRetLen
);
1270 case MCI_COLONIZED3_RETURN
:
1271 snprintfW(lpstrRet
, uRetLen
, wszCol3
,
1272 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1273 LOBYTE(HIWORD(data
)));
1275 case MCI_COLONIZED4_RETURN
:
1276 snprintfW(lpstrRet
, uRetLen
, wszCol4
,
1277 LOBYTE(LOWORD(data
)), HIBYTE(LOWORD(data
)),
1278 LOBYTE(HIWORD(data
)), HIBYTE(HIWORD(data
)));
1280 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1286 switch (dwRet
& 0xFFFF0000ul
) {
1288 /* nothing to do data[0] == lpstrRet */
1290 case MCI_INTEGER_RETURNED
:
1292 DWORD
*data
= (DWORD
*)(params
+ 1);
1293 *data
= *(LPDWORD
)lpstrRet
;
1294 snprintfW(lpstrRet
, uRetLen
, fmt_d
, *data
);
1298 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1304 DWORD
*data
= (DWORD
*)(params
+ 1);
1305 if (dwRet
& 0xFFFF0000ul
)
1306 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1307 snprintfW(lpstrRet
, uRetLen
, fmt_d4
, data
[0], data
[1], data
[2], data
[3]);
1310 default: FIXME("Unknown MCI return type %d\n", retType
);
1313 return LOWORD(dwRet
);
1316 /**************************************************************************
1317 * mciSendStringW [WINMM.@]
1319 DWORD WINAPI
mciSendStringW(LPCWSTR lpstrCommand
, LPWSTR lpstrRet
,
1320 UINT uRetLen
, HWND hwndCallback
)
1322 LPWSTR verb
, dev
, args
, devType
= NULL
;
1323 LPWINE_MCIDRIVER wmd
= 0;
1324 MCIDEVICEID uDevID
, auto_open
= 0;
1325 DWORD dwFlags
= 0, dwRet
= 0;
1330 static const WCHAR wszNew
[] = {'n','e','w',0};
1331 static const WCHAR wszSAliasS
[] = {' ','a','l','i','a','s',' ',0};
1332 static const WCHAR wszTypeS
[] = {'t','y','p','e',' ',0};
1335 MCI_GENERIC_PARMS generic
;
1336 MCI_OPEN_PARMSW open
;
1337 MCI_SOUND_PARMSW sound
;
1338 MCI_SYSINFO_PARMSW sysinfo
;
1339 DWORD dw
[MCI_DATA_SIZE
];
1342 TRACE("(%s, %p, %d, %p)\n",
1343 debugstr_w(lpstrCommand
), lpstrRet
, uRetLen
, hwndCallback
);
1344 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1346 if (!lpstrCommand
[0])
1347 return MCIERR_MISSING_COMMAND_STRING
;
1349 /* format is <command> <device> <optargs> */
1350 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand
)+1) * sizeof(WCHAR
))))
1351 return MCIERR_OUT_OF_MEMORY
;
1352 strcpyW( verb
, lpstrCommand
);
1355 memset(&data
, 0, sizeof(data
));
1357 if (!(args
= strchrW(verb
, ' '))) {
1358 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1362 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
1365 uDevID
= strcmpiW(dev
, wszAll
) ? 0 : MCI_ALL_DEVICE_ID
;
1367 /* Determine devType from open */
1368 if (!strcmpW(verb
, wszOpen
)) {
1372 /* case dev == 'new' has to be handled */
1373 if (!strcmpW(dev
, wszNew
)) {
1375 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1377 tmp
= strchrW(devType
, ' ');
1378 if (tmp
) *tmp
= '\0';
1379 devType
= str_dup_upper(devType
);
1380 if (tmp
) *tmp
= ' ';
1381 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1383 WARN("open new requires device type\n");
1384 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1387 dwFlags
|= MCI_OPEN_ELEMENT
;
1388 data
.open
.lpstrElementName
= &wszNull
[0];
1389 } else if ((devType
= strchrW(dev
, '!')) != NULL
) {
1391 tmp
= devType
; devType
= dev
; dev
= tmp
;
1393 dwFlags
|= MCI_OPEN_TYPE
;
1394 data
.open
.lpstrDeviceType
= devType
;
1395 devType
= str_dup_upper(devType
);
1396 dwFlags
|= MCI_OPEN_ELEMENT
;
1397 data
.open
.lpstrElementName
= dev
;
1398 } else if (DRIVER_GetLibName(dev
, wszMci
, buf
, sizeof(buf
))) {
1399 /* this is the name of a mci driver's type */
1400 tmp
= strchrW(dev
, ' ');
1401 if (tmp
) *tmp
= '\0';
1402 data
.open
.lpstrDeviceType
= dev
;
1403 devType
= str_dup_upper(dev
);
1404 if (tmp
) *tmp
= ' ';
1405 dwFlags
|= MCI_OPEN_TYPE
;
1407 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1409 tmp
= strchrW(devType
, ' ');
1410 if (tmp
) *tmp
= '\0';
1411 devType
= str_dup_upper(devType
);
1412 if (tmp
) *tmp
= ' ';
1413 /* dwFlags and lpstrDeviceType will be correctly set in ParseOpt loop */
1415 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
1418 devType
= str_dup_upper(buf
);
1420 dwFlags
|= MCI_OPEN_ELEMENT
;
1421 data
.open
.lpstrElementName
= dev
;
1423 if (MCI_ALL_DEVICE_ID
== uDevID
) {
1424 dwRet
= MCIERR_CANNOT_USE_ALL
;
1427 if (!strstrW(args
, wszSAliasS
) && !dev
) {
1428 dwRet
= MCIERR_NEW_REQUIRES_ALIAS
;
1432 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
1433 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
1434 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1437 } else if ((MCI_ALL_DEVICE_ID
!= uDevID
) && !(wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
)))
1438 && (lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
))) {
1439 /* auto-open uses the core command table */
1440 switch (MCI_GetMessage(lpCmd
)) {
1441 case MCI_SOUND
: /* command does not use a device name */
1444 case MCI_CLOSE
: /* don't auto-open for close */
1445 case MCI_BREAK
: /* no auto-open for system commands */
1446 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1451 static const WCHAR wszOpenWait
[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1452 WCHAR buf
[138], retbuf
[6];
1453 snprintfW(buf
, sizeof(buf
)/sizeof(WCHAR
), wszOpenWait
, dev
);
1454 /* open via mciSendString handles quoting, dev!file syntax and alias creation */
1455 if ((dwRet
= mciSendStringW(buf
, retbuf
, sizeof(retbuf
)/sizeof(WCHAR
), 0)) != 0)
1457 auto_open
= strtoulW(retbuf
, NULL
, 10);
1458 TRACE("auto-opened %u for %s\n", auto_open
, debugstr_w(dev
));
1460 /* FIXME: test for notify flag (how to preparse?) before opening */
1461 wmd
= MCI_GetDriver(auto_open
);
1463 ERR("No auto-open device %u\n", auto_open
);
1464 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1471 /* get the verb in the different command tables */
1473 /* try the device specific command table */
1474 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
1476 /* try the type specific command table */
1477 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1478 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1479 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1480 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1483 /* try core command table */
1484 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1487 TRACE("Command %s not found!\n", debugstr_w(verb
));
1488 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1491 wMsg
= MCI_GetMessage(lpCmd
);
1493 /* set return information */
1494 offset
= sizeof(data
.generic
);
1495 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1499 offset
+= sizeof(DWORD
);
1502 data
.sysinfo
.lpstrReturn
= lpstrRet
;
1503 data
.sysinfo
.dwRetSize
= uRetLen
;
1504 offset
= FIELD_OFFSET( MCI_SYSINFO_PARMSW
, dwNumber
);
1507 offset
+= 4 * sizeof(DWORD
);
1509 #ifdef MCI_INTEGER64
1511 offset
+= sizeof(DWORD_PTR
);
1515 FIXME("Unknown MCI return type %d\n", retType
);
1516 dwRet
= MCIERR_PARSER_INTERNAL
;
1520 TRACE("verb=%s on dev=%s; offset=%d\n",
1521 debugstr_w(verb
), debugstr_w(dev
), offset
);
1523 if ((dwRet
= MCI_ParseOptArgs(data
.dw
, offset
/ sizeof(DWORD
), lpCmd
, args
, &dwFlags
)))
1526 /* set up call back */
1528 if (dwFlags
& MCI_NOTIFY
) {
1529 dwRet
= MCIERR_NOTIFY_ON_AUTO_OPEN
;
1532 /* FIXME: the command should get its own notification window set up and
1533 * ask for device closing while processing the notification mechanism.
1534 * hwndCallback = ...
1535 * dwFlags |= MCI_NOTIFY;
1536 * In the meantime special-case all commands but PLAY and RECORD below. */
1538 if (dwFlags
& MCI_NOTIFY
) {
1539 data
.generic
.dwCallback
= (DWORD_PTR
)hwndCallback
;
1544 if (strcmpW(verb
, wszOpen
)) {
1545 FIXME("Cannot open with command %s\n", debugstr_w(verb
));
1546 dwRet
= MCIERR_DRIVER_INTERNAL
;
1552 /* Requirements on dev depend on the flags:
1553 * alias with INSTALLNAME, name like "digitalvideo"
1554 * with QUANTITY and NAME. */
1556 data
.sysinfo
.wDeviceType
= MCI_ALL_DEVICE_ID
;
1557 if (uDevID
!= MCI_ALL_DEVICE_ID
) {
1558 if (dwFlags
& MCI_SYSINFO_INSTALLNAME
)
1559 wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
));
1560 else if (!(data
.sysinfo
.wDeviceType
= MCI_GetDevTypeFromResource(dev
))) {
1561 dwRet
= MCIERR_DEVICE_TYPE_REQUIRED
;
1568 /* FIXME: name is optional, "sound" is a valid command.
1569 * FIXME: Parse "sound notify" as flag, not as name. */
1570 data
.sound
.lpstrSoundName
= dev
;
1571 dwFlags
|= MCI_SOUND_NAME
;
1575 TRACE("[%d, %s, %08x, %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x]\n",
1576 wmd
? wmd
->wDeviceID
: uDevID
, MCI_MessageToString(wMsg
), dwFlags
,
1577 data
.dw
[0], data
.dw
[1], data
.dw
[2], data
.dw
[3], data
.dw
[4],
1578 data
.dw
[5], data
.dw
[6], data
.dw
[7], data
.dw
[8], data
.dw
[9]);
1580 if (wMsg
== MCI_OPEN
) {
1581 if ((dwRet
= MCI_FinishOpen(wmd
, &data
.open
, dwFlags
)))
1583 /* FIXME: notification is not properly shared across two opens */
1585 dwRet
= MCI_SendCommand(wmd
? wmd
->wDeviceID
: uDevID
, wMsg
, dwFlags
, (DWORD_PTR
)&data
);
1587 if (!LOWORD(dwRet
)) {
1588 TRACE("=> 1/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1589 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, &data
.generic
, lpstrRet
, uRetLen
);
1590 TRACE("=> 2/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1592 TRACE("=> %x\n", dwRet
);
1596 /* PLAY and RECORD are the only known non-immediate commands */
1597 if (LOWORD(dwRet
) || !(wMsg
== MCI_PLAY
|| wMsg
== MCI_RECORD
))
1598 MCI_SendCommand(auto_open
, MCI_CLOSE
, 0, 0);
1600 FIXME("leaking auto-open device %u\n", auto_open
);
1602 if (wMsg
== MCI_OPEN
&& LOWORD(dwRet
) && wmd
)
1603 MCI_UnLoadMciDriver(wmd
);
1604 HeapFree(GetProcessHeap(), 0, devType
);
1605 HeapFree(GetProcessHeap(), 0, verb
);
1609 /**************************************************************************
1610 * mciSendStringA [WINMM.@]
1612 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
1613 UINT uRetLen
, HWND hwndCallback
)
1615 LPWSTR lpwstrCommand
;
1616 LPWSTR lpwstrRet
= NULL
;
1620 /* FIXME: is there something to do with lpstrReturnString ? */
1621 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, NULL
, 0 );
1622 lpwstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1623 MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, lpwstrCommand
, len
);
1626 if (uRetLen
) *lpstrRet
= '\0'; /* NT-w2k3 use memset(lpstrRet, 0, uRetLen); */
1627 lpwstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1629 HeapFree( GetProcessHeap(), 0, lpwstrCommand
);
1630 return MCIERR_OUT_OF_MEMORY
;
1633 ret
= mciSendStringW(lpwstrCommand
, lpwstrRet
, uRetLen
, hwndCallback
);
1634 if (!ret
&& lpwstrRet
)
1635 WideCharToMultiByte( CP_ACP
, 0, lpwstrRet
, -1, lpstrRet
, uRetLen
, NULL
, NULL
);
1636 HeapFree(GetProcessHeap(), 0, lpwstrCommand
);
1637 HeapFree(GetProcessHeap(), 0, lpwstrRet
);
1641 /**************************************************************************
1642 * mciExecute [WINMM.@]
1644 BOOL WINAPI
mciExecute(LPCSTR lpstrCommand
)
1649 TRACE("(%s)!\n", lpstrCommand
);
1651 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1653 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1654 sprintf(strRet
, "Unknown MCI error (%d)", ret
);
1656 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1658 /* FIXME: what shall I return ? */
1662 /**************************************************************************
1663 * mciLoadCommandResource [WINMM.@]
1665 * Strangely, this function only exists as a UNICODE one.
1667 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1669 UINT ret
= MCI_NO_COMMAND_TABLE
;
1673 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1675 /* if a file named "resname.mci" exits, then load resource "resname" from it
1676 * otherwise directly from driver
1677 * We don't support it (who uses this feature ?), but we check anyway
1681 /* FIXME: we should put this back into order, but I never found a program
1682 * actually using this feature, so we may not need it
1687 strcat(strcpy(buf
, resname
), ".mci");
1688 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1689 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1693 if ((hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
)) &&
1694 (hMem
= LoadResource(hInst
, hRsrc
))) {
1695 ret
= MCI_SetCommandTable(hMem
, type
);
1698 else WARN("No command table found in module for %s\n", debugstr_w(resNameW
));
1700 TRACE("=> %04x\n", ret
);
1704 /**************************************************************************
1705 * mciFreeCommandResource [WINMM.@]
1707 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1709 TRACE("(%08x)!\n", uTable
);
1711 if (uTable
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTable
].lpTable
)
1714 FreeResource(S_MciCmdTable
[uTable
].hMem
);
1715 S_MciCmdTable
[uTable
].hMem
= NULL
;
1716 S_MciCmdTable
[uTable
].lpTable
= NULL
;
1717 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTable
].aVerbs
);
1718 S_MciCmdTable
[uTable
].aVerbs
= 0;
1719 S_MciCmdTable
[uTable
].nVerbs
= 0;
1723 /**************************************************************************
1724 * MCI_Open [internal]
1726 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSW lpParms
)
1728 WCHAR strDevTyp
[128];
1730 LPWINE_MCIDRIVER wmd
= NULL
;
1732 TRACE("(%08X, %p)\n", dwParam
, lpParms
);
1733 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1735 /* only two low bytes are generic, the other ones are dev type specific */
1736 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1737 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1738 MCI_NOTIFY|MCI_WAIT)
1739 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0)
1740 FIXME("Unsupported yet dwFlags=%08X\n", dwParam
);
1741 #undef WINE_MCIDRIVER_SUPP
1745 if (dwParam
& MCI_OPEN_TYPE
) {
1746 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1747 WORD uDevType
= LOWORD(lpParms
->lpstrDeviceType
);
1749 if (uDevType
< MCI_DEVTYPE_FIRST
||
1750 uDevType
> MCI_DEVTYPE_LAST
||
1751 !LoadStringW(hWinMM32Instance
, uDevType
,
1752 strDevTyp
, sizeof(strDevTyp
) / sizeof(WCHAR
))) {
1753 dwRet
= MCIERR_BAD_INTEGER
;
1758 if (lpParms
->lpstrDeviceType
== NULL
) {
1759 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1762 strcpyW(strDevTyp
, lpParms
->lpstrDeviceType
);
1763 ptr
= strchrW(strDevTyp
, '!');
1765 /* this behavior is not documented in windows. However, since, in
1766 * some occasions, MCI_OPEN handling is translated by WinMM into
1767 * a call to mciSendString("open <type>"); this code shall be correct
1769 if (dwParam
& MCI_OPEN_ELEMENT
) {
1770 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1771 debugstr_w(lpParms
->lpstrElementName
),
1772 debugstr_w(strDevTyp
));
1773 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1776 dwParam
|= MCI_OPEN_ELEMENT
;
1778 /* FIXME: not a good idea to write in user supplied buffer */
1779 lpParms
->lpstrElementName
= ptr
;
1783 TRACE("devType=%s !\n", debugstr_w(strDevTyp
));
1786 if (dwParam
& MCI_OPEN_ELEMENT
) {
1787 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms
->lpstrElementName
));
1789 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1790 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1791 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1795 if (!lpParms
->lpstrElementName
) {
1796 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1800 /* type, if given as a parameter, supersedes file extension */
1801 if (!strDevTyp
[0] &&
1802 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1803 strDevTyp
, sizeof(strDevTyp
))) {
1804 static const WCHAR wszCdAudio
[] = {'C','D','A','U','D','I','O',0};
1805 if (GetDriveTypeW(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1806 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1809 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1810 strcpyW(strDevTyp
, wszCdAudio
);
1814 if (strDevTyp
[0] == 0) {
1815 FIXME("Couldn't load driver\n");
1816 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1820 if (dwParam
& MCI_OPEN_ALIAS
) {
1821 TRACE("Alias=%s !\n", debugstr_w(lpParms
->lpstrAlias
));
1822 if (!lpParms
->lpstrAlias
) {
1823 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1828 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1832 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1833 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet
);
1834 /* FIXME: is dwRet the correct ret code ? */
1838 /* only handled devices fall through */
1839 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1843 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1847 /**************************************************************************
1848 * MCI_Close [internal]
1850 static DWORD
MCI_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1853 LPWINE_MCIDRIVER wmd
;
1855 TRACE("(%04x, %08X, %p)\n", wDevID
, dwParam
, lpParms
);
1857 /* Every device must handle MCI_NOTIFY on its own. */
1858 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
1859 while (MciDrivers
) {
1860 /* Retrieve the device ID under lock, but send the message without,
1861 * the driver might be calling some winmm functions from another
1862 * thread before being fully stopped.
1864 EnterCriticalSection(&WINMM_cs
);
1867 LeaveCriticalSection(&WINMM_cs
);
1870 wDevID
= MciDrivers
->wDeviceID
;
1871 LeaveCriticalSection(&WINMM_cs
);
1872 MCI_Close(wDevID
, dwParam
, lpParms
);
1877 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1878 return MCIERR_INVALID_DEVICE_ID
;
1881 if(wmd
->CreatorThread
!= GetCurrentThreadId())
1882 return MCIERR_INVALID_DEVICE_NAME
;
1884 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD_PTR
)lpParms
);
1886 MCI_UnLoadMciDriver(wmd
);
1891 /**************************************************************************
1892 * MCI_WriteString [internal]
1894 static DWORD
MCI_WriteString(LPWSTR lpDstStr
, DWORD dstSize
, LPCWSTR lpSrcStr
)
1899 if (dstSize
<= strlenW(lpSrcStr
)) {
1900 ret
= MCIERR_PARAM_OVERFLOW
;
1902 strcpyW(lpDstStr
, lpSrcStr
);
1910 /**************************************************************************
1911 * MCI_Sysinfo [internal]
1913 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSW lpParms
)
1915 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1916 WCHAR buf
[2048], *s
, *p
;
1917 LPWINE_MCIDRIVER wmd
;
1920 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1921 if (lpParms
->lpstrReturn
== NULL
) return MCIERR_PARAM_OVERFLOW
;
1923 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1924 uDevID
, dwFlags
, lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1925 if ((WORD
)MCI_ALL_DEVICE_ID
== LOWORD(uDevID
))
1926 uDevID
= MCI_ALL_DEVICE_ID
; /* Be compatible with Win9x */
1928 switch (dwFlags
& ~(MCI_SYSINFO_OPEN
|MCI_NOTIFY
|MCI_WAIT
)) {
1929 case MCI_SYSINFO_QUANTITY
:
1930 if (lpParms
->dwRetSize
< sizeof(DWORD
))
1931 return MCIERR_PARAM_OVERFLOW
;
1932 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1933 if (uDevID
== MCI_ALL_DEVICE_ID
) {
1934 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
1935 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1936 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1937 EnterCriticalSection(&WINMM_cs
);
1938 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1941 LeaveCriticalSection(&WINMM_cs
);
1943 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1944 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
,
1945 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1946 RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1947 RegCloseKey( hKey
);
1949 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
))
1950 for (s
= buf
; *s
; s
+= strlenW(s
) + 1) cnt
++;
1953 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1954 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms
->wDeviceType
);
1955 EnterCriticalSection(&WINMM_cs
);
1956 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1957 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1959 LeaveCriticalSection(&WINMM_cs
);
1961 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms
->wDeviceType
);
1962 FIXME("Don't know how to get # of MCI devices of a given type\n");
1963 /* name = LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType))
1964 * then lookup registry and/or system.ini for name, ignoring digits suffix */
1965 switch (LOWORD(lpParms
->wDeviceType
)) {
1966 case MCI_DEVTYPE_CD_AUDIO
:
1967 case MCI_DEVTYPE_WAVEFORM_AUDIO
:
1968 case MCI_DEVTYPE_SEQUENCER
:
1971 default: /* "digitalvideo" gets 0 because it's not in the registry */
1976 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1977 TRACE("(%d) => '%d'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1978 ret
= MCI_INTEGER_RETURNED
;
1979 /* return ret; Only Win9x sends a notification in this case. */
1981 case MCI_SYSINFO_INSTALLNAME
:
1982 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1983 if ((wmd
= MCI_GetDriver(uDevID
))) {
1984 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1985 wmd
->lpstrDeviceType
);
1987 ret
= (uDevID
== MCI_ALL_DEVICE_ID
)
1988 ? MCIERR_CANNOT_USE_ALL
: MCIERR_INVALID_DEVICE_NAME
;
1990 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1992 case MCI_SYSINFO_NAME
:
1994 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1995 /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
1996 TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
1997 uDevID
== MCI_ALL_DEVICE_ID
? MCI_ALL_DEVICE_ID
: lpParms
->wDeviceType
);
1998 EnterCriticalSection(&WINMM_cs
);
1999 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
2000 /* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
2001 if (uDevID
== MCI_ALL_DEVICE_ID
||
2002 lpParms
->wDeviceType
== wmd
->wType
) {
2004 if (cnt
== lpParms
->dwNumber
) {
2005 s
= wmd
->lpstrAlias
;
2010 LeaveCriticalSection(&WINMM_cs
);
2011 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
2012 } else if (MCI_ALL_DEVICE_ID
== uDevID
) {
2013 TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms
->dwNumber
);
2014 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
, 0,
2015 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
2016 if (RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
,
2017 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
&&
2018 lpParms
->dwNumber
<= cnt
) {
2019 DWORD bufLen
= sizeof(buf
)/sizeof(buf
[0]);
2020 if (RegEnumKeyExW(hKey
, lpParms
->dwNumber
- 1,
2021 buf
, &bufLen
, 0, 0, 0, 0) == ERROR_SUCCESS
)
2024 RegCloseKey( hKey
);
2027 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
)) {
2028 for (p
= buf
; *p
; p
+= strlenW(p
) + 1, cnt
++) {
2029 TRACE("%d: %s\n", cnt
, debugstr_w(p
));
2030 if (cnt
== lpParms
->dwNumber
- 1) {
2037 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, s
) : MCIERR_OUTOFRANGE
;
2039 FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms
->wDeviceType
);
2040 /* Cheating: what is asked for is the nth device from the registry. */
2041 if (1 != lpParms
->dwNumber
|| /* Handle only one of each kind. */
2042 lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
)
2043 ret
= MCIERR_OUTOFRANGE
;
2045 LoadStringW(hWinMM32Instance
, LOWORD(lpParms
->wDeviceType
),
2046 lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
2050 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
2053 TRACE("Unsupported flag value=%08x\n", dwFlags
);
2054 ret
= MCIERR_UNRECOGNIZED_KEYWORD
;
2056 if ((dwFlags
& MCI_NOTIFY
) && HRESULT_CODE(ret
)==0)
2057 mciDriverNotify((HWND
)lpParms
->dwCallback
, uDevID
, MCI_NOTIFY_SUCCESSFUL
);
2061 /**************************************************************************
2062 * MCI_Break [internal]
2064 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
2068 if (lpParms
== NULL
)
2069 return MCIERR_NULL_PARAMETER_BLOCK
;
2071 TRACE("(%08x, %08X, vkey %04X, hwnd %p)\n", wDevID
, dwFlags
,
2072 lpParms
->nVirtKey
, lpParms
->hwndBreak
);
2074 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_BREAK
, dwFlags
, (DWORD_PTR
)lpParms
);
2075 if (!dwRet
&& (dwFlags
& MCI_NOTIFY
))
2076 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2080 /**************************************************************************
2081 * MCI_Sound [internal]
2083 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMSW lpParms
)
2087 if (dwFlags
& MCI_SOUND_NAME
) {
2088 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
2089 else dwRet
= PlaySoundW(lpParms
->lpstrSoundName
, NULL
,
2090 SND_ALIAS
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2091 ? 0 : MCIERR_HARDWARE
;
2092 } else dwRet
= PlaySoundW((LPCWSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
,
2093 SND_ALIAS_ID
| (dwFlags
& MCI_WAIT
? SND_SYNC
: SND_ASYNC
))
2094 ? 0 : MCIERR_HARDWARE
;
2096 if (!dwRet
&& lpParms
&& (dwFlags
& MCI_NOTIFY
))
2097 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
, MCI_NOTIFY_SUCCESSFUL
);
2101 /**************************************************************************
2102 * MCI_SendCommand [internal]
2104 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2106 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
2110 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
2113 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
2116 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSW
)dwParam2
);
2119 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
2122 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMSW
)dwParam2
);
2125 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
2126 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
2127 dwRet
= MCIERR_CANNOT_USE_ALL
;
2129 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
2136 /**************************************************************************
2137 * MCI_CleanUp [internal]
2139 * Some MCI commands need to be cleaned-up (when not called from
2140 * mciSendString), because MCI drivers return extra information for string
2141 * transformation. This function gets rid of them.
2143 static LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD_PTR dwParam2
)
2146 return LOWORD(dwRet
);
2149 case MCI_GETDEVCAPS
:
2150 switch (dwRet
& 0xFFFF0000ul
) {
2152 case MCI_COLONIZED3_RETURN
:
2153 case MCI_COLONIZED4_RETURN
:
2154 case MCI_INTEGER_RETURNED
:
2157 case MCI_RESOURCE_RETURNED
:
2158 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2160 LPMCI_GETDEVCAPS_PARMS lmgp
;
2162 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)dwParam2
;
2163 TRACE("Changing %08x to %08x\n", lmgp
->dwReturn
, LOWORD(lmgp
->dwReturn
));
2164 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
2168 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2169 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2173 switch (dwRet
& 0xFFFF0000ul
) {
2175 case MCI_COLONIZED3_RETURN
:
2176 case MCI_COLONIZED4_RETURN
:
2177 case MCI_INTEGER_RETURNED
:
2180 case MCI_RESOURCE_RETURNED
:
2181 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
2183 LPMCI_STATUS_PARMS lsp
;
2185 lsp
= (LPMCI_STATUS_PARMS
)dwParam2
;
2186 TRACE("Changing %08lx to %08x\n", lsp
->dwReturn
, LOWORD(lsp
->dwReturn
));
2187 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
2191 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
2192 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
2196 switch (dwRet
& 0xFFFF0000ul
) {
2198 case MCI_INTEGER_RETURNED
:
2202 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
2206 if (HIWORD(dwRet
)) {
2207 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
2208 dwRet
, MCI_MessageToString(wMsg
));
2212 return LOWORD(dwRet
);
2215 /**************************************************************************
2216 * mciGetErrorStringW [WINMM.@]
2218 BOOL WINAPI
mciGetErrorStringW(MCIERROR wError
, LPWSTR lpstrBuffer
, UINT uLength
)
2222 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2223 wError
>= MCIERR_BASE
&& wError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2225 if (LoadStringW(hWinMM32Instance
, wError
, lpstrBuffer
, uLength
) > 0) {
2232 /**************************************************************************
2233 * mciGetErrorStringA [WINMM.@]
2235 BOOL WINAPI
mciGetErrorStringA(MCIERROR dwError
, LPSTR lpstrBuffer
, UINT uLength
)
2239 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2240 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2242 if (LoadStringA(hWinMM32Instance
, dwError
, lpstrBuffer
, uLength
) > 0) {
2249 /**************************************************************************
2250 * mciDriverNotify [WINMM.@]
2252 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, MCIDEVICEID wDevID
, UINT wStatus
)
2254 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
2256 return PostMessageW(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
2259 /**************************************************************************
2260 * mciGetDriverData [WINMM.@]
2262 DWORD_PTR WINAPI
mciGetDriverData(MCIDEVICEID uDeviceID
)
2264 LPWINE_MCIDRIVER wmd
;
2266 TRACE("(%04x)\n", uDeviceID
);
2268 wmd
= MCI_GetDriver(uDeviceID
);
2271 WARN("Bad uDeviceID\n");
2275 return wmd
->dwPrivate
;
2278 /**************************************************************************
2279 * mciSetDriverData [WINMM.@]
2281 BOOL WINAPI
mciSetDriverData(MCIDEVICEID uDeviceID
, DWORD_PTR data
)
2283 LPWINE_MCIDRIVER wmd
;
2285 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
2287 wmd
= MCI_GetDriver(uDeviceID
);
2290 WARN("Bad uDeviceID\n");
2294 wmd
->dwPrivate
= data
;
2298 /**************************************************************************
2299 * mciSendCommandW [WINMM.@]
2302 DWORD WINAPI
mciSendCommandW(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2306 TRACE("(%08x, %s, %08lx, %08lx)\n",
2307 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2309 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
);
2310 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
2311 TRACE("=> %08x\n", dwRet
);
2315 /**************************************************************************
2316 * mciSendCommandA [WINMM.@]
2318 DWORD WINAPI
mciSendCommandA(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2323 TRACE("(%08x, %s, %08lx, %08lx)\n",
2324 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2326 mapped
= MCI_MapMsgAtoW(wMsg
, dwParam1
, &dwParam2
);
2329 FIXME("message %04x mapping failed\n", wMsg
);
2330 return MCIERR_OUT_OF_MEMORY
;
2332 ret
= mciSendCommandW(wDevID
, wMsg
, dwParam1
, dwParam2
);
2334 MCI_UnmapMsgAtoW(wMsg
, dwParam1
, dwParam2
, ret
);
2338 /**************************************************************************
2339 * mciGetDeviceIDA [WINMM.@]
2341 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
2343 LPWSTR w
= MCI_strdupAtoW(lpstrName
);
2344 UINT ret
= MCIERR_OUT_OF_MEMORY
;
2348 ret
= mciGetDeviceIDW(w
);
2349 HeapFree(GetProcessHeap(), 0, w
);
2354 /**************************************************************************
2355 * mciGetDeviceIDW [WINMM.@]
2357 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2359 return MCI_GetDriverFromString(lpwstrName
);
2362 /**************************************************************************
2363 * MCI_DefYieldProc [internal]
2365 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
2370 TRACE("(0x%04x, 0x%08x)\n", wDevID
, data
);
2372 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
2373 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2374 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2377 msg
.hwnd
= HWND_32(HIWORD(data
));
2378 while (!PeekMessageW(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2384 /**************************************************************************
2385 * mciSetYieldProc [WINMM.@]
2387 BOOL WINAPI
mciSetYieldProc(MCIDEVICEID uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2389 LPWINE_MCIDRIVER wmd
;
2391 TRACE("(%u, %p, %08x)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2393 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2394 WARN("Bad uDeviceID\n");
2398 wmd
->lpfnYieldProc
= fpYieldProc
;
2399 wmd
->dwYieldData
= dwYieldData
;
2404 /**************************************************************************
2405 * mciGetDeviceIDFromElementIDA [WINMM.@]
2407 UINT WINAPI
mciGetDeviceIDFromElementIDA(DWORD dwElementID
, LPCSTR lpstrType
)
2409 LPWSTR w
= MCI_strdupAtoW(lpstrType
);
2414 ret
= mciGetDeviceIDFromElementIDW(dwElementID
, w
);
2415 HeapFree(GetProcessHeap(), 0, w
);
2420 /**************************************************************************
2421 * mciGetDeviceIDFromElementIDW [WINMM.@]
2423 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2425 /* FIXME: that's rather strange, there is no
2426 * mciGetDeviceIDFromElementID32A in winmm.spec
2428 FIXME("(%u, %s) stub\n", dwElementID
, debugstr_w(lpstrType
));
2432 /**************************************************************************
2433 * mciGetYieldProc [WINMM.@]
2435 YIELDPROC WINAPI
mciGetYieldProc(MCIDEVICEID uDeviceID
, DWORD
* lpdwYieldData
)
2437 LPWINE_MCIDRIVER wmd
;
2439 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2441 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2442 WARN("Bad uDeviceID\n");
2445 if (!wmd
->lpfnYieldProc
) {
2446 WARN("No proc set\n");
2449 if (lpdwYieldData
) *lpdwYieldData
= wmd
->dwYieldData
;
2450 return wmd
->lpfnYieldProc
;
2453 /**************************************************************************
2454 * mciGetCreatorTask [WINMM.@]
2456 HTASK WINAPI
mciGetCreatorTask(MCIDEVICEID uDeviceID
)
2458 LPWINE_MCIDRIVER wmd
;
2461 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)(DWORD_PTR
)wmd
->CreatorThread
;
2463 TRACE("(%u) => %p\n", uDeviceID
, ret
);
2467 /**************************************************************************
2468 * mciDriverYield [WINMM.@]
2470 UINT WINAPI
mciDriverYield(MCIDEVICEID uDeviceID
)
2472 LPWINE_MCIDRIVER wmd
;
2475 TRACE("(%04x)\n", uDeviceID
);
2477 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
) {
2479 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2481 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);