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
40 /* to be cross checked:
41 * - heapalloc for *sizeof(WCHAR) when needed
42 * - size of string in WCHAR or bytes? (#chars for MCI_INFO, #bytes for MCI_SYSINFO)
46 #include "wine/port.h"
65 #include "wine/debug.h"
66 #include "wine/unicode.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
70 /* First MCI valid device ID (0 means error) */
71 #define MCI_MAGIC 0x0001
74 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};
75 static const WCHAR wszNull
[] = {0};
76 static const WCHAR wszAll
[] = {'A','L','L',0};
77 static const WCHAR wszMci
[] = {'M','C','I',0};
78 static const WCHAR wszOpen
[] = {'o','p','e','n',0};
79 static const WCHAR wszSystemIni
[] = {'s','y','s','t','e','m','.','i','n','i',0};
81 static WINE_MCIDRIVER
*MciDrivers
;
83 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
);
84 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
);
86 /* dup a string and uppercase it */
87 static inline LPWSTR
str_dup_upper( LPCWSTR str
)
89 INT len
= (strlenW(str
) + 1) * sizeof(WCHAR
);
90 LPWSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
93 memcpy( p
, str
, len
);
99 /**************************************************************************
100 * MCI_GetDriver [internal]
102 static LPWINE_MCIDRIVER
MCI_GetDriver(UINT wDevID
)
104 LPWINE_MCIDRIVER wmd
= 0;
106 EnterCriticalSection(&WINMM_cs
);
107 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
108 if (wmd
->wDeviceID
== wDevID
)
111 LeaveCriticalSection(&WINMM_cs
);
115 /**************************************************************************
116 * MCI_GetDriverFromString [internal]
118 static UINT
MCI_GetDriverFromString(LPCWSTR lpstrName
)
120 LPWINE_MCIDRIVER wmd
;
126 if (!strcmpiW(lpstrName
, wszAll
))
127 return MCI_ALL_DEVICE_ID
;
129 EnterCriticalSection(&WINMM_cs
);
130 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
131 if (wmd
->lpstrElementName
&& strcmpW(wmd
->lpstrElementName
, lpstrName
) == 0) {
132 ret
= wmd
->wDeviceID
;
135 if (wmd
->lpstrDeviceType
&& strcmpiW(wmd
->lpstrDeviceType
, lpstrName
) == 0) {
136 ret
= wmd
->wDeviceID
;
139 if (wmd
->lpstrAlias
&& strcmpiW(wmd
->lpstrAlias
, lpstrName
) == 0) {
140 ret
= wmd
->wDeviceID
;
144 LeaveCriticalSection(&WINMM_cs
);
149 /**************************************************************************
150 * MCI_MessageToString [internal]
152 const char* MCI_MessageToString(UINT wMsg
)
154 #define CASE(s) case (s): return #s
164 CASE(DRV_QUERYCONFIGURE
);
167 CASE(DRV_EXITSESSION
);
168 CASE(DRV_EXITAPPLICATION
);
172 CASE(MCI_CLOSE_DRIVER
);
181 CASE(MCI_GETDEVCAPS
);
185 CASE(MCI_OPEN_DRIVER
);
203 /* constants for digital video */
217 return wine_dbg_sprintf("MCI_<<%04X>>", wMsg
);
221 LPWSTR
MCI_strdupAtoW( LPCSTR str
)
226 if (!str
) return NULL
;
227 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
228 ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
229 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
233 LPSTR
MCI_strdupWtoA( LPCWSTR str
)
238 if (!str
) return NULL
;
239 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
240 ret
= HeapAlloc( GetProcessHeap(), 0, len
);
241 if (ret
) WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
245 static int MCI_MapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR
*dwParam2
)
247 if (msg
< DRV_RESERVED
) return 0;
286 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*dwParam2
;
287 MCI_OPEN_PARMSW
*mci_openW
;
290 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR
) + sizeof(*mci_openW
) + 2 * sizeof(DWORD
));
293 *ptr
++ = *dwParam2
; /* save the previous pointer */
294 *dwParam2
= (DWORD_PTR
)ptr
;
295 mci_openW
= (MCI_OPEN_PARMSW
*)ptr
;
297 if (dwParam1
& MCI_NOTIFY
)
298 mci_openW
->dwCallback
= mci_openA
->dwCallback
;
300 if (dwParam1
& MCI_OPEN_TYPE
)
302 if (dwParam1
& MCI_OPEN_TYPE_ID
)
303 mci_openW
->lpstrDeviceType
= (LPCWSTR
)mci_openA
->lpstrDeviceType
;
305 mci_openW
->lpstrDeviceType
= MCI_strdupAtoW(mci_openA
->lpstrDeviceType
);
307 if (dwParam1
& MCI_OPEN_ELEMENT
)
309 if (dwParam1
& MCI_OPEN_ELEMENT_ID
)
310 mci_openW
->lpstrElementName
= (LPCWSTR
)mci_openA
->lpstrElementName
;
312 mci_openW
->lpstrElementName
= MCI_strdupAtoW(mci_openA
->lpstrElementName
);
314 if (dwParam1
& MCI_OPEN_ALIAS
)
315 mci_openW
->lpstrAlias
= MCI_strdupAtoW(mci_openA
->lpstrAlias
);
316 /* FIXME: this is only needed for specific types of MCI devices, and
317 * may cause a segfault if the two DWORD:s don't exist at the end of
320 memcpy(mci_openW
+ 1, mci_openA
+ 1, 2 * sizeof(DWORD
));
325 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
327 MCI_ANIM_WINDOW_PARMSA
*mci_windowA
= (MCI_ANIM_WINDOW_PARMSA
*)*dwParam2
;
328 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
;
330 mci_windowW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW
));
331 if (!mci_windowW
) return -1;
333 *dwParam2
= (DWORD_PTR
)mci_windowW
;
335 mci_windowW
->lpstrText
= MCI_strdupAtoW(mci_windowA
->lpstrText
);
337 if (dwParam1
& MCI_NOTIFY
)
338 mci_windowW
->dwCallback
= mci_windowA
->dwCallback
;
339 if (dwParam1
& MCI_ANIM_WINDOW_HWND
)
340 mci_windowW
->hWnd
= mci_windowA
->hWnd
;
341 if (dwParam1
& MCI_ANIM_WINDOW_STATE
)
342 mci_windowW
->nCmdShow
= mci_windowA
->nCmdShow
;
350 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*dwParam2
;
351 MCI_SYSINFO_PARMSW
*mci_sysinfoW
;
354 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW
) + sizeof(DWORD_PTR
));
357 *ptr
++ = *dwParam2
; /* save the previous pointer */
358 *dwParam2
= (DWORD_PTR
)ptr
;
359 mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)ptr
;
361 if (dwParam1
& MCI_NOTIFY
)
362 mci_sysinfoW
->dwCallback
= mci_sysinfoA
->dwCallback
;
364 mci_sysinfoW
->dwRetSize
= mci_sysinfoA
->dwRetSize
;
365 mci_sysinfoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW
->dwRetSize
);
366 mci_sysinfoW
->dwNumber
= mci_sysinfoA
->dwNumber
;
367 mci_sysinfoW
->wDeviceType
= mci_sysinfoA
->wDeviceType
;
372 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*dwParam2
;
373 MCI_INFO_PARMSW
*mci_infoW
;
376 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW
) + sizeof(DWORD_PTR
));
379 *ptr
++ = *dwParam2
; /* save the previous pointer */
380 *dwParam2
= (DWORD_PTR
)ptr
;
381 mci_infoW
= (MCI_INFO_PARMSW
*)ptr
;
383 if (dwParam1
& MCI_NOTIFY
)
384 mci_infoW
->dwCallback
= mci_infoA
->dwCallback
;
386 mci_infoW
->dwRetSize
= mci_infoA
->dwRetSize
* sizeof(WCHAR
); /* it's not the same as SYSINFO !!! */
387 mci_infoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_infoW
->dwRetSize
);
392 MCI_SAVE_PARMSA
*mci_saveA
= (MCI_SAVE_PARMSA
*)*dwParam2
;
393 MCI_SAVE_PARMSW
*mci_saveW
;
395 mci_saveW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW
));
396 if (!mci_saveW
) return -1;
398 *dwParam2
= (DWORD_PTR
)mci_saveW
;
399 if (dwParam1
& MCI_NOTIFY
)
400 mci_saveW
->dwCallback
= mci_saveA
->dwCallback
;
401 mci_saveW
->lpfilename
= MCI_strdupAtoW(mci_saveA
->lpfilename
);
406 MCI_LOAD_PARMSA
*mci_loadA
= (MCI_LOAD_PARMSA
*)*dwParam2
;
407 MCI_LOAD_PARMSW
*mci_loadW
;
409 mci_loadW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW
));
410 if (!mci_loadW
) return -1;
412 *dwParam2
= (DWORD_PTR
)mci_loadW
;
413 if (dwParam1
& MCI_NOTIFY
)
414 mci_loadW
->dwCallback
= mci_loadA
->dwCallback
;
415 mci_loadW
->lpfilename
= MCI_strdupAtoW(mci_loadA
->lpfilename
);
421 MCI_VD_ESCAPE_PARMSA
*mci_vd_escapeA
= (MCI_VD_ESCAPE_PARMSA
*)*dwParam2
;
422 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
;
424 mci_vd_escapeW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW
));
425 if (!mci_vd_escapeW
) return -1;
427 *dwParam2
= (DWORD_PTR
)mci_vd_escapeW
;
428 if (dwParam1
& MCI_NOTIFY
)
429 mci_vd_escapeW
->dwCallback
= mci_vd_escapeA
->dwCallback
;
430 mci_vd_escapeW
->lpstrCommand
= MCI_strdupAtoW(mci_vd_escapeA
->lpstrCommand
);
434 FIXME("Message %s needs translation\n", MCI_MessageToString(msg
));
439 static DWORD
MCI_UnmapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
,
446 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
447 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*ptr
;
448 MCI_OPEN_PARMSW
*mci_openW
= (MCI_OPEN_PARMSW
*)(ptr
+ 1);
450 mci_openA
->wDeviceID
= mci_openW
->wDeviceID
;
452 if (dwParam1
& MCI_OPEN_TYPE
)
454 if (!(dwParam1
& MCI_OPEN_TYPE_ID
))
455 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrDeviceType
);
457 if (dwParam1
& MCI_OPEN_ELEMENT
)
459 if (!(dwParam1
& MCI_OPEN_ELEMENT_ID
))
460 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrElementName
);
462 if (dwParam1
& MCI_OPEN_ALIAS
)
463 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrAlias
);
464 HeapFree(GetProcessHeap(), 0, ptr
);
468 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
470 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
= (MCI_ANIM_WINDOW_PARMSW
*)dwParam2
;
472 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW
->lpstrText
);
473 HeapFree(GetProcessHeap(), 0, mci_windowW
);
479 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
480 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*ptr
;
481 MCI_SYSINFO_PARMSW
*mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)(ptr
+ 1);
485 mci_sysinfoA
->dwNumber
= mci_sysinfoW
->dwNumber
;
486 mci_sysinfoA
->wDeviceType
= mci_sysinfoW
->wDeviceType
;
487 if (dwParam1
& MCI_SYSINFO_QUANTITY
)
488 *(DWORD
*)mci_sysinfoA
->lpstrReturn
= *(DWORD
*)mci_sysinfoW
->lpstrReturn
;
490 WideCharToMultiByte(CP_ACP
, 0,
491 mci_sysinfoW
->lpstrReturn
, mci_sysinfoW
->dwRetSize
,
492 mci_sysinfoA
->lpstrReturn
, mci_sysinfoA
->dwRetSize
,
496 HeapFree(GetProcessHeap(), 0, mci_sysinfoW
->lpstrReturn
);
497 HeapFree(GetProcessHeap(), 0, ptr
);
502 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
503 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*ptr
;
504 MCI_INFO_PARMSW
*mci_infoW
= (MCI_INFO_PARMSW
*)(ptr
+ 1);
508 WideCharToMultiByte(CP_ACP
, 0,
509 mci_infoW
->lpstrReturn
, mci_infoW
->dwRetSize
/ sizeof(WCHAR
),
510 mci_infoA
->lpstrReturn
, mci_infoA
->dwRetSize
,
514 HeapFree(GetProcessHeap(), 0, mci_infoW
->lpstrReturn
);
515 HeapFree(GetProcessHeap(), 0, ptr
);
520 MCI_SAVE_PARMSW
*mci_saveW
= (MCI_SAVE_PARMSW
*)dwParam2
;
522 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW
->lpfilename
);
523 HeapFree(GetProcessHeap(), 0, mci_saveW
);
528 MCI_LOAD_PARMSW
*mci_loadW
= (MCI_LOAD_PARMSW
*)dwParam2
;
530 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW
->lpfilename
);
531 HeapFree(GetProcessHeap(), 0, mci_loadW
);
536 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
= (MCI_VD_ESCAPE_PARMSW
*)dwParam2
;
538 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW
->lpstrCommand
);
539 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW
);
544 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg
));
551 /**************************************************************************
552 * MCI_GetDevTypeFromFileName [internal]
554 static DWORD
MCI_GetDevTypeFromFileName(LPCWSTR fileName
, LPWSTR buf
, UINT len
)
558 static const WCHAR keyW
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
559 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
560 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
561 if ((tmp
= strrchrW(fileName
, '.'))) {
562 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, keyW
,
563 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
565 LONG lRet
= RegQueryValueExW( hKey
, tmp
+ 1, 0, 0, (void*)buf
, &dwLen
);
567 if (lRet
== ERROR_SUCCESS
) return 0;
569 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp
));
571 return MCIERR_EXTENSION_NOT_FOUND
;
574 #define MAX_MCICMDTABLE 20
575 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
577 typedef struct tagWINE_MCICMDTABLE
{
581 UINT nVerbs
; /* number of verbs in command table */
582 LPCWSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
583 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
585 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
587 /**************************************************************************
588 * MCI_IsCommandTableValid [internal]
590 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
599 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
600 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
602 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
605 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
608 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
609 flg
= *(const DWORD
*)lmem
;
610 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
611 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
613 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
615 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
616 case MCI_STRING
: if (inCst
) return FALSE
; break;
617 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
618 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
619 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
620 case MCI_FLAG
: if (!*str
) return FALSE
; break;
621 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
622 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
623 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
624 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
625 default: return FALSE
;
627 } while (eid
!= MCI_END_COMMAND_LIST
);
631 /**************************************************************************
632 * MCI_DumpCommandTable [internal]
634 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
641 if (!MCI_IsCommandTableValid(uTbl
)) {
642 ERR("Ooops: %d is not valid\n", uTbl
);
646 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
650 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
651 flg
= *(const DWORD
*)lmem
;
652 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
653 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
654 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
655 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
656 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
657 } while (eid
!= MCI_END_COMMAND_LIST
);
662 /**************************************************************************
663 * MCI_GetCommandTable [internal]
665 static UINT
MCI_GetCommandTable(UINT uDevType
)
671 /* first look up existing for existing devType */
672 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
673 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
677 /* well try to load id */
678 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
679 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, sizeof(buf
) / sizeof(WCHAR
))) {
682 } else if (uDevType
== 0) {
683 static const WCHAR wszCore
[] = {'C','O','R','E',0};
686 uTbl
= MCI_NO_COMMAND_TABLE
;
688 HRSRC hRsrc
= FindResourceW(hWinMM32Instance
, str
, (LPCWSTR
)RT_RCDATA
);
691 if (hRsrc
) hMem
= LoadResource(hWinMM32Instance
, hRsrc
);
693 uTbl
= MCI_SetCommandTable(hMem
, uDevType
);
695 WARN("No command table found in resource %p[%s]\n",
696 hWinMM32Instance
, debugstr_w(str
));
699 TRACE("=> %d\n", uTbl
);
703 /**************************************************************************
704 * MCI_SetCommandTable [internal]
706 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
)
709 static BOOL bInitDone
= FALSE
;
712 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
713 * can be called with 0 as a uDevType to retrieve it.
718 MCI_GetCommandTable(0);
720 TRACE("(%p, %u)\n", hMem
, uDevType
);
721 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
722 if (!S_MciCmdTable
[uTbl
].lpTable
) {
728 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
729 S_MciCmdTable
[uTbl
].lpTable
= LockResource(hMem
);
730 S_MciCmdTable
[uTbl
].hMem
= hMem
;
733 MCI_DumpCommandTable(uTbl
);
736 /* create the verbs table */
737 /* get # of entries */
738 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
742 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
743 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
744 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
745 if (eid
== MCI_COMMAND_HEAD
)
747 } while (eid
!= MCI_END_COMMAND_LIST
);
749 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCWSTR
));
750 S_MciCmdTable
[uTbl
].nVerbs
= count
;
752 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
756 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
757 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
758 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
759 if (eid
== MCI_COMMAND_HEAD
)
760 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
761 } while (eid
!= MCI_END_COMMAND_LIST
);
762 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
767 return MCI_NO_COMMAND_TABLE
;
770 /**************************************************************************
771 * MCI_UnLoadMciDriver [internal]
773 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
775 LPWINE_MCIDRIVER
* tmp
;
780 CloseDriver(wmd
->hDriver
, 0, 0);
782 if (wmd
->dwPrivate
!= 0)
783 WARN("Unloading mci driver with non nul dwPrivate field\n");
785 EnterCriticalSection(&WINMM_cs
);
786 for (tmp
= &MciDrivers
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
792 LeaveCriticalSection(&WINMM_cs
);
794 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
795 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
796 HeapFree(GetProcessHeap(), 0, wmd
->lpstrElementName
);
798 HeapFree(GetProcessHeap(), 0, wmd
);
802 /**************************************************************************
803 * MCI_OpenMciDriver [internal]
805 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCWSTR drvTyp
, DWORD_PTR lp
)
809 if (!DRIVER_GetLibName(drvTyp
, wszMci
, libName
, sizeof(libName
)))
812 /* First load driver */
813 wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
);
814 return wmd
->hDriver
!= NULL
;
817 /**************************************************************************
818 * MCI_LoadMciDriver [internal]
820 static DWORD
MCI_LoadMciDriver(LPCWSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
822 LPWSTR strDevTyp
= str_dup_upper(_strDevTyp
);
823 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
824 MCI_OPEN_DRIVER_PARMSW modp
;
827 if (!wmd
|| !strDevTyp
) {
828 dwRet
= MCIERR_OUT_OF_MEMORY
;
832 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
833 wmd
->dwYieldData
= VK_CANCEL
;
834 wmd
->CreatorThread
= GetCurrentThreadId();
836 EnterCriticalSection(&WINMM_cs
);
837 /* wmd must be inserted in list before sending opening the driver, because it
838 * may want to lookup at wDevID
840 wmd
->lpNext
= MciDrivers
;
843 for (modp
.wDeviceID
= MCI_MAGIC
;
844 MCI_GetDriver(modp
.wDeviceID
) != 0;
847 wmd
->wDeviceID
= modp
.wDeviceID
;
849 LeaveCriticalSection(&WINMM_cs
);
851 TRACE("wDevID=%04X\n", modp
.wDeviceID
);
853 modp
.lpstrParams
= NULL
;
855 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (DWORD_PTR
)&modp
)) {
856 /* silence warning if all is used... some bogus program use commands like
859 if (strcmpiW(strDevTyp
, wszAll
) == 0) {
860 dwRet
= MCIERR_CANNOT_USE_ALL
;
862 FIXME("Couldn't load driver for type %s.\n",
863 debugstr_w(strDevTyp
));
864 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
869 /* FIXME: should also check that module's description is of the form
870 * MODULENAME:[MCI] comment
873 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
874 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
875 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
877 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
878 wmd
->hDriver
, debugstr_w(strDevTyp
), modp
.wType
, modp
.wCustomCommandTable
);
880 wmd
->lpstrDeviceType
= strDevTyp
;
881 wmd
->wType
= modp
.wType
;
883 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
884 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
888 MCI_UnLoadMciDriver(wmd
);
889 HeapFree(GetProcessHeap(), 0, strDevTyp
);
894 /**************************************************************************
895 * MCI_SendCommandFrom32 [internal]
897 static DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
899 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
900 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
903 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
908 /**************************************************************************
909 * MCI_FinishOpen [internal]
911 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSW lpParms
,
914 if (dwParam
& MCI_OPEN_ELEMENT
)
916 wmd
->lpstrElementName
= HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms
->lpstrElementName
)+1) * sizeof(WCHAR
));
917 strcpyW( wmd
->lpstrElementName
, lpParms
->lpstrElementName
);
919 if (dwParam
& MCI_OPEN_ALIAS
)
921 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms
->lpstrAlias
)+1) * sizeof(WCHAR
));
922 strcpyW( wmd
->lpstrAlias
, lpParms
->lpstrAlias
);
924 lpParms
->wDeviceID
= wmd
->wDeviceID
;
926 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
930 /**************************************************************************
931 * MCI_FindCommand [internal]
933 static LPCWSTR
MCI_FindCommand(UINT uTbl
, LPCWSTR verb
)
937 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
940 /* another improvement would be to have the aVerbs array sorted,
941 * so that we could use a dichotomic search on it, rather than this dumb
944 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
945 if (strcmpiW(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
946 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
952 /**************************************************************************
953 * MCI_GetReturnType [internal]
955 static DWORD
MCI_GetReturnType(LPCWSTR lpCmd
)
957 lpCmd
= (LPCWSTR
)((const BYTE
*)(lpCmd
+ strlenW(lpCmd
) + 1) + sizeof(DWORD
) + sizeof(WORD
));
958 if (*lpCmd
== '\0' && *(const WORD
*)((const BYTE
*)(lpCmd
+ 1) + sizeof(DWORD
)) == MCI_RETURN
) {
959 return *(const DWORD
*)(lpCmd
+ 1);
964 /**************************************************************************
965 * MCI_GetMessage [internal]
967 static WORD
MCI_GetMessage(LPCWSTR lpCmd
)
969 return (WORD
)*(const DWORD
*)(lpCmd
+ strlenW(lpCmd
) + 1);
972 /**************************************************************************
973 * MCI_GetDWord [internal]
975 static BOOL
MCI_GetDWord(LPDWORD data
, LPWSTR
* ptr
)
980 val
= strtoulW(*ptr
, &ret
, 0);
984 case ' ': ret
++; break;
985 default: return FALSE
;
993 /**************************************************************************
994 * MCI_GetString [internal]
996 static DWORD
MCI_GetString(LPWSTR
* str
, LPWSTR
* args
)
1000 /* see if we have a quoted string */
1002 ptr
= strchrW(*str
= ptr
+ 1, '"');
1003 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
1004 /* FIXME: shall we escape \" from string ?? */
1005 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
1006 *ptr
++ = '\0'; /* remove trailing " */
1007 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
1009 ptr
= strchrW(ptr
, ' ');
1014 ptr
= *args
+ strlenW(*args
);
1023 #define MCI_DATA_SIZE 16
1025 /**************************************************************************
1026 * MCI_ParseOptArgs [internal]
1028 static DWORD
MCI_ParseOptArgs(LPDWORD data
, int _offset
, LPCWSTR lpCmd
,
1029 LPWSTR args
, LPDWORD dwFlags
)
1034 DWORD dwRet
, flg
, cflg
= 0;
1038 /* loop on arguments */
1040 lmem
= (const char*)lpCmd
;
1041 found
= inCst
= FALSE
;
1044 /* skip any leading white space(s) */
1045 while (*args
== ' ') args
++;
1046 TRACE("args=%s offset=%d\n", debugstr_w(args
), offset
);
1048 do { /* loop on options for command table for the requested verb */
1049 str
= (LPCWSTR
)lmem
;
1050 lmem
+= ((len
= strlenW(str
)) + 1) * sizeof(WCHAR
);
1051 flg
= *(const DWORD
*)lmem
;
1052 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
1053 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
1054 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1058 inCst
= TRUE
; cflg
= flg
; break;
1059 case MCI_END_CONSTANT
:
1060 /* there may be additional integral values after flag in constant */
1061 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
1064 inCst
= FALSE
; cflg
= 0;
1068 if (strncmpiW(args
, str
, len
) == 0 &&
1069 ((eid
== MCI_STRING
&& len
== 0) || args
[len
] == 0 || args
[len
] == ' ')) {
1070 /* store good values into data[] */
1072 while (*args
== ' ') args
++;
1076 case MCI_COMMAND_HEAD
:
1078 case MCI_END_COMMAND
:
1079 case MCI_END_COMMAND_LIST
:
1080 case MCI_CONSTANT
: /* done above */
1081 case MCI_END_CONSTANT
: /* done above */
1088 data
[offset
] |= flg
;
1093 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
1094 return MCIERR_BAD_INTEGER
;
1099 /* store rect in data (offset..offset+3) */
1101 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
1102 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
1103 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
1104 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
1105 ERR("Bad rect %s\n", debugstr_w(args
));
1106 return MCIERR_BAD_INTEGER
;
1111 if ((dwRet
= MCI_GetString((LPWSTR
*)&data
[offset
], &args
)))
1114 default: ERR("oops\n");
1116 /* exit inside while loop, except if just entered in constant area definition */
1117 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
1119 /* have offset incremented if needed */
1121 case MCI_COMMAND_HEAD
:
1123 case MCI_END_COMMAND
:
1124 case MCI_END_COMMAND_LIST
:
1126 case MCI_FLAG
: break;
1127 case MCI_INTEGER
: if (!inCst
) offset
++; break;
1128 case MCI_END_CONSTANT
:
1129 case MCI_STRING
: offset
++; break;
1130 case MCI_RECT
: offset
+= 4; break;
1131 default: ERR("oops\n");
1134 } while (eid
!= MCI_END_COMMAND
);
1136 WARN("Optarg %s not found\n", debugstr_w(args
));
1137 return MCIERR_UNRECOGNIZED_COMMAND
;
1139 if (offset
== MCI_DATA_SIZE
) {
1140 ERR("Internal data[] buffer overflow\n");
1141 return MCIERR_PARSER_INTERNAL
;
1147 /**************************************************************************
1148 * MCI_HandleReturnValues [internal]
1150 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
1151 LPDWORD data
, LPWSTR lpstrRet
, UINT uRetLen
)
1153 static const WCHAR wszLd
[] = {'%','l','d',0};
1154 static const WCHAR wszLd4
[] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1155 static const WCHAR wszCol3
[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1156 static const WCHAR wszCol4
[] = {'%','0','2','d',':','%','0','2','d',':','%','0','2','d',':','%','0','2','d',0};
1160 case 0: /* nothing to return */
1163 switch (dwRet
& 0xFFFF0000ul
) {
1165 case MCI_INTEGER_RETURNED
:
1166 snprintfW(lpstrRet
, uRetLen
, wszLd
, data
[1]);
1168 case MCI_RESOURCE_RETURNED
:
1169 /* return string which ID is HIWORD(data[1]),
1170 * string is loaded from mmsystem.dll */
1171 LoadStringW(hWinMM32Instance
, HIWORD(data
[1]), lpstrRet
, uRetLen
);
1173 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1174 /* return string which ID is HIWORD(data[1]),
1175 * string is loaded from driver */
1176 /* FIXME: this is wrong for a 16 bit handle */
1177 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1178 HIWORD(data
[1]), lpstrRet
, uRetLen
);
1180 case MCI_COLONIZED3_RETURN
:
1181 snprintfW(lpstrRet
, uRetLen
, wszCol3
,
1182 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
1183 LOBYTE(HIWORD(data
[1])));
1185 case MCI_COLONIZED4_RETURN
:
1186 snprintfW(lpstrRet
, uRetLen
, wszCol4
,
1187 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
1188 LOBYTE(HIWORD(data
[1])), HIBYTE(HIWORD(data
[1])));
1190 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1194 switch (dwRet
& 0xFFFF0000ul
) {
1196 /* nothing to do data[1] == lpstrRet */
1198 case MCI_INTEGER_RETURNED
:
1199 data
[1] = *(LPDWORD
)lpstrRet
;
1200 snprintfW(lpstrRet
, uRetLen
, wszLd
, data
[1]);
1203 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1208 if (dwRet
& 0xFFFF0000ul
)
1209 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1210 snprintfW(lpstrRet
, uRetLen
, wszLd4
,
1211 data
[1], data
[2], data
[3], data
[4]);
1213 default: ERR("oops\n");
1216 return LOWORD(dwRet
);
1219 /**************************************************************************
1220 * mciSendStringW [WINMM.@]
1222 DWORD WINAPI
mciSendStringW(LPCWSTR lpstrCommand
, LPWSTR lpstrRet
,
1223 UINT uRetLen
, HWND hwndCallback
)
1225 LPWSTR verb
, dev
, args
;
1226 LPWINE_MCIDRIVER wmd
= 0;
1227 DWORD dwFlags
= 0, dwRet
= 0;
1229 DWORD data
[MCI_DATA_SIZE
];
1232 static const WCHAR wszNew
[] = {'n','e','w',0};
1233 static const WCHAR wszSAliasS
[] = {' ','a','l','i','a','s',' ',0};
1234 static const WCHAR wszTypeS
[] = {'t','y','p','e',' ',0};
1236 TRACE("(%s, %p, %d, %p)\n",
1237 debugstr_w(lpstrCommand
), lpstrRet
, uRetLen
, hwndCallback
);
1239 /* format is <command> <device> <optargs> */
1240 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand
)+1) * sizeof(WCHAR
))))
1241 return MCIERR_OUT_OF_MEMORY
;
1242 strcpyW( verb
, lpstrCommand
);
1245 memset(data
, 0, sizeof(data
));
1247 if (!(args
= strchrW(verb
, ' '))) {
1248 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1252 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
1256 /* Determine devType from open */
1257 if (!strcmpW(verb
, wszOpen
)) {
1258 LPWSTR devType
, tmp
;
1261 /* case dev == 'new' has to be handled */
1262 if (!strcmpW(dev
, wszNew
)) {
1264 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1266 tmp
= strchrW(devType
, ' ');
1267 if (tmp
) *tmp
= '\0';
1268 devType
= str_dup_upper(devType
);
1269 if (tmp
) *tmp
= ' ';
1270 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1272 WARN("open new requires device type\n");
1273 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1276 } else if ((devType
= strchrW(dev
, '!')) != NULL
) {
1278 tmp
= devType
; devType
= dev
; dev
= tmp
;
1280 dwFlags
|= MCI_OPEN_TYPE
;
1281 data
[2] = (DWORD
)devType
;
1282 devType
= str_dup_upper(devType
);
1283 dwFlags
|= MCI_OPEN_ELEMENT
;
1284 data
[3] = (DWORD
)dev
;
1285 } else if (DRIVER_GetLibName(dev
, wszMci
, buf
, sizeof(buf
))) {
1286 /* this is the name of a mci driver's type */
1287 tmp
= strchrW(dev
, ' ');
1288 if (tmp
) *tmp
= '\0';
1289 data
[2] = (DWORD
)dev
;
1290 devType
= str_dup_upper(dev
);
1291 if (tmp
) *tmp
= ' ';
1292 dwFlags
|= MCI_OPEN_TYPE
;
1294 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1296 tmp
= strchrW(devType
, ' ');
1297 if (tmp
) *tmp
= '\0';
1298 devType
= str_dup_upper(devType
);
1299 if (tmp
) *tmp
= ' ';
1300 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1302 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
1305 devType
= str_dup_upper(buf
);
1307 dwFlags
|= MCI_OPEN_ELEMENT
;
1308 data
[3] = (DWORD
)dev
;
1310 if (!strstrW(args
, wszSAliasS
) && !dev
) {
1311 dwRet
= MCIERR_NEW_REQUIRES_ALIAS
;
1315 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
1316 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
1317 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1318 HeapFree(GetProcessHeap(), 0, devType
);
1320 MCI_UnLoadMciDriver(wmd
);
1323 } else if (!(wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
)))) {
1325 static const WCHAR wszOpenWait
[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1327 sprintfW(buf
, wszOpenWait
, dev
);
1329 if ((dwRet
= mciSendStringW(buf
, NULL
, 0, 0)) != 0)
1332 wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
));
1334 /* FIXME: memory leak, MCI driver is not closed */
1335 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1340 /* get the verb in the different command tables */
1342 /* try the device specific command table */
1343 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
1345 /* try the type specific command table */
1346 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1347 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1348 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1349 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1352 /* try core command table */
1353 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1356 TRACE("Command %s not found!\n", debugstr_w(verb
));
1357 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1361 /* set return information */
1362 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1363 case 0: offset
= 1; break;
1364 case MCI_INTEGER
: offset
= 2; break;
1365 case MCI_STRING
: data
[1] = (DWORD
)lpstrRet
; data
[2] = uRetLen
; offset
= 3; break;
1366 case MCI_RECT
: offset
= 5; break;
1367 default: ERR("oops\n");
1370 TRACE("verb=%s on dev=%s; offset=%d\n",
1371 debugstr_w(verb
), debugstr_w(dev
), offset
);
1373 if ((dwRet
= MCI_ParseOptArgs(data
, offset
, lpCmd
, args
, &dwFlags
)))
1376 /* set up call back */
1377 if (dwFlags
& MCI_NOTIFY
) {
1378 data
[0] = (DWORD
)hwndCallback
;
1381 /* FIXME: the command should get it's own notification window set up and
1382 * ask for device closing while processing the notification mechanism
1384 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1386 TRACE("[%d, %s, %08x, %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s]\n",
1387 wmd
->wDeviceID
, MCI_MessageToString(MCI_GetMessage(lpCmd
)), dwFlags
,
1388 data
[0], debugstr_w((WCHAR
*)data
[0]), data
[1], debugstr_w((WCHAR
*)data
[1]),
1389 data
[2], debugstr_w((WCHAR
*)data
[2]), data
[3], debugstr_w((WCHAR
*)data
[3]),
1390 data
[4], debugstr_w((WCHAR
*)data
[4]), data
[5], debugstr_w((WCHAR
*)data
[5]));
1392 if (strcmpW(verb
, wszOpen
) == 0) {
1393 if ((dwRet
= MCI_FinishOpen(wmd
, (LPMCI_OPEN_PARMSW
)data
, dwFlags
)))
1394 MCI_UnLoadMciDriver(wmd
);
1395 /* FIXME: notification is not properly shared across two opens */
1397 dwRet
= MCI_SendCommand(wmd
->wDeviceID
, MCI_GetMessage(lpCmd
), dwFlags
, (DWORD_PTR
)data
);
1399 TRACE("=> 1/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1400 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, data
, lpstrRet
, uRetLen
);
1401 TRACE("=> 2/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1404 HeapFree(GetProcessHeap(), 0, verb
);
1408 /**************************************************************************
1409 * mciSendStringA [WINMM.@]
1411 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
1412 UINT uRetLen
, HWND hwndCallback
)
1414 LPWSTR lpwstrCommand
;
1415 LPWSTR lpwstrRet
= NULL
;
1419 /* FIXME: is there something to do with lpstrReturnString ? */
1420 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, NULL
, 0 );
1421 lpwstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1422 MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, lpwstrCommand
, len
);
1425 lpwstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1427 WARN("no memory\n");
1428 HeapFree( GetProcessHeap(), 0, lpwstrCommand
);
1429 return MCIERR_OUT_OF_MEMORY
;
1432 ret
= mciSendStringW(lpwstrCommand
, lpwstrRet
, uRetLen
, hwndCallback
);
1433 if (!ret
&& lpwstrRet
)
1434 WideCharToMultiByte( CP_ACP
, 0, lpwstrRet
, -1, lpstrRet
, uRetLen
, NULL
, NULL
);
1435 HeapFree(GetProcessHeap(), 0, lpwstrCommand
);
1436 HeapFree(GetProcessHeap(), 0, lpwstrRet
);
1440 /**************************************************************************
1441 * mciExecute [WINMM.@]
1443 BOOL WINAPI
mciExecute(LPCSTR lpstrCommand
)
1448 TRACE("(%s)!\n", lpstrCommand
);
1450 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1452 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1453 sprintf(strRet
, "Unknown MCI error (%d)", ret
);
1455 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1457 /* FIXME: what shall I return ? */
1461 /**************************************************************************
1462 * mciLoadCommandResource [WINMM.@]
1464 * Strangely, this function only exists as a UNICODE one.
1466 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1468 UINT ret
= MCI_NO_COMMAND_TABLE
;
1472 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1474 /* if a file named "resname.mci" exits, then load resource "resname" from it
1475 * otherwise directly from driver
1476 * We don't support it (who uses this feature ?), but we check anyway
1480 /* FIXME: we should put this back into order, but I never found a program
1481 * actually using this feature, so we may not need it
1486 strcat(strcpy(buf
, resname
), ".mci");
1487 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1488 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1492 if ((hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
)) &&
1493 (hMem
= LoadResource(hInst
, hRsrc
))) {
1494 ret
= MCI_SetCommandTable(hMem
, type
);
1497 else WARN("No command table found in module for %s\n", debugstr_w(resNameW
));
1499 TRACE("=> %04x\n", ret
);
1503 /**************************************************************************
1504 * mciFreeCommandResource [WINMM.@]
1506 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1508 TRACE("(%08x)!\n", uTable
);
1510 if (uTable
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTable
].lpTable
)
1513 FreeResource(S_MciCmdTable
[uTable
].hMem
);
1514 S_MciCmdTable
[uTable
].hMem
= NULL
;
1515 S_MciCmdTable
[uTable
].lpTable
= NULL
;
1516 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTable
].aVerbs
);
1517 S_MciCmdTable
[uTable
].aVerbs
= 0;
1518 S_MciCmdTable
[uTable
].nVerbs
= 0;
1522 /**************************************************************************
1523 * MCI_Open [internal]
1525 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSW lpParms
)
1527 WCHAR strDevTyp
[128];
1529 LPWINE_MCIDRIVER wmd
= NULL
;
1531 TRACE("(%08X, %p)\n", dwParam
, lpParms
);
1532 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1534 /* only two low bytes are generic, the other ones are dev type specific */
1535 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1536 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1537 MCI_NOTIFY|MCI_WAIT)
1538 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1539 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1541 #undef WINE_MCIDRIVER_SUPP
1545 if (dwParam
& MCI_OPEN_TYPE
) {
1546 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1547 WORD uDevType
= LOWORD(lpParms
->lpstrDeviceType
);
1549 if (uDevType
< MCI_DEVTYPE_FIRST
||
1550 uDevType
> MCI_DEVTYPE_LAST
||
1551 !LoadStringW(hWinMM32Instance
, uDevType
,
1552 strDevTyp
, sizeof(strDevTyp
) / sizeof(WCHAR
))) {
1553 dwRet
= MCIERR_BAD_INTEGER
;
1558 if (lpParms
->lpstrDeviceType
== NULL
) {
1559 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1562 strcpyW(strDevTyp
, lpParms
->lpstrDeviceType
);
1563 ptr
= strchrW(strDevTyp
, '!');
1565 /* this behavior is not documented in windows. However, since, in
1566 * some occasions, MCI_OPEN handling is translated by WinMM into
1567 * a call to mciSendString("open <type>"); this code shall be correct
1569 if (dwParam
& MCI_OPEN_ELEMENT
) {
1570 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1571 debugstr_w(lpParms
->lpstrElementName
),
1572 debugstr_w(strDevTyp
));
1573 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1576 dwParam
|= MCI_OPEN_ELEMENT
;
1578 /* FIXME: not a good idea to write in user supplied buffer */
1579 lpParms
->lpstrElementName
= ptr
;
1583 TRACE("devType=%s !\n", debugstr_w(strDevTyp
));
1586 if (dwParam
& MCI_OPEN_ELEMENT
) {
1587 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms
->lpstrElementName
));
1589 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1590 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1591 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1595 if (!lpParms
->lpstrElementName
) {
1596 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1600 /* type, if given as a parameter, supersedes file extension */
1601 if (!strDevTyp
[0] &&
1602 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1603 strDevTyp
, sizeof(strDevTyp
))) {
1604 static const WCHAR wszCdAudio
[] = {'C','D','A','U','D','I','O',0};
1605 if (GetDriveTypeW(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1606 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1609 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1610 strcpyW(strDevTyp
, wszCdAudio
);
1614 if (strDevTyp
[0] == 0) {
1615 FIXME("Couldn't load driver\n");
1616 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1620 if (dwParam
& MCI_OPEN_ALIAS
) {
1621 TRACE("Alias=%s !\n", debugstr_w(lpParms
->lpstrAlias
));
1622 if (!lpParms
->lpstrAlias
) {
1623 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1628 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1632 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1633 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet
);
1634 /* FIXME: is dwRet the correct ret code ? */
1638 /* only handled devices fall through */
1639 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1641 if (dwParam
& MCI_NOTIFY
)
1642 mciDriverNotify((HWND
)lpParms
->dwCallback
, wmd
->wDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1646 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1648 if (dwParam
& MCI_NOTIFY
)
1649 mciDriverNotify((HWND
)lpParms
->dwCallback
, 0, MCI_NOTIFY_FAILURE
);
1653 /**************************************************************************
1654 * MCI_Close [internal]
1656 static DWORD
MCI_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1659 LPWINE_MCIDRIVER wmd
;
1661 TRACE("(%04x, %08X, %p)\n", wDevID
, dwParam
, lpParms
);
1663 /* Every device must handle MCI_NOTIFY on its own. */
1664 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
1665 while (MciDrivers
) {
1666 /* Retrieve the device ID under lock, but send the message without,
1667 * the driver might be calling some winmm functions from another
1668 * thread before being fully stopped.
1670 EnterCriticalSection(&WINMM_cs
);
1673 LeaveCriticalSection(&WINMM_cs
);
1676 wDevID
= MciDrivers
->wDeviceID
;
1677 LeaveCriticalSection(&WINMM_cs
);
1678 MCI_Close(wDevID
, dwParam
, lpParms
);
1683 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1684 return MCIERR_INVALID_DEVICE_ID
;
1687 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD_PTR
)lpParms
);
1689 MCI_UnLoadMciDriver(wmd
);
1694 /**************************************************************************
1695 * MCI_WriteString [internal]
1697 static DWORD
MCI_WriteString(LPWSTR lpDstStr
, DWORD dstSize
, LPCWSTR lpSrcStr
)
1702 dstSize
/= sizeof(WCHAR
);
1703 if (dstSize
<= strlenW(lpSrcStr
)) {
1704 lstrcpynW(lpDstStr
, lpSrcStr
, dstSize
- 1);
1705 ret
= MCIERR_PARAM_OVERFLOW
;
1707 strcpyW(lpDstStr
, lpSrcStr
);
1715 /**************************************************************************
1716 * MCI_Sysinfo [internal]
1718 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSW lpParms
)
1720 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1721 WCHAR buf
[2048], *s
= buf
, *p
;
1722 LPWINE_MCIDRIVER wmd
;
1725 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1726 if (lpParms
->lpstrReturn
== NULL
) return MCIERR_PARAM_OVERFLOW
;
1728 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1729 uDevID
, dwFlags
, lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1731 switch (dwFlags
& ~MCI_SYSINFO_OPEN
) {
1732 case MCI_SYSINFO_QUANTITY
:
1733 if (lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
) {
1734 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1735 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1736 EnterCriticalSection(&WINMM_cs
);
1737 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1740 LeaveCriticalSection(&WINMM_cs
);
1742 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1743 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
,
1744 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1745 RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1746 RegCloseKey( hKey
);
1748 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
))
1749 for (s
= buf
; *s
; s
+= strlenW(s
) + 1) cnt
++;
1752 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1753 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms
->wDeviceType
);
1754 EnterCriticalSection(&WINMM_cs
);
1755 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1756 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1758 LeaveCriticalSection(&WINMM_cs
);
1760 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms
->wDeviceType
);
1761 FIXME("Don't know how to get # of MCI devices of a given type\n");
1765 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1766 TRACE("(%d) => '%d'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1767 ret
= MCI_INTEGER_RETURNED
;
1769 case MCI_SYSINFO_INSTALLNAME
:
1770 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1771 if ((wmd
= MCI_GetDriver(uDevID
))) {
1772 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1773 wmd
->lpstrDeviceType
);
1775 *lpParms
->lpstrReturn
= 0;
1776 ret
= MCIERR_INVALID_DEVICE_ID
;
1778 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1780 case MCI_SYSINFO_NAME
:
1781 TRACE("MCI_SYSINFO_NAME\n");
1782 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1783 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1784 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1787 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
, 0,
1788 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1789 if (RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
,
1790 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
&&
1791 lpParms
->dwNumber
<= cnt
) {
1792 DWORD bufLen
= sizeof(buf
)/sizeof(buf
[0]);
1793 if (RegEnumKeyExW(hKey
, lpParms
->dwNumber
- 1,
1794 buf
, &bufLen
, 0, 0, 0, 0) == ERROR_SUCCESS
)
1797 RegCloseKey( hKey
);
1800 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
)) {
1801 for (p
= buf
; *p
; p
+= strlenW(p
) + 1, cnt
++) {
1802 TRACE("%d: %s\n", cnt
, debugstr_w(p
));
1803 if (cnt
== lpParms
->dwNumber
- 1) {
1810 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
/ sizeof(WCHAR
), s
) : MCIERR_OUTOFRANGE
;
1812 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1815 TRACE("Unsupported flag value=%08x\n", dwFlags
);
1816 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1821 /**************************************************************************
1822 * MCI_Break [internal]
1824 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1828 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1830 if (dwFlags
& MCI_NOTIFY
)
1831 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1832 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1837 /**************************************************************************
1838 * MCI_Sound [internal]
1840 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMSW lpParms
)
1844 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1846 if (dwFlags
& MCI_SOUND_NAME
)
1847 dwRet
= sndPlaySoundW(lpParms
->lpstrSoundName
, SND_SYNC
) ? MMSYSERR_NOERROR
: MMSYSERR_ERROR
;
1849 dwRet
= MMSYSERR_ERROR
; /* what should be done ??? */
1850 if (dwFlags
& MCI_NOTIFY
)
1851 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1852 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1857 /**************************************************************************
1858 * MCI_SendCommand [internal]
1860 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1862 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1866 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
1869 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1872 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSW
)dwParam2
);
1875 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1878 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMSW
)dwParam2
);
1881 if ((UINT16
)wDevID
== (UINT16
)MCI_ALL_DEVICE_ID
) {
1882 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1883 dwRet
= MCIERR_CANNOT_USE_ALL
;
1885 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
1892 /**************************************************************************
1893 * MCI_CleanUp [internal]
1895 * Some MCI commands need to be cleaned-up (when not called from
1896 * mciSendString), because MCI drivers return extra information for string
1897 * transformation. This function gets rid of them.
1899 static LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD_PTR dwParam2
)
1902 return LOWORD(dwRet
);
1905 case MCI_GETDEVCAPS
:
1906 switch (dwRet
& 0xFFFF0000ul
) {
1908 case MCI_COLONIZED3_RETURN
:
1909 case MCI_COLONIZED4_RETURN
:
1910 case MCI_INTEGER_RETURNED
:
1913 case MCI_RESOURCE_RETURNED
:
1914 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1916 LPMCI_GETDEVCAPS_PARMS lmgp
;
1918 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)dwParam2
;
1919 TRACE("Changing %08x to %08x\n", lmgp
->dwReturn
, LOWORD(lmgp
->dwReturn
));
1920 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
1924 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1925 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1929 switch (dwRet
& 0xFFFF0000ul
) {
1931 case MCI_COLONIZED3_RETURN
:
1932 case MCI_COLONIZED4_RETURN
:
1933 case MCI_INTEGER_RETURNED
:
1936 case MCI_RESOURCE_RETURNED
:
1937 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1939 LPMCI_STATUS_PARMS lsp
;
1941 lsp
= (LPMCI_STATUS_PARMS
)dwParam2
;
1942 TRACE("Changing %08lx to %08x\n", lsp
->dwReturn
, LOWORD(lsp
->dwReturn
));
1943 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
1947 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1948 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1952 switch (dwRet
& 0xFFFF0000ul
) {
1954 case MCI_INTEGER_RETURNED
:
1958 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
1962 if (HIWORD(dwRet
)) {
1963 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1964 dwRet
, MCI_MessageToString(wMsg
));
1968 return LOWORD(dwRet
);
1971 /**************************************************************************
1972 * mciGetErrorStringW [WINMM.@]
1974 BOOL WINAPI
mciGetErrorStringW(MCIERROR wError
, LPWSTR lpstrBuffer
, UINT uLength
)
1978 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
1979 wError
>= MCIERR_BASE
&& wError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
1981 if (LoadStringW(hWinMM32Instance
, wError
, lpstrBuffer
, uLength
) > 0) {
1988 /**************************************************************************
1989 * mciGetErrorStringA [WINMM.@]
1991 BOOL WINAPI
mciGetErrorStringA(MCIERROR dwError
, LPSTR lpstrBuffer
, UINT uLength
)
1995 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
1996 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
1998 if (LoadStringA(hWinMM32Instance
, dwError
, lpstrBuffer
, uLength
) > 0) {
2005 /**************************************************************************
2006 * mciDriverNotify [WINMM.@]
2008 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, MCIDEVICEID wDevID
, UINT wStatus
)
2010 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
2012 return PostMessageW(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
2015 /**************************************************************************
2016 * mciGetDriverData [WINMM.@]
2018 DWORD_PTR WINAPI
mciGetDriverData(MCIDEVICEID uDeviceID
)
2020 LPWINE_MCIDRIVER wmd
;
2022 TRACE("(%04x)\n", uDeviceID
);
2024 wmd
= MCI_GetDriver(uDeviceID
);
2027 WARN("Bad uDeviceID\n");
2031 return wmd
->dwPrivate
;
2034 /**************************************************************************
2035 * mciSetDriverData [WINMM.@]
2037 BOOL WINAPI
mciSetDriverData(MCIDEVICEID uDeviceID
, DWORD_PTR data
)
2039 LPWINE_MCIDRIVER wmd
;
2041 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
2043 wmd
= MCI_GetDriver(uDeviceID
);
2046 WARN("Bad uDeviceID\n");
2050 wmd
->dwPrivate
= data
;
2054 /**************************************************************************
2055 * mciSendCommandW [WINMM.@]
2058 DWORD WINAPI
mciSendCommandW(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2062 TRACE("(%08x, %s, %08lx, %08lx)\n",
2063 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2065 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
);
2066 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
2067 TRACE("=> %08x\n", dwRet
);
2071 /**************************************************************************
2072 * mciSendCommandA [WINMM.@]
2074 DWORD WINAPI
mciSendCommandA(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2079 TRACE("(%08x, %s, %08lx, %08lx)\n",
2080 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2082 mapped
= MCI_MapMsgAtoW(wMsg
, dwParam1
, &dwParam2
);
2085 FIXME("message %04x mapping failed\n", wMsg
);
2086 return MMSYSERR_NOMEM
;
2088 ret
= mciSendCommandW(wDevID
, wMsg
, dwParam1
, dwParam2
);
2090 MCI_UnmapMsgAtoW(wMsg
, dwParam1
, dwParam2
, ret
);
2094 /**************************************************************************
2095 * mciGetDeviceIDA [WINMM.@]
2097 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
2099 LPWSTR w
= MCI_strdupAtoW(lpstrName
);
2100 UINT ret
= MCIERR_OUT_OF_MEMORY
;
2104 ret
= mciGetDeviceIDW(w
);
2105 HeapFree(GetProcessHeap(), 0, w
);
2110 /**************************************************************************
2111 * mciGetDeviceIDW [WINMM.@]
2113 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2115 return MCI_GetDriverFromString(lpwstrName
);
2118 /**************************************************************************
2119 * MCI_DefYieldProc [internal]
2121 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
2126 TRACE("(0x%04x, 0x%08x)\n", wDevID
, data
);
2128 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
2129 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2130 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2133 msg
.hwnd
= HWND_32(HIWORD(data
));
2134 while (!PeekMessageW(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2140 /**************************************************************************
2141 * mciSetYieldProc [WINMM.@]
2143 BOOL WINAPI
mciSetYieldProc(MCIDEVICEID uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2145 LPWINE_MCIDRIVER wmd
;
2147 TRACE("(%u, %p, %08x)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2149 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2150 WARN("Bad uDeviceID\n");
2154 wmd
->lpfnYieldProc
= fpYieldProc
;
2155 wmd
->dwYieldData
= dwYieldData
;
2160 /**************************************************************************
2161 * mciGetDeviceIDFromElementIDA [WINMM.@]
2163 UINT WINAPI
mciGetDeviceIDFromElementIDA(DWORD dwElementID
, LPCSTR lpstrType
)
2165 LPWSTR w
= MCI_strdupAtoW(lpstrType
);
2170 ret
= mciGetDeviceIDFromElementIDW(dwElementID
, w
);
2171 HeapFree(GetProcessHeap(), 0, w
);
2176 /**************************************************************************
2177 * mciGetDeviceIDFromElementIDW [WINMM.@]
2179 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2181 /* FIXME: that's rather strange, there is no
2182 * mciGetDeviceIDFromElementID32A in winmm.spec
2184 FIXME("(%u, %s) stub\n", dwElementID
, debugstr_w(lpstrType
));
2188 /**************************************************************************
2189 * mciGetYieldProc [WINMM.@]
2191 YIELDPROC WINAPI
mciGetYieldProc(MCIDEVICEID uDeviceID
, DWORD
* lpdwYieldData
)
2193 LPWINE_MCIDRIVER wmd
;
2195 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2197 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2198 WARN("Bad uDeviceID\n");
2201 if (!wmd
->lpfnYieldProc
) {
2202 WARN("No proc set\n");
2205 if (lpdwYieldData
) *lpdwYieldData
= wmd
->dwYieldData
;
2206 return wmd
->lpfnYieldProc
;
2209 /**************************************************************************
2210 * mciGetCreatorTask [WINMM.@]
2212 HTASK WINAPI
mciGetCreatorTask(MCIDEVICEID uDeviceID
)
2214 LPWINE_MCIDRIVER wmd
;
2217 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)wmd
->CreatorThread
;
2219 TRACE("(%u) => %p\n", uDeviceID
, ret
);
2223 /**************************************************************************
2224 * mciDriverYield [WINMM.@]
2226 UINT WINAPI
mciDriverYield(MCIDEVICEID uDeviceID
)
2228 LPWINE_MCIDRIVER wmd
;
2231 TRACE("(%04x)\n", uDeviceID
);
2233 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
) {
2235 PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2237 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);