winmm: Improve MCI's Sysinfo command.

This commit is contained in:
Jörg Höhle 2009-11-17 22:07:55 +01:00 committed by Alexandre Julliard
parent e89468734d
commit f70b2f5493
2 changed files with 48 additions and 13 deletions

View File

@ -1733,10 +1733,16 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParm
TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n", TRACE("(%08x, %08X, %p[num=%d, wDevTyp=%u])\n",
uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType); uDevID, dwFlags, lpParms, lpParms->dwNumber, lpParms->wDeviceType);
if ((WORD)MCI_ALL_DEVICE_ID == LOWORD(uDevID))
uDevID = MCI_ALL_DEVICE_ID; /* Be compatible with Win9x */
switch (dwFlags & ~MCI_SYSINFO_OPEN) { switch (dwFlags & ~(MCI_SYSINFO_OPEN|MCI_NOTIFY|MCI_WAIT)) {
case MCI_SYSINFO_QUANTITY: case MCI_SYSINFO_QUANTITY:
if (lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST) { if (lpParms->dwRetSize < sizeof(DWORD))
return MCIERR_PARAM_OVERFLOW;
/* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
if (uDevID == MCI_ALL_DEVICE_ID) {
/* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
if (dwFlags & MCI_SYSINFO_OPEN) { if (dwFlags & MCI_SYSINFO_OPEN) {
TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n"); TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers\n");
EnterCriticalSection(&WINMM_cs); EnterCriticalSection(&WINMM_cs);
@ -1756,14 +1762,14 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParm
} }
} else { } else {
if (dwFlags & MCI_SYSINFO_OPEN) { if (dwFlags & MCI_SYSINFO_OPEN) {
TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %u\n", lpParms->wDeviceType); TRACE("MCI_SYSINFO_QUANTITY: # of open MCI drivers of type %d\n", lpParms->wDeviceType);
EnterCriticalSection(&WINMM_cs); EnterCriticalSection(&WINMM_cs);
for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) { for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
if (wmd->wType == lpParms->wDeviceType) cnt++; if (wmd->wType == lpParms->wDeviceType) cnt++;
} }
LeaveCriticalSection(&WINMM_cs); LeaveCriticalSection(&WINMM_cs);
} else { } else {
TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %u\n", lpParms->wDeviceType); TRACE("MCI_SYSINFO_QUANTITY: # of installed MCI drivers of type %d\n", lpParms->wDeviceType);
FIXME("Don't know how to get # of MCI devices of a given type\n"); FIXME("Don't know how to get # of MCI devices of a given type\n");
cnt = 1; cnt = 1;
} }
@ -1771,6 +1777,7 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParm
*(DWORD*)lpParms->lpstrReturn = cnt; *(DWORD*)lpParms->lpstrReturn = cnt;
TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn); TRACE("(%d) => '%d'\n", lpParms->dwNumber, *(DWORD*)lpParms->lpstrReturn);
ret = MCI_INTEGER_RETURNED; ret = MCI_INTEGER_RETURNED;
/* return ret; Only Win9x sends a notification in this case. */
break; break;
case MCI_SYSINFO_INSTALLNAME: case MCI_SYSINFO_INSTALLNAME:
TRACE("MCI_SYSINFO_INSTALLNAME\n"); TRACE("MCI_SYSINFO_INSTALLNAME\n");
@ -1784,12 +1791,27 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParm
TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn)); TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
break; break;
case MCI_SYSINFO_NAME: case MCI_SYSINFO_NAME:
TRACE("MCI_SYSINFO_NAME\n"); s = NULL;
if (dwFlags & MCI_SYSINFO_OPEN) { if (dwFlags & MCI_SYSINFO_OPEN) {
FIXME("Don't handle MCI_SYSINFO_NAME|MCI_SYSINFO_OPEN (yet)\n"); /* Win9x returns 0 for 0 < uDevID < (UINT16)MCI_ALL_DEVICE_ID */
ret = MCIERR_UNRECOGNIZED_COMMAND; TRACE("MCI_SYSINFO_NAME: nth alias of type %d\n",
} else { uDevID == MCI_ALL_DEVICE_ID ? MCI_ALL_DEVICE_ID : lpParms->wDeviceType);
s = NULL; EnterCriticalSection(&WINMM_cs);
for (wmd = MciDrivers; wmd; wmd = wmd->lpNext) {
/* wDeviceType == MCI_ALL_DEVICE_ID is not recognized. */
if (uDevID == MCI_ALL_DEVICE_ID ||
lpParms->wDeviceType == wmd->wType) {
cnt++;
if (cnt == lpParms->dwNumber) {
s = wmd->lpstrAlias;
break;
}
}
}
LeaveCriticalSection(&WINMM_cs);
ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
} else if (MCI_ALL_DEVICE_ID == uDevID) {
TRACE("MCI_SYSINFO_NAME: device #%d\n", lpParms->dwNumber);
if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0, if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, wszHklmMci, 0,
KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) { KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS) {
if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, if (RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt,
@ -1814,13 +1836,26 @@ static DWORD MCI_SysInfo(UINT uDevID, DWORD dwFlags, LPMCI_SYSINFO_PARMSW lpParm
} }
} }
ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE; ret = s ? MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR), s) : MCIERR_OUTOFRANGE;
} else {
FIXME("MCI_SYSINFO_NAME: nth device of type %d\n", lpParms->wDeviceType);
/* Cheating: what is asked for is the nth device from the registry. */
if (1 != lpParms->dwNumber || /* Handle only one of each kind. */
lpParms->wDeviceType < MCI_DEVTYPE_FIRST || lpParms->wDeviceType > MCI_DEVTYPE_LAST)
ret = MCIERR_OUTOFRANGE;
else {
LoadStringW(hWinMM32Instance, LOWORD(lpParms->wDeviceType),
lpParms->lpstrReturn, lpParms->dwRetSize / sizeof(WCHAR));
ret = 0;
}
} }
TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn)); TRACE("(%d) => %s\n", lpParms->dwNumber, debugstr_w(lpParms->lpstrReturn));
break; break;
default: default:
TRACE("Unsupported flag value=%08x\n", dwFlags); TRACE("Unsupported flag value=%08x\n", dwFlags);
ret = MCIERR_UNRECOGNIZED_COMMAND; ret = MCIERR_UNRECOGNIZED_KEYWORD;
} }
if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
mciDriverNotify((HWND)lpParms->dwCallback, uDevID, MCI_NOTIFY_SUCCESSFUL);
return ret; return ret;
} }

