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)
51 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
53 /* First MCI valid device ID (0 means error) */
54 #define MCI_MAGIC 0x0001
57 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};
58 static const WCHAR wszNull
[] = {0};
59 static const WCHAR wszAll
[] = {'A','L','L',0};
60 static const WCHAR wszMci
[] = {'M','C','I',0};
61 static const WCHAR wszOpen
[] = {'o','p','e','n',0};
62 static const WCHAR wszSystemIni
[] = {'s','y','s','t','e','m','.','i','n','i',0};
64 static WINE_MCIDRIVER
*MciDrivers
;
66 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
);
67 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
);
69 /* dup a string and uppercase it */
70 static inline LPWSTR
str_dup_upper( LPCWSTR str
)
72 INT len
= (strlenW(str
) + 1) * sizeof(WCHAR
);
73 LPWSTR p
= HeapAlloc( GetProcessHeap(), 0, len
);
76 memcpy( p
, str
, len
);
82 /**************************************************************************
83 * MCI_GetDriver [internal]
85 static LPWINE_MCIDRIVER
MCI_GetDriver(UINT16 wDevID
)
87 LPWINE_MCIDRIVER wmd
= 0;
89 EnterCriticalSection(&WINMM_cs
);
90 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
91 if (wmd
->wDeviceID
== wDevID
)
94 LeaveCriticalSection(&WINMM_cs
);
98 /**************************************************************************
99 * MCI_GetDriverFromString [internal]
101 static UINT
MCI_GetDriverFromString(LPCWSTR lpstrName
)
103 LPWINE_MCIDRIVER wmd
;
109 if (!strcmpiW(lpstrName
, wszAll
))
110 return MCI_ALL_DEVICE_ID
;
112 EnterCriticalSection(&WINMM_cs
);
113 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
114 if (wmd
->lpstrElementName
&& strcmpW(wmd
->lpstrElementName
, lpstrName
) == 0) {
115 ret
= wmd
->wDeviceID
;
118 if (wmd
->lpstrDeviceType
&& strcmpiW(wmd
->lpstrDeviceType
, lpstrName
) == 0) {
119 ret
= wmd
->wDeviceID
;
122 if (wmd
->lpstrAlias
&& strcmpiW(wmd
->lpstrAlias
, lpstrName
) == 0) {
123 ret
= wmd
->wDeviceID
;
127 LeaveCriticalSection(&WINMM_cs
);
132 /**************************************************************************
133 * MCI_MessageToString [internal]
135 const char* MCI_MessageToString(UINT wMsg
)
137 static char buffer
[100];
139 #define CASE(s) case (s): return #s
149 CASE(DRV_QUERYCONFIGURE
);
152 CASE(DRV_EXITSESSION
);
153 CASE(DRV_EXITAPPLICATION
);
157 CASE(MCI_CLOSE_DRIVER
);
166 CASE(MCI_GETDEVCAPS
);
170 CASE(MCI_OPEN_DRIVER
);
188 /* constants for digital video */
202 sprintf(buffer
, "MCI_<<%04X>>", wMsg
);
207 LPWSTR
MCI_strdupAtoW( LPCSTR str
)
212 if (!str
) return NULL
;
213 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
214 ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
215 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
219 LPSTR
MCI_strdupWtoA( LPCWSTR str
)
224 if (!str
) return NULL
;
225 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
226 ret
= HeapAlloc( GetProcessHeap(), 0, len
);
227 if (ret
) WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
231 static int MCI_MapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR
*dwParam2
)
233 if (msg
< DRV_RESERVED
) return 0;
272 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*dwParam2
;
273 MCI_OPEN_PARMSW
*mci_openW
;
276 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD_PTR
) + sizeof(*mci_openW
) + 2 * sizeof(DWORD
));
279 *ptr
++ = *dwParam2
; /* save the previous pointer */
280 *dwParam2
= (DWORD_PTR
)ptr
;
281 mci_openW
= (MCI_OPEN_PARMSW
*)ptr
;
283 if (dwParam1
& MCI_NOTIFY
)
284 mci_openW
->dwCallback
= mci_openA
->dwCallback
;
286 if (dwParam1
& MCI_OPEN_TYPE
)
288 if (dwParam1
& MCI_OPEN_TYPE_ID
)
289 mci_openW
->lpstrDeviceType
= (LPCWSTR
)mci_openA
->lpstrDeviceType
;
291 mci_openW
->lpstrDeviceType
= MCI_strdupAtoW(mci_openA
->lpstrDeviceType
);
293 if (dwParam1
& MCI_OPEN_ELEMENT
)
295 if (dwParam1
& MCI_OPEN_ELEMENT_ID
)
296 mci_openW
->lpstrElementName
= (LPCWSTR
)mci_openA
->lpstrElementName
;
298 mci_openW
->lpstrElementName
= MCI_strdupAtoW(mci_openA
->lpstrElementName
);
300 if (dwParam1
& MCI_OPEN_ALIAS
)
301 mci_openW
->lpstrAlias
= MCI_strdupAtoW(mci_openA
->lpstrAlias
);
302 /* FIXME: this is only needed for specific types of MCI devices, and
303 * may cause a segfault if the two DWORD:s don't exist at the end of
306 memcpy(mci_openW
+ 1, mci_openA
+ 1, 2 * sizeof(DWORD
));
311 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
313 MCI_ANIM_WINDOW_PARMSA
*mci_windowA
= (MCI_ANIM_WINDOW_PARMSA
*)*dwParam2
;
314 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
;
316 mci_windowW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowW
));
317 if (!mci_windowW
) return -1;
319 *dwParam2
= (DWORD_PTR
)mci_windowW
;
321 mci_windowW
->lpstrText
= MCI_strdupAtoW(mci_windowA
->lpstrText
);
323 if (dwParam1
& MCI_NOTIFY
)
324 mci_windowW
->dwCallback
= mci_windowA
->dwCallback
;
325 if (dwParam1
& MCI_ANIM_WINDOW_HWND
)
326 mci_windowW
->hWnd
= mci_windowA
->hWnd
;
327 if (dwParam1
& MCI_ANIM_WINDOW_STATE
)
328 mci_windowW
->nCmdShow
= mci_windowA
->nCmdShow
;
336 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*dwParam2
;
337 MCI_SYSINFO_PARMSW
*mci_sysinfoW
;
340 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoW
) + sizeof(DWORD_PTR
));
343 *ptr
++ = *dwParam2
; /* save the previous pointer */
344 *dwParam2
= (DWORD_PTR
)ptr
;
345 mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)ptr
;
347 if (dwParam1
& MCI_NOTIFY
)
348 mci_sysinfoW
->dwCallback
= mci_sysinfoA
->dwCallback
;
350 mci_sysinfoW
->dwRetSize
= mci_sysinfoA
->dwRetSize
;
351 mci_sysinfoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_sysinfoW
->dwRetSize
);
352 mci_sysinfoW
->dwNumber
= mci_sysinfoA
->dwNumber
;
353 mci_sysinfoW
->wDeviceType
= mci_sysinfoA
->wDeviceType
;
358 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*dwParam2
;
359 MCI_INFO_PARMSW
*mci_infoW
;
362 ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_infoW
) + sizeof(DWORD_PTR
));
365 *ptr
++ = *dwParam2
; /* save the previous pointer */
366 *dwParam2
= (DWORD_PTR
)ptr
;
367 mci_infoW
= (MCI_INFO_PARMSW
*)ptr
;
369 if (dwParam1
& MCI_NOTIFY
)
370 mci_infoW
->dwCallback
= mci_infoA
->dwCallback
;
372 mci_infoW
->dwRetSize
= mci_infoA
->dwRetSize
* sizeof(WCHAR
); /* it's not the same as SYSINFO !!! */
373 mci_infoW
->lpstrReturn
= HeapAlloc(GetProcessHeap(), 0, mci_infoW
->dwRetSize
);
378 MCI_SAVE_PARMSA
*mci_saveA
= (MCI_SAVE_PARMSA
*)*dwParam2
;
379 MCI_SAVE_PARMSW
*mci_saveW
;
381 mci_saveW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_saveW
));
382 if (!mci_saveW
) return -1;
384 *dwParam2
= (DWORD_PTR
)mci_saveW
;
385 if (dwParam1
& MCI_NOTIFY
)
386 mci_saveW
->dwCallback
= mci_saveA
->dwCallback
;
387 mci_saveW
->lpfilename
= MCI_strdupAtoW(mci_saveA
->lpfilename
);
392 MCI_LOAD_PARMSA
*mci_loadA
= (MCI_LOAD_PARMSA
*)*dwParam2
;
393 MCI_LOAD_PARMSW
*mci_loadW
;
395 mci_loadW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_loadW
));
396 if (!mci_loadW
) return -1;
398 *dwParam2
= (DWORD_PTR
)mci_loadW
;
399 if (dwParam1
& MCI_NOTIFY
)
400 mci_loadW
->dwCallback
= mci_loadA
->dwCallback
;
401 mci_loadW
->lpfilename
= MCI_strdupAtoW(mci_loadA
->lpfilename
);
407 MCI_VD_ESCAPE_PARMSA
*mci_vd_escapeA
= (MCI_VD_ESCAPE_PARMSA
*)*dwParam2
;
408 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
;
410 mci_vd_escapeW
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_vd_escapeW
));
411 if (!mci_vd_escapeW
) return -1;
413 *dwParam2
= (DWORD_PTR
)mci_vd_escapeW
;
414 if (dwParam1
& MCI_NOTIFY
)
415 mci_vd_escapeW
->dwCallback
= mci_vd_escapeA
->dwCallback
;
416 mci_vd_escapeW
->lpstrCommand
= MCI_strdupAtoW(mci_vd_escapeA
->lpstrCommand
);
420 FIXME("Message %s needs translation\n", MCI_MessageToString(msg
));
425 static DWORD
MCI_UnmapMsgAtoW(UINT msg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
,
432 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
433 MCI_OPEN_PARMSA
*mci_openA
= (MCI_OPEN_PARMSA
*)*ptr
;
434 MCI_OPEN_PARMSW
*mci_openW
= (MCI_OPEN_PARMSW
*)(ptr
+ 1);
436 mci_openA
->wDeviceID
= mci_openW
->wDeviceID
;
438 if (dwParam1
& MCI_OPEN_TYPE
)
440 if (!(dwParam1
& MCI_OPEN_TYPE_ID
))
441 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrDeviceType
);
443 if (dwParam1
& MCI_OPEN_ELEMENT
)
445 if (!(dwParam1
& MCI_OPEN_ELEMENT_ID
))
446 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrElementName
);
448 if (dwParam1
& MCI_OPEN_ALIAS
)
449 HeapFree(GetProcessHeap(), 0, (LPWSTR
)mci_openW
->lpstrAlias
);
450 HeapFree(GetProcessHeap(), 0, ptr
);
454 if (dwParam1
& MCI_ANIM_WINDOW_TEXT
)
456 MCI_ANIM_WINDOW_PARMSW
*mci_windowW
= (MCI_ANIM_WINDOW_PARMSW
*)dwParam2
;
458 HeapFree(GetProcessHeap(), 0, (void*)mci_windowW
->lpstrText
);
459 HeapFree(GetProcessHeap(), 0, mci_windowW
);
465 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
466 MCI_SYSINFO_PARMSA
*mci_sysinfoA
= (MCI_SYSINFO_PARMSA
*)*ptr
;
467 MCI_SYSINFO_PARMSW
*mci_sysinfoW
= (MCI_SYSINFO_PARMSW
*)(ptr
+ 1);
471 mci_sysinfoA
->dwNumber
= mci_sysinfoW
->dwNumber
;
472 mci_sysinfoA
->wDeviceType
= mci_sysinfoW
->wDeviceType
;
473 if (dwParam1
& MCI_SYSINFO_QUANTITY
)
474 *(DWORD
*)mci_sysinfoA
->lpstrReturn
= *(DWORD
*)mci_sysinfoW
->lpstrReturn
;
476 WideCharToMultiByte(CP_ACP
, 0,
477 mci_sysinfoW
->lpstrReturn
, mci_sysinfoW
->dwRetSize
,
478 mci_sysinfoA
->lpstrReturn
, mci_sysinfoA
->dwRetSize
,
482 HeapFree(GetProcessHeap(), 0, mci_sysinfoW
->lpstrReturn
);
483 HeapFree(GetProcessHeap(), 0, ptr
);
488 DWORD_PTR
*ptr
= (DWORD_PTR
*)dwParam2
- 1;
489 MCI_INFO_PARMSA
*mci_infoA
= (MCI_INFO_PARMSA
*)*ptr
;
490 MCI_INFO_PARMSW
*mci_infoW
= (MCI_INFO_PARMSW
*)(ptr
+ 1);
494 WideCharToMultiByte(CP_ACP
, 0,
495 mci_infoW
->lpstrReturn
, mci_infoW
->dwRetSize
/ sizeof(WCHAR
),
496 mci_infoA
->lpstrReturn
, mci_infoA
->dwRetSize
,
500 HeapFree(GetProcessHeap(), 0, mci_infoW
->lpstrReturn
);
501 HeapFree(GetProcessHeap(), 0, ptr
);
506 MCI_SAVE_PARMSW
*mci_saveW
= (MCI_SAVE_PARMSW
*)dwParam2
;
508 HeapFree(GetProcessHeap(), 0, (void*)mci_saveW
->lpfilename
);
509 HeapFree(GetProcessHeap(), 0, mci_saveW
);
514 MCI_LOAD_PARMSW
*mci_loadW
= (MCI_LOAD_PARMSW
*)dwParam2
;
516 HeapFree(GetProcessHeap(), 0, (void*)mci_loadW
->lpfilename
);
517 HeapFree(GetProcessHeap(), 0, mci_loadW
);
522 MCI_VD_ESCAPE_PARMSW
*mci_vd_escapeW
= (MCI_VD_ESCAPE_PARMSW
*)dwParam2
;
524 HeapFree(GetProcessHeap(), 0, (void*)mci_vd_escapeW
->lpstrCommand
);
525 HeapFree(GetProcessHeap(), 0, mci_vd_escapeW
);
530 FIXME("Message %s needs unmapping\n", MCI_MessageToString(msg
));
537 /**************************************************************************
538 * MCI_GetDevTypeFromFileName [internal]
540 static DWORD
MCI_GetDevTypeFromFileName(LPCWSTR fileName
, LPWSTR buf
, UINT len
)
544 static const WCHAR keyW
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\',
545 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
546 'M','C','I',' ','E','x','t','e','n','s','i','o','n','s',0};
547 if ((tmp
= strrchrW(fileName
, '.'))) {
548 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, keyW
,
549 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
551 LONG lRet
= RegQueryValueExW( hKey
, tmp
+ 1, 0, 0, (void*)buf
, &dwLen
);
553 if (lRet
== ERROR_SUCCESS
) return 0;
555 TRACE("No ...\\MCI Extensions entry for %s found.\n", debugstr_w(tmp
));
557 return MCIERR_EXTENSION_NOT_FOUND
;
560 #define MAX_MCICMDTABLE 20
561 #define MCI_COMMAND_TABLE_NOT_LOADED 0xFFFE
563 typedef struct tagWINE_MCICMDTABLE
{
567 UINT nVerbs
; /* number of verbs in command table */
568 LPCWSTR
* aVerbs
; /* array of verbs to speed up the verb look up process */
569 } WINE_MCICMDTABLE
, *LPWINE_MCICMDTABLE
;
571 static WINE_MCICMDTABLE S_MciCmdTable
[MAX_MCICMDTABLE
];
573 /**************************************************************************
574 * MCI_IsCommandTableValid [internal]
576 static BOOL
MCI_IsCommandTableValid(UINT uTbl
)
585 TRACE("Dumping cmdTbl=%d [lpTable=%p devType=%d]\n",
586 uTbl
, S_MciCmdTable
[uTbl
].lpTable
, S_MciCmdTable
[uTbl
].uDevType
);
588 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
591 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
594 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
595 flg
= *(const DWORD
*)lmem
;
596 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
597 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
599 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
601 case MCI_COMMAND_HEAD
: if (!*str
|| !flg
) return FALSE
; idx
= 0; break; /* check unicity of str in table */
602 case MCI_STRING
: if (inCst
) return FALSE
; break;
603 case MCI_INTEGER
: if (!*str
) return FALSE
; break;
604 case MCI_END_COMMAND
: if (*str
|| flg
|| idx
== 0) return FALSE
; idx
= 0; break;
605 case MCI_RETURN
: if (*str
|| idx
!= 1) return FALSE
; break;
606 case MCI_FLAG
: if (!*str
) return FALSE
; break;
607 case MCI_END_COMMAND_LIST
: if (*str
|| flg
) return FALSE
; idx
= 0; break;
608 case MCI_RECT
: if (!*str
|| inCst
) return FALSE
; break;
609 case MCI_CONSTANT
: if (inCst
) return FALSE
; inCst
= TRUE
; break;
610 case MCI_END_CONSTANT
: if (*str
|| flg
|| !inCst
) return FALSE
; inCst
= FALSE
; break;
611 default: return FALSE
;
613 } while (eid
!= MCI_END_COMMAND_LIST
);
617 /**************************************************************************
618 * MCI_DumpCommandTable [internal]
620 static BOOL
MCI_DumpCommandTable(UINT uTbl
)
627 if (!MCI_IsCommandTableValid(uTbl
)) {
628 ERR("Ooops: %d is not valid\n", uTbl
);
632 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
636 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
637 flg
= *(const DWORD
*)lmem
;
638 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
639 /* TRACE("cmd=%s %08lx %04x\n", debugstr_w(str), flg, eid); */
640 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
641 } while (eid
!= MCI_END_COMMAND
&& eid
!= MCI_END_COMMAND_LIST
);
642 /* EPP TRACE(" => end of command%s\n", (eid == MCI_END_COMMAND_LIST) ? " list" : ""); */
643 } while (eid
!= MCI_END_COMMAND_LIST
);
648 /**************************************************************************
649 * MCI_GetCommandTable [internal]
651 static UINT
MCI_GetCommandTable(UINT uDevType
)
657 /* first look up existing for existing devType */
658 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
659 if (S_MciCmdTable
[uTbl
].lpTable
&& S_MciCmdTable
[uTbl
].uDevType
== uDevType
)
663 /* well try to load id */
664 if (uDevType
>= MCI_DEVTYPE_FIRST
&& uDevType
<= MCI_DEVTYPE_LAST
) {
665 if (LoadStringW(hWinMM32Instance
, uDevType
, buf
, sizeof(buf
) / sizeof(WCHAR
))) {
668 } else if (uDevType
== 0) {
669 static const WCHAR wszCore
[] = {'C','O','R','E',0};
672 uTbl
= MCI_NO_COMMAND_TABLE
;
674 HRSRC hRsrc
= FindResourceW(hWinMM32Instance
, str
, (LPCWSTR
)RT_RCDATA
);
677 if (hRsrc
) hMem
= LoadResource(hWinMM32Instance
, hRsrc
);
679 uTbl
= MCI_SetCommandTable(hMem
, uDevType
);
681 WARN("No command table found in resource %p[%s]\n",
682 hWinMM32Instance
, debugstr_w(str
));
685 TRACE("=> %d\n", uTbl
);
689 /**************************************************************************
690 * MCI_SetCommandTable [internal]
692 static UINT
MCI_SetCommandTable(HGLOBAL hMem
, UINT uDevType
)
695 static BOOL bInitDone
= FALSE
;
698 * The CORE command table must be loaded first, so that MCI_GetCommandTable()
699 * can be called with 0 as a uDevType to retrieve it.
704 MCI_GetCommandTable(0);
706 TRACE("(%p, %u)\n", hMem
, uDevType
);
707 for (uTbl
= 0; uTbl
< MAX_MCICMDTABLE
; uTbl
++) {
708 if (!S_MciCmdTable
[uTbl
].lpTable
) {
714 S_MciCmdTable
[uTbl
].uDevType
= uDevType
;
715 S_MciCmdTable
[uTbl
].lpTable
= LockResource(hMem
);
716 S_MciCmdTable
[uTbl
].hMem
= hMem
;
719 MCI_DumpCommandTable(uTbl
);
722 /* create the verbs table */
723 /* get # of entries */
724 lmem
= S_MciCmdTable
[uTbl
].lpTable
;
728 lmem
+= (strlenW(str
) + 1) * sizeof(WCHAR
);
729 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
730 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
731 if (eid
== MCI_COMMAND_HEAD
)
733 } while (eid
!= MCI_END_COMMAND_LIST
);
735 S_MciCmdTable
[uTbl
].aVerbs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(LPCWSTR
));
736 S_MciCmdTable
[uTbl
].nVerbs
= count
;
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
)
746 S_MciCmdTable
[uTbl
].aVerbs
[count
++] = str
;
747 } while (eid
!= MCI_END_COMMAND_LIST
);
748 /* assert(count == S_MciCmdTable[uTbl].nVerbs); */
753 return MCI_NO_COMMAND_TABLE
;
756 /**************************************************************************
757 * MCI_UnLoadMciDriver [internal]
759 static BOOL
MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd
)
761 LPWINE_MCIDRIVER
* tmp
;
766 CloseDriver(wmd
->hDriver
, 0, 0);
768 if (wmd
->dwPrivate
!= 0)
769 WARN("Unloading mci driver with non nul dwPrivate field\n");
771 EnterCriticalSection(&WINMM_cs
);
772 for (tmp
= &MciDrivers
; *tmp
; tmp
= &(*tmp
)->lpNext
) {
778 LeaveCriticalSection(&WINMM_cs
);
780 HeapFree(GetProcessHeap(), 0, wmd
->lpstrDeviceType
);
781 HeapFree(GetProcessHeap(), 0, wmd
->lpstrAlias
);
782 HeapFree(GetProcessHeap(), 0, wmd
->lpstrElementName
);
784 HeapFree(GetProcessHeap(), 0, wmd
);
788 /**************************************************************************
789 * MCI_OpenMciDriver [internal]
791 static BOOL
MCI_OpenMciDriver(LPWINE_MCIDRIVER wmd
, LPCWSTR drvTyp
, DWORD_PTR lp
)
795 if (!DRIVER_GetLibName(drvTyp
, wszMci
, libName
, sizeof(libName
)))
798 /* First load driver */
799 wmd
->hDriver
= (HDRVR
)DRIVER_TryOpenDriver32(libName
, lp
);
800 return wmd
->hDriver
!= NULL
;
803 /**************************************************************************
804 * MCI_LoadMciDriver [internal]
806 static DWORD
MCI_LoadMciDriver(LPCWSTR _strDevTyp
, LPWINE_MCIDRIVER
* lpwmd
)
808 LPWSTR strDevTyp
= str_dup_upper(_strDevTyp
);
809 LPWINE_MCIDRIVER wmd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wmd
));
810 MCI_OPEN_DRIVER_PARMSW modp
;
813 if (!wmd
|| !strDevTyp
) {
814 dwRet
= MCIERR_OUT_OF_MEMORY
;
818 wmd
->lpfnYieldProc
= MCI_DefYieldProc
;
819 wmd
->dwYieldData
= VK_CANCEL
;
820 wmd
->CreatorThread
= GetCurrentThreadId();
822 EnterCriticalSection(&WINMM_cs
);
823 /* wmd must be inserted in list before sending opening the driver, because it
824 * may want to lookup at wDevID
826 wmd
->lpNext
= MciDrivers
;
829 for (modp
.wDeviceID
= MCI_MAGIC
;
830 MCI_GetDriver(modp
.wDeviceID
) != 0;
833 wmd
->wDeviceID
= modp
.wDeviceID
;
835 LeaveCriticalSection(&WINMM_cs
);
837 TRACE("wDevID=%04X\n", modp
.wDeviceID
);
839 modp
.lpstrParams
= NULL
;
841 if (!MCI_OpenMciDriver(wmd
, strDevTyp
, (DWORD_PTR
)&modp
)) {
842 /* silence warning if all is used... some bogus program use commands like
845 if (strcmpiW(strDevTyp
, wszAll
) == 0) {
846 dwRet
= MCIERR_CANNOT_USE_ALL
;
848 FIXME("Couldn't load driver for type %s.\n",
849 debugstr_w(strDevTyp
));
850 dwRet
= MCIERR_DEVICE_NOT_INSTALLED
;
855 /* FIXME: should also check that module's description is of the form
856 * MODULENAME:[MCI] comment
859 /* some drivers will return 0x0000FFFF, some others 0xFFFFFFFF */
860 wmd
->uSpecificCmdTable
= LOWORD(modp
.wCustomCommandTable
);
861 wmd
->uTypeCmdTable
= MCI_COMMAND_TABLE_NOT_LOADED
;
863 TRACE("Loaded driver %p (%s), type is %d, cmdTable=%08x\n",
864 wmd
->hDriver
, debugstr_w(strDevTyp
), modp
.wType
, modp
.wCustomCommandTable
);
866 wmd
->lpstrDeviceType
= strDevTyp
;
867 wmd
->wType
= modp
.wType
;
869 TRACE("mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n",
870 modp
.wDeviceID
, modp
.wType
, modp
.wDeviceID
);
874 MCI_UnLoadMciDriver(wmd
);
875 HeapFree(GetProcessHeap(), 0, strDevTyp
);
880 /**************************************************************************
881 * MCI_SendCommandFrom32 [internal]
883 static DWORD
MCI_SendCommandFrom32(MCIDEVICEID wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
885 DWORD dwRet
= MCIERR_INVALID_DEVICE_ID
;
886 LPWINE_MCIDRIVER wmd
= MCI_GetDriver(wDevID
);
889 dwRet
= SendDriverMessage(wmd
->hDriver
, wMsg
, dwParam1
, dwParam2
);
894 /**************************************************************************
895 * MCI_FinishOpen [internal]
897 static DWORD
MCI_FinishOpen(LPWINE_MCIDRIVER wmd
, LPMCI_OPEN_PARMSW lpParms
,
900 if (dwParam
& MCI_OPEN_ELEMENT
)
902 wmd
->lpstrElementName
= HeapAlloc(GetProcessHeap(),0,(strlenW(lpParms
->lpstrElementName
)+1) * sizeof(WCHAR
));
903 strcpyW( wmd
->lpstrElementName
, lpParms
->lpstrElementName
);
905 if (dwParam
& MCI_OPEN_ALIAS
)
907 wmd
->lpstrAlias
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpParms
->lpstrAlias
)+1) * sizeof(WCHAR
));
908 strcpyW( wmd
->lpstrAlias
, lpParms
->lpstrAlias
);
910 lpParms
->wDeviceID
= wmd
->wDeviceID
;
912 return MCI_SendCommandFrom32(wmd
->wDeviceID
, MCI_OPEN_DRIVER
, dwParam
,
916 /**************************************************************************
917 * MCI_FindCommand [internal]
919 static LPCWSTR
MCI_FindCommand(UINT uTbl
, LPCWSTR verb
)
923 if (uTbl
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTbl
].lpTable
)
926 /* another improvement would be to have the aVerbs array sorted,
927 * so that we could use a dichotomic search on it, rather than this dumb
930 for (idx
= 0; idx
< S_MciCmdTable
[uTbl
].nVerbs
; idx
++) {
931 if (strcmpiW(S_MciCmdTable
[uTbl
].aVerbs
[idx
], verb
) == 0)
932 return S_MciCmdTable
[uTbl
].aVerbs
[idx
];
938 /**************************************************************************
939 * MCI_GetReturnType [internal]
941 static DWORD
MCI_GetReturnType(LPCWSTR lpCmd
)
943 lpCmd
= (LPCWSTR
)((const BYTE
*)(lpCmd
+ strlenW(lpCmd
) + 1) + sizeof(DWORD
) + sizeof(WORD
));
944 if (*lpCmd
== '\0' && *(const WORD
*)((const BYTE
*)(lpCmd
+ 1) + sizeof(DWORD
)) == MCI_RETURN
) {
945 return *(const DWORD
*)(lpCmd
+ 1);
950 /**************************************************************************
951 * MCI_GetMessage [internal]
953 static WORD
MCI_GetMessage(LPCWSTR lpCmd
)
955 return (WORD
)*(const DWORD
*)(lpCmd
+ strlenW(lpCmd
) + 1);
958 /**************************************************************************
959 * MCI_GetDWord [internal]
961 static BOOL
MCI_GetDWord(DWORD_PTR
*data
, LPWSTR
* ptr
)
966 val
= strtoulW(*ptr
, &ret
, 0);
970 case ' ': ret
++; break;
971 default: return FALSE
;
979 /**************************************************************************
980 * MCI_GetString [internal]
982 static DWORD
MCI_GetString(LPWSTR
* str
, LPWSTR
* args
)
986 /* see if we have a quoted string */
988 ptr
= strchrW(*str
= ptr
+ 1, '"');
989 if (!ptr
) return MCIERR_NO_CLOSING_QUOTE
;
990 /* FIXME: shall we escape \" from string ?? */
991 if (ptr
[-1] == '\\') TRACE("Ooops: un-escaped \"\n");
992 *ptr
++ = '\0'; /* remove trailing " */
993 if (*ptr
!= ' ' && *ptr
!= '\0') return MCIERR_EXTRA_CHARACTERS
;
995 ptr
= strchrW(ptr
, ' ');
1000 ptr
= *args
+ strlenW(*args
);
1009 #define MCI_DATA_SIZE 16
1011 /**************************************************************************
1012 * MCI_ParseOptArgs [internal]
1014 static DWORD
MCI_ParseOptArgs(DWORD_PTR
*data
, int _offset
, LPCWSTR lpCmd
,
1015 LPWSTR args
, LPDWORD dwFlags
)
1020 DWORD dwRet
, flg
, cflg
= 0;
1024 /* loop on arguments */
1026 lmem
= (const char*)lpCmd
;
1027 found
= inCst
= FALSE
;
1030 /* skip any leading white space(s) */
1031 while (*args
== ' ') args
++;
1032 TRACE("args=%s offset=%d\n", debugstr_w(args
), offset
);
1034 do { /* loop on options for command table for the requested verb */
1035 str
= (LPCWSTR
)lmem
;
1036 lmem
+= ((len
= strlenW(str
)) + 1) * sizeof(WCHAR
);
1037 flg
= *(const DWORD
*)lmem
;
1038 eid
= *(const WORD
*)(lmem
+ sizeof(DWORD
));
1039 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
1040 /* TRACE("\tcmd=%s inCst=%c eid=%04x\n", debugstr_w(str), inCst ? 'Y' : 'N', eid); */
1044 inCst
= TRUE
; cflg
= flg
; break;
1045 case MCI_END_CONSTANT
:
1046 /* there may be additional integral values after flag in constant */
1047 if (inCst
&& MCI_GetDWord(&(data
[offset
]), &args
)) {
1050 inCst
= FALSE
; cflg
= 0;
1054 if (strncmpiW(args
, str
, len
) == 0 &&
1055 ((eid
== MCI_STRING
&& len
== 0) || args
[len
] == 0 || args
[len
] == ' ')) {
1056 /* store good values into data[] */
1058 while (*args
== ' ') args
++;
1062 case MCI_COMMAND_HEAD
:
1064 case MCI_END_COMMAND
:
1065 case MCI_END_COMMAND_LIST
:
1066 case MCI_CONSTANT
: /* done above */
1067 case MCI_END_CONSTANT
: /* done above */
1074 data
[offset
] |= flg
;
1079 if (!MCI_GetDWord(&(data
[offset
]), &args
)) {
1080 return MCIERR_BAD_INTEGER
;
1085 /* store rect in data (offset..offset+3) */
1087 if (!MCI_GetDWord(&(data
[offset
+0]), &args
) ||
1088 !MCI_GetDWord(&(data
[offset
+1]), &args
) ||
1089 !MCI_GetDWord(&(data
[offset
+2]), &args
) ||
1090 !MCI_GetDWord(&(data
[offset
+3]), &args
)) {
1091 ERR("Bad rect %s\n", debugstr_w(args
));
1092 return MCIERR_BAD_INTEGER
;
1097 if ((dwRet
= MCI_GetString((LPWSTR
*)&data
[offset
], &args
)))
1100 default: ERR("oops\n");
1102 /* exit inside while loop, except if just entered in constant area definition */
1103 if (!inCst
|| eid
!= MCI_CONSTANT
) eid
= MCI_END_COMMAND
;
1105 /* have offset incremented if needed */
1107 case MCI_COMMAND_HEAD
:
1109 case MCI_END_COMMAND
:
1110 case MCI_END_COMMAND_LIST
:
1112 case MCI_FLAG
: break;
1113 case MCI_INTEGER
: if (!inCst
) offset
++; break;
1114 case MCI_END_CONSTANT
:
1115 case MCI_STRING
: offset
++; break;
1116 case MCI_RECT
: offset
+= 4; break;
1117 default: ERR("oops\n");
1120 } while (eid
!= MCI_END_COMMAND
);
1122 WARN("Optarg %s not found\n", debugstr_w(args
));
1123 return MCIERR_UNRECOGNIZED_COMMAND
;
1125 if (offset
== MCI_DATA_SIZE
) {
1126 ERR("Internal data[] buffer overflow\n");
1127 return MCIERR_PARSER_INTERNAL
;
1133 /**************************************************************************
1134 * MCI_HandleReturnValues [internal]
1136 static DWORD
MCI_HandleReturnValues(DWORD dwRet
, LPWINE_MCIDRIVER wmd
, DWORD retType
,
1137 DWORD_PTR
*data
, LPWSTR lpstrRet
, UINT uRetLen
)
1139 static const WCHAR wszLd
[] = {'%','l','d',0};
1140 static const WCHAR wszLd4
[] = {'%','l','d',' ','%','l','d',' ','%','l','d',' ','%','l','d',0};
1141 static const WCHAR wszCol3
[] = {'%','d',':','%','d',':','%','d',0};
1142 static const WCHAR wszCol4
[] = {'%','d',':','%','d',':','%','d',':','%','d',0};
1146 case 0: /* nothing to return */
1149 switch (dwRet
& 0xFFFF0000ul
) {
1151 case MCI_INTEGER_RETURNED
:
1152 snprintfW(lpstrRet
, uRetLen
, wszLd
, data
[1]);
1154 case MCI_RESOURCE_RETURNED
:
1155 /* return string which ID is HIWORD(data[1]),
1156 * string is loaded from mmsystem.dll */
1157 LoadStringW(hWinMM32Instance
, HIWORD(data
[1]), lpstrRet
, uRetLen
);
1159 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1160 /* return string which ID is HIWORD(data[1]),
1161 * string is loaded from driver */
1162 /* FIXME: this is wrong for a 16 bit handle */
1163 LoadStringW(GetDriverModuleHandle(wmd
->hDriver
),
1164 HIWORD(data
[1]), lpstrRet
, uRetLen
);
1166 case MCI_COLONIZED3_RETURN
:
1167 snprintfW(lpstrRet
, uRetLen
, wszCol3
,
1168 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
1169 LOBYTE(HIWORD(data
[1])));
1171 case MCI_COLONIZED4_RETURN
:
1172 snprintfW(lpstrRet
, uRetLen
, wszCol4
,
1173 LOBYTE(LOWORD(data
[1])), HIBYTE(LOWORD(data
[1])),
1174 LOBYTE(HIWORD(data
[1])), HIBYTE(HIWORD(data
[1])));
1176 default: ERR("Ooops (%04X)\n", HIWORD(dwRet
));
1180 switch (dwRet
& 0xFFFF0000ul
) {
1182 /* nothing to do data[1] == lpstrRet */
1184 case MCI_INTEGER_RETURNED
:
1185 data
[1] = *(LPDWORD
)lpstrRet
;
1186 snprintfW(lpstrRet
, uRetLen
, wszLd
, data
[1]);
1189 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1194 if (dwRet
& 0xFFFF0000ul
)
1195 WARN("Oooch. MCI_STRING and HIWORD(dwRet)=%04x\n", HIWORD(dwRet
));
1196 snprintfW(lpstrRet
, uRetLen
, wszLd4
,
1197 data
[1], data
[2], data
[3], data
[4]);
1199 default: ERR("oops\n");
1202 return LOWORD(dwRet
);
1205 /**************************************************************************
1206 * mciSendStringW [WINMM.@]
1208 DWORD WINAPI
mciSendStringW(LPCWSTR lpstrCommand
, LPWSTR lpstrRet
,
1209 UINT uRetLen
, HWND hwndCallback
)
1211 LPWSTR verb
, dev
, args
;
1212 LPWINE_MCIDRIVER wmd
= 0;
1213 DWORD dwFlags
= 0, dwRet
= 0;
1215 DWORD_PTR data
[MCI_DATA_SIZE
];
1218 LPWSTR devAlias
= NULL
;
1219 static const WCHAR wszNew
[] = {'n','e','w',0};
1220 static const WCHAR wszSAliasS
[] = {' ','a','l','i','a','s',' ',0};
1221 static const WCHAR wszTypeS
[] = {'t','y','p','e',' ',0};
1223 TRACE("(%s, %p, %d, %p)\n",
1224 debugstr_w(lpstrCommand
), lpstrRet
, uRetLen
, hwndCallback
);
1226 /* format is <command> <device> <optargs> */
1227 if (!(verb
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpstrCommand
)+1) * sizeof(WCHAR
))))
1228 return MCIERR_OUT_OF_MEMORY
;
1229 strcpyW( verb
, lpstrCommand
);
1232 memset(data
, 0, sizeof(data
));
1234 if (!(args
= strchrW(verb
, ' '))) {
1235 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1239 if ((dwRet
= MCI_GetString(&dev
, &args
))) {
1243 /* Determine devType from open */
1244 if (!strcmpW(verb
, wszOpen
)) {
1245 LPWSTR devType
, tmp
;
1248 /* case dev == 'new' has to be handled */
1249 if (!strcmpW(dev
, wszNew
)) {
1251 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1253 tmp
= strchrW(devType
, ' ');
1254 if (tmp
) *tmp
= '\0';
1255 devType
= str_dup_upper(devType
);
1256 if (tmp
) *tmp
= ' ';
1257 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1259 WARN("open new requires device type\n");
1260 dwRet
= MCIERR_MISSING_DEVICE_NAME
;
1263 } else if ((devType
= strchrW(dev
, '!')) != NULL
) {
1265 tmp
= devType
; devType
= dev
; dev
= tmp
;
1267 dwFlags
|= MCI_OPEN_TYPE
;
1268 data
[2] = (DWORD_PTR
)devType
;
1269 devType
= str_dup_upper(devType
);
1270 dwFlags
|= MCI_OPEN_ELEMENT
;
1271 data
[3] = (DWORD_PTR
)dev
;
1272 } else if (DRIVER_GetLibName(dev
, wszMci
, buf
, sizeof(buf
))) {
1273 /* this is the name of a mci driver's type */
1274 tmp
= strchrW(dev
, ' ');
1275 if (tmp
) *tmp
= '\0';
1276 data
[2] = (DWORD_PTR
)dev
;
1277 devType
= str_dup_upper(dev
);
1278 if (tmp
) *tmp
= ' ';
1279 dwFlags
|= MCI_OPEN_TYPE
;
1281 if ((devType
= strstrW(args
, wszTypeS
)) != NULL
) {
1283 tmp
= strchrW(devType
, ' ');
1284 if (tmp
) *tmp
= '\0';
1285 devType
= str_dup_upper(devType
);
1286 if (tmp
) *tmp
= ' ';
1287 /* dwFlags and data[2] will be correctly set in ParseOpt loop */
1289 if ((dwRet
= MCI_GetDevTypeFromFileName(dev
, buf
, sizeof(buf
))))
1292 devType
= str_dup_upper(buf
);
1294 dwFlags
|= MCI_OPEN_ELEMENT
;
1295 data
[3] = (DWORD_PTR
)dev
;
1297 if ((devAlias
= strstrW(args
, wszSAliasS
))) {
1300 if (!(tmp
= strchrW(devAlias
,' '))) tmp
= devAlias
+ strlenW(devAlias
);
1301 if (tmp
) *tmp
= '\0';
1302 tmp2
= HeapAlloc(GetProcessHeap(), 0, (tmp
- devAlias
+ 1) * sizeof(WCHAR
) );
1303 memcpy( tmp2
, devAlias
, (tmp
- devAlias
) * sizeof(WCHAR
) );
1304 tmp2
[tmp
- devAlias
] = 0;
1305 data
[4] = (DWORD_PTR
)tmp2
;
1306 /* should be done in regular options parsing */
1307 /* dwFlags |= MCI_OPEN_ALIAS; */
1308 } else if (dev
== 0) {
1309 /* "open new" requires alias */
1310 dwRet
= MCIERR_NEW_REQUIRES_ALIAS
;
1314 dwRet
= MCI_LoadMciDriver(devType
, &wmd
);
1315 if (dwRet
== MCIERR_DEVICE_NOT_INSTALLED
)
1316 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1317 HeapFree(GetProcessHeap(), 0, devType
);
1319 MCI_UnLoadMciDriver(wmd
);
1322 } else if (!(wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
)))) {
1324 static const WCHAR wszOpenWait
[] = {'o','p','e','n',' ','%','s',' ','w','a','i','t',0};
1326 sprintfW(buf
, wszOpenWait
, dev
);
1328 if ((dwRet
= mciSendStringW(buf
, NULL
, 0, 0)) != 0)
1331 wmd
= MCI_GetDriver(mciGetDeviceIDW(dev
));
1333 /* FIXME: memory leak, MCI driver is not closed */
1334 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1339 /* get the verb in the different command tables */
1341 /* try the device specific command table */
1342 lpCmd
= MCI_FindCommand(wmd
->uSpecificCmdTable
, verb
);
1344 /* try the type specific command table */
1345 if (wmd
->uTypeCmdTable
== MCI_COMMAND_TABLE_NOT_LOADED
)
1346 wmd
->uTypeCmdTable
= MCI_GetCommandTable(wmd
->wType
);
1347 if (wmd
->uTypeCmdTable
!= MCI_NO_COMMAND_TABLE
)
1348 lpCmd
= MCI_FindCommand(wmd
->uTypeCmdTable
, verb
);
1351 /* try core command table */
1352 if (!lpCmd
) lpCmd
= MCI_FindCommand(MCI_GetCommandTable(0), verb
);
1355 TRACE("Command %s not found!\n", debugstr_w(verb
));
1356 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1360 /* set return information */
1361 switch (retType
= MCI_GetReturnType(lpCmd
)) {
1362 case 0: offset
= 1; break;
1363 case MCI_INTEGER
: offset
= 2; break;
1364 case MCI_STRING
: data
[1] = (DWORD_PTR
)lpstrRet
; data
[2] = uRetLen
; offset
= 3; break;
1365 case MCI_RECT
: offset
= 5; break;
1366 default: ERR("oops\n");
1369 TRACE("verb=%s on dev=%s; offset=%d\n",
1370 debugstr_w(verb
), debugstr_w(dev
), offset
);
1372 if ((dwRet
= MCI_ParseOptArgs(data
, offset
, lpCmd
, args
, &dwFlags
)))
1375 /* set up call back */
1376 if (dwFlags
& MCI_NOTIFY
) {
1377 data
[0] = (DWORD_PTR
)hwndCallback
;
1380 /* FIXME: the command should get it's own notification window set up and
1381 * ask for device closing while processing the notification mechanism
1383 if (lpstrRet
&& uRetLen
) *lpstrRet
= '\0';
1385 TRACE("[%d, %s, %08x, %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s %08x/%s]\n",
1386 wmd
->wDeviceID
, MCI_MessageToString(MCI_GetMessage(lpCmd
)), dwFlags
,
1387 data
[0], debugstr_w((WCHAR
*)data
[0]), data
[1], debugstr_w((WCHAR
*)data
[1]),
1388 data
[2], debugstr_w((WCHAR
*)data
[2]), data
[3], debugstr_w((WCHAR
*)data
[3]),
1389 data
[4], debugstr_w((WCHAR
*)data
[4]), data
[5], debugstr_w((WCHAR
*)data
[5]));
1391 if (strcmpW(verb
, wszOpen
) == 0) {
1392 if ((dwRet
= MCI_FinishOpen(wmd
, (LPMCI_OPEN_PARMSW
)data
, dwFlags
)))
1393 MCI_UnLoadMciDriver(wmd
);
1394 /* FIXME: notification is not properly shared across two opens */
1396 dwRet
= MCI_SendCommand(wmd
->wDeviceID
, MCI_GetMessage(lpCmd
), dwFlags
, (DWORD_PTR
)data
);
1398 TRACE("=> 1/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1399 dwRet
= MCI_HandleReturnValues(dwRet
, wmd
, retType
, data
, lpstrRet
, uRetLen
);
1400 TRACE("=> 2/ %x (%s)\n", dwRet
, debugstr_w(lpstrRet
));
1403 HeapFree(GetProcessHeap(), 0, verb
);
1407 /**************************************************************************
1408 * mciSendStringA [WINMM.@]
1410 DWORD WINAPI
mciSendStringA(LPCSTR lpstrCommand
, LPSTR lpstrRet
,
1411 UINT uRetLen
, HWND hwndCallback
)
1413 LPWSTR lpwstrCommand
;
1414 LPWSTR lpwstrRet
= NULL
;
1418 /* FIXME: is there something to do with lpstrReturnString ? */
1419 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, NULL
, 0 );
1420 lpwstrCommand
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1421 MultiByteToWideChar( CP_ACP
, 0, lpstrCommand
, -1, lpwstrCommand
, len
);
1424 lpwstrRet
= HeapAlloc(GetProcessHeap(), 0, uRetLen
* sizeof(WCHAR
));
1426 WARN("no memory\n");
1427 HeapFree( GetProcessHeap(), 0, lpwstrCommand
);
1428 return MCIERR_OUT_OF_MEMORY
;
1431 ret
= mciSendStringW(lpwstrCommand
, lpwstrRet
, uRetLen
, hwndCallback
);
1432 if (!ret
&& lpwstrRet
)
1433 WideCharToMultiByte( CP_ACP
, 0, lpwstrRet
, -1, lpstrRet
, uRetLen
, NULL
, NULL
);
1434 HeapFree(GetProcessHeap(), 0, lpwstrCommand
);
1435 HeapFree(GetProcessHeap(), 0, lpwstrRet
);
1439 /**************************************************************************
1440 * mciExecute [WINMM.@]
1442 BOOL WINAPI
mciExecute(LPCSTR lpstrCommand
)
1447 TRACE("(%s)!\n", lpstrCommand
);
1449 ret
= mciSendStringA(lpstrCommand
, strRet
, sizeof(strRet
), 0);
1451 if (!mciGetErrorStringA(ret
, strRet
, sizeof(strRet
))) {
1452 sprintf(strRet
, "Unknown MCI error (%lu)", ret
);
1454 MessageBoxA(0, strRet
, "Error in mciExecute()", MB_OK
);
1456 /* FIXME: what shall I return ? */
1460 /**************************************************************************
1461 * mciLoadCommandResource [WINMM.@]
1463 * Strangely, this function only exists as a UNICODE one.
1465 UINT WINAPI
mciLoadCommandResource(HINSTANCE hInst
, LPCWSTR resNameW
, UINT type
)
1467 UINT ret
= MCI_NO_COMMAND_TABLE
;
1471 TRACE("(%p, %s, %d)!\n", hInst
, debugstr_w(resNameW
), type
);
1473 /* if a file named "resname.mci" exits, then load resource "resname" from it
1474 * otherwise directly from driver
1475 * We don't support it (who uses this feature ?), but we check anyway
1479 /* FIXME: we should put this back into order, but I never found a program
1480 * actually using this feature, so we may not need it
1485 strcat(strcpy(buf
, resname
), ".mci");
1486 if (OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1487 FIXME("NIY: command table to be loaded from '%s'\n", ofs
.szPathName
);
1491 if ((hRsrc
= FindResourceW(hInst
, resNameW
, (LPWSTR
)RT_RCDATA
)) &&
1492 (hMem
= LoadResource(hInst
, hRsrc
))) {
1493 ret
= MCI_SetCommandTable(hMem
, type
);
1496 else WARN("No command table found in module for %s\n", debugstr_w(resNameW
));
1498 TRACE("=> %04x\n", ret
);
1502 /**************************************************************************
1503 * mciFreeCommandResource [WINMM.@]
1505 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1507 TRACE("(%08x)!\n", uTable
);
1509 if (uTable
>= MAX_MCICMDTABLE
|| !S_MciCmdTable
[uTable
].lpTable
)
1512 FreeResource(S_MciCmdTable
[uTable
].hMem
);
1513 S_MciCmdTable
[uTable
].hMem
= NULL
;
1514 S_MciCmdTable
[uTable
].lpTable
= NULL
;
1515 HeapFree(GetProcessHeap(), 0, S_MciCmdTable
[uTable
].aVerbs
);
1516 S_MciCmdTable
[uTable
].aVerbs
= 0;
1517 S_MciCmdTable
[uTable
].nVerbs
= 0;
1521 /**************************************************************************
1522 * MCI_Open [internal]
1524 static DWORD
MCI_Open(DWORD dwParam
, LPMCI_OPEN_PARMSW lpParms
)
1526 WCHAR strDevTyp
[128];
1528 LPWINE_MCIDRIVER wmd
= NULL
;
1530 TRACE("(%08X, %p)\n", dwParam
, lpParms
);
1531 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1533 /* only two low bytes are generic, the other ones are dev type specific */
1534 #define WINE_MCIDRIVER_SUPP (0xFFFF0000|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT| \
1535 MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID| \
1536 MCI_NOTIFY|MCI_WAIT)
1537 if ((dwParam
& ~WINE_MCIDRIVER_SUPP
) != 0) {
1538 FIXME("Unsupported yet dwFlags=%08lX\n", dwParam
& ~WINE_MCIDRIVER_SUPP
);
1540 #undef WINE_MCIDRIVER_SUPP
1544 if (dwParam
& MCI_OPEN_TYPE
) {
1545 if (dwParam
& MCI_OPEN_TYPE_ID
) {
1546 WORD uDevType
= LOWORD(lpParms
->lpstrDeviceType
);
1548 if (uDevType
< MCI_DEVTYPE_FIRST
||
1549 uDevType
> MCI_DEVTYPE_LAST
||
1550 !LoadStringW(hWinMM32Instance
, uDevType
,
1551 strDevTyp
, sizeof(strDevTyp
) / sizeof(WCHAR
))) {
1552 dwRet
= MCIERR_BAD_INTEGER
;
1557 if (lpParms
->lpstrDeviceType
== NULL
) {
1558 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1561 strcpyW(strDevTyp
, lpParms
->lpstrDeviceType
);
1562 ptr
= strchrW(strDevTyp
, '!');
1564 /* this behavior is not documented in windows. However, since, in
1565 * some occasions, MCI_OPEN handling is translated by WinMM into
1566 * a call to mciSendString("open <type>"); this code shall be correct
1568 if (dwParam
& MCI_OPEN_ELEMENT
) {
1569 ERR("Both MCI_OPEN_ELEMENT(%s) and %s are used\n",
1570 debugstr_w(lpParms
->lpstrElementName
),
1571 debugstr_w(strDevTyp
));
1572 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1575 dwParam
|= MCI_OPEN_ELEMENT
;
1577 /* FIXME: not a good idea to write in user supplied buffer */
1578 lpParms
->lpstrElementName
= ptr
;
1582 TRACE("devType=%s !\n", debugstr_w(strDevTyp
));
1585 if (dwParam
& MCI_OPEN_ELEMENT
) {
1586 TRACE("lpstrElementName=%s\n", debugstr_w(lpParms
->lpstrElementName
));
1588 if (dwParam
& MCI_OPEN_ELEMENT_ID
) {
1589 FIXME("Unsupported yet flag MCI_OPEN_ELEMENT_ID\n");
1590 dwRet
= MCIERR_UNRECOGNIZED_KEYWORD
;
1594 if (!lpParms
->lpstrElementName
) {
1595 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1599 /* type, if given as a parameter, supersedes file extension */
1600 if (!strDevTyp
[0] &&
1601 MCI_GetDevTypeFromFileName(lpParms
->lpstrElementName
,
1602 strDevTyp
, sizeof(strDevTyp
))) {
1603 static const WCHAR wszCdAudio
[] = {'C','D','A','U','D','I','O',0};
1604 if (GetDriveTypeW(lpParms
->lpstrElementName
) != DRIVE_CDROM
) {
1605 dwRet
= MCIERR_EXTENSION_NOT_FOUND
;
1608 /* FIXME: this will not work if several CDROM drives are installed on the machine */
1609 strcpyW(strDevTyp
, wszCdAudio
);
1613 if (strDevTyp
[0] == 0) {
1614 FIXME("Couldn't load driver\n");
1615 dwRet
= MCIERR_INVALID_DEVICE_NAME
;
1619 if (dwParam
& MCI_OPEN_ALIAS
) {
1620 TRACE("Alias=%s !\n", debugstr_w(lpParms
->lpstrAlias
));
1621 if (!lpParms
->lpstrAlias
) {
1622 dwRet
= MCIERR_NULL_PARAMETER_BLOCK
;
1627 if ((dwRet
= MCI_LoadMciDriver(strDevTyp
, &wmd
))) {
1631 if ((dwRet
= MCI_FinishOpen(wmd
, lpParms
, dwParam
))) {
1632 TRACE("Failed to open driver (MCI_OPEN_DRIVER) [%08x], closing\n", dwRet
);
1633 /* FIXME: is dwRet the correct ret code ? */
1637 /* only handled devices fall through */
1638 TRACE("wDevID=%04X wDeviceID=%d dwRet=%d\n", wmd
->wDeviceID
, lpParms
->wDeviceID
, dwRet
);
1640 if (dwParam
& MCI_NOTIFY
)
1641 mciDriverNotify((HWND
)lpParms
->dwCallback
, wmd
->wDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1645 if (wmd
) MCI_UnLoadMciDriver(wmd
);
1647 if (dwParam
& MCI_NOTIFY
)
1648 mciDriverNotify((HWND
)lpParms
->dwCallback
, 0, MCI_NOTIFY_FAILURE
);
1652 /**************************************************************************
1653 * MCI_Close [internal]
1655 static DWORD
MCI_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
1658 LPWINE_MCIDRIVER wmd
;
1660 TRACE("(%04x, %08X, %p)\n", wDevID
, dwParam
, lpParms
);
1662 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1663 /* FIXME: shall I notify once after all is done, or for
1664 * each of the open drivers ? if the latest, which notif
1665 * to return when only one fails ?
1667 while (MciDrivers
) {
1668 /* Retrieve the device ID under lock, but send the message without,
1669 * the driver might be calling some winmm functions from another
1670 * thread before being fully stopped.
1672 EnterCriticalSection(&WINMM_cs
);
1675 LeaveCriticalSection(&WINMM_cs
);
1678 wDevID
= MciDrivers
->wDeviceID
;
1679 LeaveCriticalSection(&WINMM_cs
);
1680 MCI_Close(wDevID
, dwParam
, lpParms
);
1685 if (!(wmd
= MCI_GetDriver(wDevID
))) {
1686 return MCIERR_INVALID_DEVICE_ID
;
1689 dwRet
= MCI_SendCommandFrom32(wDevID
, MCI_CLOSE_DRIVER
, dwParam
, (DWORD_PTR
)lpParms
);
1691 MCI_UnLoadMciDriver(wmd
);
1693 if (dwParam
& MCI_NOTIFY
)
1694 mciDriverNotify(lpParms
? (HWND
)lpParms
->dwCallback
: 0,
1696 dwRet
? MCI_NOTIFY_FAILURE
: MCI_NOTIFY_SUCCESSFUL
);
1701 /**************************************************************************
1702 * MCI_WriteString [internal]
1704 static DWORD
MCI_WriteString(LPWSTR lpDstStr
, DWORD dstSize
, LPCWSTR lpSrcStr
)
1709 dstSize
/= sizeof(WCHAR
);
1710 if (dstSize
<= strlenW(lpSrcStr
)) {
1711 lstrcpynW(lpDstStr
, lpSrcStr
, dstSize
- 1);
1712 ret
= MCIERR_PARAM_OVERFLOW
;
1714 strcpyW(lpDstStr
, lpSrcStr
);
1722 /**************************************************************************
1723 * MCI_Sysinfo [internal]
1725 static DWORD
MCI_SysInfo(UINT uDevID
, DWORD dwFlags
, LPMCI_SYSINFO_PARMSW lpParms
)
1727 DWORD ret
= MCIERR_INVALID_DEVICE_ID
, cnt
= 0;
1728 WCHAR buf
[2048], *s
= buf
, *p
;
1729 LPWINE_MCIDRIVER wmd
;
1732 if (lpParms
== NULL
|| lpParms
->lpstrReturn
== NULL
)
1733 return MCIERR_NULL_PARAMETER_BLOCK
;
1735 TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
1736 uDevID
, dwFlags
, lpParms
, lpParms
->dwNumber
, lpParms
->wDeviceType
);
1738 switch (dwFlags
& ~MCI_SYSINFO_OPEN
) {
1739 case MCI_SYSINFO_QUANTITY
:
1740 if (lpParms
->wDeviceType
< MCI_DEVTYPE_FIRST
|| lpParms
->wDeviceType
> MCI_DEVTYPE_LAST
) {
1741 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1742 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
1743 EnterCriticalSection(&WINMM_cs
);
1744 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1747 LeaveCriticalSection(&WINMM_cs
);
1749 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers\n");
1750 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
,
1751 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1752 RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
1753 RegCloseKey( hKey
);
1755 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
))
1756 for (s
= buf
; *s
; s
+= strlenW(s
) + 1) cnt
++;
1759 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1760 TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms
->wDeviceType
);
1761 EnterCriticalSection(&WINMM_cs
);
1762 for (wmd
= MciDrivers
; wmd
; wmd
= wmd
->lpNext
) {
1763 if (wmd
->wType
== lpParms
->wDeviceType
) cnt
++;
1765 LeaveCriticalSection(&WINMM_cs
);
1767 TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms
->wDeviceType
);
1768 FIXME("Don't know how to get # of MCI devices of a given type\n");
1772 *(DWORD
*)lpParms
->lpstrReturn
= cnt
;
1773 TRACE("(%d) => '%d'\n", lpParms
->dwNumber
, *(DWORD
*)lpParms
->lpstrReturn
);
1774 ret
= MCI_INTEGER_RETURNED
;
1776 case MCI_SYSINFO_INSTALLNAME
:
1777 TRACE("MCI_SYSINFO_INSTALLNAME\n");
1778 if ((wmd
= MCI_GetDriver(uDevID
))) {
1779 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
,
1780 wmd
->lpstrDeviceType
);
1782 *lpParms
->lpstrReturn
= 0;
1783 ret
= MCIERR_INVALID_DEVICE_ID
;
1785 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1787 case MCI_SYSINFO_NAME
:
1788 TRACE("MCI_SYSINFO_NAME\n");
1789 if (dwFlags
& MCI_SYSINFO_OPEN
) {
1790 FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n");
1791 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1794 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, wszHklmMci
, 0,
1795 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
) {
1796 if (RegQueryInfoKeyW( hKey
, 0, 0, 0, &cnt
,
1797 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
&&
1798 lpParms
->dwNumber
<= cnt
) {
1799 DWORD bufLen
= sizeof(buf
)/sizeof(buf
[0]);
1800 if (RegEnumKeyExW(hKey
, lpParms
->dwNumber
- 1,
1801 buf
, &bufLen
, 0, 0, 0, 0) == ERROR_SUCCESS
)
1804 RegCloseKey( hKey
);
1807 if (GetPrivateProfileStringW(wszMci
, 0, wszNull
, buf
, sizeof(buf
) / sizeof(buf
[0]), wszSystemIni
)) {
1808 for (p
= buf
; *p
; p
+= strlenW(p
) + 1, cnt
++) {
1809 TRACE("%d: %s\n", cnt
, debugstr_w(p
));
1810 if (cnt
== lpParms
->dwNumber
- 1) {
1817 ret
= s
? MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
/ sizeof(WCHAR
), s
) : MCIERR_OUTOFRANGE
;
1819 TRACE("(%d) => %s\n", lpParms
->dwNumber
, debugstr_w(lpParms
->lpstrReturn
));
1822 TRACE("Unsupported flag value=%08x\n", dwFlags
);
1823 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
1828 /**************************************************************************
1829 * MCI_Break [internal]
1831 static DWORD
MCI_Break(UINT wDevID
, DWORD dwFlags
, LPMCI_BREAK_PARMS lpParms
)
1835 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1837 if (dwFlags
& MCI_NOTIFY
)
1838 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1839 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1844 /**************************************************************************
1845 * MCI_Sound [internal]
1847 static DWORD
MCI_Sound(UINT wDevID
, DWORD dwFlags
, LPMCI_SOUND_PARMSW lpParms
)
1851 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1853 if (dwFlags
& MCI_SOUND_NAME
)
1854 dwRet
= sndPlaySoundW(lpParms
->lpstrSoundName
, SND_SYNC
) ? MMSYSERR_NOERROR
: MMSYSERR_ERROR
;
1856 dwRet
= MMSYSERR_ERROR
; /* what should be done ??? */
1857 if (dwFlags
& MCI_NOTIFY
)
1858 mciDriverNotify((HWND
)lpParms
->dwCallback
, wDevID
,
1859 (dwRet
== 0) ? MCI_NOTIFY_SUCCESSFUL
: MCI_NOTIFY_FAILURE
);
1864 /**************************************************************************
1865 * MCI_SendCommand [internal]
1867 DWORD
MCI_SendCommand(UINT wDevID
, UINT16 wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1869 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1873 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
1876 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1879 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSW
)dwParam2
);
1882 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1885 dwRet
= MCI_Sound(wDevID
, dwParam1
, (LPMCI_SOUND_PARMSW
)dwParam2
);
1888 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1889 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1890 dwRet
= MCIERR_CANNOT_USE_ALL
;
1892 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
1899 /**************************************************************************
1900 * MCI_CleanUp [internal]
1902 * Some MCI commands need to be cleaned-up (when not called from
1903 * mciSendString), because MCI drivers return extra information for string
1904 * transformation. This function gets rid of them.
1906 static LRESULT
MCI_CleanUp(LRESULT dwRet
, UINT wMsg
, DWORD_PTR dwParam2
)
1909 return LOWORD(dwRet
);
1912 case MCI_GETDEVCAPS
:
1913 switch (dwRet
& 0xFFFF0000ul
) {
1915 case MCI_COLONIZED3_RETURN
:
1916 case MCI_COLONIZED4_RETURN
:
1917 case MCI_INTEGER_RETURNED
:
1920 case MCI_RESOURCE_RETURNED
:
1921 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1923 LPMCI_GETDEVCAPS_PARMS lmgp
;
1925 lmgp
= (LPMCI_GETDEVCAPS_PARMS
)dwParam2
;
1926 TRACE("Changing %08x to %08x\n", lmgp
->dwReturn
, LOWORD(lmgp
->dwReturn
));
1927 lmgp
->dwReturn
= LOWORD(lmgp
->dwReturn
);
1931 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1932 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1936 switch (dwRet
& 0xFFFF0000ul
) {
1938 case MCI_COLONIZED3_RETURN
:
1939 case MCI_COLONIZED4_RETURN
:
1940 case MCI_INTEGER_RETURNED
:
1943 case MCI_RESOURCE_RETURNED
:
1944 case MCI_RESOURCE_RETURNED
|MCI_RESOURCE_DRIVER
:
1946 LPMCI_STATUS_PARMS lsp
;
1948 lsp
= (LPMCI_STATUS_PARMS
)dwParam2
;
1949 TRACE("Changing %08lx to %08x\n", lsp
->dwReturn
, LOWORD(lsp
->dwReturn
));
1950 lsp
->dwReturn
= LOWORD(lsp
->dwReturn
);
1954 FIXME("Unsupported value for hiword (%04x) returned by DriverProc(%s)\n",
1955 HIWORD(dwRet
), MCI_MessageToString(wMsg
));
1959 switch (dwRet
& 0xFFFF0000ul
) {
1961 case MCI_INTEGER_RETURNED
:
1965 FIXME("Unsupported value for hiword (%04x)\n", HIWORD(dwRet
));
1969 if (HIWORD(dwRet
)) {
1970 FIXME("Got non null hiword for dwRet=0x%08lx for command %s\n",
1971 dwRet
, MCI_MessageToString(wMsg
));
1975 return LOWORD(dwRet
);
1978 /**************************************************************************
1979 * mciGetErrorStringW [WINMM.@]
1981 BOOL WINAPI
mciGetErrorStringW(MCIERROR wError
, LPWSTR lpstrBuffer
, UINT uLength
)
1985 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
1986 wError
>= MCIERR_BASE
&& wError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
1988 if (LoadStringW(hWinMM32Instance
, wError
, lpstrBuffer
, uLength
) > 0) {
1995 /**************************************************************************
1996 * mciGetErrorStringA [WINMM.@]
1998 BOOL WINAPI
mciGetErrorStringA(MCIERROR dwError
, LPSTR lpstrBuffer
, UINT uLength
)
2002 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
2003 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
2005 if (LoadStringA(hWinMM32Instance
, dwError
, lpstrBuffer
, uLength
) > 0) {
2012 /**************************************************************************
2013 * mciDriverNotify [WINMM.@]
2015 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, MCIDEVICEID wDevID
, UINT wStatus
)
2017 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
2019 return PostMessageW(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
2022 /**************************************************************************
2023 * mciGetDriverData [WINMM.@]
2025 DWORD_PTR WINAPI
mciGetDriverData(MCIDEVICEID uDeviceID
)
2027 LPWINE_MCIDRIVER wmd
;
2029 TRACE("(%04x)\n", uDeviceID
);
2031 wmd
= MCI_GetDriver(uDeviceID
);
2034 WARN("Bad uDeviceID\n");
2038 return wmd
->dwPrivate
;
2041 /**************************************************************************
2042 * mciSetDriverData [WINMM.@]
2044 BOOL WINAPI
mciSetDriverData(MCIDEVICEID uDeviceID
, DWORD_PTR data
)
2046 LPWINE_MCIDRIVER wmd
;
2048 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
2050 wmd
= MCI_GetDriver(uDeviceID
);
2053 WARN("Bad uDeviceID\n");
2057 wmd
->dwPrivate
= data
;
2061 /**************************************************************************
2062 * mciSendCommandW [WINMM.@]
2065 DWORD WINAPI
mciSendCommandW(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2069 TRACE("(%08x, %s, %08lx, %08lx)\n",
2070 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2072 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
);
2073 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
2074 TRACE("=> %08x\n", dwRet
);
2078 /**************************************************************************
2079 * mciSendCommandA [WINMM.@]
2081 DWORD WINAPI
mciSendCommandA(MCIDEVICEID wDevID
, UINT wMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2086 TRACE("(%08x, %s, %08lx, %08lx)\n",
2087 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
2089 mapped
= MCI_MapMsgAtoW(wMsg
, dwParam1
, &dwParam2
);
2092 FIXME("message %04x mapping failed\n", wMsg
);
2093 return MMSYSERR_NOMEM
;
2095 ret
= mciSendCommandW(wDevID
, wMsg
, dwParam1
, dwParam2
);
2097 MCI_UnmapMsgAtoW(wMsg
, dwParam1
, dwParam2
, ret
);
2101 /**************************************************************************
2102 * mciGetDeviceIDA [WINMM.@]
2104 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
2106 LPWSTR w
= MCI_strdupAtoW(lpstrName
);
2107 UINT ret
= MCIERR_OUT_OF_MEMORY
;
2111 ret
= mciGetDeviceIDW(w
);
2112 HeapFree(GetProcessHeap(), 0, w
);
2117 /**************************************************************************
2118 * mciGetDeviceIDW [WINMM.@]
2120 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2122 return MCI_GetDriverFromString(lpwstrName
);
2125 /******************************************************************
2128 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
2130 static void MyUserYield(void)
2132 HMODULE mod
= GetModuleHandleA( "user32.dll" );
2135 FARPROC proc
= GetProcAddress( mod
, "UserYield16" );
2140 /**************************************************************************
2141 * MCI_DefYieldProc [internal]
2143 static UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
2147 TRACE("(0x%04x, 0x%08x)\n", wDevID
, data
);
2149 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
2150 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2156 msg
.hwnd
= HWND_32(HIWORD(data
));
2157 while (!PeekMessageW(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2163 /**************************************************************************
2164 * mciSetYieldProc [WINMM.@]
2166 BOOL WINAPI
mciSetYieldProc(MCIDEVICEID uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2168 LPWINE_MCIDRIVER wmd
;
2170 TRACE("(%u, %p, %08x)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2172 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2173 WARN("Bad uDeviceID\n");
2177 wmd
->lpfnYieldProc
= fpYieldProc
;
2178 wmd
->dwYieldData
= dwYieldData
;
2183 /**************************************************************************
2184 * mciGetDeviceIDFromElementIDA [WINMM.@]
2186 UINT WINAPI
mciGetDeviceIDFromElementIDA(DWORD dwElementID
, LPCSTR lpstrType
)
2188 LPWSTR w
= MCI_strdupAtoW(lpstrType
);
2193 ret
= mciGetDeviceIDFromElementIDW(dwElementID
, w
);
2194 HeapFree(GetProcessHeap(), 0, w
);
2199 /**************************************************************************
2200 * mciGetDeviceIDFromElementIDW [WINMM.@]
2202 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2204 /* FIXME: that's rather strange, there is no
2205 * mciGetDeviceIDFromElementID32A in winmm.spec
2207 FIXME("(%u, %s) stub\n", dwElementID
, debugstr_w(lpstrType
));
2211 /**************************************************************************
2212 * mciGetYieldProc [WINMM.@]
2214 YIELDPROC WINAPI
mciGetYieldProc(MCIDEVICEID uDeviceID
, DWORD
* lpdwYieldData
)
2216 LPWINE_MCIDRIVER wmd
;
2218 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2220 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2221 WARN("Bad uDeviceID\n");
2224 if (!wmd
->lpfnYieldProc
) {
2225 WARN("No proc set\n");
2228 if (lpdwYieldData
) *lpdwYieldData
= wmd
->dwYieldData
;
2229 return wmd
->lpfnYieldProc
;
2232 /**************************************************************************
2233 * mciGetCreatorTask [WINMM.@]
2235 HTASK WINAPI
mciGetCreatorTask(MCIDEVICEID uDeviceID
)
2237 LPWINE_MCIDRIVER wmd
;
2240 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)wmd
->CreatorThread
;
2242 TRACE("(%u) => %p\n", uDeviceID
, ret
);
2246 /**************************************************************************
2247 * mciDriverYield [WINMM.@]
2249 UINT WINAPI
mciDriverYield(MCIDEVICEID uDeviceID
)
2251 LPWINE_MCIDRIVER wmd
;
2254 TRACE("(%04x)\n", uDeviceID
);
2256 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
) {
2259 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);