1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1993 Martin Ayotte
7 * 1998-2003 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * 99/4 added mmTask and mmThread functions support
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
41 #include "wine/winuser16.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
48 static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16);
49 static LPWINE_DRIVER DRIVER_OpenDriver16(LPCWSTR, LPCWSTR, LPARAM);
50 static LRESULT DRIVER_CloseDriver16(HDRVR16, LPARAM, LPARAM);
51 static LRESULT DRIVER_SendMessage16(HDRVR16, UINT, LPARAM, LPARAM);
52 static LRESULT MMIO_Callback16(SEGPTR, LPMMIOINFO, UINT, LPARAM, LPARAM);
54 /* ###################################################
56 * ###################################################
59 /**************************************************************************
60 * DllEntryPoint (MMSYSTEM.4)
62 * MMSYSTEM DLL entry point
65 BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
66 WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
68 TRACE("%p 0x%x\n", hinstDLL, fdwReason);
71 case DLL_PROCESS_ATTACH:
72 /* need to load WinMM in order to:
73 * - initiate correctly shared variables (WINMM_Init())
75 if (!GetModuleHandleA("WINMM.DLL"))
77 ERR("Could not load sibling WinMM.dll\n");
80 /* hook in our 16 bit function pointers */
81 pFnGetMMThread16 = WINMM_GetmmThread;
82 pFnOpenDriver16 = DRIVER_OpenDriver16;
83 pFnCloseDriver16 = DRIVER_CloseDriver16;
84 pFnSendMessage16 = DRIVER_SendMessage16;
85 pFnMmioCallback16 = MMIO_Callback16;
86 pFnReleaseThunkLock = ReleaseThunkLock;
87 pFnRestoreThunkLock = RestoreThunkLock;
90 case DLL_PROCESS_DETACH:
91 pFnGetMMThread16 = NULL;
92 pFnOpenDriver16 = NULL;
93 pFnCloseDriver16 = NULL;
94 pFnSendMessage16 = NULL;
95 pFnMmioCallback16 = NULL;
96 pFnReleaseThunkLock = NULL;
97 pFnRestoreThunkLock = NULL;
98 /* FIXME: add equivalent for MMDRV_Init16() */
100 case DLL_THREAD_ATTACH:
101 case DLL_THREAD_DETACH:
107 /**************************************************************************
110 int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
111 WORD cbHeapSize, LPSTR lpCmdLine)
113 TRACE("STUB: Unloading MMSystem DLL ... hInst=%04X\n", hInstance);
117 /* ###################################################
119 * ###################################################
122 /**************************************************************************
123 * PlaySound [MMSYSTEM.3]
125 BOOL16 WINAPI PlaySound16(LPCSTR pszSound, HMODULE16 hmod, DWORD fdwSound)
130 if ((fdwSound & SND_RESOURCE) == SND_RESOURCE)
135 if (!(res = FindResource16( hmod, pszSound, "WAVE" ))) return FALSE;
136 if (!(handle = LoadResource16( hmod, res ))) return FALSE;
137 pszSound = LockResource16(handle);
138 fdwSound = (fdwSound & ~SND_RESOURCE) | SND_MEMORY;
139 /* FIXME: FreeResource16 */
142 ReleaseThunkLock(&lc);
143 retv = PlaySoundA(pszSound, 0, fdwSound);
144 RestoreThunkLock(lc);
149 /**************************************************************************
150 * sndPlaySound [MMSYSTEM.2]
152 BOOL16 WINAPI sndPlaySound16(LPCSTR lpszSoundName, UINT16 uFlags)
157 ReleaseThunkLock(&lc);
158 retv = sndPlaySoundA(lpszSoundName, uFlags);
159 RestoreThunkLock(lc);
164 /* ###################################################
166 * ###################################################
169 /**************************************************************************
170 * mmsystemGetVersion [MMSYSTEM.5]
173 UINT16 WINAPI mmsystemGetVersion16(void)
175 return mmsystemGetVersion();
178 /**************************************************************************
179 * DriverCallback [MMSYSTEM.31]
181 BOOL16 WINAPI DriverCallback16(DWORD dwCallBack, UINT16 uFlags, HDRVR16 hDev,
182 WORD wMsg, DWORD dwUser, DWORD dwParam1,
185 return DriverCallback(dwCallBack, uFlags, HDRVR_32(hDev), wMsg, dwUser, dwParam1, dwParam2);
188 /**************************************************************************
189 * OutputDebugStr [MMSYSTEM.30]
191 void WINAPI OutputDebugStr16(LPCSTR str)
193 OutputDebugStringA( str );
197 /* ###################################################
199 * ###################################################
202 /**************************************************************************
203 * Mixer devices. New to Win95
206 /**************************************************************************
207 * mixerGetNumDevs [MMSYSTEM.800]
209 UINT16 WINAPI mixerGetNumDevs16(void)
211 return MMDRV_GetNum(MMDRV_MIXER);
214 /**************************************************************************
215 * mixerGetDevCaps [MMSYSTEM.801]
217 UINT16 WINAPI mixerGetDevCaps16(UINT16 uDeviceID, LPMIXERCAPS16 lpCaps,
223 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
225 ret = mixerGetDevCapsA(uDeviceID, &micA, sizeof(micA));
226 if (ret == MMSYSERR_NOERROR) {
228 mic16.wMid = micA.wMid;
229 mic16.wPid = micA.wPid;
230 mic16.vDriverVersion = micA.vDriverVersion;
231 strcpy(mic16.szPname, micA.szPname);
232 mic16.fdwSupport = micA.fdwSupport;
233 mic16.cDestinations = micA.cDestinations;
234 memcpy(lpCaps, &mic16, min(uSize, sizeof(mic16)));
239 /**************************************************************************
240 * mixerOpen [MMSYSTEM.802]
242 UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix, UINT16 uDeviceID, DWORD dwCallback,
243 DWORD dwInstance, DWORD fdwOpen)
248 ret = MIXER_Open(&hmix, uDeviceID, dwCallback, dwInstance, fdwOpen, FALSE);
249 if (lphmix) *lphmix = HMIXER_16(hmix);
253 /**************************************************************************
254 * mixerClose [MMSYSTEM.803]
256 UINT16 WINAPI mixerClose16(HMIXER16 hMix)
258 return mixerClose(HMIXER_32(hMix));
261 /**************************************************************************
262 * mixerGetID (MMSYSTEM.806)
264 UINT16 WINAPI mixerGetID16(HMIXEROBJ16 hmix, LPUINT16 lpid, DWORD fdwID)
267 UINT ret = mixerGetID(HMIXEROBJ_32(hmix), &xid, fdwID);
274 /**************************************************************************
275 * mixerGetControlDetails [MMSYSTEM.808]
277 UINT16 WINAPI mixerGetControlDetails16(HMIXEROBJ16 hmix,
278 LPMIXERCONTROLDETAILS16 lpmcd,
281 DWORD ret = MMSYSERR_NOTENABLED;
284 TRACE("(%04x, %p, %08x)\n", hmix, lpmcd, fdwDetails);
286 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
287 return MMSYSERR_INVALPARAM;
289 sppaDetails = (SEGPTR)lpmcd->paDetails;
290 lpmcd->paDetails = MapSL(sppaDetails);
291 ret = mixerGetControlDetailsA(HMIXEROBJ_32(hmix),
292 (LPMIXERCONTROLDETAILS)lpmcd, fdwDetails);
293 lpmcd->paDetails = (LPVOID)sppaDetails;
298 /**************************************************************************
299 * mixerGetLineControls [MMSYSTEM.807]
301 UINT16 WINAPI mixerGetLineControls16(HMIXEROBJ16 hmix,
302 LPMIXERLINECONTROLS16 lpmlc16,
305 MIXERLINECONTROLSA mlcA;
308 LPMIXERCONTROL16 lpmc16;
310 TRACE("(%04x, %p, %08x)\n", hmix, lpmlc16, fdwControls);
312 if (lpmlc16 == NULL || lpmlc16->cbStruct != sizeof(*lpmlc16) ||
313 lpmlc16->cbmxctrl != sizeof(MIXERCONTROL16))
314 return MMSYSERR_INVALPARAM;
316 mlcA.cbStruct = sizeof(mlcA);
317 mlcA.dwLineID = lpmlc16->dwLineID;
318 mlcA.u.dwControlID = lpmlc16->u.dwControlID;
319 mlcA.u.dwControlType = lpmlc16->u.dwControlType;
320 mlcA.cControls = lpmlc16->cControls;
321 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
322 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
323 mlcA.cControls * mlcA.cbmxctrl);
325 ret = mixerGetLineControlsA(HMIXEROBJ_32(hmix), &mlcA, fdwControls);
327 if (ret == MMSYSERR_NOERROR) {
328 lpmlc16->dwLineID = mlcA.dwLineID;
329 lpmlc16->u.dwControlID = mlcA.u.dwControlID;
330 lpmlc16->u.dwControlType = mlcA.u.dwControlType;
331 lpmlc16->cControls = mlcA.cControls;
333 lpmc16 = MapSL(lpmlc16->pamxctrl);
335 for (i = 0; i < mlcA.cControls; i++) {
336 lpmc16[i].cbStruct = sizeof(MIXERCONTROL16);
337 lpmc16[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
338 lpmc16[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
339 lpmc16[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
340 lpmc16[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
341 strcpy(lpmc16[i].szShortName, mlcA.pamxctrl[i].szShortName);
342 strcpy(lpmc16[i].szName, mlcA.pamxctrl[i].szName);
343 /* sizeof(lpmc16[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
344 memcpy(&lpmc16[i].Bounds, &mlcA.pamxctrl[i].Bounds,
345 sizeof(mlcA.pamxctrl[i].Bounds));
346 /* sizeof(lpmc16[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
347 memcpy(&lpmc16[i].Metrics, &mlcA.pamxctrl[i].Metrics,
348 sizeof(mlcA.pamxctrl[i].Metrics));
352 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
357 /**************************************************************************
358 * mixerGetLineInfo [MMSYSTEM.805]
360 UINT16 WINAPI mixerGetLineInfo16(HMIXEROBJ16 hmix, LPMIXERLINE16 lpmli16,
366 TRACE("(%04x, %p, %08x)\n", hmix, lpmli16, fdwInfo);
368 if (lpmli16 == NULL || lpmli16->cbStruct != sizeof(*lpmli16))
369 return MMSYSERR_INVALPARAM;
371 mliA.cbStruct = sizeof(mliA);
372 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
373 case MIXER_GETLINEINFOF_COMPONENTTYPE:
374 mliA.dwComponentType = lpmli16->dwComponentType;
376 case MIXER_GETLINEINFOF_DESTINATION:
377 mliA.dwDestination = lpmli16->dwDestination;
379 case MIXER_GETLINEINFOF_LINEID:
380 mliA.dwLineID = lpmli16->dwLineID;
382 case MIXER_GETLINEINFOF_SOURCE:
383 mliA.dwDestination = lpmli16->dwDestination;
384 mliA.dwSource = lpmli16->dwSource;
386 case MIXER_GETLINEINFOF_TARGETTYPE:
387 mliA.Target.dwType = lpmli16->Target.dwType;
388 mliA.Target.wMid = lpmli16->Target.wMid;
389 mliA.Target.wPid = lpmli16->Target.wPid;
390 mliA.Target.vDriverVersion = lpmli16->Target.vDriverVersion;
391 strcpy(mliA.Target.szPname, lpmli16->Target.szPname);
394 FIXME("Unsupported fdwControls=0x%08x\n", fdwInfo);
397 ret = mixerGetLineInfoA(HMIXEROBJ_32(hmix), &mliA, fdwInfo);
399 lpmli16->dwDestination = mliA.dwDestination;
400 lpmli16->dwSource = mliA.dwSource;
401 lpmli16->dwLineID = mliA.dwLineID;
402 lpmli16->fdwLine = mliA.fdwLine;
403 lpmli16->dwUser = mliA.dwUser;
404 lpmli16->dwComponentType = mliA.dwComponentType;
405 lpmli16->cChannels = mliA.cChannels;
406 lpmli16->cConnections = mliA.cConnections;
407 lpmli16->cControls = mliA.cControls;
408 strcpy(lpmli16->szShortName, mliA.szShortName);
409 strcpy(lpmli16->szName, mliA.szName);
410 lpmli16->Target.dwType = mliA.Target.dwType;
411 lpmli16->Target.dwDeviceID = mliA.Target.dwDeviceID;
412 lpmli16->Target.wMid = mliA.Target.wMid;
413 lpmli16->Target.wPid = mliA.Target.wPid;
414 lpmli16->Target.vDriverVersion = mliA.Target.vDriverVersion;
415 strcpy(lpmli16->Target.szPname, mliA.Target.szPname);
420 /**************************************************************************
421 * mixerSetControlDetails [MMSYSTEM.809]
423 UINT16 WINAPI mixerSetControlDetails16(HMIXEROBJ16 hmix,
424 LPMIXERCONTROLDETAILS16 lpmcd,
427 TRACE("(%04x, %p, %08x)\n", hmix, lpmcd, fdwDetails);
428 return MMSYSERR_NOTENABLED;
431 /**************************************************************************
432 * mixerMessage [MMSYSTEM.804]
434 DWORD WINAPI mixerMessage16(HMIXER16 hmix, UINT16 uMsg, DWORD dwParam1,
437 return mixerMessage(HMIXER_32(hmix), uMsg, dwParam1, dwParam2);
440 /**************************************************************************
441 * auxGetNumDevs [MMSYSTEM.350]
443 UINT16 WINAPI auxGetNumDevs16(void)
445 return MMDRV_GetNum(MMDRV_AUX);
448 /* ###################################################
450 * ###################################################
453 /**************************************************************************
454 * auxGetDevCaps [MMSYSTEM.351]
456 UINT16 WINAPI auxGetDevCaps16(UINT16 uDeviceID, LPAUXCAPS16 lpCaps, UINT16 uSize)
461 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
463 ret = auxGetDevCapsA(uDeviceID, &acA, sizeof(acA));
464 if (ret == MMSYSERR_NOERROR) {
466 ac16.wMid = acA.wMid;
467 ac16.wPid = acA.wPid;
468 ac16.vDriverVersion = acA.vDriverVersion;
469 strcpy(ac16.szPname, acA.szPname);
470 ac16.wTechnology = acA.wTechnology;
471 ac16.dwSupport = acA.dwSupport;
472 memcpy(lpCaps, &ac16, min(uSize, sizeof(ac16)));
477 /**************************************************************************
478 * auxGetVolume [MMSYSTEM.352]
480 UINT16 WINAPI auxGetVolume16(UINT16 uDeviceID, LPDWORD lpdwVolume)
484 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
486 if ((wmld = MMDRV_Get((HANDLE)(ULONG_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
487 return MMSYSERR_INVALHANDLE;
488 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
491 /**************************************************************************
492 * auxSetVolume [MMSYSTEM.353]
494 UINT16 WINAPI auxSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
498 TRACE("(%04X, %u) !\n", uDeviceID, dwVolume);
500 if ((wmld = MMDRV_Get((HANDLE)(ULONG_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
501 return MMSYSERR_INVALHANDLE;
502 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
505 /**************************************************************************
506 * auxOutMessage [MMSYSTEM.354]
508 DWORD WINAPI auxOutMessage16(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
512 TRACE("(%04X, %04X, %08X, %08X)\n", uDeviceID, uMessage, dw1, dw2);
515 case AUXDM_GETNUMDEVS:
516 case AUXDM_SETVOLUME:
517 /* no argument conversion needed */
519 case AUXDM_GETVOLUME:
520 return auxGetVolume16(uDeviceID, MapSL(dw1));
521 case AUXDM_GETDEVCAPS:
522 return auxGetDevCaps16(uDeviceID, MapSL(dw1), dw2);
524 TRACE("(%04x, %04x, %08x, %08x): unhandled message\n",
525 uDeviceID, uMessage, dw1, dw2);
528 if ((wmld = MMDRV_Get((HANDLE)(ULONG_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
529 return MMSYSERR_INVALHANDLE;
531 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
534 /* ###################################################
536 * ###################################################
539 /**************************************************************************
540 * mciGetErrorString [MMSYSTEM.706]
542 BOOL16 WINAPI mciGetErrorString16(DWORD wError, LPSTR lpstrBuffer, UINT16 uLength)
544 return mciGetErrorStringA(wError, lpstrBuffer, uLength);
547 /**************************************************************************
548 * mciDriverNotify [MMSYSTEM.711]
550 BOOL16 WINAPI mciDriverNotify16(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
552 TRACE("(%04X, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
554 return PostMessageA(HWND_32(hWndCallBack), MM_MCINOTIFY, wStatus, wDevID);
557 /**************************************************************************
558 * mciGetDriverData [MMSYSTEM.708]
560 DWORD WINAPI mciGetDriverData16(UINT16 uDeviceID)
562 return mciGetDriverData(uDeviceID);
565 /**************************************************************************
566 * mciSetDriverData [MMSYSTEM.707]
568 BOOL16 WINAPI mciSetDriverData16(UINT16 uDeviceID, DWORD data)
570 return mciSetDriverData(uDeviceID, data);
573 /**************************************************************************
574 * mciSendCommand [MMSYSTEM.701]
576 DWORD WINAPI mciSendCommand16(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
580 TRACE("(%04X, %s, %08X, %08X)\n",
581 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
583 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, FALSE);
584 dwRet = MCI_CleanUp(dwRet, wMsg, (DWORD)MapSL(dwParam2));
585 TRACE("=> %d\n", dwRet);
589 /**************************************************************************
590 * mciGetDeviceID [MMSYSTEM.703]
592 UINT16 WINAPI mciGetDeviceID16(LPCSTR lpstrName)
594 TRACE("(\"%s\")\n", lpstrName);
596 return mciGetDeviceIDA(lpstrName);
599 /**************************************************************************
600 * mciSetYieldProc [MMSYSTEM.714]
602 BOOL16 WINAPI mciSetYieldProc16(UINT16 uDeviceID, YIELDPROC16 fpYieldProc, DWORD dwYieldData)
604 LPWINE_MCIDRIVER wmd;
606 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
608 if (!(wmd = MCI_GetDriver(uDeviceID))) {
609 WARN("Bad uDeviceID\n");
613 wmd->lpfnYieldProc = (YIELDPROC)fpYieldProc;
614 wmd->dwYieldData = dwYieldData;
620 /**************************************************************************
621 * mciGetDeviceIDFromElementID [MMSYSTEM.715]
623 UINT16 WINAPI mciGetDeviceIDFromElementID16(DWORD dwElementID, LPCSTR lpstrType)
625 FIXME("(%u, %s) stub\n", dwElementID, lpstrType);
629 /**************************************************************************
630 * mciGetYieldProc [MMSYSTEM.716]
632 YIELDPROC16 WINAPI mciGetYieldProc16(UINT16 uDeviceID, DWORD* lpdwYieldData)
634 LPWINE_MCIDRIVER wmd;
636 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
638 if (!(wmd = MCI_GetDriver(uDeviceID))) {
639 WARN("Bad uDeviceID\n");
642 if (!wmd->lpfnYieldProc) {
643 WARN("No proc set\n");
647 WARN("Proc is 32 bit\n");
650 if (lpdwYieldData) *lpdwYieldData = wmd->dwYieldData;
651 return (YIELDPROC16)wmd->lpfnYieldProc;
654 /**************************************************************************
655 * mciGetCreatorTask [MMSYSTEM.717]
657 HTASK16 WINAPI mciGetCreatorTask16(UINT16 uDeviceID)
659 LPWINE_MCIDRIVER wmd;
662 if ((wmd = MCI_GetDriver(uDeviceID)))
663 ret = HTASK_16(wmd->CreatorThread);
665 TRACE("(%u) => %04x\n", uDeviceID, ret);
669 /**************************************************************************
670 * mciDriverYield [MMSYSTEM.710]
672 UINT16 WINAPI mciDriverYield16(UINT16 uDeviceID)
674 LPWINE_MCIDRIVER wmd;
677 /* TRACE("(%04x)\n", uDeviceID); */
679 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || wmd->bIs32) {
682 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
688 /* ###################################################
690 * ###################################################
693 /**************************************************************************
694 * midiOutGetNumDevs [MMSYSTEM.201]
696 UINT16 WINAPI midiOutGetNumDevs16(void)
698 return MMDRV_GetNum(MMDRV_MIDIOUT);
701 /**************************************************************************
702 * midiOutGetDevCaps [MMSYSTEM.202]
704 UINT16 WINAPI midiOutGetDevCaps16(UINT16 uDeviceID, LPMIDIOUTCAPS16 lpCaps,
710 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
712 ret = midiOutGetDevCapsA(uDeviceID, &mocA, sizeof(mocA));
713 if (ret == MMSYSERR_NOERROR) {
715 moc16.wMid = mocA.wMid;
716 moc16.wPid = mocA.wPid;
717 moc16.vDriverVersion = mocA.vDriverVersion;
718 strcpy(moc16.szPname, mocA.szPname);
719 moc16.wTechnology = mocA.wTechnology;
720 moc16.wVoices = mocA.wVoices;
721 moc16.wNotes = mocA.wNotes;
722 moc16.wChannelMask = mocA.wChannelMask;
723 moc16.dwSupport = mocA.dwSupport;
724 memcpy(lpCaps, &moc16, min(uSize, sizeof(moc16)));
729 /**************************************************************************
730 * midiOutGetErrorText [MMSYSTEM.203]
731 * midiInGetErrorText [MMSYSTEM.303]
733 UINT16 WINAPI midiOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
735 return midiOutGetErrorTextA(uError, lpText, uSize);
738 /**************************************************************************
739 * midiOutOpen [MMSYSTEM.204]
741 UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID,
742 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
747 ret = MIDI_OutOpen(&hmo, uDeviceID, dwCallback, dwInstance, dwFlags, FALSE);
749 if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo);
753 /**************************************************************************
754 * midiOutClose [MMSYSTEM.205]
756 UINT16 WINAPI midiOutClose16(HMIDIOUT16 hMidiOut)
758 return midiOutClose(HMIDIOUT_32(hMidiOut));
761 /**************************************************************************
762 * midiOutPrepareHeader [MMSYSTEM.206]
764 UINT16 WINAPI midiOutPrepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
765 SEGPTR lpsegMidiOutHdr, /* [???] */
766 UINT16 uSize) /* [in] */
770 TRACE("(%04X, %08x, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
772 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
773 return MMSYSERR_INVALHANDLE;
775 return MMDRV_Message(wmld, MODM_PREPARE, lpsegMidiOutHdr, uSize, FALSE);
778 /**************************************************************************
779 * midiOutUnprepareHeader [MMSYSTEM.207]
781 UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
782 SEGPTR lpsegMidiOutHdr, /* [???] */
783 UINT16 uSize) /* [in] */
786 LPMIDIHDR16 lpMidiOutHdr = MapSL(lpsegMidiOutHdr);
788 TRACE("(%04X, %08x, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
790 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
791 return MMSYSERR_NOERROR;
794 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
795 return MMSYSERR_INVALHANDLE;
797 return MMDRV_Message(wmld, MODM_UNPREPARE, lpsegMidiOutHdr, uSize, FALSE);
800 /**************************************************************************
801 * midiOutShortMsg [MMSYSTEM.208]
803 UINT16 WINAPI midiOutShortMsg16(HMIDIOUT16 hMidiOut, DWORD dwMsg)
805 return midiOutShortMsg(HMIDIOUT_32(hMidiOut), dwMsg);
808 /**************************************************************************
809 * midiOutLongMsg [MMSYSTEM.209]
811 UINT16 WINAPI midiOutLongMsg16(HMIDIOUT16 hMidiOut, /* [in] */
812 LPMIDIHDR16 lpsegMidiOutHdr, /* [???] NOTE: SEGPTR */
813 UINT16 uSize) /* [in] */
817 TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
819 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
820 return MMSYSERR_INVALHANDLE;
822 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpsegMidiOutHdr, uSize, FALSE);
825 /**************************************************************************
826 * midiOutReset [MMSYSTEM.210]
828 UINT16 WINAPI midiOutReset16(HMIDIOUT16 hMidiOut)
830 return midiOutReset(HMIDIOUT_32(hMidiOut));
833 /**************************************************************************
834 * midiOutGetVolume [MMSYSTEM.211]
836 UINT16 WINAPI midiOutGetVolume16(UINT16 uDeviceID, DWORD* lpdwVolume)
838 return midiOutGetVolume(HMIDIOUT_32(uDeviceID), lpdwVolume);
841 /**************************************************************************
842 * midiOutSetVolume [MMSYSTEM.212]
844 UINT16 WINAPI midiOutSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
846 return midiOutSetVolume(HMIDIOUT_32(uDeviceID), dwVolume);
849 /**************************************************************************
850 * midiOutCachePatches [MMSYSTEM.213]
852 UINT16 WINAPI midiOutCachePatches16(HMIDIOUT16 hMidiOut, UINT16 uBank,
853 WORD* lpwPatchArray, UINT16 uFlags)
855 return midiOutCachePatches(HMIDIOUT_32(hMidiOut), uBank, lpwPatchArray,
859 /**************************************************************************
860 * midiOutCacheDrumPatches [MMSYSTEM.214]
862 UINT16 WINAPI midiOutCacheDrumPatches16(HMIDIOUT16 hMidiOut, UINT16 uPatch,
863 WORD* lpwKeyArray, UINT16 uFlags)
865 return midiOutCacheDrumPatches(HMIDIOUT_32(hMidiOut), uPatch, lpwKeyArray, uFlags);
868 /**************************************************************************
869 * midiOutGetID [MMSYSTEM.215]
871 UINT16 WINAPI midiOutGetID16(HMIDIOUT16 hMidiOut, UINT16* lpuDeviceID)
875 TRACE("(%04X, %p)\n", hMidiOut, lpuDeviceID);
877 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
878 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
879 return MMSYSERR_INVALHANDLE;
881 *lpuDeviceID = wmld->uDeviceID;
882 return MMSYSERR_NOERROR;
885 /**************************************************************************
886 * midiOutMessage [MMSYSTEM.216]
888 DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage,
889 DWORD dwParam1, DWORD dwParam2)
893 TRACE("(%04X, %04X, %08X, %08X)\n", hMidiOut, uMessage, dwParam1, dwParam2);
895 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
896 return MMSYSERR_INVALHANDLE;
901 FIXME("can't handle OPEN or CLOSE message!\n");
902 return MMSYSERR_NOTSUPPORTED;
905 return midiOutGetVolume16(hMidiOut, MapSL(dwParam1));
907 return midiOutLongMsg16(hMidiOut, MapSL(dwParam1), dwParam2);
909 /* lpMidiOutHdr is still a segmented pointer for this function */
910 return midiOutPrepareHeader16(hMidiOut, dwParam1, dwParam2);
912 return midiOutUnprepareHeader16(hMidiOut, dwParam1, dwParam2);
914 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
917 /**************************************************************************
918 * midiInGetNumDevs [MMSYSTEM.301]
920 UINT16 WINAPI midiInGetNumDevs16(void)
922 return MMDRV_GetNum(MMDRV_MIDIIN);
925 /**************************************************************************
926 * midiInGetDevCaps [MMSYSTEM.302]
928 UINT16 WINAPI midiInGetDevCaps16(UINT16 uDeviceID, LPMIDIINCAPS16 lpCaps,
934 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
936 ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
937 if (ret == MMSYSERR_NOERROR) {
939 mic16.wMid = micA.wMid;
940 mic16.wPid = micA.wPid;
941 mic16.vDriverVersion = micA.vDriverVersion;
942 strcpy(mic16.szPname, micA.szPname);
943 mic16.dwSupport = micA.dwSupport;
944 memcpy(lpCaps, &mic16, min(uSize, sizeof(mic16)));
949 /**************************************************************************
950 * midiInOpen [MMSYSTEM.304]
952 UINT16 WINAPI midiInOpen16(HMIDIIN16* lphMidiIn, UINT16 uDeviceID,
953 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
958 ret = MIDI_InOpen(&xhmid, uDeviceID, dwCallback, dwInstance, dwFlags, FALSE);
960 if (lphMidiIn) *lphMidiIn = HMIDIIN_16(xhmid);
964 /**************************************************************************
965 * midiInClose [MMSYSTEM.305]
967 UINT16 WINAPI midiInClose16(HMIDIIN16 hMidiIn)
969 return midiInClose(HMIDIIN_32(hMidiIn));
972 /**************************************************************************
973 * midiInPrepareHeader [MMSYSTEM.306]
975 UINT16 WINAPI midiInPrepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
976 SEGPTR lpsegMidiInHdr, /* [???] */
977 UINT16 uSize) /* [in] */
981 TRACE("(%04X, %08x, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
983 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
984 return MMSYSERR_INVALHANDLE;
986 return MMDRV_Message(wmld, MIDM_PREPARE, lpsegMidiInHdr, uSize, FALSE);
989 /**************************************************************************
990 * midiInUnprepareHeader [MMSYSTEM.307]
992 UINT16 WINAPI midiInUnprepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
993 SEGPTR lpsegMidiInHdr, /* [???] */
994 UINT16 uSize) /* [in] */
997 LPMIDIHDR16 lpMidiInHdr = MapSL(lpsegMidiInHdr);
999 TRACE("(%04X, %08x, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
1001 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1002 return MMSYSERR_NOERROR;
1005 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1006 return MMSYSERR_INVALHANDLE;
1008 return MMDRV_Message(wmld, MIDM_UNPREPARE, lpsegMidiInHdr, uSize, FALSE);
1011 /**************************************************************************
1012 * midiInAddBuffer [MMSYSTEM.308]
1014 UINT16 WINAPI midiInAddBuffer16(HMIDIIN16 hMidiIn, /* [in] */
1015 MIDIHDR16* lpsegMidiInHdr, /* [???] NOTE: SEGPTR */
1016 UINT16 uSize) /* [in] */
1020 TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
1022 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1023 return MMSYSERR_INVALHANDLE;
1025 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpsegMidiInHdr, uSize, FALSE);
1028 /**************************************************************************
1029 * midiInStart [MMSYSTEM.309]
1031 UINT16 WINAPI midiInStart16(HMIDIIN16 hMidiIn)
1033 return midiInStart(HMIDIIN_32(hMidiIn));
1036 /**************************************************************************
1037 * midiInStop [MMSYSTEM.310]
1039 UINT16 WINAPI midiInStop16(HMIDIIN16 hMidiIn)
1041 return midiInStop(HMIDIIN_32(hMidiIn));
1044 /**************************************************************************
1045 * midiInReset [MMSYSTEM.311]
1047 UINT16 WINAPI midiInReset16(HMIDIIN16 hMidiIn)
1049 return midiInReset(HMIDIIN_32(hMidiIn));
1052 /**************************************************************************
1053 * midiInGetID [MMSYSTEM.312]
1055 UINT16 WINAPI midiInGetID16(HMIDIIN16 hMidiIn, UINT16* lpuDeviceID)
1059 TRACE("(%04X, %p)\n", hMidiIn, lpuDeviceID);
1061 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1063 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, TRUE)) == NULL)
1064 return MMSYSERR_INVALHANDLE;
1066 *lpuDeviceID = wmld->uDeviceID;
1068 return MMSYSERR_NOERROR;
1071 /**************************************************************************
1072 * midiInMessage [MMSYSTEM.313]
1074 DWORD WINAPI midiInMessage16(HMIDIIN16 hMidiIn, UINT16 uMessage,
1075 DWORD dwParam1, DWORD dwParam2)
1079 TRACE("(%04X, %04X, %08X, %08X)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1084 FIXME("can't handle OPEN or CLOSE message!\n");
1085 return MMSYSERR_NOTSUPPORTED;
1087 case MIDM_GETDEVCAPS:
1088 return midiInGetDevCaps16(hMidiIn, MapSL(dwParam1), dwParam2);
1090 return midiInPrepareHeader16(hMidiIn, dwParam1, dwParam2);
1091 case MIDM_UNPREPARE:
1092 return midiInUnprepareHeader16(hMidiIn, dwParam1, dwParam2);
1093 case MIDM_ADDBUFFER:
1094 return midiInAddBuffer16(hMidiIn, MapSL(dwParam1), dwParam2);
1097 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1098 return MMSYSERR_INVALHANDLE;
1100 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1103 /**************************************************************************
1104 * midiStreamClose [MMSYSTEM.252]
1106 MMRESULT16 WINAPI midiStreamClose16(HMIDISTRM16 hMidiStrm)
1108 return midiStreamClose(HMIDISTRM_32(hMidiStrm));
1111 /**************************************************************************
1112 * midiStreamOpen [MMSYSTEM.251]
1114 MMRESULT16 WINAPI midiStreamOpen16(HMIDISTRM16* phMidiStrm, LPUINT16 devid,
1115 DWORD cMidi, DWORD dwCallback,
1116 DWORD dwInstance, DWORD fdwOpen)
1118 HMIDISTRM hMidiStrm32;
1122 if (!phMidiStrm || !devid)
1123 return MMSYSERR_INVALPARAM;
1125 ret = MIDI_StreamOpen(&hMidiStrm32, &devid32, cMidi, dwCallback,
1126 dwInstance, fdwOpen, FALSE);
1127 *phMidiStrm = HMIDISTRM_16(hMidiStrm32);
1132 /**************************************************************************
1133 * midiStreamOut [MMSYSTEM.254]
1135 MMRESULT16 WINAPI midiStreamOut16(HMIDISTRM16 hMidiStrm, LPMIDIHDR16 lpMidiHdr, UINT16 cbMidiHdr)
1137 return midiStreamOut(HMIDISTRM_32(hMidiStrm), (LPMIDIHDR)lpMidiHdr,
1141 /**************************************************************************
1142 * midiStreamPause [MMSYSTEM.255]
1144 MMRESULT16 WINAPI midiStreamPause16(HMIDISTRM16 hMidiStrm)
1146 return midiStreamPause(HMIDISTRM_32(hMidiStrm));
1149 /**************************************************************************
1150 * midiStreamPosition [MMSYSTEM.253]
1152 MMRESULT16 WINAPI midiStreamPosition16(HMIDISTRM16 hMidiStrm, LPMMTIME16 lpmmt16, UINT16 cbmmt)
1158 return MMSYSERR_INVALPARAM;
1159 MMSYSTEM_MMTIME16to32(&mmt32, lpmmt16);
1160 ret = midiStreamPosition(HMIDISTRM_32(hMidiStrm), &mmt32, sizeof(MMTIME));
1161 MMSYSTEM_MMTIME32to16(lpmmt16, &mmt32);
1165 /**************************************************************************
1166 * midiStreamProperty [MMSYSTEM.250]
1168 MMRESULT16 WINAPI midiStreamProperty16(HMIDISTRM16 hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1170 return midiStreamProperty(HMIDISTRM_32(hMidiStrm), lpPropData, dwProperty);
1173 /**************************************************************************
1174 * midiStreamRestart [MMSYSTEM.256]
1176 MMRESULT16 WINAPI midiStreamRestart16(HMIDISTRM16 hMidiStrm)
1178 return midiStreamRestart(HMIDISTRM_32(hMidiStrm));
1181 /**************************************************************************
1182 * midiStreamStop [MMSYSTEM.257]
1184 MMRESULT16 WINAPI midiStreamStop16(HMIDISTRM16 hMidiStrm)
1186 return midiStreamStop(HMIDISTRM_32(hMidiStrm));
1189 /* ###################################################
1191 * ###################################################
1194 /**************************************************************************
1195 * waveOutGetNumDevs [MMSYSTEM.401]
1197 UINT16 WINAPI waveOutGetNumDevs16(void)
1199 return MMDRV_GetNum(MMDRV_WAVEOUT);
1202 /**************************************************************************
1203 * waveOutGetDevCaps [MMSYSTEM.402]
1205 UINT16 WINAPI waveOutGetDevCaps16(UINT16 uDeviceID,
1206 LPWAVEOUTCAPS16 lpCaps, UINT16 uSize)
1210 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
1212 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1214 ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
1215 if (ret == MMSYSERR_NOERROR) {
1216 WAVEOUTCAPS16 woc16;
1217 woc16.wMid = wocA.wMid;
1218 woc16.wPid = wocA.wPid;
1219 woc16.vDriverVersion = wocA.vDriverVersion;
1220 strcpy(woc16.szPname, wocA.szPname);
1221 woc16.dwFormats = wocA.dwFormats;
1222 woc16.wChannels = wocA.wChannels;
1223 woc16.dwSupport = wocA.dwSupport;
1224 memcpy(lpCaps, &woc16, min(uSize, sizeof(woc16)));
1229 /**************************************************************************
1230 * waveOutGetErrorText [MMSYSTEM.403]
1231 * waveInGetErrorText [MMSYSTEM.503]
1233 UINT16 WINAPI waveOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
1235 return waveOutGetErrorTextA(uError, lpText, uSize);
1238 /**************************************************************************
1239 * waveOutOpen [MMSYSTEM.404]
1241 UINT16 WINAPI waveOutOpen16(HWAVEOUT16* lphWaveOut, UINT16 uDeviceID,
1242 LPCWAVEFORMATEX lpFormat, DWORD dwCallback,
1243 DWORD dwInstance, DWORD dwFlags)
1248 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1249 * call the 32 bit version
1250 * however, we need to promote correctly the wave mapper id
1251 * (0xFFFFFFFF and not 0x0000FFFF)
1253 ret = WAVE_Open(&hWaveOut, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1254 MMDRV_WAVEOUT, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1256 if (lphWaveOut != NULL) *lphWaveOut = HWAVEOUT_16(hWaveOut);
1260 /**************************************************************************
1261 * waveOutClose [MMSYSTEM.405]
1263 UINT16 WINAPI waveOutClose16(HWAVEOUT16 hWaveOut)
1268 ReleaseThunkLock(&level);
1269 ret = waveOutClose(HWAVEOUT_32(hWaveOut));
1270 RestoreThunkLock(level);
1274 /**************************************************************************
1275 * waveOutPrepareHeader [MMSYSTEM.406]
1277 UINT16 WINAPI waveOutPrepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1278 SEGPTR lpsegWaveOutHdr, /* [???] */
1279 UINT16 uSize) /* [in] */
1282 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1285 TRACE("(%04X, %08x, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1287 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
1289 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1290 return MMSYSERR_INVALHANDLE;
1292 if ((result = MMDRV_Message(wmld, WODM_PREPARE, lpsegWaveOutHdr,
1293 uSize, FALSE)) != MMSYSERR_NOTSUPPORTED)
1296 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
1297 return WAVERR_STILLPLAYING;
1299 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
1300 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
1302 return MMSYSERR_NOERROR;
1305 /**************************************************************************
1306 * waveOutUnprepareHeader [MMSYSTEM.407]
1308 UINT16 WINAPI waveOutUnprepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1309 SEGPTR lpsegWaveOutHdr, /* [???] */
1310 UINT16 uSize) /* [in] */
1313 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1315 TRACE("(%04X, %08x, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1317 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
1318 return MMSYSERR_NOERROR;
1321 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1322 return MMSYSERR_INVALHANDLE;
1324 return MMDRV_Message(wmld, WODM_UNPREPARE, lpsegWaveOutHdr, uSize, FALSE);
1327 /**************************************************************************
1328 * waveOutWrite [MMSYSTEM.408]
1330 UINT16 WINAPI waveOutWrite16(HWAVEOUT16 hWaveOut, /* [in] */
1331 LPWAVEHDR lpsegWaveOutHdr, /* [???] NOTE: SEGPTR */
1332 UINT16 uSize) /* [in] */
1336 TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1338 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1339 return MMSYSERR_INVALHANDLE;
1341 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpsegWaveOutHdr, uSize, FALSE);
1344 /**************************************************************************
1345 * waveOutBreakLoop [MMSYSTEM.419]
1347 UINT16 WINAPI waveOutBreakLoop16(HWAVEOUT16 hWaveOut16)
1352 ReleaseThunkLock(&level);
1353 ret = waveOutBreakLoop(HWAVEOUT_32(hWaveOut16));
1354 RestoreThunkLock(level);
1358 /**************************************************************************
1359 * waveOutPause [MMSYSTEM.409]
1361 UINT16 WINAPI waveOutPause16(HWAVEOUT16 hWaveOut16)
1366 ReleaseThunkLock(&level);
1367 ret = waveOutPause(HWAVEOUT_32(hWaveOut16));
1368 RestoreThunkLock(level);
1372 /**************************************************************************
1373 * waveOutReset [MMSYSTEM.411]
1375 UINT16 WINAPI waveOutReset16(HWAVEOUT16 hWaveOut16)
1380 ReleaseThunkLock(&level);
1381 ret = waveOutReset(HWAVEOUT_32(hWaveOut16));
1382 RestoreThunkLock(level);
1386 /**************************************************************************
1387 * waveOutRestart [MMSYSTEM.410]
1389 UINT16 WINAPI waveOutRestart16(HWAVEOUT16 hWaveOut16)
1394 ReleaseThunkLock(&level);
1395 ret = waveOutRestart(HWAVEOUT_32(hWaveOut16));
1396 RestoreThunkLock(level);
1400 /**************************************************************************
1401 * waveOutGetPosition [MMSYSTEM.412]
1403 UINT16 WINAPI waveOutGetPosition16(HWAVEOUT16 hWaveOut, LPMMTIME16 lpTime,
1409 mmt.wType = lpTime->wType;
1410 ret = waveOutGetPosition(HWAVEOUT_32(hWaveOut), &mmt, sizeof(mmt));
1411 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1415 /**************************************************************************
1416 * waveOutGetPitch [MMSYSTEM.413]
1418 UINT16 WINAPI waveOutGetPitch16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1420 return waveOutGetPitch(HWAVEOUT_32(hWaveOut16), lpdw);
1423 /**************************************************************************
1424 * waveOutSetPitch [MMSYSTEM.414]
1426 UINT16 WINAPI waveOutSetPitch16(HWAVEOUT16 hWaveOut16, DWORD dw)
1428 return waveOutSetPitch(HWAVEOUT_32(hWaveOut16), dw);
1431 /**************************************************************************
1432 * waveOutGetPlaybackRate [MMSYSTEM.417]
1434 UINT16 WINAPI waveOutGetPlaybackRate16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1436 return waveOutGetPlaybackRate(HWAVEOUT_32(hWaveOut16), lpdw);
1439 /**************************************************************************
1440 * waveOutSetPlaybackRate [MMSYSTEM.418]
1442 UINT16 WINAPI waveOutSetPlaybackRate16(HWAVEOUT16 hWaveOut16, DWORD dw)
1444 return waveOutSetPlaybackRate(HWAVEOUT_32(hWaveOut16), dw);
1447 /**************************************************************************
1448 * waveOutGetVolume [MMSYSTEM.415]
1450 UINT16 WINAPI waveOutGetVolume16(UINT16 devid, LPDWORD lpdw)
1452 return waveOutGetVolume(HWAVEOUT_32(devid), lpdw);
1455 /**************************************************************************
1456 * waveOutSetVolume [MMSYSTEM.416]
1458 UINT16 WINAPI waveOutSetVolume16(UINT16 devid, DWORD dw)
1460 return waveOutSetVolume(HWAVEOUT_32(devid), dw);
1463 /**************************************************************************
1464 * waveOutGetID [MMSYSTEM.420]
1466 UINT16 WINAPI waveOutGetID16(HWAVEOUT16 hWaveOut, UINT16* lpuDeviceID)
1470 TRACE("(%04X, %p);\n", hWaveOut, lpuDeviceID);
1472 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1474 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1475 return MMSYSERR_INVALHANDLE;
1477 *lpuDeviceID = wmld->uDeviceID;
1481 /**************************************************************************
1482 * waveOutMessage [MMSYSTEM.421]
1484 DWORD WINAPI waveOutMessage16(HWAVEOUT16 hWaveOut, UINT16 uMessage,
1485 DWORD dwParam1, DWORD dwParam2)
1489 TRACE("(%04x, %u, %d, %d)\n", hWaveOut, uMessage, dwParam1, dwParam2);
1491 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL) {
1492 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, TRUE)) != NULL) {
1493 if (uMessage == DRV_QUERYDRVENTRY || uMessage == DRV_QUERYDEVNODE)
1494 dwParam1 = (DWORD)MapSL(dwParam1);
1495 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1497 return MMSYSERR_INVALHANDLE;
1501 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1502 return MMSYSERR_INVALPARAM;
1504 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1507 /**************************************************************************
1508 * waveInGetNumDevs [MMSYSTEM.501]
1510 UINT16 WINAPI waveInGetNumDevs16(void)
1512 return MMDRV_GetNum(MMDRV_WAVEIN);
1515 /**************************************************************************
1516 * waveInGetDevCaps [MMSYSTEM.502]
1518 UINT16 WINAPI waveInGetDevCaps16(UINT16 uDeviceID, LPWAVEINCAPS16 lpCaps,
1524 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1526 ret = waveInGetDevCapsA(uDeviceID, &wicA, sizeof(wicA));
1527 if (ret == MMSYSERR_NOERROR) {
1529 wic16.wMid = wicA.wMid;
1530 wic16.wPid = wicA.wPid;
1531 wic16.vDriverVersion = wicA.vDriverVersion;
1532 strcpy(wic16.szPname, wicA.szPname);
1533 wic16.dwFormats = wicA.dwFormats;
1534 wic16.wChannels = wicA.wChannels;
1535 memcpy(lpCaps, &wic16, min(uSize, sizeof(wic16)));
1540 /**************************************************************************
1541 * waveInOpen [MMSYSTEM.504]
1543 UINT16 WINAPI waveInOpen16(HWAVEIN16* lphWaveIn, UINT16 uDeviceID,
1544 LPCWAVEFORMATEX lpFormat, DWORD dwCallback,
1545 DWORD dwInstance, DWORD dwFlags)
1550 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1551 * call the 32 bit version
1552 * however, we need to promote correctly the wave mapper id
1553 * (0xFFFFFFFF and not 0x0000FFFF)
1555 ret = WAVE_Open(&hWaveIn, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1556 MMDRV_WAVEIN, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1558 if (lphWaveIn != NULL) *lphWaveIn = HWAVEIN_16(hWaveIn);
1562 /**************************************************************************
1563 * waveInClose [MMSYSTEM.505]
1565 UINT16 WINAPI waveInClose16(HWAVEIN16 hWaveIn)
1570 ReleaseThunkLock(&level);
1571 ret = waveInClose(HWAVEIN_32(hWaveIn));
1572 RestoreThunkLock(level);
1576 /**************************************************************************
1577 * waveInPrepareHeader [MMSYSTEM.506]
1579 UINT16 WINAPI waveInPrepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1580 SEGPTR lpsegWaveInHdr, /* [???] */
1581 UINT16 uSize) /* [in] */
1584 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1587 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
1589 if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
1590 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1591 return MMSYSERR_INVALHANDLE;
1593 lpWaveInHdr->dwBytesRecorded = 0;
1595 ret = MMDRV_Message(wmld, WIDM_PREPARE, lpsegWaveInHdr, uSize, FALSE);
1599 /**************************************************************************
1600 * waveInUnprepareHeader [MMSYSTEM.507]
1602 UINT16 WINAPI waveInUnprepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1603 SEGPTR lpsegWaveInHdr, /* [???] */
1604 UINT16 uSize) /* [in] */
1607 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1609 TRACE("(%04X, %08x, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1611 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1613 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
1614 return MMSYSERR_NOERROR;
1617 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1618 return MMSYSERR_INVALHANDLE;
1620 return MMDRV_Message(wmld, WIDM_UNPREPARE, lpsegWaveInHdr, uSize, FALSE);
1623 /**************************************************************************
1624 * waveInAddBuffer [MMSYSTEM.508]
1626 UINT16 WINAPI waveInAddBuffer16(HWAVEIN16 hWaveIn, /* [in] */
1627 WAVEHDR* lpsegWaveInHdr, /* [???] NOTE: SEGPTR */
1628 UINT16 uSize) /* [in] */
1632 TRACE("(%04X, %p, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1634 if (lpsegWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1635 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1636 return MMSYSERR_INVALHANDLE;
1638 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpsegWaveInHdr, uSize, FALSE);
1641 /**************************************************************************
1642 * waveInReset [MMSYSTEM.511]
1644 UINT16 WINAPI waveInReset16(HWAVEIN16 hWaveIn16)
1649 ReleaseThunkLock(&level);
1650 ret = waveInReset(HWAVEIN_32(hWaveIn16));
1651 RestoreThunkLock(level);
1655 /**************************************************************************
1656 * waveInStart [MMSYSTEM.509]
1658 UINT16 WINAPI waveInStart16(HWAVEIN16 hWaveIn16)
1663 ReleaseThunkLock(&level);
1664 ret = waveInStart(HWAVEIN_32(hWaveIn16));
1665 RestoreThunkLock(level);
1669 /**************************************************************************
1670 * waveInStop [MMSYSTEM.510]
1672 UINT16 WINAPI waveInStop16(HWAVEIN16 hWaveIn16)
1677 ReleaseThunkLock(&level);
1678 ret = waveInStop(HWAVEIN_32(hWaveIn16));
1679 RestoreThunkLock(level);
1683 /**************************************************************************
1684 * waveInGetPosition [MMSYSTEM.512]
1686 UINT16 WINAPI waveInGetPosition16(HWAVEIN16 hWaveIn, LPMMTIME16 lpTime,
1692 mmt.wType = lpTime->wType;
1693 ret = waveInGetPosition(HWAVEIN_32(hWaveIn), &mmt, sizeof(mmt));
1694 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1698 /**************************************************************************
1699 * waveInGetID [MMSYSTEM.513]
1701 UINT16 WINAPI waveInGetID16(HWAVEIN16 hWaveIn, UINT16* lpuDeviceID)
1705 TRACE("(%04X, %p);\n", hWaveIn, lpuDeviceID);
1707 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1709 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1710 return MMSYSERR_INVALHANDLE;
1712 *lpuDeviceID = wmld->uDeviceID;
1713 return MMSYSERR_NOERROR;
1716 /**************************************************************************
1717 * waveInMessage [MMSYSTEM.514]
1719 DWORD WINAPI waveInMessage16(HWAVEIN16 hWaveIn, UINT16 uMessage,
1720 DWORD dwParam1, DWORD dwParam2)
1724 TRACE("(%04x, %u, %d, %d)\n", hWaveIn, uMessage, dwParam1, dwParam2);
1726 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL) {
1727 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, TRUE)) != NULL) {
1728 if (uMessage == DRV_QUERYDRVENTRY || uMessage == DRV_QUERYDEVNODE)
1729 dwParam1 = (DWORD)MapSL(dwParam1);
1730 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1732 return MMSYSERR_INVALHANDLE;
1736 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1737 return MMSYSERR_INVALPARAM;
1739 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1742 /* ###################################################
1744 * ###################################################
1747 /*#define USE_MM_TSK_WINE*/
1749 /**************************************************************************
1750 * mmTaskCreate [MMSYSTEM.900]
1752 * Creates a 16 bit MM task. It's entry point is lpFunc, and it should be
1753 * called upon creation with dwPmt as parameter.
1755 HINSTANCE16 WINAPI mmTaskCreate16(SEGPTR spProc, HINSTANCE16 *lphMmTask, DWORD dwPmt)
1760 DWORD showCmd = 0x40002;
1763 TRACE("(%08x, %p, %08x);\n", spProc, lphMmTask, dwPmt);
1764 /* This to work requires NE modules to be started with a binary command line
1765 * which is not currently the case. A patch exists but has never been committed.
1766 * A workaround would be to integrate code for mmtask.tsk into Wine, but
1767 * this requires tremendous work (starting with patching tools/build to
1768 * create NE executables (and not only DLLs) for builtins modules.
1771 FIXME("This is currently broken. It will fail\n");
1774 *(LPDWORD)(cmdline + 1) = (DWORD)spProc;
1775 *(LPDWORD)(cmdline + 5) = dwPmt;
1776 *(LPDWORD)(cmdline + 9) = 0;
1778 lp.hEnvironment = 0;
1779 lp.cmdLine = MapLS(cmdline);
1780 lp.showCmd = MapLS(&showCmd);
1783 #ifndef USE_MM_TSK_WINE
1784 handle = LoadModule16("c:\\windows\\system\\mmtask.tsk", &lp);
1786 handle = LoadModule16("mmtask.tsk", &lp);
1789 ret = (handle) ? 1 : 2;
1795 *lphMmTask = handle;
1797 UnMapLS( lp.cmdLine );
1798 UnMapLS( lp.showCmd );
1799 TRACE("=> 0x%04x/%d\n", handle, ret);
1803 #ifdef USE_MM_TSK_WINE
1804 /* C equivalent to mmtask.tsk binary content */
1805 void mmTaskEntryPoint16(LPSTR cmdLine, WORD di, WORD si)
1807 int len = cmdLine[0x80];
1810 void (*fpProc)(DWORD) = MapSL(*((DWORD*)(cmdLine + 1)));
1811 DWORD dwPmt = *((DWORD*)(cmdLine + 5));
1814 InitTask16(); /* FIXME: pmts / from context ? */
1817 if (SetMessageQueue16(0x40)) {
1819 if (HIWORD(fpProc)) {
1821 /* EPP StackEnter16(); */
1833 /**************************************************************************
1834 * mmTaskBlock [MMSYSTEM.902]
1836 void WINAPI mmTaskBlock16(HINSTANCE16 hInst)
1841 GetMessageA(&msg, 0, 0, 0);
1843 TranslateMessage(&msg);
1844 DispatchMessageA(&msg);
1846 } while (msg.message < 0x3A0);
1849 /**************************************************************************
1850 * mmTaskSignal [MMSYSTEM.903]
1852 LRESULT WINAPI mmTaskSignal16(HTASK16 ht)
1854 TRACE("(%04x);\n", ht);
1855 return PostThreadMessageW( HTASK_32(ht), WM_USER, 0, 0 );
1858 /**************************************************************************
1859 * mmGetCurrentTask [MMSYSTEM.904]
1861 HTASK16 WINAPI mmGetCurrentTask16(void)
1863 return GetCurrentTask();
1866 /**************************************************************************
1867 * mmTaskYield [MMSYSTEM.905]
1869 void WINAPI mmTaskYield16(void)
1873 if (PeekMessageA(&msg, 0, 0, 0, 0)) {
1878 extern DWORD WINAPI GetProcessFlags(DWORD);
1880 /******************************************************************
1885 static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16 h)
1887 return MapSL(MAKESEGPTR(h, 0));
1890 DWORD WINAPI WINE_mmThreadEntryPoint(LPVOID);
1892 /**************************************************************************
1893 * mmThreadCreate [MMSYSTEM.1120]
1896 * Creates a MM thread, calling fpThreadAddr(dwPmt).
1898 * bit.0 set means create a 16 bit task instead of thread calling a 16 bit proc
1899 * bit.1 set means to open a VxD for this thread (unsupported)
1901 LRESULT WINAPI mmThreadCreate16(FARPROC16 fpThreadAddr, LPHANDLE16 lpHndl, DWORD dwPmt, DWORD dwFlags)
1906 TRACE("(%p, %p, %08x, %08x)!\n", fpThreadAddr, lpHndl, dwPmt, dwFlags);
1908 hndl = GlobalAlloc16(sizeof(WINE_MMTHREAD), GMEM_SHARE|GMEM_ZEROINIT);
1913 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
1916 /* force mmtask routines even if mmthread is required */
1917 /* this will work only if the patch about binary cmd line and NE tasks
1923 lpMMThd->dwSignature = WINE_MMTHREAD_CREATED;
1924 lpMMThd->dwCounter = 0;
1925 lpMMThd->hThread = 0;
1926 lpMMThd->dwThreadID = 0;
1927 lpMMThd->fpThread = (DWORD)fpThreadAddr;
1928 lpMMThd->dwThreadPmt = dwPmt;
1929 lpMMThd->dwSignalCount = 0;
1930 lpMMThd->hEvent = 0;
1932 lpMMThd->dwStatus = 0;
1933 lpMMThd->dwFlags = dwFlags;
1936 if ((dwFlags & 1) == 0 && (GetProcessFlags(GetCurrentThreadId()) & 8) == 0) {
1937 lpMMThd->hEvent = CreateEventW(NULL, FALSE, TRUE, NULL);
1939 TRACE("Let's go crazy... trying new MM thread. lpMMThd=%p\n", lpMMThd);
1940 if (lpMMThd->dwFlags & 2) {
1941 /* as long as we don't support MM VxD in wine, we don't need
1942 * to care about this flag
1944 /* FIXME("Don't know how to properly open VxD handles\n"); */
1945 /* lpMMThd->hVxD = OpenVxDHandle(lpMMThd->hEvent); */
1948 lpMMThd->hThread = CreateThread(0, 0, WINE_mmThreadEntryPoint,
1949 (LPVOID)(DWORD_PTR)hndl, CREATE_SUSPENDED, &lpMMThd->dwThreadID);
1950 if (lpMMThd->hThread == 0) {
1951 WARN("Couldn't create thread\n");
1952 /* clean-up(VxDhandle...); devicedirectio... */
1953 if (lpMMThd->hEvent != 0)
1954 CloseHandle(lpMMThd->hEvent);
1957 SetThreadPriority(lpMMThd->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1958 TRACE("Got a nice thread hndl=%p id=0x%08x\n", lpMMThd->hThread, lpMMThd->dwThreadID);
1962 /* get WINE_mmThreadEntryPoint()
1963 * 2047 is its ordinal in mmsystem.spec
1965 FARPROC16 fp = GetProcAddress16(GetModuleHandle16("MMSYSTEM"), (LPCSTR)2047);
1967 TRACE("farproc seg=0x%p lin=%p\n", fp, MapSL((SEGPTR)fp));
1969 ret = (fp == 0) ? 2 : mmTaskCreate16((DWORD)fp, 0, hndl);
1973 if (lpMMThd->hThread && !ResumeThread(lpMMThd->hThread))
1974 WARN("Couldn't resume thread\n");
1976 while (lpMMThd->dwStatus != 0x10) { /* test also HIWORD of dwStatus */
1990 TRACE("ok => %ld\n", ret);
1994 /**************************************************************************
1995 * mmThreadSignal [MMSYSTEM.1121]
1997 void WINAPI mmThreadSignal16(HANDLE16 hndl)
1999 TRACE("(%04x)!\n", hndl);
2002 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2004 lpMMThd->dwCounter++;
2005 if (lpMMThd->hThread != 0) {
2006 InterlockedIncrement(&lpMMThd->dwSignalCount);
2007 SetEvent(lpMMThd->hEvent);
2009 mmTaskSignal16(lpMMThd->hTask);
2011 lpMMThd->dwCounter--;
2015 static void MMSYSTEM_ThreadBlock(WINE_MMTHREAD* lpMMThd)
2020 if (lpMMThd->dwThreadID != GetCurrentThreadId())
2021 ERR("Not called by thread itself\n");
2024 ResetEvent(lpMMThd->hEvent);
2025 if (InterlockedDecrement(&lpMMThd->dwSignalCount) >= 0)
2027 InterlockedIncrement(&lpMMThd->dwSignalCount);
2031 ret = MsgWaitForMultipleObjects(1, &lpMMThd->hEvent, FALSE, INFINITE, QS_ALLINPUT);
2033 case WAIT_OBJECT_0: /* Event */
2036 case WAIT_OBJECT_0 + 1: /* Msg */
2038 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
2039 TranslateMessage(&msg);
2040 DispatchMessageA(&msg);
2044 WARN("S2.x unsupported ret val 0x%08x\n", ret);
2050 /**************************************************************************
2051 * mmThreadBlock [MMSYSTEM.1122]
2053 void WINAPI mmThreadBlock16(HANDLE16 hndl)
2055 TRACE("(%04x)!\n", hndl);
2058 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2060 if (lpMMThd->hThread != 0) {
2063 ReleaseThunkLock(&lc);
2064 MMSYSTEM_ThreadBlock(lpMMThd);
2065 RestoreThunkLock(lc);
2067 mmTaskBlock16(lpMMThd->hTask);
2073 /**************************************************************************
2074 * mmThreadIsCurrent [MMSYSTEM.1123]
2076 BOOL16 WINAPI mmThreadIsCurrent16(HANDLE16 hndl)
2080 TRACE("(%04x)!\n", hndl);
2082 if (hndl && mmThreadIsValid16(hndl)) {
2083 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2084 ret = (GetCurrentThreadId() == lpMMThd->dwThreadID);
2086 TRACE("=> %d\n", ret);
2090 /**************************************************************************
2091 * mmThreadIsValid [MMSYSTEM.1124]
2093 BOOL16 WINAPI mmThreadIsValid16(HANDLE16 hndl)
2097 TRACE("(%04x)!\n", hndl);
2100 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2102 if (!IsBadWritePtr(lpMMThd, sizeof(WINE_MMTHREAD)) &&
2103 lpMMThd->dwSignature == WINE_MMTHREAD_CREATED &&
2104 IsTask16(lpMMThd->hTask)) {
2105 lpMMThd->dwCounter++;
2106 if (lpMMThd->hThread != 0) {
2108 if (GetExitCodeThread(lpMMThd->hThread, &dwThreadRet) &&
2109 dwThreadRet == STATUS_PENDING) {
2115 lpMMThd->dwCounter--;
2118 TRACE("=> %d\n", ret);
2122 /**************************************************************************
2123 * mmThreadGetTask [MMSYSTEM.1125]
2125 HANDLE16 WINAPI mmThreadGetTask16(HANDLE16 hndl)
2129 TRACE("(%04x)\n", hndl);
2131 if (mmThreadIsValid16(hndl)) {
2132 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2133 ret = lpMMThd->hTask;
2138 /**************************************************************************
2139 * __wine_mmThreadEntryPoint (MMSYSTEM.2047)
2141 DWORD WINAPI WINE_mmThreadEntryPoint(LPVOID p)
2143 HANDLE16 hndl = (HANDLE16)(DWORD_PTR)p;
2144 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2146 TRACE("(%04x %p)\n", hndl, lpMMThd);
2148 lpMMThd->hTask = LOWORD(GetCurrentTask());
2149 TRACE("[10-%p] setting hTask to 0x%08x\n", lpMMThd->hThread, lpMMThd->hTask);
2150 lpMMThd->dwStatus = 0x10;
2151 MMSYSTEM_ThreadBlock(lpMMThd);
2152 TRACE("[20-%p]\n", lpMMThd->hThread);
2153 lpMMThd->dwStatus = 0x20;
2154 if (lpMMThd->fpThread) {
2155 WOWCallback16(lpMMThd->fpThread, lpMMThd->dwThreadPmt);
2157 lpMMThd->dwStatus = 0x30;
2158 TRACE("[30-%p]\n", lpMMThd->hThread);
2159 while (lpMMThd->dwCounter) {
2163 TRACE("[XX-%p]\n", lpMMThd->hThread);
2165 lpMMThd->dwSignature = WINE_MMTHREAD_DELETED;
2166 /* close lpMMThread->hVxD directIO */
2167 if (lpMMThd->hEvent)
2168 CloseHandle(lpMMThd->hEvent);
2175 typedef BOOL16 (WINAPI *MMCPLCALLBACK)(HWND, LPCSTR, LPCSTR, LPCSTR);
2177 /**************************************************************************
2178 * mmShowMMCPLPropertySheet [MMSYSTEM.1150]
2180 BOOL16 WINAPI mmShowMMCPLPropertySheet16(HWND hWnd, LPCSTR lpStrDevice,
2181 LPCSTR lpStrTab, LPCSTR lpStrTitle)
2186 TRACE("(%p \"%s\" \"%s\" \"%s\")\n", hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2188 hndl = LoadLibraryA("MMSYS.CPL");
2190 MMCPLCALLBACK fp = (MMCPLCALLBACK)GetProcAddress(hndl, "ShowMMCPLPropertySheet");
2193 ReleaseThunkLock(&lc);
2194 ret = (fp)(hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2195 RestoreThunkLock(lc);
2203 /**************************************************************************
2204 * StackEnter [MMSYSTEM.32]
2206 void WINAPI StackEnter16(void)
2209 /* mmsystem.dll from Win 95 does only this: so does Wine */
2214 /**************************************************************************
2215 * StackLeave [MMSYSTEM.33]
2217 void WINAPI StackLeave16(void)
2220 /* mmsystem.dll from Win 95 does only this: so does Wine */
2225 /**************************************************************************
2226 * WMMMidiRunOnce [MMSYSTEM.8]
2228 void WINAPI WMMMidiRunOnce16(void)
2230 FIXME("(), stub!\n");
2233 /* ###################################################
2235 * ###################################################
2238 /**************************************************************************
2239 * DRIVER_MapMsg32To16 [internal]
2241 * Map a 32 bit driver message to a 16 bit driver message.
2243 static WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, LPARAM *lParam1, LPARAM *lParam2)
2245 WINMM_MapType ret = WINMM_MAP_MSGERROR;
2252 case DRV_QUERYCONFIGURE:
2254 case DRV_EXITSESSION:
2255 case DRV_EXITAPPLICATION:
2257 case DRV_CLOSE: /* should be 0/0 */
2258 case DRV_OPEN: /* pass through */
2259 /* lParam1 and lParam2 are not used */
2264 /* lParam1 is a handle to a window (conf) or to a driver (inst) or not used,
2265 * lParam2 is a pointer to DRVCONFIGINFO
2268 LPDRVCONFIGINFO16 dci16 = HeapAlloc( GetProcessHeap(), 0, sizeof(*dci16) );
2269 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2);
2272 LPSTR str1 = NULL,str2;
2274 dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
2276 if (dci32->lpszDCISectionName) {
2277 len = WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCISectionName, -1, NULL, 0, NULL, NULL );
2278 str1 = HeapAlloc( GetProcessHeap(), 0, len );
2280 WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCISectionName, -1, str1, len, NULL, NULL );
2281 dci16->lpszDCISectionName = MapLS( str1 );
2283 HeapFree( GetProcessHeap(), 0, dci16);
2284 return WINMM_MAP_NOMEM;
2287 dci16->lpszDCISectionName = 0L;
2289 if (dci32->lpszDCIAliasName) {
2290 len = WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCIAliasName, -1, NULL, 0, NULL, NULL );
2291 str2 = HeapAlloc( GetProcessHeap(), 0, len );
2293 WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCIAliasName, -1, str2, len, NULL, NULL );
2294 dci16->lpszDCIAliasName = MapLS( str2 );
2296 HeapFree( GetProcessHeap(), 0, str1);
2297 HeapFree( GetProcessHeap(), 0, dci16);
2298 return WINMM_MAP_NOMEM;
2301 dci16->lpszDCISectionName = 0L;
2304 return WINMM_MAP_NOMEM;
2306 *lParam2 = MapLS( dci16 );
2307 ret = WINMM_MAP_OKMEM;
2313 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2314 FIXME("Unknown message 0x%04x\n", wMsg);
2321 /**************************************************************************
2322 * DRIVER_UnMapMsg32To16 [internal]
2324 * UnMap a 32 bit driver message to a 16 bit driver message.
2326 static WINMM_MapType DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
2328 WINMM_MapType ret = WINMM_MAP_MSGERROR;
2335 case DRV_QUERYCONFIGURE:
2337 case DRV_EXITSESSION:
2338 case DRV_EXITAPPLICATION:
2342 /* lParam1 and lParam2 are not used */
2346 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
2348 LPDRVCONFIGINFO16 dci16 = MapSL(lParam2);
2349 HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCISectionName) );
2350 HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCIAliasName) );
2352 UnMapLS( dci16->lpszDCISectionName );
2353 UnMapLS( dci16->lpszDCIAliasName );
2354 HeapFree( GetProcessHeap(), 0, dci16 );
2359 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2360 FIXME("Unknown message 0x%04x\n", wMsg);
2367 /**************************************************************************
2368 * DRIVER_TryOpenDriver16 [internal]
2370 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
2372 static LPWINE_DRIVER DRIVER_OpenDriver16(LPCWSTR fn, LPCWSTR sn, LPARAM lParam2)
2374 LPWINE_DRIVER lpDrv = NULL;
2375 LPCSTR cause = NULL;
2376 LPSTR fnA = NULL, snA = NULL;
2379 TRACE("(%s, %s, %08lX);\n", debugstr_w(fn), debugstr_w(sn), lParam2);
2381 lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
2382 if (lpDrv == NULL) {cause = "OOM"; goto exit;}
2386 len = WideCharToMultiByte( CP_ACP, 0, fn, -1, NULL, 0, NULL, NULL );
2387 fnA = HeapAlloc(GetProcessHeap(), 0, len);
2388 if (fnA == NULL) {cause = "OOM"; goto exit;}
2389 WideCharToMultiByte( CP_ACP, 0, fn, -1, fnA, len, NULL, NULL );
2394 len = WideCharToMultiByte( CP_ACP, 0, sn, -1, NULL, 0, NULL, NULL );
2395 snA = HeapAlloc(GetProcessHeap(), 0, len);
2396 if (snA == NULL) {cause = "OOM"; goto exit;}
2397 WideCharToMultiByte( CP_ACP, 0, sn, -1, snA, len, NULL, NULL );
2400 /* FIXME: shall we do some black magic here on sn ?
2401 * drivers32 => drivers
2405 lpDrv->d.d16.hDriver16 = OpenDriver16(fnA, snA, lParam2);
2406 if (lpDrv->d.d16.hDriver16 == 0) {cause = "Not a 16 bit driver"; goto exit;}
2407 lpDrv->dwFlags = WINE_GDF_16BIT;
2410 HeapFree(GetProcessHeap(), 0, fnA);
2411 HeapFree(GetProcessHeap(), 0, snA);
2415 TRACE("Unable to load 16 bit module %s[%s]: %s\n",
2416 debugstr_w(fn), debugstr_w(sn), cause);
2417 HeapFree(GetProcessHeap(), 0, lpDrv);
2421 TRACE("=> %p\n", lpDrv);
2425 /******************************************************************
2426 * DRIVER_SendMessage16
2430 static LRESULT DRIVER_SendMessage16(HDRVR16 hDrv16, UINT msg,
2431 LPARAM lParam1, LPARAM lParam2)
2436 TRACE("Before sdm16 call hDrv=%04x wMsg=%04x p1=%08lx p2=%08lx\n",
2437 hDrv16, msg, lParam1, lParam2);
2439 switch (map = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2)) {
2440 case WINMM_MAP_OKMEM:
2442 ret = SendDriverMessage16(hDrv16, msg, lParam1, lParam2);
2443 if (map == WINMM_MAP_OKMEM)
2444 DRIVER_UnMapMsg32To16(msg, lParam1, lParam2);
2451 /******************************************************************
2452 * DRIVER_CloseDriver16
2456 static LRESULT DRIVER_CloseDriver16(HDRVR16 hDrv16, LPARAM lParam1, LPARAM lParam2)
2458 return CloseDriver16(hDrv16, lParam1, lParam2);
2461 /**************************************************************************
2462 * DrvOpen [MMSYSTEM.1100]
2464 HDRVR16 WINAPI DrvOpen16(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
2466 return OpenDriver16(lpDriverName, lpSectionName, lParam);
2469 /**************************************************************************
2470 * DrvClose [MMSYSTEM.1101]
2472 LRESULT WINAPI DrvClose16(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
2474 return CloseDriver16(hDrv, lParam1, lParam2);
2477 /**************************************************************************
2478 * DrvSendMessage [MMSYSTEM.1102]
2480 LRESULT WINAPI DrvSendMessage16(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
2483 return SendDriverMessage16(hDrv, msg, lParam1, lParam2);
2486 /**************************************************************************
2487 * DrvGetModuleHandle [MMSYSTEM.1103]
2489 HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
2491 return GetDriverModuleHandle16(hDrv);
2494 /**************************************************************************
2495 * DrvDefDriverProc [MMSYSTEM.1104]
2497 LRESULT WINAPI DrvDefDriverProc16(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg,
2498 DWORD dwParam1, DWORD dwParam2)
2500 return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
2503 /**************************************************************************
2504 * DriverProc [MMSYSTEM.6]
2506 LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
2507 DWORD dwParam1, DWORD dwParam2)
2509 TRACE("dwDevID=%08x hDrv=%04x wMsg=%04x dwParam1=%08x dwParam2=%08x\n",
2510 dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2512 return DrvDefDriverProc16(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2515 /* ###################################################
2517 * ###################################################
2520 /******************************************************************
2521 * MMSYSTEM_MMTIME32to16
2525 void MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16, const MMTIME* mmt32)
2527 mmt16->wType = mmt32->wType;
2528 /* layout of rest is the same for 32/16,
2529 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
2531 memcpy(&(mmt16->u), &(mmt32->u), sizeof(mmt16->u));
2534 /******************************************************************
2535 * MMSYSTEM_MMTIME16to32
2539 void MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16)
2541 mmt32->wType = mmt16->wType;
2542 /* layout of rest is the same for 32/16,
2543 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
2545 memcpy(&(mmt32->u), &(mmt16->u), sizeof(mmt16->u));
2548 /**************************************************************************
2549 * timeGetSystemTime [MMSYSTEM.601]
2551 MMRESULT16 WINAPI timeGetSystemTime16(LPMMTIME16 lpTime, UINT16 wSize)
2553 if (wSize >= sizeof(*lpTime)) {
2554 lpTime->wType = TIME_MS;
2555 lpTime->u.ms = GetTickCount();
2557 TRACE("=> %u\n", lpTime->u.ms);
2563 /**************************************************************************
2564 * timeSetEvent [MMSYSTEM.602]
2566 MMRESULT16 WINAPI timeSetEvent16(UINT16 wDelay, UINT16 wResol, LPTIMECALLBACK16 lpFunc,
2567 DWORD dwUser, UINT16 wFlags)
2569 if (wFlags & WINE_TIMER_IS32)
2570 WARN("Unknown windows flag... wine internally used.. ooch\n");
2572 return TIME_SetEventInternal(wDelay, wResol, (LPTIMECALLBACK)lpFunc,
2573 dwUser, wFlags & ~WINE_TIMER_IS32);
2576 /**************************************************************************
2577 * timeKillEvent [MMSYSTEM.603]
2579 MMRESULT16 WINAPI timeKillEvent16(UINT16 wID)
2581 return timeKillEvent(wID);
2584 /**************************************************************************
2585 * timeGetDevCaps [MMSYSTEM.604]
2587 MMRESULT16 WINAPI timeGetDevCaps16(LPTIMECAPS16 lpCaps, UINT16 wSize)
2591 TRACE("(%p, %u) !\n", lpCaps, wSize);
2593 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2595 ret = timeGetDevCaps(&caps, sizeof(caps));
2596 if (ret == MMSYSERR_NOERROR) {
2598 tc16.wPeriodMin = caps.wPeriodMin;
2599 tc16.wPeriodMax = caps.wPeriodMax;
2600 memcpy(lpCaps, &tc16, min(wSize, sizeof(tc16)));
2605 /**************************************************************************
2606 * timeBeginPeriod [MMSYSTEM.605]
2608 MMRESULT16 WINAPI timeBeginPeriod16(UINT16 wPeriod)
2610 TRACE("(%u) !\n", wPeriod);
2612 return timeBeginPeriod(wPeriod);
2615 /**************************************************************************
2616 * timeEndPeriod [MMSYSTEM.606]
2618 MMRESULT16 WINAPI timeEndPeriod16(UINT16 wPeriod)
2620 TRACE("(%u) !\n", wPeriod);
2622 return timeEndPeriod(wPeriod);
2625 /**************************************************************************
2626 * mciSendString [MMSYSTEM.702]
2628 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
2629 UINT16 uRetLen, HWND16 hwndCallback)
2631 return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback));
2634 /**************************************************************************
2635 * mciLoadCommandResource [MMSYSTEM.705]
2637 UINT16 WINAPI mciLoadCommandResource16(HINSTANCE16 hInst, LPCSTR resname, UINT16 type)
2643 unsigned pos = 0, size = 1024, len;
2647 UINT16 ret = MCIERR_OUT_OF_MEMORY;
2649 if (!(res = FindResource16( hInst, resname, (LPSTR)RT_RCDATA))) return MCI_NO_COMMAND_TABLE;
2650 if (!(handle = LoadResource16( hInst, res ))) return MCI_NO_COMMAND_TABLE;
2651 ptr16 = LockResource16(handle);
2652 /* converting the 16 bit resource table into a 32W one */
2653 if ((ptr32 = HeapAlloc(GetProcessHeap(), 0, size)))
2656 str = (LPCSTR)ptr16;
2657 ptr16 += strlen(str) + 1;
2658 flg = *(const DWORD*)ptr16;
2659 eid = *(const WORD*)(ptr16 + sizeof(DWORD));
2660 ptr16 += sizeof(DWORD) + sizeof(WORD);
2661 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) * sizeof(WCHAR);
2662 if (pos + len + sizeof(DWORD) + sizeof(WORD) > size)
2664 while (pos + len * sizeof(WCHAR) + sizeof(DWORD) + sizeof(WORD) > size) size += 1024;
2665 ptr32 = HeapReAlloc(GetProcessHeap(), 0, ptr32, size);
2666 if (!ptr32) goto the_end;
2668 MultiByteToWideChar(CP_ACP, 0, str, -1, (LPWSTR)(ptr32 + pos), len / sizeof(WCHAR));
2669 *(DWORD*)(ptr32 + pos + len) = flg;
2670 *(WORD*)(ptr32 + pos + len + sizeof(DWORD)) = eid;
2671 pos += len + sizeof(DWORD) + sizeof(WORD);
2672 } while (eid != MCI_END_COMMAND_LIST);
2675 FreeResource16( handle );
2676 if (ptr32) ret = MCI_SetCommandTable(ptr32, type);
2680 /**************************************************************************
2681 * mciFreeCommandResource [MMSYSTEM.713]
2683 BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
2685 TRACE("(%04x)!\n", uTable);
2687 return MCI_DeleteCommandTable(uTable, TRUE);
2690 /* ###################################################
2692 * ###################################################
2695 /****************************************************************
2696 * MMIO_Map32To16 [INTERNAL]
2698 static LRESULT MMIO_Map32To16(DWORD wMsg, LPARAM* lp1, LPARAM* lp2)
2708 case MMIOM_WRITEFLUSH:
2709 *lp1 = MapLS( (void *)*lp1 );
2712 *lp1 = MapLS( (void *)*lp1 );
2713 *lp2 = MapLS( (void *)*lp2 );
2716 if (wMsg < MMIOM_USER)
2717 TRACE("Not a mappable message (%d)\n", wMsg);
2719 return MMSYSERR_NOERROR;
2722 /****************************************************************
2723 * MMIO_UnMap32To16 [INTERNAL]
2725 static LRESULT MMIO_UnMap32To16(DWORD wMsg, LPARAM lParam1, LPARAM lParam2,
2726 LPARAM lp1, LPARAM lp2)
2736 case MMIOM_WRITEFLUSH:
2744 if (wMsg < MMIOM_USER)
2745 TRACE("Not a mappable message (%d)\n", wMsg);
2747 return MMSYSERR_NOERROR;
2750 /******************************************************************
2755 static LRESULT MMIO_Callback16(SEGPTR cb16, LPMMIOINFO lpmmioinfo, UINT uMessage,
2756 LPARAM lParam1, LPARAM lParam2)
2759 MMIOINFO16 mmioInfo16;
2760 SEGPTR segmmioInfo16;
2761 LPARAM lp1 = lParam1, lp2 = lParam2;
2764 memset(&mmioInfo16, 0, sizeof(MMIOINFO16));
2765 mmioInfo16.lDiskOffset = lpmmioinfo->lDiskOffset;
2766 mmioInfo16.adwInfo[0] = lpmmioinfo->adwInfo[0];
2767 mmioInfo16.adwInfo[1] = lpmmioinfo->adwInfo[1];
2768 mmioInfo16.adwInfo[2] = lpmmioinfo->adwInfo[2];
2769 /* map (lParam1, lParam2) into (lp1, lp2) 32=>16 */
2770 if ((result = MMIO_Map32To16(uMessage, &lp1, &lp2)) != MMSYSERR_NOERROR)
2773 segmmioInfo16 = MapLS(&mmioInfo16);
2774 args[6] = HIWORD(segmmioInfo16);
2775 args[5] = LOWORD(segmmioInfo16);
2777 args[3] = HIWORD(lp1);
2778 args[2] = LOWORD(lp1);
2779 args[1] = HIWORD(lp2);
2780 args[0] = LOWORD(lp2);
2781 WOWCallback16Ex( cb16, WCB16_PASCAL, sizeof(args), args, &result );
2782 UnMapLS(segmmioInfo16);
2783 MMIO_UnMap32To16(uMessage, lParam1, lParam2, lp1, lp2);
2785 lpmmioinfo->lDiskOffset = mmioInfo16.lDiskOffset;
2786 lpmmioinfo->adwInfo[0] = mmioInfo16.adwInfo[0];
2787 lpmmioinfo->adwInfo[1] = mmioInfo16.adwInfo[1];
2788 lpmmioinfo->adwInfo[2] = mmioInfo16.adwInfo[2];
2793 /******************************************************************
2794 * MMIO_ResetSegmentedData
2797 static LRESULT MMIO_SetSegmentedBuffer(HMMIO hmmio, SEGPTR ptr, BOOL release)
2801 if ((wm = MMIO_Get(hmmio)) == NULL)
2802 return MMSYSERR_INVALHANDLE;
2803 if (release) UnMapLS(wm->segBuffer16);
2804 wm->segBuffer16 = ptr;
2805 return MMSYSERR_NOERROR;
2808 /**************************************************************************
2809 * mmioOpen [MMSYSTEM.1210]
2811 HMMIO16 WINAPI mmioOpen16(LPSTR szFileName, MMIOINFO16* lpmmioinfo16,
2819 memset(&mmioinfo, 0, sizeof(mmioinfo));
2821 mmioinfo.dwFlags = lpmmioinfo16->dwFlags;
2822 mmioinfo.fccIOProc = lpmmioinfo16->fccIOProc;
2823 mmioinfo.pIOProc = (LPMMIOPROC)lpmmioinfo16->pIOProc;
2824 mmioinfo.cchBuffer = lpmmioinfo16->cchBuffer;
2825 mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo16->pchBuffer);
2826 mmioinfo.adwInfo[0] = lpmmioinfo16->adwInfo[0];
2827 /* if we don't have a file name, it's likely a passed open file descriptor */
2829 mmioinfo.adwInfo[0] = (DWORD)DosFileHandleToWin32Handle(mmioinfo.adwInfo[0]);
2830 mmioinfo.adwInfo[1] = lpmmioinfo16->adwInfo[1];
2831 mmioinfo.adwInfo[2] = lpmmioinfo16->adwInfo[2];
2833 ret = MMIO_Open(szFileName, &mmioinfo, dwOpenFlags, MMIO_PROC_16);
2834 MMIO_SetSegmentedBuffer(mmioinfo.hmmio, (SEGPTR)lpmmioinfo16->pchBuffer, FALSE);
2836 lpmmioinfo16->wErrorRet = mmioinfo.wErrorRet;
2837 lpmmioinfo16->hmmio = HMMIO_16(mmioinfo.hmmio);
2839 ret = MMIO_Open(szFileName, NULL, dwOpenFlags, MMIO_PROC_32A);
2841 return HMMIO_16(ret);
2844 /**************************************************************************
2845 * mmioClose [MMSYSTEM.1211]
2847 MMRESULT16 WINAPI mmioClose16(HMMIO16 hmmio, UINT16 uFlags)
2849 MMIO_SetSegmentedBuffer(HMMIO_32(hmmio), 0, TRUE);
2850 return mmioClose(HMMIO_32(hmmio), uFlags);
2853 /**************************************************************************
2854 * mmioRead [MMSYSTEM.1212]
2856 LONG WINAPI mmioRead16(HMMIO16 hmmio, HPSTR pch, LONG cch)
2858 return mmioRead(HMMIO_32(hmmio), pch, cch);
2861 /**************************************************************************
2862 * mmioWrite [MMSYSTEM.1213]
2864 LONG WINAPI mmioWrite16(HMMIO16 hmmio, HPCSTR pch, LONG cch)
2866 return mmioWrite(HMMIO_32(hmmio),pch,cch);
2869 /**************************************************************************
2870 * mmioSeek [MMSYSTEM.1214]
2872 LONG WINAPI mmioSeek16(HMMIO16 hmmio, LONG lOffset, INT16 iOrigin)
2874 return mmioSeek(HMMIO_32(hmmio), lOffset, iOrigin);
2877 /**************************************************************************
2878 * mmioGetInfo [MMSYSTEM.1215]
2880 MMRESULT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2886 TRACE("(0x%04x,%p,0x%08x)\n", hmmio, lpmmioinfo, uFlags);
2888 if ((wm = MMIO_Get(HMMIO_32(hmmio))) == NULL)
2889 return MMSYSERR_INVALHANDLE;
2891 ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2892 if (ret != MMSYSERR_NOERROR) return ret;
2894 lpmmioinfo->dwFlags = mmioinfo.dwFlags;
2895 lpmmioinfo->fccIOProc = mmioinfo.fccIOProc;
2896 lpmmioinfo->pIOProc = (wm->ioProc->type == MMIO_PROC_16) ?
2897 (LPMMIOPROC16)wm->ioProc->pIOProc : NULL;
2898 lpmmioinfo->wErrorRet = mmioinfo.wErrorRet;
2899 lpmmioinfo->hTask = HTASK_16(mmioinfo.hTask);
2900 lpmmioinfo->cchBuffer = mmioinfo.cchBuffer;
2901 lpmmioinfo->pchBuffer = (void*)wm->segBuffer16;
2902 lpmmioinfo->pchNext = (void*)(wm->segBuffer16 + (mmioinfo.pchNext - mmioinfo.pchBuffer));
2903 lpmmioinfo->pchEndRead = (void*)(wm->segBuffer16 + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
2904 lpmmioinfo->pchEndWrite = (void*)(wm->segBuffer16 + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
2905 lpmmioinfo->lBufOffset = mmioinfo.lBufOffset;
2906 lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
2907 lpmmioinfo->adwInfo[0] = mmioinfo.adwInfo[0];
2908 lpmmioinfo->adwInfo[1] = mmioinfo.adwInfo[1];
2909 lpmmioinfo->adwInfo[2] = mmioinfo.adwInfo[2];
2910 lpmmioinfo->dwReserved1 = 0;
2911 lpmmioinfo->dwReserved2 = 0;
2912 lpmmioinfo->hmmio = HMMIO_16(mmioinfo.hmmio);
2914 return MMSYSERR_NOERROR;
2917 /**************************************************************************
2918 * mmioSetInfo [MMSYSTEM.1216]
2920 MMRESULT16 WINAPI mmioSetInfo16(HMMIO16 hmmio, const MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2925 TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
2927 ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, 0);
2928 if (ret != MMSYSERR_NOERROR) return ret;
2930 /* check if seg and lin buffers are the same */
2931 if (mmioinfo.cchBuffer != lpmmioinfo->cchBuffer ||
2932 mmioinfo.pchBuffer != MapSL((DWORD)lpmmioinfo->pchBuffer))
2933 return MMSYSERR_INVALPARAM;
2935 /* check pointers coherence */
2936 if (lpmmioinfo->pchNext < lpmmioinfo->pchBuffer ||
2937 lpmmioinfo->pchNext > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2938 lpmmioinfo->pchEndRead < lpmmioinfo->pchBuffer ||
2939 lpmmioinfo->pchEndRead > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2940 lpmmioinfo->pchEndWrite < lpmmioinfo->pchBuffer ||
2941 lpmmioinfo->pchEndWrite > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer)
2942 return MMSYSERR_INVALPARAM;
2944 mmioinfo.pchNext = mmioinfo.pchBuffer + (lpmmioinfo->pchNext - lpmmioinfo->pchBuffer);
2945 mmioinfo.pchEndRead = mmioinfo.pchBuffer + (lpmmioinfo->pchEndRead - lpmmioinfo->pchBuffer);
2946 mmioinfo.pchEndWrite = mmioinfo.pchBuffer + (lpmmioinfo->pchEndWrite - lpmmioinfo->pchBuffer);
2948 return mmioSetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2951 /**************************************************************************
2952 * mmioSetBuffer [MMSYSTEM.1217]
2954 MMRESULT16 WINAPI mmioSetBuffer16(HMMIO16 hmmio, LPSTR pchBuffer,
2955 LONG cchBuffer, UINT16 uFlags)
2957 MMRESULT ret = mmioSetBuffer(HMMIO_32(hmmio), MapSL((DWORD)pchBuffer),
2960 if (ret == MMSYSERR_NOERROR)
2961 MMIO_SetSegmentedBuffer(HMMIO_32(hmmio), (DWORD)pchBuffer, TRUE);
2963 UnMapLS((DWORD)pchBuffer);
2967 /**************************************************************************
2968 * mmioFlush [MMSYSTEM.1218]
2970 MMRESULT16 WINAPI mmioFlush16(HMMIO16 hmmio, UINT16 uFlags)
2972 return mmioFlush(HMMIO_32(hmmio), uFlags);
2975 /***********************************************************************
2976 * mmioAdvance [MMSYSTEM.1219]
2978 MMRESULT16 WINAPI mmioAdvance16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2983 /* WARNING: this heavily relies on mmioAdvance implementation (for choosing which
2988 mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo->pchBuffer);
2989 mmioinfo.pchNext = MapSL((DWORD)lpmmioinfo->pchNext);
2990 mmioinfo.dwFlags = lpmmioinfo->dwFlags;
2991 mmioinfo.lBufOffset = lpmmioinfo->lBufOffset;
2992 ret = mmioAdvance(HMMIO_32(hmmio), &mmioinfo, uFlags);
2995 ret = mmioAdvance(HMMIO_32(hmmio), NULL, uFlags);
2997 if (ret != MMSYSERR_NOERROR) return ret;
3001 lpmmioinfo->dwFlags = mmioinfo.dwFlags;
3002 lpmmioinfo->pchNext = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchNext - mmioinfo.pchBuffer));
3003 lpmmioinfo->pchEndRead = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
3004 lpmmioinfo->pchEndWrite = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
3005 lpmmioinfo->lBufOffset = mmioinfo.lBufOffset;
3006 lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
3009 return MMSYSERR_NOERROR;
3012 /**************************************************************************
3013 * mmioStringToFOURCC [MMSYSTEM.1220]
3015 FOURCC WINAPI mmioStringToFOURCC16(LPCSTR sz, UINT16 uFlags)
3017 return mmioStringToFOURCCA(sz, uFlags);
3020 /**************************************************************************
3021 * mmioInstallIOProc [MMSYSTEM.1221]
3023 LPMMIOPROC16 WINAPI mmioInstallIOProc16(FOURCC fccIOProc, LPMMIOPROC16 pIOProc,
3026 return (LPMMIOPROC16)MMIO_InstallIOProc(fccIOProc, (LPMMIOPROC)pIOProc,
3027 dwFlags, MMIO_PROC_16);
3030 /**************************************************************************
3031 * mmioSendMessage [MMSYSTEM.1222]
3033 LRESULT WINAPI mmioSendMessage16(HMMIO16 hmmio, UINT16 uMessage,
3034 LPARAM lParam1, LPARAM lParam2)
3036 return MMIO_SendMessage(HMMIO_32(hmmio), uMessage,
3037 lParam1, lParam2, MMIO_PROC_16);
3040 /**************************************************************************
3041 * mmioDescend [MMSYSTEM.1223]
3043 MMRESULT16 WINAPI mmioDescend16(HMMIO16 hmmio, LPMMCKINFO lpck,
3044 const MMCKINFO* lpckParent, UINT16 uFlags)
3046 return mmioDescend(HMMIO_32(hmmio), lpck, lpckParent, uFlags);
3049 /**************************************************************************
3050 * mmioAscend [MMSYSTEM.1224]
3052 MMRESULT16 WINAPI mmioAscend16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
3054 return mmioAscend(HMMIO_32(hmmio),lpck,uFlags);
3057 /**************************************************************************
3058 * mmioCreateChunk [MMSYSTEM.1225]
3060 MMRESULT16 WINAPI mmioCreateChunk16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
3062 return mmioCreateChunk(HMMIO_32(hmmio), lpck, uFlags);
3065 /**************************************************************************
3066 * mmioRename [MMSYSTEM.1226]
3068 MMRESULT16 WINAPI mmioRename16(LPCSTR szFileName, LPCSTR szNewFileName,
3069 MMIOINFO16* lpmmioinfo, DWORD dwRenameFlags)
3075 if (lpmmioinfo != NULL && lpmmioinfo->pIOProc != NULL &&
3076 lpmmioinfo->fccIOProc == 0) {
3077 FIXME("Can't handle this case yet\n");
3078 return MMSYSERR_ERROR;
3081 /* this is a bit hacky, but it'll work if we get a fourCC code or nothing.
3082 * but a non installed ioproc without a fourcc won't do
3084 if (lpmmioinfo && lpmmioinfo->fccIOProc && lpmmioinfo->pIOProc) {
3085 MMIO_InstallIOProc(lpmmioinfo->fccIOProc, (LPMMIOPROC)lpmmioinfo->pIOProc,
3086 MMIO_INSTALLPROC, MMIO_PROC_16);
3089 memset(&mmioinfo, 0, sizeof(mmioinfo));
3090 mmioinfo.fccIOProc = lpmmioinfo->fccIOProc;
3091 ret = mmioRenameA(szFileName, szNewFileName, &mmioinfo, dwRenameFlags);
3093 MMIO_InstallIOProc(lpmmioinfo->fccIOProc, NULL,
3094 MMIO_REMOVEPROC, MMIO_PROC_16);
3099 /* ###################################################
3101 * ###################################################
3104 /**************************************************************************
3105 * joyGetNumDevs [MMSYSTEM.101]
3107 UINT16 WINAPI joyGetNumDevs16(void)
3109 return joyGetNumDevs();
3112 /**************************************************************************
3113 * joyGetDevCaps [MMSYSTEM.102]
3115 MMRESULT16 WINAPI joyGetDevCaps16(UINT16 wID, LPJOYCAPS16 lpCaps, UINT16 wSize)
3120 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
3122 ret = joyGetDevCapsA(wID, &jca, sizeof(jca));
3124 if (ret != JOYERR_NOERROR) return ret;
3125 lpCaps->wMid = jca.wMid;
3126 lpCaps->wPid = jca.wPid;
3127 strcpy(lpCaps->szPname, jca.szPname);
3128 lpCaps->wXmin = jca.wXmin;
3129 lpCaps->wXmax = jca.wXmax;
3130 lpCaps->wYmin = jca.wYmin;
3131 lpCaps->wYmax = jca.wYmax;
3132 lpCaps->wZmin = jca.wZmin;
3133 lpCaps->wZmax = jca.wZmax;
3134 lpCaps->wNumButtons = jca.wNumButtons;
3135 lpCaps->wPeriodMin = jca.wPeriodMin;
3136 lpCaps->wPeriodMax = jca.wPeriodMax;
3138 if (wSize >= sizeof(JOYCAPS16)) { /* Win95 extensions ? */
3139 lpCaps->wRmin = jca.wRmin;
3140 lpCaps->wRmax = jca.wRmax;
3141 lpCaps->wUmin = jca.wUmin;
3142 lpCaps->wUmax = jca.wUmax;
3143 lpCaps->wVmin = jca.wVmin;
3144 lpCaps->wVmax = jca.wVmax;
3145 lpCaps->wCaps = jca.wCaps;
3146 lpCaps->wMaxAxes = jca.wMaxAxes;
3147 lpCaps->wNumAxes = jca.wNumAxes;
3148 lpCaps->wMaxButtons = jca.wMaxButtons;
3149 strcpy(lpCaps->szRegKey, jca.szRegKey);
3150 strcpy(lpCaps->szOEMVxD, jca.szOEMVxD);
3156 /**************************************************************************
3157 * joyGetPosEx [MMSYSTEM.110]
3159 MMRESULT16 WINAPI joyGetPosEx16(UINT16 wID, LPJOYINFOEX lpInfo)
3161 return joyGetPosEx(wID, lpInfo);
3164 /**************************************************************************
3165 * joyGetPos [MMSYSTEM.103]
3167 MMRESULT16 WINAPI joyGetPos16(UINT16 wID, LPJOYINFO16 lpInfo)
3172 TRACE("(%d, %p);\n", wID, lpInfo);
3174 if ((ret = joyGetPos(wID, &ji)) == JOYERR_NOERROR) {
3175 lpInfo->wXpos = ji.wXpos;
3176 lpInfo->wYpos = ji.wYpos;
3177 lpInfo->wZpos = ji.wZpos;
3178 lpInfo->wButtons = ji.wButtons;
3183 /**************************************************************************
3184 * joyGetThreshold [MMSYSTEM.104]
3186 MMRESULT16 WINAPI joyGetThreshold16(UINT16 wID, LPUINT16 lpThreshold)
3191 ret = joyGetThreshold(wID, &t);
3192 if (ret == JOYERR_NOERROR)
3197 /**************************************************************************
3198 * joyReleaseCapture [MMSYSTEM.105]
3200 MMRESULT16 WINAPI joyReleaseCapture16(UINT16 wID)
3202 return joyReleaseCapture(wID);
3205 /**************************************************************************
3206 * joySetCapture [MMSYSTEM.106]
3208 MMRESULT16 WINAPI joySetCapture16(HWND16 hWnd, UINT16 wID, UINT16 wPeriod, BOOL16 bChanged)
3210 return joySetCapture(HWND_32(hWnd), wID, wPeriod, bChanged);
3213 /**************************************************************************
3214 * joySetThreshold [MMSYSTEM.107]
3216 MMRESULT16 WINAPI joySetThreshold16(UINT16 wID, UINT16 wThreshold)
3218 return joySetThreshold(wID,wThreshold);
3221 /**************************************************************************
3222 * joySetCalibration [MMSYSTEM.109]
3224 MMRESULT16 WINAPI joySetCalibration16(UINT16 wID)
3226 FIXME("(%04X): stub.\n", wID);
3227 return JOYERR_NOCANDO;