View File

@ -230,7 +230,7 @@ static void test_openCloseWAVE(HWND hwnd)
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
err = mciSendString(command_sysinfo, buf, sizeof(buf), NULL); err = mciSendString(command_sysinfo, buf, sizeof(buf), NULL);
ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err)); ok(!err,"mci %s returned %s\n", command_sysinfo, dbg_mcierr(err));
todo_wine ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf); ok(buf[0] == '0' && buf[1] == 0, "mci %s, expected output buffer '0', got: '%s'\n", command_sysinfo, buf);
err = mciSendString("open new type waveaudio", buf, sizeof(buf), NULL); err = mciSendString("open new type waveaudio", buf, sizeof(buf), NULL);
ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err)); ok(err==MCIERR_NEW_REQUIRES_ALIAS,"mci open new without alias returned %s\n", dbg_mcierr(err));
@ -724,7 +724,7 @@ static void test_AutoOpenWAVE(HWND hwnd)
err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL); err = mciSendString("sysinfo waveaudio quantity open", buf, sizeof(buf), NULL);
ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err)); ok(!err,"mci sysinfo waveaudio quantity open returned %s\n", dbg_mcierr(err));
if(!err) todo_wine ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf); if(!err) ok(!strcmp(buf,"0"), "sysinfo quantity open expected 0, got: %s, some more tests will fail.\n", buf);
/* Who knows why some machines pass all tests but return MCIERR_HARDWARE here? */ /* Who knows why some machines pass all tests but return MCIERR_HARDWARE here? */
err = mciSendString("sound NoSuchSoundDefined wait", NULL, 0, NULL); err = mciSendString("sound NoSuchSoundDefined wait", NULL, 0, NULL);
@ -736,7 +736,7 @@ static void test_AutoOpenWAVE(HWND hwnd)
buf[0]=0; buf[0]=0;
err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL); err = mciSendString("sysinfo waveaudio name 1 open", buf, sizeof(buf), NULL);
todo_wine ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err)); ok(err==MCIERR_OUTOFRANGE,"sysinfo waveaudio name 1 returned %s\n", dbg_mcierr(err));
if(!err) trace("sysinfo dangling open alias: %s\n", buf); if(!err) trace("sysinfo dangling open alias: %s\n", buf);
err = mciSendString("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL); err = mciSendString("play no-such-file-exists.wav notify", buf, sizeof(buf), NULL);