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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 99/4 added mmTask and mmThread functions support
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
43 #include "wine/winuser16.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
50 static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16);
51 static LPWINE_DRIVER DRIVER_OpenDriver16(LPCWSTR, LPCWSTR, LPARAM);
52 static LRESULT DRIVER_CloseDriver16(HDRVR16, LPARAM, LPARAM);
53 static LRESULT DRIVER_SendMessage16(HDRVR16, UINT, LPARAM, LPARAM);
54 static LRESULT MMIO_Callback16(SEGPTR, LPMMIOINFO, UINT, LPARAM, LPARAM);
56 /* ###################################################
58 * ###################################################
61 /**************************************************************************
62 * DllEntryPoint (MMSYSTEM.2046)
64 * MMSYSTEM DLL entry point
67 BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
68 WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
70 TRACE("%p 0x%lx\n", hinstDLL, fdwReason);
73 case DLL_PROCESS_ATTACH:
74 /* need to load WinMM in order to:
75 * - initiate correctly shared variables (WINMM_Init())
77 if (!GetModuleHandleA("WINMM.DLL") && !LoadLibraryA("WINMM.DLL"))
79 ERR("Could not load sibling WinMM.dll\n");
82 WINMM_IData->hWinMM16Instance = hinstDLL;
83 /* hook in our 16 bit function pointers */
84 pFnGetMMThread16 = WINMM_GetmmThread;
85 pFnOpenDriver16 = DRIVER_OpenDriver16;
86 pFnCloseDriver16 = DRIVER_CloseDriver16;
87 pFnSendMessage16 = DRIVER_SendMessage16;
88 pFnMmioCallback16 = MMIO_Callback16;
89 pFnReleaseThunkLock = ReleaseThunkLock;
90 pFnRestoreThunkLock = RestoreThunkLock;
93 case DLL_PROCESS_DETACH:
94 WINMM_IData->hWinMM16Instance = 0;
95 pFnGetMMThread16 = NULL;
96 pFnOpenDriver16 = NULL;
97 pFnCloseDriver16 = NULL;
98 pFnSendMessage16 = NULL;
99 pFnMmioCallback16 = NULL;
100 pFnReleaseThunkLock = NULL;
101 pFnRestoreThunkLock = NULL;
102 /* FIXME: add equivalent for MMDRV_Init16() */
104 case DLL_THREAD_ATTACH:
105 case DLL_THREAD_DETACH:
111 /**************************************************************************
112 * MMSYSTEM_WEP [MMSYSTEM.1]
114 int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
115 WORD cbHeapSize, LPSTR lpCmdLine)
117 FIXME("STUB: Unloading MMSystem DLL ... hInst=%04X \n", hInstance);
121 /* ###################################################
123 * ###################################################
126 /**************************************************************************
127 * PlaySound [MMSYSTEM.3]
129 BOOL16 WINAPI PlaySound16(LPCSTR pszSound, HMODULE16 hmod, DWORD fdwSound)
134 if ((fdwSound & SND_RESOURCE) == SND_RESOURCE)
139 if (!(res = FindResource16( hmod, pszSound, "WAVE" ))) return FALSE;
140 if (!(handle = LoadResource16( hmod, res ))) return FALSE;
141 pszSound = LockResource16(handle);
142 fdwSound = (fdwSound & ~SND_RESOURCE) | SND_MEMORY;
143 /* FIXME: FreeResource16 */
146 ReleaseThunkLock(&lc);
147 retv = PlaySoundA(pszSound, 0, fdwSound);
148 RestoreThunkLock(lc);
153 /**************************************************************************
154 * sndPlaySound [MMSYSTEM.2]
156 BOOL16 WINAPI sndPlaySound16(LPCSTR lpszSoundName, UINT16 uFlags)
161 ReleaseThunkLock(&lc);
162 retv = sndPlaySoundA(lpszSoundName, uFlags);
163 RestoreThunkLock(lc);
168 /* ###################################################
170 * ###################################################
173 /**************************************************************************
174 * mmsystemGetVersion [MMSYSTEM.5]
177 UINT16 WINAPI mmsystemGetVersion16(void)
179 return mmsystemGetVersion();
182 /**************************************************************************
183 * DriverCallback [MMSYSTEM.31]
185 BOOL16 WINAPI DriverCallback16(DWORD dwCallBack, UINT16 uFlags, HDRVR16 hDev,
186 WORD wMsg, DWORD dwUser, DWORD dwParam1,
189 return DriverCallback(dwCallBack, uFlags, HDRVR_32(hDev), wMsg, dwUser, dwParam1, dwParam2);
192 /**************************************************************************
193 * OutputDebugStr [MMSYSTEM.30]
195 void WINAPI OutputDebugStr16(LPCSTR str)
197 OutputDebugStringA( str );
201 /* ###################################################
203 * ###################################################
206 /**************************************************************************
207 * Mixer devices. New to Win95
210 /**************************************************************************
211 * mixerGetNumDevs [MMSYSTEM.800]
213 UINT16 WINAPI mixerGetNumDevs16(void)
215 return MMDRV_GetNum(MMDRV_MIXER);
218 /**************************************************************************
219 * mixerGetDevCaps [MMSYSTEM.801]
221 UINT16 WINAPI mixerGetDevCaps16(UINT16 uDeviceID, LPMIXERCAPS16 lpCaps,
227 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
229 ret = mixerGetDevCapsA(uDeviceID, &micA, sizeof(micA));
230 if (ret == MMSYSERR_NOERROR) {
232 mic16.wMid = micA.wMid;
233 mic16.wPid = micA.wPid;
234 mic16.vDriverVersion = micA.vDriverVersion;
235 strcpy(mic16.szPname, micA.szPname);
236 mic16.fdwSupport = micA.fdwSupport;
237 mic16.cDestinations = micA.cDestinations;
238 memcpy(lpCaps, &mic16, min(uSize, sizeof(mic16)));
243 /**************************************************************************
244 * mixerOpen [MMSYSTEM.802]
246 UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix, UINT16 uDeviceID, DWORD dwCallback,
247 DWORD dwInstance, DWORD fdwOpen)
252 ret = MIXER_Open(&hmix, uDeviceID, dwCallback, dwInstance, fdwOpen, FALSE);
253 if (lphmix) *lphmix = HMIXER_16(hmix);
257 /**************************************************************************
258 * mixerClose [MMSYSTEM.803]
260 UINT16 WINAPI mixerClose16(HMIXER16 hMix)
262 return mixerClose(HMIXER_32(hMix));
265 /**************************************************************************
266 * mixerGetID (MMSYSTEM.806)
268 UINT16 WINAPI mixerGetID16(HMIXEROBJ16 hmix, LPUINT16 lpid, DWORD fdwID)
271 UINT ret = mixerGetID(HMIXEROBJ_32(hmix), &xid, fdwID);
278 /**************************************************************************
279 * mixerGetControlDetails [MMSYSTEM.808]
281 UINT16 WINAPI mixerGetControlDetails16(HMIXEROBJ16 hmix,
282 LPMIXERCONTROLDETAILS16 lpmcd,
285 DWORD ret = MMSYSERR_NOTENABLED;
288 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
290 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
291 return MMSYSERR_INVALPARAM;
293 sppaDetails = (SEGPTR)lpmcd->paDetails;
294 lpmcd->paDetails = MapSL(sppaDetails);
295 ret = mixerGetControlDetailsA(HMIXEROBJ_32(hmix),
296 (LPMIXERCONTROLDETAILS)lpmcd, fdwDetails);
297 lpmcd->paDetails = (LPVOID)sppaDetails;
302 /**************************************************************************
303 * mixerGetLineControls [MMSYSTEM.807]
305 UINT16 WINAPI mixerGetLineControls16(HMIXEROBJ16 hmix,
306 LPMIXERLINECONTROLS16 lpmlc16,
309 MIXERLINECONTROLSA mlcA;
312 LPMIXERCONTROL16 lpmc16;
314 TRACE("(%04x, %p, %08lx)\n", hmix, lpmlc16, fdwControls);
316 if (lpmlc16 == NULL || lpmlc16->cbStruct != sizeof(*lpmlc16) ||
317 lpmlc16->cbmxctrl != sizeof(MIXERCONTROL16))
318 return MMSYSERR_INVALPARAM;
320 mlcA.cbStruct = sizeof(mlcA);
321 mlcA.dwLineID = lpmlc16->dwLineID;
322 mlcA.u.dwControlID = lpmlc16->u.dwControlID;
323 mlcA.u.dwControlType = lpmlc16->u.dwControlType;
324 mlcA.cControls = lpmlc16->cControls;
325 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
326 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
327 mlcA.cControls * mlcA.cbmxctrl);
329 ret = mixerGetLineControlsA(HMIXEROBJ_32(hmix), &mlcA, fdwControls);
331 if (ret == MMSYSERR_NOERROR) {
332 lpmlc16->dwLineID = mlcA.dwLineID;
333 lpmlc16->u.dwControlID = mlcA.u.dwControlID;
334 lpmlc16->u.dwControlType = mlcA.u.dwControlType;
335 lpmlc16->cControls = mlcA.cControls;
337 lpmc16 = MapSL(lpmlc16->pamxctrl);
339 for (i = 0; i < mlcA.cControls; i++) {
340 lpmc16[i].cbStruct = sizeof(MIXERCONTROL16);
341 lpmc16[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
342 lpmc16[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
343 lpmc16[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
344 lpmc16[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
345 strcpy(lpmc16[i].szShortName, mlcA.pamxctrl[i].szShortName);
346 strcpy(lpmc16[i].szName, mlcA.pamxctrl[i].szName);
347 /* sizeof(lpmc16[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
348 memcpy(&lpmc16[i].Bounds, &mlcA.pamxctrl[i].Bounds,
349 sizeof(mlcA.pamxctrl[i].Bounds));
350 /* sizeof(lpmc16[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
351 memcpy(&lpmc16[i].Metrics, &mlcA.pamxctrl[i].Metrics,
352 sizeof(mlcA.pamxctrl[i].Metrics));
356 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
361 /**************************************************************************
362 * mixerGetLineInfo [MMSYSTEM.805]
364 UINT16 WINAPI mixerGetLineInfo16(HMIXEROBJ16 hmix, LPMIXERLINE16 lpmli16,
370 TRACE("(%04x, %p, %08lx)\n", hmix, lpmli16, fdwInfo);
372 if (lpmli16 == NULL || lpmli16->cbStruct != sizeof(*lpmli16))
373 return MMSYSERR_INVALPARAM;
375 mliA.cbStruct = sizeof(mliA);
376 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
377 case MIXER_GETLINEINFOF_COMPONENTTYPE:
378 mliA.dwComponentType = lpmli16->dwComponentType;
380 case MIXER_GETLINEINFOF_DESTINATION:
381 mliA.dwDestination = lpmli16->dwDestination;
383 case MIXER_GETLINEINFOF_LINEID:
384 mliA.dwLineID = lpmli16->dwLineID;
386 case MIXER_GETLINEINFOF_SOURCE:
387 mliA.dwDestination = lpmli16->dwDestination;
388 mliA.dwSource = lpmli16->dwSource;
390 case MIXER_GETLINEINFOF_TARGETTYPE:
391 mliA.Target.dwType = lpmli16->Target.dwType;
392 mliA.Target.wMid = lpmli16->Target.wMid;
393 mliA.Target.wPid = lpmli16->Target.wPid;
394 mliA.Target.vDriverVersion = lpmli16->Target.vDriverVersion;
395 strcpy(mliA.Target.szPname, lpmli16->Target.szPname);
398 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo);
401 ret = mixerGetLineInfoA(HMIXEROBJ_32(hmix), &mliA, fdwInfo);
403 lpmli16->dwDestination = mliA.dwDestination;
404 lpmli16->dwSource = mliA.dwSource;
405 lpmli16->dwLineID = mliA.dwLineID;
406 lpmli16->fdwLine = mliA.fdwLine;
407 lpmli16->dwUser = mliA.dwUser;
408 lpmli16->dwComponentType = mliA.dwComponentType;
409 lpmli16->cChannels = mliA.cChannels;
410 lpmli16->cConnections = mliA.cConnections;
411 lpmli16->cControls = mliA.cControls;
412 strcpy(lpmli16->szShortName, mliA.szShortName);
413 strcpy(lpmli16->szName, mliA.szName);
414 lpmli16->Target.dwType = mliA.Target.dwType;
415 lpmli16->Target.dwDeviceID = mliA.Target.dwDeviceID;
416 lpmli16->Target.wMid = mliA.Target.wMid;
417 lpmli16->Target.wPid = mliA.Target.wPid;
418 lpmli16->Target.vDriverVersion = mliA.Target.vDriverVersion;
419 strcpy(lpmli16->Target.szPname, mliA.Target.szPname);
424 /**************************************************************************
425 * mixerSetControlDetails [MMSYSTEM.809]
427 UINT16 WINAPI mixerSetControlDetails16(HMIXEROBJ16 hmix,
428 LPMIXERCONTROLDETAILS16 lpmcd,
431 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
432 return MMSYSERR_NOTENABLED;
435 /**************************************************************************
436 * mixerMessage [MMSYSTEM.804]
438 DWORD WINAPI mixerMessage16(HMIXER16 hmix, UINT16 uMsg, DWORD dwParam1,
441 return mixerMessage(HMIXER_32(hmix), uMsg, dwParam1, dwParam2);
444 /**************************************************************************
445 * auxGetNumDevs [MMSYSTEM.350]
447 UINT16 WINAPI auxGetNumDevs16(void)
449 return MMDRV_GetNum(MMDRV_AUX);
452 /* ###################################################
454 * ###################################################
457 /**************************************************************************
458 * auxGetDevCaps [MMSYSTEM.351]
460 UINT16 WINAPI auxGetDevCaps16(UINT16 uDeviceID, LPAUXCAPS16 lpCaps, UINT16 uSize)
465 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
467 ret = auxGetDevCapsA(uDeviceID, &acA, sizeof(acA));
468 if (ret == MMSYSERR_NOERROR) {
470 ac16.wMid = acA.wMid;
471 ac16.wPid = acA.wPid;
472 ac16.vDriverVersion = acA.vDriverVersion;
473 strcpy(ac16.szPname, acA.szPname);
474 ac16.wTechnology = acA.wTechnology;
475 ac16.dwSupport = acA.dwSupport;
476 memcpy(lpCaps, &ac16, min(uSize, sizeof(ac16)));
481 /**************************************************************************
482 * auxGetVolume [MMSYSTEM.352]
484 UINT16 WINAPI auxGetVolume16(UINT16 uDeviceID, LPDWORD lpdwVolume)
488 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
490 if ((wmld = MMDRV_Get((HANDLE)(ULONG_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
491 return MMSYSERR_INVALHANDLE;
492 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
495 /**************************************************************************
496 * auxSetVolume [MMSYSTEM.353]
498 UINT16 WINAPI auxSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
502 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
504 if ((wmld = MMDRV_Get((HANDLE)(ULONG_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
505 return MMSYSERR_INVALHANDLE;
506 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
509 /**************************************************************************
510 * auxOutMessage [MMSYSTEM.354]
512 DWORD WINAPI auxOutMessage16(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
516 TRACE("(%04X, %04X, %08lX, %08lX)\n", uDeviceID, uMessage, dw1, dw2);
519 case AUXDM_GETNUMDEVS:
520 case AUXDM_SETVOLUME:
521 /* no argument conversion needed */
523 case AUXDM_GETVOLUME:
524 return auxGetVolume16(uDeviceID, MapSL(dw1));
525 case AUXDM_GETDEVCAPS:
526 return auxGetDevCaps16(uDeviceID, MapSL(dw1), dw2);
528 TRACE("(%04x, %04x, %08lx, %08lx): unhandled message\n",
529 uDeviceID, uMessage, dw1, dw2);
532 if ((wmld = MMDRV_Get((HANDLE)(ULONG_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
533 return MMSYSERR_INVALHANDLE;
535 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
538 /* ###################################################
540 * ###################################################
543 /**************************************************************************
544 * mciGetErrorString [MMSYSTEM.706]
546 BOOL16 WINAPI mciGetErrorString16(DWORD wError, LPSTR lpstrBuffer, UINT16 uLength)
548 return mciGetErrorStringA(wError, lpstrBuffer, uLength);
551 /**************************************************************************
552 * mciDriverNotify [MMSYSTEM.711]
554 BOOL16 WINAPI mciDriverNotify16(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
556 TRACE("(%04X, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
558 return PostMessageA(HWND_32(hWndCallBack), MM_MCINOTIFY, wStatus, wDevID);
561 /**************************************************************************
562 * mciGetDriverData [MMSYSTEM.708]
564 DWORD WINAPI mciGetDriverData16(UINT16 uDeviceID)
566 return mciGetDriverData(uDeviceID);
569 /**************************************************************************
570 * mciSetDriverData [MMSYSTEM.707]
572 BOOL16 WINAPI mciSetDriverData16(UINT16 uDeviceID, DWORD data)
574 return mciSetDriverData(uDeviceID, data);
577 /**************************************************************************
578 * mciSendCommand [MMSYSTEM.701]
580 DWORD WINAPI mciSendCommand16(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
584 TRACE("(%04X, %s, %08lX, %08lX)\n",
585 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
587 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, FALSE);
588 dwRet = MCI_CleanUp(dwRet, wMsg, (DWORD)MapSL(dwParam2));
589 TRACE("=> %ld\n", dwRet);
593 /**************************************************************************
594 * mciGetDeviceID [MMSYSTEM.703]
596 UINT16 WINAPI mciGetDeviceID16(LPCSTR lpstrName)
598 TRACE("(\"%s\")\n", lpstrName);
600 return mciGetDeviceIDA(lpstrName);
603 /**************************************************************************
604 * mciSetYieldProc [MMSYSTEM.714]
606 BOOL16 WINAPI mciSetYieldProc16(UINT16 uDeviceID, YIELDPROC16 fpYieldProc, DWORD dwYieldData)
608 LPWINE_MCIDRIVER wmd;
610 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
612 if (!(wmd = MCI_GetDriver(uDeviceID))) {
613 WARN("Bad uDeviceID\n");
617 wmd->lpfnYieldProc = (YIELDPROC)fpYieldProc;
618 wmd->dwYieldData = dwYieldData;
624 /**************************************************************************
625 * mciGetDeviceIDFromElementID [MMSYSTEM.715]
627 UINT16 WINAPI mciGetDeviceIDFromElementID16(DWORD dwElementID, LPCSTR lpstrType)
629 FIXME("(%lu, %s) stub\n", dwElementID, lpstrType);
633 /**************************************************************************
634 * mciGetYieldProc [MMSYSTEM.716]
636 YIELDPROC16 WINAPI mciGetYieldProc16(UINT16 uDeviceID, DWORD* lpdwYieldData)
638 LPWINE_MCIDRIVER wmd;
640 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
642 if (!(wmd = MCI_GetDriver(uDeviceID))) {
643 WARN("Bad uDeviceID\n");
646 if (!wmd->lpfnYieldProc) {
647 WARN("No proc set\n");
651 WARN("Proc is 32 bit\n");
654 return (YIELDPROC16)wmd->lpfnYieldProc;
657 /**************************************************************************
658 * mciGetCreatorTask [MMSYSTEM.717]
660 HTASK16 WINAPI mciGetCreatorTask16(UINT16 uDeviceID)
662 LPWINE_MCIDRIVER wmd;
665 if ((wmd = MCI_GetDriver(uDeviceID)))
666 ret = HTASK_16(wmd->CreatorThread);
668 TRACE("(%u) => %04x\n", uDeviceID, ret);
672 /**************************************************************************
673 * mciDriverYield [MMSYSTEM.710]
675 UINT16 WINAPI mciDriverYield16(UINT16 uDeviceID)
677 LPWINE_MCIDRIVER wmd;
680 /* TRACE("(%04x)\n", uDeviceID); */
682 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || wmd->bIs32) {
685 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
691 /* ###################################################
693 * ###################################################
696 /**************************************************************************
697 * midiOutGetNumDevs [MMSYSTEM.201]
699 UINT16 WINAPI midiOutGetNumDevs16(void)
701 return MMDRV_GetNum(MMDRV_MIDIOUT);
704 /**************************************************************************
705 * midiOutGetDevCaps [MMSYSTEM.202]
707 UINT16 WINAPI midiOutGetDevCaps16(UINT16 uDeviceID, LPMIDIOUTCAPS16 lpCaps,
713 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
715 ret = midiOutGetDevCapsA(uDeviceID, &mocA, sizeof(mocA));
716 if (ret == MMSYSERR_NOERROR) {
718 moc16.wMid = mocA.wMid;
719 moc16.wPid = mocA.wPid;
720 moc16.vDriverVersion = mocA.vDriverVersion;
721 strcpy(moc16.szPname, mocA.szPname);
722 moc16.wTechnology = mocA.wTechnology;
723 moc16.wVoices = mocA.wVoices;
724 moc16.wNotes = mocA.wNotes;
725 moc16.wChannelMask = mocA.wChannelMask;
726 moc16.dwSupport = mocA.dwSupport;
727 memcpy(lpCaps, &moc16, min(uSize, sizeof(moc16)));
732 /**************************************************************************
733 * midiOutGetErrorText [MMSYSTEM.203]
734 * midiInGetErrorText [MMSYSTEM.203]
736 UINT16 WINAPI midiOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
738 return midiOutGetErrorTextA(uError, lpText, uSize);
741 /**************************************************************************
742 * midiOutOpen [MMSYSTEM.204]
744 UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID,
745 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
750 ret = MIDI_OutOpen(&hmo, uDeviceID, dwCallback, dwInstance, dwFlags, FALSE);
752 if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo);
756 /**************************************************************************
757 * midiOutClose [MMSYSTEM.205]
759 UINT16 WINAPI midiOutClose16(HMIDIOUT16 hMidiOut)
761 return midiOutClose(HMIDIOUT_32(hMidiOut));
764 /**************************************************************************
765 * midiOutPrepareHeader [MMSYSTEM.206]
767 UINT16 WINAPI midiOutPrepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
768 SEGPTR lpsegMidiOutHdr, /* [???] */
769 UINT16 uSize) /* [in] */
773 TRACE("(%04X, %08lx, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
775 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
776 return MMSYSERR_INVALHANDLE;
778 return MMDRV_Message(wmld, MODM_PREPARE, lpsegMidiOutHdr, uSize, FALSE);
781 /**************************************************************************
782 * midiOutUnprepareHeader [MMSYSTEM.207]
784 UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
785 SEGPTR lpsegMidiOutHdr, /* [???] */
786 UINT16 uSize) /* [in] */
789 LPMIDIHDR16 lpMidiOutHdr = MapSL(lpsegMidiOutHdr);
791 TRACE("(%04X, %08lx, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
793 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
794 return MMSYSERR_NOERROR;
797 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
798 return MMSYSERR_INVALHANDLE;
800 return MMDRV_Message(wmld, MODM_UNPREPARE, lpsegMidiOutHdr, uSize, FALSE);
803 /**************************************************************************
804 * midiOutShortMsg [MMSYSTEM.208]
806 UINT16 WINAPI midiOutShortMsg16(HMIDIOUT16 hMidiOut, DWORD dwMsg)
808 return midiOutShortMsg(HMIDIOUT_32(hMidiOut), dwMsg);
811 /**************************************************************************
812 * midiOutLongMsg [MMSYSTEM.209]
814 UINT16 WINAPI midiOutLongMsg16(HMIDIOUT16 hMidiOut, /* [in] */
815 LPMIDIHDR16 lpsegMidiOutHdr, /* [???] NOTE: SEGPTR */
816 UINT16 uSize) /* [in] */
820 TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
822 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
823 return MMSYSERR_INVALHANDLE;
825 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpsegMidiOutHdr, uSize, FALSE);
828 /**************************************************************************
829 * midiOutReset [MMSYSTEM.210]
831 UINT16 WINAPI midiOutReset16(HMIDIOUT16 hMidiOut)
833 return midiOutReset(HMIDIOUT_32(hMidiOut));
836 /**************************************************************************
837 * midiOutGetVolume [MMSYSTEM.211]
839 UINT16 WINAPI midiOutGetVolume16(UINT16 uDeviceID, DWORD* lpdwVolume)
841 return midiOutGetVolume(HMIDIOUT_32(uDeviceID), lpdwVolume);
844 /**************************************************************************
845 * midiOutSetVolume [MMSYSTEM.212]
847 UINT16 WINAPI midiOutSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
849 return midiOutSetVolume(HMIDIOUT_32(uDeviceID), dwVolume);
852 /**************************************************************************
853 * midiOutCachePatches [MMSYSTEM.213]
855 UINT16 WINAPI midiOutCachePatches16(HMIDIOUT16 hMidiOut, UINT16 uBank,
856 WORD* lpwPatchArray, UINT16 uFlags)
858 return midiOutCachePatches(HMIDIOUT_32(hMidiOut), uBank, lpwPatchArray,
862 /**************************************************************************
863 * midiOutCacheDrumPatches [MMSYSTEM.214]
865 UINT16 WINAPI midiOutCacheDrumPatches16(HMIDIOUT16 hMidiOut, UINT16 uPatch,
866 WORD* lpwKeyArray, UINT16 uFlags)
868 return midiOutCacheDrumPatches(HMIDIOUT_32(hMidiOut), uPatch, lpwKeyArray, uFlags);
871 /**************************************************************************
872 * midiOutGetID [MMSYSTEM.215]
874 UINT16 WINAPI midiOutGetID16(HMIDIOUT16 hMidiOut, UINT16* lpuDeviceID)
878 TRACE("(%04X, %p)\n", hMidiOut, lpuDeviceID);
880 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
881 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
882 return MMSYSERR_INVALHANDLE;
884 *lpuDeviceID = wmld->uDeviceID;
885 return MMSYSERR_NOERROR;
888 /**************************************************************************
889 * midiOutMessage [MMSYSTEM.216]
891 DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage,
892 DWORD dwParam1, DWORD dwParam2)
896 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
898 if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
899 return MMSYSERR_INVALHANDLE;
904 FIXME("can't handle OPEN or CLOSE message!\n");
905 return MMSYSERR_NOTSUPPORTED;
908 return midiOutGetVolume16(hMidiOut, MapSL(dwParam1));
910 return midiOutLongMsg16(hMidiOut, MapSL(dwParam1), dwParam2);
912 /* lpMidiOutHdr is still a segmented pointer for this function */
913 return midiOutPrepareHeader16(hMidiOut, dwParam1, dwParam2);
915 return midiOutUnprepareHeader16(hMidiOut, dwParam1, dwParam2);
917 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
920 /**************************************************************************
921 * midiInGetNumDevs [MMSYSTEM.301]
923 UINT16 WINAPI midiInGetNumDevs16(void)
925 return MMDRV_GetNum(MMDRV_MIDIIN);
928 /**************************************************************************
929 * midiInGetDevCaps [MMSYSTEM.302]
931 UINT16 WINAPI midiInGetDevCaps16(UINT16 uDeviceID, LPMIDIINCAPS16 lpCaps,
937 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
939 ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
940 if (ret == MMSYSERR_NOERROR) {
942 mic16.wMid = micA.wMid;
943 mic16.wPid = micA.wPid;
944 mic16.vDriverVersion = micA.vDriverVersion;
945 strcpy(mic16.szPname, micA.szPname);
946 mic16.dwSupport = micA.dwSupport;
947 memcpy(lpCaps, &mic16, min(uSize, sizeof(mic16)));
952 /**************************************************************************
953 * midiInOpen [MMSYSTEM.304]
955 UINT16 WINAPI midiInOpen16(HMIDIIN16* lphMidiIn, UINT16 uDeviceID,
956 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
961 ret = MIDI_InOpen(&xhmid, uDeviceID, dwCallback, dwInstance, dwFlags, FALSE);
963 if (lphMidiIn) *lphMidiIn = HMIDIIN_16(xhmid);
967 /**************************************************************************
968 * midiInClose [MMSYSTEM.305]
970 UINT16 WINAPI midiInClose16(HMIDIIN16 hMidiIn)
972 return midiInClose(HMIDIIN_32(hMidiIn));
975 /**************************************************************************
976 * midiInPrepareHeader [MMSYSTEM.306]
978 UINT16 WINAPI midiInPrepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
979 SEGPTR lpsegMidiInHdr, /* [???] */
980 UINT16 uSize) /* [in] */
984 TRACE("(%04X, %08lx, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
986 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
987 return MMSYSERR_INVALHANDLE;
989 return MMDRV_Message(wmld, MIDM_PREPARE, lpsegMidiInHdr, uSize, FALSE);
992 /**************************************************************************
993 * midiInUnprepareHeader [MMSYSTEM.307]
995 UINT16 WINAPI midiInUnprepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
996 SEGPTR lpsegMidiInHdr, /* [???] */
997 UINT16 uSize) /* [in] */
1000 LPMIDIHDR16 lpMidiInHdr = MapSL(lpsegMidiInHdr);
1002 TRACE("(%04X, %08lx, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
1004 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1005 return MMSYSERR_NOERROR;
1008 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1009 return MMSYSERR_INVALHANDLE;
1011 return MMDRV_Message(wmld, MIDM_UNPREPARE, lpsegMidiInHdr, uSize, FALSE);
1014 /**************************************************************************
1015 * midiInAddBuffer [MMSYSTEM.308]
1017 UINT16 WINAPI midiInAddBuffer16(HMIDIIN16 hMidiIn, /* [in] */
1018 MIDIHDR16* lpsegMidiInHdr, /* [???] NOTE: SEGPTR */
1019 UINT16 uSize) /* [in] */
1023 TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
1025 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1026 return MMSYSERR_INVALHANDLE;
1028 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpsegMidiInHdr, uSize, FALSE);
1031 /**************************************************************************
1032 * midiInStart [MMSYSTEM.309]
1034 UINT16 WINAPI midiInStart16(HMIDIIN16 hMidiIn)
1036 return midiInStart(HMIDIIN_32(hMidiIn));
1039 /**************************************************************************
1040 * midiInStop [MMSYSTEM.310]
1042 UINT16 WINAPI midiInStop16(HMIDIIN16 hMidiIn)
1044 return midiInStop(HMIDIIN_32(hMidiIn));
1047 /**************************************************************************
1048 * midiInReset [MMSYSTEM.311]
1050 UINT16 WINAPI midiInReset16(HMIDIIN16 hMidiIn)
1052 return midiInReset(HMIDIIN_32(hMidiIn));
1055 /**************************************************************************
1056 * midiInGetID [MMSYSTEM.312]
1058 UINT16 WINAPI midiInGetID16(HMIDIIN16 hMidiIn, UINT16* lpuDeviceID)
1062 TRACE("(%04X, %p)\n", hMidiIn, lpuDeviceID);
1064 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1066 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, TRUE)) == NULL)
1067 return MMSYSERR_INVALHANDLE;
1069 *lpuDeviceID = wmld->uDeviceID;
1071 return MMSYSERR_NOERROR;
1074 /**************************************************************************
1075 * midiInMessage [MMSYSTEM.313]
1077 DWORD WINAPI midiInMessage16(HMIDIIN16 hMidiIn, UINT16 uMessage,
1078 DWORD dwParam1, DWORD dwParam2)
1082 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1087 FIXME("can't handle OPEN or CLOSE message!\n");
1088 return MMSYSERR_NOTSUPPORTED;
1090 case MIDM_GETDEVCAPS:
1091 return midiInGetDevCaps16(hMidiIn, MapSL(dwParam1), dwParam2);
1093 return midiInPrepareHeader16(hMidiIn, dwParam1, dwParam2);
1094 case MIDM_UNPREPARE:
1095 return midiInUnprepareHeader16(hMidiIn, dwParam1, dwParam2);
1096 case MIDM_ADDBUFFER:
1097 return midiInAddBuffer16(hMidiIn, MapSL(dwParam1), dwParam2);
1100 if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1101 return MMSYSERR_INVALHANDLE;
1103 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1106 /**************************************************************************
1107 * midiStreamClose [MMSYSTEM.252]
1109 MMRESULT16 WINAPI midiStreamClose16(HMIDISTRM16 hMidiStrm)
1111 return midiStreamClose(HMIDISTRM_32(hMidiStrm));
1114 /**************************************************************************
1115 * midiStreamOpen [MMSYSTEM.251]
1117 MMRESULT16 WINAPI midiStreamOpen16(HMIDISTRM16* phMidiStrm, LPUINT16 devid,
1118 DWORD cMidi, DWORD dwCallback,
1119 DWORD dwInstance, DWORD fdwOpen)
1121 HMIDISTRM hMidiStrm32;
1125 if (!phMidiStrm || !devid)
1126 return MMSYSERR_INVALPARAM;
1128 ret = MIDI_StreamOpen(&hMidiStrm32, &devid32, cMidi, dwCallback,
1129 dwInstance, fdwOpen, FALSE);
1130 *phMidiStrm = HMIDISTRM_16(hMidiStrm32);
1135 /**************************************************************************
1136 * midiStreamOut [MMSYSTEM.254]
1138 MMRESULT16 WINAPI midiStreamOut16(HMIDISTRM16 hMidiStrm, LPMIDIHDR16 lpMidiHdr, UINT16 cbMidiHdr)
1140 return midiStreamOut(HMIDISTRM_32(hMidiStrm), (LPMIDIHDR)lpMidiHdr,
1144 /**************************************************************************
1145 * midiStreamPause [MMSYSTEM.255]
1147 MMRESULT16 WINAPI midiStreamPause16(HMIDISTRM16 hMidiStrm)
1149 return midiStreamPause(HMIDISTRM_32(hMidiStrm));
1152 /**************************************************************************
1153 * midiStreamPosition [MMSYSTEM.253]
1155 MMRESULT16 WINAPI midiStreamPosition16(HMIDISTRM16 hMidiStrm, LPMMTIME16 lpmmt16, UINT16 cbmmt)
1161 return MMSYSERR_INVALPARAM;
1162 MMSYSTEM_MMTIME16to32(&mmt32, lpmmt16);
1163 ret = midiStreamPosition(HMIDISTRM_32(hMidiStrm), &mmt32, sizeof(MMTIME));
1164 MMSYSTEM_MMTIME32to16(lpmmt16, &mmt32);
1168 /**************************************************************************
1169 * midiStreamProperty [MMSYSTEM.250]
1171 MMRESULT16 WINAPI midiStreamProperty16(HMIDISTRM16 hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1173 return midiStreamProperty(HMIDISTRM_32(hMidiStrm), lpPropData, dwProperty);
1176 /**************************************************************************
1177 * midiStreamRestart [MMSYSTEM.256]
1179 MMRESULT16 WINAPI midiStreamRestart16(HMIDISTRM16 hMidiStrm)
1181 return midiStreamRestart(HMIDISTRM_32(hMidiStrm));
1184 /**************************************************************************
1185 * midiStreamStop [MMSYSTEM.257]
1187 MMRESULT16 WINAPI midiStreamStop16(HMIDISTRM16 hMidiStrm)
1189 return midiStreamStop(HMIDISTRM_32(hMidiStrm));
1192 /* ###################################################
1194 * ###################################################
1197 /**************************************************************************
1198 * waveOutGetNumDevs [MMSYSTEM.401]
1200 UINT16 WINAPI waveOutGetNumDevs16(void)
1202 return MMDRV_GetNum(MMDRV_WAVEOUT);
1205 /**************************************************************************
1206 * waveOutGetDevCaps [MMSYSTEM.402]
1208 UINT16 WINAPI waveOutGetDevCaps16(UINT16 uDeviceID,
1209 LPWAVEOUTCAPS16 lpCaps, UINT16 uSize)
1213 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
1215 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1217 ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
1218 if (ret == MMSYSERR_NOERROR) {
1219 WAVEOUTCAPS16 woc16;
1220 woc16.wMid = wocA.wMid;
1221 woc16.wPid = wocA.wPid;
1222 woc16.vDriverVersion = wocA.vDriverVersion;
1223 strcpy(woc16.szPname, wocA.szPname);
1224 woc16.dwFormats = wocA.dwFormats;
1225 woc16.wChannels = wocA.wChannels;
1226 woc16.dwSupport = wocA.dwSupport;
1227 memcpy(lpCaps, &woc16, min(uSize, sizeof(woc16)));
1232 /**************************************************************************
1233 * waveOutGetErrorText [MMSYSTEM.403]
1234 * waveInGetErrorText [MMSYSTEM.403]
1236 UINT16 WINAPI waveOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
1238 return waveOutGetErrorTextA(uError, lpText, uSize);
1241 /**************************************************************************
1242 * waveOutOpen [MMSYSTEM.404]
1244 UINT16 WINAPI waveOutOpen16(HWAVEOUT16* lphWaveOut, UINT16 uDeviceID,
1245 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
1246 DWORD dwInstance, DWORD dwFlags)
1251 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1252 * call the 32 bit version
1253 * however, we need to promote correctly the wave mapper id
1254 * (0xFFFFFFFF and not 0x0000FFFF)
1256 ret = WAVE_Open(&hWaveOut, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1257 MMDRV_WAVEOUT, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1259 if (lphWaveOut != NULL) *lphWaveOut = HWAVEOUT_16(hWaveOut);
1263 /**************************************************************************
1264 * waveOutClose [MMSYSTEM.405]
1266 UINT16 WINAPI waveOutClose16(HWAVEOUT16 hWaveOut)
1271 ReleaseThunkLock(&level);
1272 ret = waveOutClose(HWAVEOUT_32(hWaveOut));
1273 RestoreThunkLock(level);
1277 /**************************************************************************
1278 * waveOutPrepareHeader [MMSYSTEM.406]
1280 UINT16 WINAPI waveOutPrepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1281 SEGPTR lpsegWaveOutHdr, /* [???] */
1282 UINT16 uSize) /* [in] */
1285 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1287 TRACE("(%04X, %08lx, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1289 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
1291 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1292 return MMSYSERR_INVALHANDLE;
1294 return MMDRV_Message(wmld, WODM_PREPARE, lpsegWaveOutHdr, uSize, FALSE);
1297 /**************************************************************************
1298 * waveOutUnprepareHeader [MMSYSTEM.407]
1300 UINT16 WINAPI waveOutUnprepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1301 SEGPTR lpsegWaveOutHdr, /* [???] */
1302 UINT16 uSize) /* [in] */
1305 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1307 TRACE("(%04X, %08lx, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1309 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
1310 return MMSYSERR_NOERROR;
1313 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1314 return MMSYSERR_INVALHANDLE;
1316 return MMDRV_Message(wmld, WODM_UNPREPARE, lpsegWaveOutHdr, uSize, FALSE);
1319 /**************************************************************************
1320 * waveOutWrite [MMSYSTEM.408]
1322 UINT16 WINAPI waveOutWrite16(HWAVEOUT16 hWaveOut, /* [in] */
1323 LPWAVEHDR lpsegWaveOutHdr, /* [???] NOTE: SEGPTR */
1324 UINT16 uSize) /* [in] */
1328 TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1330 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1331 return MMSYSERR_INVALHANDLE;
1333 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpsegWaveOutHdr, uSize, FALSE);
1336 /**************************************************************************
1337 * waveOutBreakLoop [MMSYSTEM.419]
1339 UINT16 WINAPI waveOutBreakLoop16(HWAVEOUT16 hWaveOut16)
1344 ReleaseThunkLock(&level);
1345 ret = waveOutBreakLoop(HWAVEOUT_32(hWaveOut16));
1346 RestoreThunkLock(level);
1350 /**************************************************************************
1351 * waveOutPause [MMSYSTEM.409]
1353 UINT16 WINAPI waveOutPause16(HWAVEOUT16 hWaveOut16)
1358 ReleaseThunkLock(&level);
1359 ret = waveOutPause(HWAVEOUT_32(hWaveOut16));
1360 RestoreThunkLock(level);
1364 /**************************************************************************
1365 * waveOutReset [MMSYSTEM.411]
1367 UINT16 WINAPI waveOutReset16(HWAVEOUT16 hWaveOut16)
1372 ReleaseThunkLock(&level);
1373 ret = waveOutReset(HWAVEOUT_32(hWaveOut16));
1374 RestoreThunkLock(level);
1378 /**************************************************************************
1379 * waveOutRestart [MMSYSTEM.410]
1381 UINT16 WINAPI waveOutRestart16(HWAVEOUT16 hWaveOut16)
1386 ReleaseThunkLock(&level);
1387 ret = waveOutRestart(HWAVEOUT_32(hWaveOut16));
1388 RestoreThunkLock(level);
1392 /**************************************************************************
1393 * waveOutGetPosition [MMSYSTEM.412]
1395 UINT16 WINAPI waveOutGetPosition16(HWAVEOUT16 hWaveOut, LPMMTIME16 lpTime,
1401 mmt.wType = lpTime->wType;
1402 ret = waveOutGetPosition(HWAVEOUT_32(hWaveOut), &mmt, sizeof(mmt));
1403 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1407 /**************************************************************************
1408 * waveOutGetPitch [MMSYSTEM.413]
1410 UINT16 WINAPI waveOutGetPitch16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1412 return waveOutGetPitch(HWAVEOUT_32(hWaveOut16), lpdw);
1415 /**************************************************************************
1416 * waveOutSetPitch [MMSYSTEM.414]
1418 UINT16 WINAPI waveOutSetPitch16(HWAVEOUT16 hWaveOut16, DWORD dw)
1420 return waveOutSetPitch(HWAVEOUT_32(hWaveOut16), dw);
1423 /**************************************************************************
1424 * waveOutGetPlaybackRate [MMSYSTEM.417]
1426 UINT16 WINAPI waveOutGetPlaybackRate16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1428 return waveOutGetPlaybackRate(HWAVEOUT_32(hWaveOut16), lpdw);
1431 /**************************************************************************
1432 * waveOutSetPlaybackRate [MMSYSTEM.418]
1434 UINT16 WINAPI waveOutSetPlaybackRate16(HWAVEOUT16 hWaveOut16, DWORD dw)
1436 return waveOutSetPlaybackRate(HWAVEOUT_32(hWaveOut16), dw);
1439 /**************************************************************************
1440 * waveOutGetVolume [MMSYSTEM.415]
1442 UINT16 WINAPI waveOutGetVolume16(UINT16 devid, LPDWORD lpdw)
1444 return waveOutGetVolume(HWAVEOUT_32(devid), lpdw);
1447 /**************************************************************************
1448 * waveOutSetVolume [MMSYSTEM.416]
1450 UINT16 WINAPI waveOutSetVolume16(UINT16 devid, DWORD dw)
1452 return waveOutSetVolume(HWAVEOUT_32(devid), dw);
1455 /**************************************************************************
1456 * waveOutGetID [MMSYSTEM.420]
1458 UINT16 WINAPI waveOutGetID16(HWAVEOUT16 hWaveOut, UINT16* lpuDeviceID)
1462 TRACE("(%04X, %p);\n", hWaveOut, lpuDeviceID);
1464 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1466 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1467 return MMSYSERR_INVALHANDLE;
1469 *lpuDeviceID = wmld->uDeviceID;
1473 /**************************************************************************
1474 * waveOutMessage [MMSYSTEM.421]
1476 DWORD WINAPI waveOutMessage16(HWAVEOUT16 hWaveOut, UINT16 uMessage,
1477 DWORD dwParam1, DWORD dwParam2)
1481 TRACE("(%04x, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
1483 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL) {
1484 if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, TRUE)) != NULL) {
1485 if (uMessage == DRV_QUERYDRVENTRY || uMessage == DRV_QUERYDEVNODE)
1486 dwParam1 = (DWORD)MapSL(dwParam1);
1487 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1489 return MMSYSERR_INVALHANDLE;
1493 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1494 return MMSYSERR_INVALPARAM;
1496 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1499 /**************************************************************************
1500 * waveInGetNumDevs [MMSYSTEM.501]
1502 UINT16 WINAPI waveInGetNumDevs16(void)
1504 return MMDRV_GetNum(MMDRV_WAVEIN);
1507 /**************************************************************************
1508 * waveInGetDevCaps [MMSYSTEM.502]
1510 UINT16 WINAPI waveInGetDevCaps16(UINT16 uDeviceID, LPWAVEINCAPS16 lpCaps,
1516 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1518 ret = waveInGetDevCapsA(uDeviceID, &wicA, sizeof(wicA));
1519 if (ret == MMSYSERR_NOERROR) {
1521 wic16.wMid = wicA.wMid;
1522 wic16.wPid = wicA.wPid;
1523 wic16.vDriverVersion = wicA.vDriverVersion;
1524 strcpy(wic16.szPname, wicA.szPname);
1525 wic16.dwFormats = wicA.dwFormats;
1526 wic16.wChannels = wicA.wChannels;
1527 memcpy(lpCaps, &wic16, min(uSize, sizeof(wic16)));
1532 /**************************************************************************
1533 * waveInOpen [MMSYSTEM.504]
1535 UINT16 WINAPI waveInOpen16(HWAVEIN16* lphWaveIn, UINT16 uDeviceID,
1536 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
1537 DWORD dwInstance, DWORD dwFlags)
1542 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1543 * call the 32 bit version
1544 * however, we need to promote correctly the wave mapper id
1545 * (0xFFFFFFFF and not 0x0000FFFF)
1547 ret = WAVE_Open(&hWaveIn, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1548 MMDRV_WAVEIN, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1550 if (lphWaveIn != NULL) *lphWaveIn = HWAVEIN_16(hWaveIn);
1554 /**************************************************************************
1555 * waveInClose [MMSYSTEM.505]
1557 UINT16 WINAPI waveInClose16(HWAVEIN16 hWaveIn)
1562 ReleaseThunkLock(&level);
1563 ret = waveInClose(HWAVEIN_32(hWaveIn));
1564 RestoreThunkLock(level);
1568 /**************************************************************************
1569 * waveInPrepareHeader [MMSYSTEM.506]
1571 UINT16 WINAPI waveInPrepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1572 SEGPTR lpsegWaveInHdr, /* [???] */
1573 UINT16 uSize) /* [in] */
1576 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1579 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
1581 if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
1582 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1583 return MMSYSERR_INVALHANDLE;
1585 lpWaveInHdr->dwBytesRecorded = 0;
1587 ret = MMDRV_Message(wmld, WIDM_PREPARE, lpsegWaveInHdr, uSize, FALSE);
1591 /**************************************************************************
1592 * waveInUnprepareHeader [MMSYSTEM.507]
1594 UINT16 WINAPI waveInUnprepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1595 SEGPTR lpsegWaveInHdr, /* [???] */
1596 UINT16 uSize) /* [in] */
1599 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1601 TRACE("(%04X, %08lx, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1603 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1605 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
1606 return MMSYSERR_NOERROR;
1609 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1610 return MMSYSERR_INVALHANDLE;
1612 return MMDRV_Message(wmld, WIDM_UNPREPARE, lpsegWaveInHdr, uSize, FALSE);
1615 /**************************************************************************
1616 * waveInAddBuffer [MMSYSTEM.508]
1618 UINT16 WINAPI waveInAddBuffer16(HWAVEIN16 hWaveIn, /* [in] */
1619 WAVEHDR* lpsegWaveInHdr, /* [???] NOTE: SEGPTR */
1620 UINT16 uSize) /* [in] */
1624 TRACE("(%04X, %p, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1626 if (lpsegWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1627 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1628 return MMSYSERR_INVALHANDLE;
1630 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpsegWaveInHdr, uSize, FALSE);
1633 /**************************************************************************
1634 * waveInReset [MMSYSTEM.511]
1636 UINT16 WINAPI waveInReset16(HWAVEIN16 hWaveIn16)
1641 ReleaseThunkLock(&level);
1642 ret = waveInReset(HWAVEIN_32(hWaveIn16));
1643 RestoreThunkLock(level);
1647 /**************************************************************************
1648 * waveInStart [MMSYSTEM.509]
1650 UINT16 WINAPI waveInStart16(HWAVEIN16 hWaveIn16)
1655 ReleaseThunkLock(&level);
1656 ret = waveInStart(HWAVEIN_32(hWaveIn16));
1657 RestoreThunkLock(level);
1661 /**************************************************************************
1662 * waveInStop [MMSYSTEM.510]
1664 UINT16 WINAPI waveInStop16(HWAVEIN16 hWaveIn16)
1669 ReleaseThunkLock(&level);
1670 ret = waveInStop(HWAVEIN_32(hWaveIn16));
1671 RestoreThunkLock(level);
1675 /**************************************************************************
1676 * waveInGetPosition [MMSYSTEM.512]
1678 UINT16 WINAPI waveInGetPosition16(HWAVEIN16 hWaveIn, LPMMTIME16 lpTime,
1684 mmt.wType = lpTime->wType;
1685 ret = waveInGetPosition(HWAVEIN_32(hWaveIn), &mmt, sizeof(mmt));
1686 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1690 /**************************************************************************
1691 * waveInGetID [MMSYSTEM.513]
1693 UINT16 WINAPI waveInGetID16(HWAVEIN16 hWaveIn, UINT16* lpuDeviceID)
1697 TRACE("(%04X, %p);\n", hWaveIn, lpuDeviceID);
1699 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1701 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1702 return MMSYSERR_INVALHANDLE;
1704 *lpuDeviceID = wmld->uDeviceID;
1705 return MMSYSERR_NOERROR;
1708 /**************************************************************************
1709 * waveInMessage [MMSYSTEM.514]
1711 DWORD WINAPI waveInMessage16(HWAVEIN16 hWaveIn, UINT16 uMessage,
1712 DWORD dwParam1, DWORD dwParam2)
1716 TRACE("(%04x, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
1718 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL) {
1719 if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, TRUE)) != NULL) {
1720 if (uMessage == DRV_QUERYDRVENTRY || uMessage == DRV_QUERYDEVNODE)
1721 dwParam1 = (DWORD)MapSL(dwParam1);
1722 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1724 return MMSYSERR_INVALHANDLE;
1728 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1729 return MMSYSERR_INVALPARAM;
1731 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1734 /* ###################################################
1736 * ###################################################
1739 /*#define USE_MM_TSK_WINE*/
1741 /**************************************************************************
1742 * mmTaskCreate [MMSYSTEM.900]
1744 * Creates a 16 bit MM task. It's entry point is lpFunc, and it should be
1745 * called upon creation with dwPmt as parameter.
1747 HINSTANCE16 WINAPI mmTaskCreate16(SEGPTR spProc, HINSTANCE16 *lphMmTask, DWORD dwPmt)
1752 DWORD showCmd = 0x40002;
1755 TRACE("(%08lx, %p, %08lx);\n", spProc, lphMmTask, dwPmt);
1756 /* This to work requires NE modules to be started with a binary command line
1757 * which is not currently the case. A patch exists but has never been committed.
1758 * A workaround would be to integrate code for mmtask.tsk into Wine, but
1759 * this requires tremendous work (starting with patching tools/build to
1760 * create NE executables (and not only DLLs) for builtins modules.
1763 FIXME("This is currently broken. It will fail\n");
1766 *(LPDWORD)(cmdline + 1) = (DWORD)spProc;
1767 *(LPDWORD)(cmdline + 5) = dwPmt;
1768 *(LPDWORD)(cmdline + 9) = 0;
1770 lp.hEnvironment = 0;
1771 lp.cmdLine = MapLS(cmdline);
1772 lp.showCmd = MapLS(&showCmd);
1775 #ifndef USE_MM_TSK_WINE
1776 handle = LoadModule16("c:\\windows\\system\\mmtask.tsk", &lp);
1778 handle = LoadModule16("mmtask.tsk", &lp);
1781 ret = (handle) ? 1 : 2;
1787 *lphMmTask = handle;
1789 UnMapLS( lp.cmdLine );
1790 UnMapLS( lp.showCmd );
1791 TRACE("=> 0x%04x/%d\n", handle, ret);
1795 #ifdef USE_MM_TSK_WINE
1796 /* C equivalent to mmtask.tsk binary content */
1797 void mmTaskEntryPoint16(LPSTR cmdLine, WORD di, WORD si)
1799 int len = cmdLine[0x80];
1802 void (*fpProc)(DWORD) = MapSL(*((DWORD*)(cmdLine + 1)));
1803 DWORD dwPmt = *((DWORD*)(cmdLine + 5));
1806 InitTask16(); /* FIXME: pmts / from context ? */
1809 if (SetMessageQueue16(0x40)) {
1811 if (HIWORD(fpProc)) {
1813 /* EPP StackEnter16(); */
1825 /**************************************************************************
1826 * mmTaskBlock [MMSYSTEM.902]
1828 void WINAPI mmTaskBlock16(HINSTANCE16 hInst)
1833 GetMessageA(&msg, 0, 0, 0);
1835 TranslateMessage(&msg);
1836 DispatchMessageA(&msg);
1838 } while (msg.message < 0x3A0);
1841 /**************************************************************************
1842 * mmTaskSignal [MMSYSTEM.903]
1844 LRESULT WINAPI mmTaskSignal16(HTASK16 ht)
1846 TRACE("(%04x);\n", ht);
1847 return PostThreadMessageW( HTASK_32(ht), WM_USER, 0, 0 );
1850 /**************************************************************************
1851 * mmGetCurrentTask [MMSYSTEM.904]
1853 HTASK16 WINAPI mmGetCurrentTask16(void)
1855 return GetCurrentTask();
1858 /**************************************************************************
1859 * mmTaskYield [MMSYSTEM.905]
1861 void WINAPI mmTaskYield16(void)
1865 if (PeekMessageA(&msg, 0, 0, 0, 0)) {
1870 extern DWORD WINAPI GetProcessFlags(DWORD);
1872 /******************************************************************
1877 static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16 h)
1879 return (WINE_MMTHREAD*)MapSL( MAKESEGPTR(h, 0) );
1882 DWORD WINAPI WINE_mmThreadEntryPoint(LPVOID);
1884 /**************************************************************************
1885 * mmThreadCreate [MMSYSTEM.1120]
1888 * Creates a MM thread, calling fpThreadAddr(dwPmt).
1890 * bit.0 set means create a 16 bit task instead of thread calling a 16 bit proc
1891 * bit.1 set means to open a VxD for this thread (unsupported)
1893 LRESULT WINAPI mmThreadCreate16(FARPROC16 fpThreadAddr, LPHANDLE16 lpHndl, DWORD dwPmt, DWORD dwFlags)
1898 TRACE("(%p, %p, %08lx, %08lx)!\n", fpThreadAddr, lpHndl, dwPmt, dwFlags);
1900 hndl = GlobalAlloc16(sizeof(WINE_MMTHREAD), GMEM_SHARE|GMEM_ZEROINIT);
1905 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
1908 /* force mmtask routines even if mmthread is required */
1909 /* this will work only if the patch about binary cmd line and NE tasks
1915 lpMMThd->dwSignature = WINE_MMTHREAD_CREATED;
1916 lpMMThd->dwCounter = 0;
1917 lpMMThd->hThread = 0;
1918 lpMMThd->dwThreadID = 0;
1919 lpMMThd->fpThread = (DWORD)fpThreadAddr;
1920 lpMMThd->dwThreadPmt = dwPmt;
1921 lpMMThd->dwSignalCount = 0;
1922 lpMMThd->hEvent = 0;
1924 lpMMThd->dwStatus = 0;
1925 lpMMThd->dwFlags = dwFlags;
1928 if ((dwFlags & 1) == 0 && (GetProcessFlags(GetCurrentThreadId()) & 8) == 0) {
1929 lpMMThd->hEvent = CreateEventW(NULL, FALSE, TRUE, NULL);
1931 TRACE("Let's go crazy... trying new MM thread. lpMMThd=%p\n", lpMMThd);
1932 if (lpMMThd->dwFlags & 2) {
1933 /* as long as we don't support MM VxD in wine, we don't need
1934 * to care about this flag
1936 /* FIXME("Don't know how to properly open VxD handles\n"); */
1937 /* lpMMThd->hVxD = OpenVxDHandle(lpMMThd->hEvent); */
1940 lpMMThd->hThread = CreateThread(0, 0, WINE_mmThreadEntryPoint,
1941 (LPVOID)(DWORD_PTR)hndl, CREATE_SUSPENDED, &lpMMThd->dwThreadID);
1942 if (lpMMThd->hThread == 0) {
1943 WARN("Couldn't create thread\n");
1944 /* clean-up(VxDhandle...); devicedirectio... */
1945 if (lpMMThd->hEvent != 0)
1946 CloseHandle(lpMMThd->hEvent);
1949 TRACE("Got a nice thread hndl=%p id=0x%08lx\n", lpMMThd->hThread, lpMMThd->dwThreadID);
1953 /* get WINE_mmThreadEntryPoint()
1954 * 2047 is its ordinal in mmsystem.spec
1956 FARPROC16 fp = GetProcAddress16(GetModuleHandle16("MMSYSTEM"), (LPCSTR)2047);
1958 TRACE("farproc seg=0x%08lx lin=%p\n", (DWORD)fp, MapSL((SEGPTR)fp));
1960 ret = (fp == 0) ? 2 : mmTaskCreate16((DWORD)fp, 0, hndl);
1964 if (lpMMThd->hThread && !ResumeThread(lpMMThd->hThread))
1965 WARN("Couldn't resume thread\n");
1967 while (lpMMThd->dwStatus != 0x10) { /* test also HIWORD of dwStatus */
1981 TRACE("ok => %ld\n", ret);
1985 /**************************************************************************
1986 * mmThreadSignal [MMSYSTEM.1121]
1988 void WINAPI mmThreadSignal16(HANDLE16 hndl)
1990 TRACE("(%04x)!\n", hndl);
1993 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
1995 lpMMThd->dwCounter++;
1996 if (lpMMThd->hThread != 0) {
1997 InterlockedIncrement(&lpMMThd->dwSignalCount);
1998 SetEvent(lpMMThd->hEvent);
2000 mmTaskSignal16(lpMMThd->hTask);
2002 lpMMThd->dwCounter--;
2006 static void MMSYSTEM_ThreadBlock(WINE_MMTHREAD* lpMMThd)
2011 if (lpMMThd->dwThreadID != GetCurrentThreadId())
2012 ERR("Not called by thread itself\n");
2015 ResetEvent(lpMMThd->hEvent);
2016 if (InterlockedDecrement(&lpMMThd->dwSignalCount) >= 0)
2018 InterlockedIncrement(&lpMMThd->dwSignalCount);
2022 ret = MsgWaitForMultipleObjects(1, &lpMMThd->hEvent, FALSE, INFINITE, QS_ALLINPUT);
2024 case WAIT_OBJECT_0: /* Event */
2027 case WAIT_OBJECT_0 + 1: /* Msg */
2029 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
2030 TranslateMessage(&msg);
2031 DispatchMessageA(&msg);
2035 WARN("S2.x unsupported ret val 0x%08lx\n", ret);
2041 /**************************************************************************
2042 * mmThreadBlock [MMSYSTEM.1122]
2044 void WINAPI mmThreadBlock16(HANDLE16 hndl)
2046 TRACE("(%04x)!\n", hndl);
2049 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2051 if (lpMMThd->hThread != 0) {
2054 ReleaseThunkLock(&lc);
2055 MMSYSTEM_ThreadBlock(lpMMThd);
2056 RestoreThunkLock(lc);
2058 mmTaskBlock16(lpMMThd->hTask);
2064 /**************************************************************************
2065 * mmThreadIsCurrent [MMSYSTEM.1123]
2067 BOOL16 WINAPI mmThreadIsCurrent16(HANDLE16 hndl)
2071 TRACE("(%04x)!\n", hndl);
2073 if (hndl && mmThreadIsValid16(hndl)) {
2074 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2075 ret = (GetCurrentThreadId() == lpMMThd->dwThreadID);
2077 TRACE("=> %d\n", ret);
2081 /**************************************************************************
2082 * mmThreadIsValid [MMSYSTEM.1124]
2084 BOOL16 WINAPI mmThreadIsValid16(HANDLE16 hndl)
2088 TRACE("(%04x)!\n", hndl);
2091 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2093 if (!IsBadWritePtr(lpMMThd, sizeof(WINE_MMTHREAD)) &&
2094 lpMMThd->dwSignature == WINE_MMTHREAD_CREATED &&
2095 IsTask16(lpMMThd->hTask)) {
2096 lpMMThd->dwCounter++;
2097 if (lpMMThd->hThread != 0) {
2099 if (GetExitCodeThread(lpMMThd->hThread, &dwThreadRet) &&
2100 dwThreadRet == STATUS_PENDING) {
2106 lpMMThd->dwCounter--;
2109 TRACE("=> %d\n", ret);
2113 /**************************************************************************
2114 * mmThreadGetTask [MMSYSTEM.1125]
2116 HANDLE16 WINAPI mmThreadGetTask16(HANDLE16 hndl)
2120 TRACE("(%04x)\n", hndl);
2122 if (mmThreadIsValid16(hndl)) {
2123 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2124 ret = lpMMThd->hTask;
2129 /**************************************************************************
2130 * __wine_mmThreadEntryPoint (MMSYSTEM.2047)
2132 DWORD WINAPI WINE_mmThreadEntryPoint(LPVOID p)
2134 HANDLE16 hndl = (HANDLE16)(DWORD_PTR)p;
2135 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2137 TRACE("(%04x %p)\n", hndl, lpMMThd);
2139 lpMMThd->hTask = LOWORD(GetCurrentTask());
2140 TRACE("[10-%p] setting hTask to 0x%08x\n", lpMMThd->hThread, lpMMThd->hTask);
2141 lpMMThd->dwStatus = 0x10;
2142 MMSYSTEM_ThreadBlock(lpMMThd);
2143 TRACE("[20-%p]\n", lpMMThd->hThread);
2144 lpMMThd->dwStatus = 0x20;
2145 if (lpMMThd->fpThread) {
2146 WOWCallback16(lpMMThd->fpThread, lpMMThd->dwThreadPmt);
2148 lpMMThd->dwStatus = 0x30;
2149 TRACE("[30-%p]\n", lpMMThd->hThread);
2150 while (lpMMThd->dwCounter) {
2152 /* K32WOWYield16();*/
2154 TRACE("[XX-%p]\n", lpMMThd->hThread);
2156 lpMMThd->dwSignature = WINE_MMTHREAD_DELETED;
2157 /* close lpMMThread->hVxD directIO */
2158 if (lpMMThd->hEvent)
2159 CloseHandle(lpMMThd->hEvent);
2166 typedef BOOL16 (WINAPI *MMCPLCALLBACK)(HWND, LPCSTR, LPCSTR, LPCSTR);
2168 /**************************************************************************
2169 * mmShowMMCPLPropertySheet [MMSYSTEM.1150]
2171 BOOL16 WINAPI mmShowMMCPLPropertySheet16(HWND hWnd, LPCSTR lpStrDevice,
2172 LPCSTR lpStrTab, LPCSTR lpStrTitle)
2177 TRACE("(%p \"%s\" \"%s\" \"%s\")\n", hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2179 hndl = LoadLibraryA("MMSYS.CPL");
2181 MMCPLCALLBACK fp = (MMCPLCALLBACK)GetProcAddress(hndl, "ShowMMCPLPropertySheet");
2184 ReleaseThunkLock(&lc);
2185 ret = (fp)(hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2186 RestoreThunkLock(lc);
2194 /**************************************************************************
2195 * StackEnter [MMSYSTEM.32]
2197 void WINAPI StackEnter16(void)
2200 /* mmsystem.dll from Win 95 does only this: so does Wine */
2205 /**************************************************************************
2206 * StackLeave [MMSYSTEM.33]
2208 void WINAPI StackLeave16(void)
2211 /* mmsystem.dll from Win 95 does only this: so does Wine */
2216 /**************************************************************************
2217 * WMMMidiRunOnce [MMSYSTEM.8]
2219 void WINAPI WMMMidiRunOnce16(void)
2221 FIXME("(), stub!\n");
2224 /* ###################################################
2226 * ###################################################
2229 /**************************************************************************
2230 * DRIVER_MapMsg32To16 [internal]
2232 * Map a 32 bit driver message to a 16 bit driver message.
2234 static WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
2236 WINMM_MapType ret = WINMM_MAP_MSGERROR;
2243 case DRV_QUERYCONFIGURE:
2245 case DRV_EXITSESSION:
2246 case DRV_EXITAPPLICATION:
2248 case DRV_CLOSE: /* should be 0/0 */
2249 case DRV_OPEN: /* pass through */
2250 /* lParam1 and lParam2 are not used */
2255 /* lParam1 is a handle to a window (conf) or to a driver (inst) or not used,
2256 * lParam2 is a pointer to DRVCONFIGINFO
2259 LPDRVCONFIGINFO16 dci16 = HeapAlloc( GetProcessHeap(), 0, sizeof(*dci16) );
2260 LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2);
2263 LPSTR str1 = NULL,str2;
2265 dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
2267 if (dci32->lpszDCISectionName) {
2268 len = WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCISectionName, -1, NULL, 0, NULL, NULL );
2269 str1 = HeapAlloc( GetProcessHeap(), 0, len );
2271 WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCISectionName, -1, str1, len, NULL, NULL );
2272 dci16->lpszDCISectionName = MapLS( str1 );
2274 HeapFree( GetProcessHeap(), 0, dci16);
2275 return WINMM_MAP_NOMEM;
2278 dci16->lpszDCISectionName = 0L;
2280 if (dci32->lpszDCIAliasName) {
2281 len = WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCIAliasName, -1, NULL, 0, NULL, NULL );
2282 str2 = HeapAlloc( GetProcessHeap(), 0, len );
2284 WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCIAliasName, -1, str2, len, NULL, NULL );
2285 dci16->lpszDCIAliasName = MapLS( str2 );
2287 HeapFree( GetProcessHeap(), 0, str1);
2288 HeapFree( GetProcessHeap(), 0, dci16);
2289 return WINMM_MAP_NOMEM;
2292 dci16->lpszDCISectionName = 0L;
2295 return WINMM_MAP_NOMEM;
2297 *lParam2 = MapLS( dci16 );
2298 ret = WINMM_MAP_OKMEM;
2304 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2305 FIXME("Unknown message 0x%04x\n", wMsg);
2312 /**************************************************************************
2313 * DRIVER_UnMapMsg32To16 [internal]
2315 * UnMap a 32 bit driver message to a 16 bit driver message.
2317 static WINMM_MapType DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
2319 WINMM_MapType ret = WINMM_MAP_MSGERROR;
2326 case DRV_QUERYCONFIGURE:
2328 case DRV_EXITSESSION:
2329 case DRV_EXITAPPLICATION:
2333 /* lParam1 and lParam2 are not used */
2337 /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
2339 LPDRVCONFIGINFO16 dci16 = MapSL(lParam2);
2340 HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCISectionName) );
2341 HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCIAliasName) );
2343 UnMapLS( dci16->lpszDCISectionName );
2344 UnMapLS( dci16->lpszDCIAliasName );
2345 HeapFree( GetProcessHeap(), 0, dci16 );
2350 if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2351 FIXME("Unknown message 0x%04x\n", wMsg);
2358 /**************************************************************************
2359 * DRIVER_TryOpenDriver16 [internal]
2361 * Tries to load a 16 bit driver whose DLL's (module) name is lpFileName.
2363 static LPWINE_DRIVER DRIVER_OpenDriver16(LPCWSTR fn, LPCWSTR sn, LPARAM lParam2)
2365 LPWINE_DRIVER lpDrv = NULL;
2366 LPCSTR cause = NULL;
2367 LPSTR fnA = NULL, snA = NULL;
2370 TRACE("(%s, %s, %08lX);\n", debugstr_w(fn), debugstr_w(sn), lParam2);
2372 lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
2373 if (lpDrv == NULL) {cause = "OOM"; goto exit;}
2377 len = WideCharToMultiByte( CP_ACP, 0, fn, -1, NULL, 0, NULL, NULL );
2378 fnA = HeapAlloc(GetProcessHeap(), 0, len);
2379 if (fnA == NULL) {cause = "OOM"; goto exit;}
2380 WideCharToMultiByte( CP_ACP, 0, fn, -1, fnA, len, NULL, NULL );
2385 len = WideCharToMultiByte( CP_ACP, 0, sn, -1, NULL, 0, NULL, NULL );
2386 snA = HeapAlloc(GetProcessHeap(), 0, len);
2387 if (snA == NULL) {cause = "OOM"; goto exit;}
2388 WideCharToMultiByte( CP_ACP, 0, sn, -1, snA, len, NULL, NULL );
2391 /* FIXME: shall we do some black magic here on sn ?
2392 * drivers32 => drivers
2396 lpDrv->d.d16.hDriver16 = OpenDriver16(fnA, snA, lParam2);
2397 if (lpDrv->d.d16.hDriver16 == 0) {cause = "Not a 16 bit driver"; goto exit;}
2398 lpDrv->dwFlags = WINE_GDF_16BIT;
2400 TRACE("=> %p\n", lpDrv);
2404 HeapFree(GetProcessHeap(), 0, lpDrv);
2405 HeapFree(GetProcessHeap(), 0, fnA);
2406 HeapFree(GetProcessHeap(), 0, snA);
2407 TRACE("Unable to load 16 bit module %s[%s]: %s\n",
2408 debugstr_w(fn), debugstr_w(sn), cause);
2412 /******************************************************************
2413 * DRIVER_SendMessage16
2417 static LRESULT DRIVER_SendMessage16(HDRVR16 hDrv16, UINT msg,
2418 LPARAM lParam1, LPARAM lParam2)
2423 TRACE("Before sdm16 call hDrv=%04x wMsg=%04x p1=%08lx p2=%08lx\n",
2424 hDrv16, msg, lParam1, lParam2);
2426 switch (map = DRIVER_MapMsg32To16(msg, &lParam1, &lParam2)) {
2427 case WINMM_MAP_OKMEM:
2429 ret = SendDriverMessage16(hDrv16, msg, lParam1, lParam2);
2430 if (map == WINMM_MAP_OKMEM)
2431 DRIVER_UnMapMsg32To16(msg, lParam1, lParam2);
2438 /******************************************************************
2439 * DRIVER_CloseDriver16
2443 static LRESULT DRIVER_CloseDriver16(HDRVR16 hDrv16, LPARAM lParam1, LPARAM lParam2)
2445 return CloseDriver16(hDrv16, lParam1, lParam2);
2448 /**************************************************************************
2449 * DrvOpen [MMSYSTEM.1100]
2451 HDRVR16 WINAPI DrvOpen16(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
2453 return OpenDriver16(lpDriverName, lpSectionName, lParam);
2456 /**************************************************************************
2457 * DrvClose [MMSYSTEM.1101]
2459 LRESULT WINAPI DrvClose16(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
2461 return CloseDriver16(hDrv, lParam1, lParam2);
2464 /**************************************************************************
2465 * DrvSendMessage [MMSYSTEM.1102]
2467 LRESULT WINAPI DrvSendMessage16(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
2470 return SendDriverMessage16(hDrv, msg, lParam1, lParam2);
2473 /**************************************************************************
2474 * DrvGetModuleHandle [MMSYSTEM.1103]
2476 HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
2478 return GetDriverModuleHandle16(hDrv);
2481 /**************************************************************************
2482 * DrvDefDriverProc [MMSYSTEM.1104]
2484 LRESULT WINAPI DrvDefDriverProc16(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg,
2485 DWORD dwParam1, DWORD dwParam2)
2487 return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
2490 /**************************************************************************
2491 * DriverProc [MMSYSTEM.6]
2493 LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
2494 DWORD dwParam1, DWORD dwParam2)
2496 TRACE("dwDevID=%08lx hDrv=%04x wMsg=%04x dwParam1=%08lx dwParam2=%08lx\n",
2497 dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2499 return DrvDefDriverProc16(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2502 /* ###################################################
2504 * ###################################################
2507 /******************************************************************
2508 * MMSYSTEM_MMTIME32to16
2512 void MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16, const MMTIME* mmt32)
2514 mmt16->wType = mmt32->wType;
2515 /* layout of rest is the same for 32/16,
2516 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
2518 memcpy(&(mmt16->u), &(mmt32->u), sizeof(mmt16->u));
2521 /******************************************************************
2522 * MMSYSTEM_MMTIME16to32
2526 void MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16)
2528 mmt32->wType = mmt16->wType;
2529 /* layout of rest is the same for 32/16,
2530 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
2532 memcpy(&(mmt32->u), &(mmt16->u), sizeof(mmt16->u));
2535 /**************************************************************************
2536 * timeGetSystemTime [MMSYSTEM.601]
2538 MMRESULT16 WINAPI timeGetSystemTime16(LPMMTIME16 lpTime, UINT16 wSize)
2540 if (wSize >= sizeof(*lpTime)) {
2541 lpTime->wType = TIME_MS;
2542 lpTime->u.ms = GetTickCount();
2544 TRACE("=> %lu\n", lpTime->u.ms);
2550 /**************************************************************************
2551 * timeSetEvent [MMSYSTEM.602]
2553 MMRESULT16 WINAPI timeSetEvent16(UINT16 wDelay, UINT16 wResol, LPTIMECALLBACK16 lpFunc,
2554 DWORD dwUser, UINT16 wFlags)
2556 if (wFlags & WINE_TIMER_IS32)
2557 WARN("Unknown windows flag... wine internally used.. ooch\n");
2559 return TIME_SetEventInternal(wDelay, wResol, (LPTIMECALLBACK)lpFunc,
2560 dwUser, wFlags & ~WINE_TIMER_IS32);
2563 /**************************************************************************
2564 * timeKillEvent [MMSYSTEM.603]
2566 MMRESULT16 WINAPI timeKillEvent16(UINT16 wID)
2568 return timeKillEvent(wID);
2571 /**************************************************************************
2572 * timeGetDevCaps [MMSYSTEM.604]
2574 MMRESULT16 WINAPI timeGetDevCaps16(LPTIMECAPS16 lpCaps, UINT16 wSize)
2578 TRACE("(%p, %u) !\n", lpCaps, wSize);
2580 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2582 ret = timeGetDevCaps(&caps, sizeof(caps));
2583 if (ret == MMSYSERR_NOERROR) {
2585 tc16.wPeriodMin = caps.wPeriodMin;
2586 tc16.wPeriodMax = caps.wPeriodMax;
2587 memcpy(lpCaps, &tc16, min(wSize, sizeof(tc16)));
2592 /**************************************************************************
2593 * timeBeginPeriod [MMSYSTEM.605]
2595 MMRESULT16 WINAPI timeBeginPeriod16(UINT16 wPeriod)
2597 TRACE("(%u) !\n", wPeriod);
2599 return timeBeginPeriod(wPeriod);
2602 /**************************************************************************
2603 * timeEndPeriod [MMSYSTEM.606]
2605 MMRESULT16 WINAPI timeEndPeriod16(UINT16 wPeriod)
2607 TRACE("(%u) !\n", wPeriod);
2609 return timeEndPeriod(wPeriod);
2612 /**************************************************************************
2613 * mciSendString [MMSYSTEM.702]
2615 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
2616 UINT16 uRetLen, HWND16 hwndCallback)
2618 return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback));
2621 /**************************************************************************
2622 * mciLoadCommandResource [MMSYSTEM.705]
2624 UINT16 WINAPI mciLoadCommandResource16(HINSTANCE16 hInst, LPCSTR resname, UINT16 type)
2630 unsigned pos = 0, size = 1024, len;
2634 UINT16 ret = MCIERR_OUT_OF_MEMORY;
2636 if (!(res = FindResource16( hInst, resname, (LPSTR)RT_RCDATA))) return MCI_NO_COMMAND_TABLE;
2637 if (!(handle = LoadResource16( hInst, res ))) return MCI_NO_COMMAND_TABLE;
2638 ptr16 = LockResource16(handle);
2639 /* converting the 16 bit resource table into a 32W one */
2640 if ((ptr32 = HeapAlloc(GetProcessHeap(), 0, size)))
2643 str = (LPCSTR)ptr16;
2644 ptr16 += strlen(str) + 1;
2645 flg = *(const DWORD*)ptr16;
2646 eid = *(const WORD*)(ptr16 + sizeof(DWORD));
2647 ptr16 += sizeof(DWORD) + sizeof(WORD);
2648 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) * sizeof(WCHAR);
2649 if (pos + len + sizeof(DWORD) + sizeof(WORD) > size)
2651 while (pos + len * sizeof(WCHAR) + sizeof(DWORD) + sizeof(WORD) > size) size += 1024;
2652 ptr32 = HeapReAlloc(GetProcessHeap(), 0, ptr32, size);
2653 if (!ptr32) goto the_end;
2655 MultiByteToWideChar(CP_ACP, 0, str, -1, (LPWSTR)(ptr32 + pos), len / sizeof(WCHAR));
2656 *(DWORD*)(ptr32 + pos + len) = flg;
2657 *(WORD*)(ptr32 + pos + len + sizeof(DWORD)) = eid;
2658 pos += len + sizeof(DWORD) + sizeof(WORD);
2659 } while (eid != MCI_END_COMMAND_LIST);
2662 FreeResource16( handle );
2663 if (ptr32) ret = MCI_SetCommandTable(ptr32, type);
2667 /**************************************************************************
2668 * mciFreeCommandResource [MMSYSTEM.713]
2670 BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
2672 TRACE("(%04x)!\n", uTable);
2674 return MCI_DeleteCommandTable(uTable, TRUE);
2677 /* ###################################################
2679 * ###################################################
2682 /****************************************************************
2683 * MMIO_Map32To16 [INTERNAL]
2685 static LRESULT MMIO_Map32To16(DWORD wMsg, LPARAM* lp1, LPARAM* lp2)
2695 case MMIOM_WRITEFLUSH:
2696 *lp1 = MapLS( (void *)*lp1 );
2699 *lp1 = MapLS( (void *)*lp1 );
2700 *lp2 = MapLS( (void *)*lp2 );
2703 if (wMsg < MMIOM_USER)
2704 TRACE("Not a mappable message (%ld)\n", wMsg);
2706 return MMSYSERR_NOERROR;
2709 /****************************************************************
2710 * MMIO_UnMap32To16 [INTERNAL]
2712 static LRESULT MMIO_UnMap32To16(DWORD wMsg, LPARAM lParam1, LPARAM lParam2,
2713 LPARAM lp1, LPARAM lp2)
2723 case MMIOM_WRITEFLUSH:
2731 if (wMsg < MMIOM_USER)
2732 TRACE("Not a mappable message (%ld)\n", wMsg);
2734 return MMSYSERR_NOERROR;
2737 /******************************************************************
2742 static LRESULT MMIO_Callback16(SEGPTR cb16, LPMMIOINFO lpmmioinfo, UINT uMessage,
2743 LPARAM lParam1, LPARAM lParam2)
2746 MMIOINFO16 mmioInfo16;
2747 SEGPTR segmmioInfo16;
2748 LPARAM lp1 = lParam1, lp2 = lParam2;
2751 memset(&mmioInfo16, 0, sizeof(MMIOINFO16));
2752 mmioInfo16.lDiskOffset = lpmmioinfo->lDiskOffset;
2753 mmioInfo16.adwInfo[0] = lpmmioinfo->adwInfo[0];
2754 mmioInfo16.adwInfo[1] = lpmmioinfo->adwInfo[1];
2755 mmioInfo16.adwInfo[2] = lpmmioinfo->adwInfo[2];
2756 /* map (lParam1, lParam2) into (lp1, lp2) 32=>16 */
2757 if ((result = MMIO_Map32To16(uMessage, &lp1, &lp2)) != MMSYSERR_NOERROR)
2760 segmmioInfo16 = MapLS(&mmioInfo16);
2761 args[6] = HIWORD(segmmioInfo16);
2762 args[5] = LOWORD(segmmioInfo16);
2764 args[3] = HIWORD(lp1);
2765 args[2] = LOWORD(lp1);
2766 args[1] = HIWORD(lp2);
2767 args[0] = LOWORD(lp2);
2768 WOWCallback16Ex( cb16, WCB16_PASCAL, sizeof(args), args, &result );
2769 UnMapLS(segmmioInfo16);
2770 MMIO_UnMap32To16(uMessage, lParam1, lParam2, lp1, lp2);
2772 lpmmioinfo->lDiskOffset = mmioInfo16.lDiskOffset;
2773 lpmmioinfo->adwInfo[0] = mmioInfo16.adwInfo[0];
2774 lpmmioinfo->adwInfo[1] = mmioInfo16.adwInfo[1];
2775 lpmmioinfo->adwInfo[2] = mmioInfo16.adwInfo[2];
2780 /******************************************************************
2781 * MMIO_ResetSegmentedData
2784 static LRESULT MMIO_SetSegmentedBuffer(HMMIO hmmio, SEGPTR ptr, BOOL release)
2788 if ((wm = MMIO_Get(hmmio)) == NULL)
2789 return MMSYSERR_INVALHANDLE;
2790 if (release) UnMapLS(wm->segBuffer16);
2791 wm->segBuffer16 = ptr;
2792 return MMSYSERR_NOERROR;
2795 /**************************************************************************
2796 * mmioOpen [MMSYSTEM.1210]
2798 HMMIO16 WINAPI mmioOpen16(LPSTR szFileName, MMIOINFO16* lpmmioinfo16,
2806 memset(&mmioinfo, 0, sizeof(mmioinfo));
2808 mmioinfo.dwFlags = lpmmioinfo16->dwFlags;
2809 mmioinfo.fccIOProc = lpmmioinfo16->fccIOProc;
2810 mmioinfo.pIOProc = (LPMMIOPROC)lpmmioinfo16->pIOProc;
2811 mmioinfo.cchBuffer = lpmmioinfo16->cchBuffer;
2812 mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo16->pchBuffer);
2813 mmioinfo.adwInfo[0] = lpmmioinfo16->adwInfo[0];
2814 /* if we don't have a file name, it's likely a passed open file descriptor */
2816 mmioinfo.adwInfo[0] = (DWORD)DosFileHandleToWin32Handle(mmioinfo.adwInfo[0]);
2817 mmioinfo.adwInfo[1] = lpmmioinfo16->adwInfo[1];
2818 mmioinfo.adwInfo[2] = lpmmioinfo16->adwInfo[2];
2820 ret = MMIO_Open(szFileName, &mmioinfo, dwOpenFlags, MMIO_PROC_16);
2821 MMIO_SetSegmentedBuffer(mmioinfo.hmmio, (SEGPTR)lpmmioinfo16->pchBuffer, FALSE);
2823 lpmmioinfo16->wErrorRet = mmioinfo.wErrorRet;
2824 lpmmioinfo16->hmmio = HMMIO_16(mmioinfo.hmmio);
2826 ret = MMIO_Open(szFileName, NULL, dwOpenFlags, MMIO_PROC_32A);
2828 return HMMIO_16(ret);
2831 /**************************************************************************
2832 * mmioClose [MMSYSTEM.1211]
2834 MMRESULT16 WINAPI mmioClose16(HMMIO16 hmmio, UINT16 uFlags)
2836 MMIO_SetSegmentedBuffer(HMMIO_32(hmmio), (SEGPTR)NULL, TRUE);
2837 return mmioClose(HMMIO_32(hmmio), uFlags);
2840 /**************************************************************************
2841 * mmioRead [MMSYSTEM.1212]
2843 LONG WINAPI mmioRead16(HMMIO16 hmmio, HPSTR pch, LONG cch)
2845 return mmioRead(HMMIO_32(hmmio), pch, cch);
2848 /**************************************************************************
2849 * mmioWrite [MMSYSTEM.1213]
2851 LONG WINAPI mmioWrite16(HMMIO16 hmmio, HPCSTR pch, LONG cch)
2853 return mmioWrite(HMMIO_32(hmmio),pch,cch);
2856 /**************************************************************************
2857 * mmioSeek [MMSYSTEM.1214]
2859 LONG WINAPI mmioSeek16(HMMIO16 hmmio, LONG lOffset, INT16 iOrigin)
2861 return mmioSeek(HMMIO_32(hmmio), lOffset, iOrigin);
2864 /**************************************************************************
2865 * mmioGetInfo [MMSYSTEM.1215]
2867 MMRESULT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2873 TRACE("(0x%04x,%p,0x%08x)\n", hmmio, lpmmioinfo, uFlags);
2875 if ((wm = MMIO_Get(HMMIO_32(hmmio))) == NULL)
2876 return MMSYSERR_INVALHANDLE;
2878 ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2879 if (ret != MMSYSERR_NOERROR) return ret;
2881 lpmmioinfo->dwFlags = mmioinfo.dwFlags;
2882 lpmmioinfo->fccIOProc = mmioinfo.fccIOProc;
2883 lpmmioinfo->pIOProc = (wm->ioProc->type == MMIO_PROC_16) ?
2884 (LPMMIOPROC16)wm->ioProc->pIOProc : NULL;
2885 lpmmioinfo->wErrorRet = mmioinfo.wErrorRet;
2886 lpmmioinfo->hTask = HTASK_16(mmioinfo.hTask);
2887 lpmmioinfo->cchBuffer = mmioinfo.cchBuffer;
2888 lpmmioinfo->pchBuffer = (void*)wm->segBuffer16;
2889 lpmmioinfo->pchNext = (void*)(wm->segBuffer16 + (mmioinfo.pchNext - mmioinfo.pchBuffer));
2890 lpmmioinfo->pchEndRead = (void*)(wm->segBuffer16 + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
2891 lpmmioinfo->pchEndWrite = (void*)(wm->segBuffer16 + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
2892 lpmmioinfo->lBufOffset = mmioinfo.lBufOffset;
2893 lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
2894 lpmmioinfo->adwInfo[0] = mmioinfo.adwInfo[0];
2895 lpmmioinfo->adwInfo[1] = mmioinfo.adwInfo[1];
2896 lpmmioinfo->adwInfo[2] = mmioinfo.adwInfo[2];
2897 lpmmioinfo->dwReserved1 = 0;
2898 lpmmioinfo->dwReserved2 = 0;
2899 lpmmioinfo->hmmio = HMMIO_16(mmioinfo.hmmio);
2901 return MMSYSERR_NOERROR;
2904 /**************************************************************************
2905 * mmioSetInfo [MMSYSTEM.1216]
2907 MMRESULT16 WINAPI mmioSetInfo16(HMMIO16 hmmio, const MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2912 TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
2914 ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, 0);
2915 if (ret != MMSYSERR_NOERROR) return ret;
2917 /* check if seg and lin buffers are the same */
2918 if (mmioinfo.cchBuffer != lpmmioinfo->cchBuffer ||
2919 mmioinfo.pchBuffer != MapSL((DWORD)lpmmioinfo->pchBuffer))
2920 return MMSYSERR_INVALPARAM;
2922 /* check pointers coherence */
2923 if (lpmmioinfo->pchNext < lpmmioinfo->pchBuffer ||
2924 lpmmioinfo->pchNext > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2925 lpmmioinfo->pchEndRead < lpmmioinfo->pchBuffer ||
2926 lpmmioinfo->pchEndRead > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2927 lpmmioinfo->pchEndWrite < lpmmioinfo->pchBuffer ||
2928 lpmmioinfo->pchEndWrite > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer)
2929 return MMSYSERR_INVALPARAM;
2931 mmioinfo.pchNext = mmioinfo.pchBuffer + (lpmmioinfo->pchNext - lpmmioinfo->pchBuffer);
2932 mmioinfo.pchEndRead = mmioinfo.pchBuffer + (lpmmioinfo->pchEndRead - lpmmioinfo->pchBuffer);
2933 mmioinfo.pchEndWrite = mmioinfo.pchBuffer + (lpmmioinfo->pchEndWrite - lpmmioinfo->pchBuffer);
2935 return mmioSetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2938 /**************************************************************************
2939 * mmioSetBuffer [MMSYSTEM.1217]
2941 MMRESULT16 WINAPI mmioSetBuffer16(HMMIO16 hmmio, LPSTR pchBuffer,
2942 LONG cchBuffer, UINT16 uFlags)
2944 MMRESULT ret = mmioSetBuffer(HMMIO_32(hmmio), MapSL((DWORD)pchBuffer),
2947 if (ret == MMSYSERR_NOERROR)
2948 MMIO_SetSegmentedBuffer(HMMIO_32(hmmio), (DWORD)pchBuffer, TRUE);
2950 UnMapLS((DWORD)pchBuffer);
2954 /**************************************************************************
2955 * mmioFlush [MMSYSTEM.1218]
2957 MMRESULT16 WINAPI mmioFlush16(HMMIO16 hmmio, UINT16 uFlags)
2959 return mmioFlush(HMMIO_32(hmmio), uFlags);
2962 /***********************************************************************
2963 * mmioAdvance [MMSYSTEM.1219]
2965 MMRESULT16 WINAPI mmioAdvance16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2970 /* WARNING: this heavily relies on mmioAdvance implementation (for choosing which
2975 mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo->pchBuffer);
2976 mmioinfo.pchNext = MapSL((DWORD)lpmmioinfo->pchNext);
2977 mmioinfo.dwFlags = lpmmioinfo->dwFlags;
2978 mmioinfo.lBufOffset = lpmmioinfo->lBufOffset;
2979 ret = mmioAdvance(HMMIO_32(hmmio), &mmioinfo, uFlags);
2982 ret = mmioAdvance(HMMIO_32(hmmio), NULL, uFlags);
2984 if (ret != MMSYSERR_NOERROR) return ret;
2988 lpmmioinfo->dwFlags = mmioinfo.dwFlags;
2989 lpmmioinfo->pchNext = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchNext - mmioinfo.pchBuffer));
2990 lpmmioinfo->pchEndRead = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
2991 lpmmioinfo->pchEndWrite = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
2992 lpmmioinfo->lBufOffset = mmioinfo.lBufOffset;
2993 lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
2996 return MMSYSERR_NOERROR;
2999 /**************************************************************************
3000 * mmioStringToFOURCC [MMSYSTEM.1220]
3002 FOURCC WINAPI mmioStringToFOURCC16(LPCSTR sz, UINT16 uFlags)
3004 return mmioStringToFOURCCA(sz, uFlags);
3007 /**************************************************************************
3008 * mmioInstallIOProc [MMSYSTEM.1221]
3010 LPMMIOPROC16 WINAPI mmioInstallIOProc16(FOURCC fccIOProc, LPMMIOPROC16 pIOProc,
3013 return (LPMMIOPROC16)MMIO_InstallIOProc(fccIOProc, (LPMMIOPROC)pIOProc,
3014 dwFlags, MMIO_PROC_16);
3017 /**************************************************************************
3018 * mmioSendMessage [MMSYSTEM.1222]
3020 LRESULT WINAPI mmioSendMessage16(HMMIO16 hmmio, UINT16 uMessage,
3021 LPARAM lParam1, LPARAM lParam2)
3023 return MMIO_SendMessage(HMMIO_32(hmmio), uMessage,
3024 lParam1, lParam2, MMIO_PROC_16);
3027 /**************************************************************************
3028 * mmioDescend [MMSYSTEM.1223]
3030 MMRESULT16 WINAPI mmioDescend16(HMMIO16 hmmio, LPMMCKINFO lpck,
3031 const MMCKINFO* lpckParent, UINT16 uFlags)
3033 return mmioDescend(HMMIO_32(hmmio), lpck, lpckParent, uFlags);
3036 /**************************************************************************
3037 * mmioAscend [MMSYSTEM.1224]
3039 MMRESULT16 WINAPI mmioAscend16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
3041 return mmioAscend(HMMIO_32(hmmio),lpck,uFlags);
3044 /**************************************************************************
3045 * mmioCreateChunk [MMSYSTEM.1225]
3047 MMRESULT16 WINAPI mmioCreateChunk16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
3049 return mmioCreateChunk(HMMIO_32(hmmio), lpck, uFlags);
3052 /**************************************************************************
3053 * mmioRename [MMSYSTEM.1226]
3055 MMRESULT16 WINAPI mmioRename16(LPCSTR szFileName, LPCSTR szNewFileName,
3056 MMIOINFO16* lpmmioinfo, DWORD dwRenameFlags)
3062 if (lpmmioinfo != NULL && lpmmioinfo->pIOProc != NULL &&
3063 lpmmioinfo->fccIOProc == 0) {
3064 FIXME("Can't handle this case yet\n");
3065 return MMSYSERR_ERROR;
3068 /* this is a bit hacky, but it'll work if we get a fourCC code or nothing.
3069 * but a non installed ioproc without a fourcc won't do
3071 if (lpmmioinfo && lpmmioinfo->fccIOProc && lpmmioinfo->pIOProc) {
3072 MMIO_InstallIOProc(lpmmioinfo->fccIOProc, (LPMMIOPROC)lpmmioinfo->pIOProc,
3073 MMIO_INSTALLPROC, MMIO_PROC_16);
3076 memset(&mmioinfo, 0, sizeof(mmioinfo));
3077 mmioinfo.fccIOProc = lpmmioinfo->fccIOProc;
3078 ret = mmioRenameA(szFileName, szNewFileName, &mmioinfo, dwRenameFlags);
3080 MMIO_InstallIOProc(lpmmioinfo->fccIOProc, NULL,
3081 MMIO_REMOVEPROC, MMIO_PROC_16);
3086 /* ###################################################
3088 * ###################################################
3091 /**************************************************************************
3092 * joyGetNumDevs [MMSYSTEM.101]
3094 UINT16 WINAPI joyGetNumDevs16(void)
3096 return joyGetNumDevs();
3099 /**************************************************************************
3100 * joyGetDevCaps [MMSYSTEM.102]
3102 MMRESULT16 WINAPI joyGetDevCaps16(UINT16 wID, LPJOYCAPS16 lpCaps, UINT16 wSize)
3107 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
3109 ret = joyGetDevCapsA(wID, &jca, sizeof(jca));
3111 if (ret != JOYERR_NOERROR) return ret;
3112 lpCaps->wMid = jca.wMid;
3113 lpCaps->wPid = jca.wPid;
3114 strcpy(lpCaps->szPname, jca.szPname);
3115 lpCaps->wXmin = jca.wXmin;
3116 lpCaps->wXmax = jca.wXmax;
3117 lpCaps->wYmin = jca.wYmin;
3118 lpCaps->wYmax = jca.wYmax;
3119 lpCaps->wZmin = jca.wZmin;
3120 lpCaps->wZmax = jca.wZmax;
3121 lpCaps->wNumButtons = jca.wNumButtons;
3122 lpCaps->wPeriodMin = jca.wPeriodMin;
3123 lpCaps->wPeriodMax = jca.wPeriodMax;
3125 if (wSize >= sizeof(JOYCAPS16)) { /* Win95 extensions ? */
3126 lpCaps->wRmin = jca.wRmin;
3127 lpCaps->wRmax = jca.wRmax;
3128 lpCaps->wUmin = jca.wUmin;
3129 lpCaps->wUmax = jca.wUmax;
3130 lpCaps->wVmin = jca.wVmin;
3131 lpCaps->wVmax = jca.wVmax;
3132 lpCaps->wCaps = jca.wCaps;
3133 lpCaps->wMaxAxes = jca.wMaxAxes;
3134 lpCaps->wNumAxes = jca.wNumAxes;
3135 lpCaps->wMaxButtons = jca.wMaxButtons;
3136 strcpy(lpCaps->szRegKey, jca.szRegKey);
3137 strcpy(lpCaps->szOEMVxD, jca.szOEMVxD);
3143 /**************************************************************************
3144 * joyGetPosEx [MMSYSTEM.110]
3146 MMRESULT16 WINAPI joyGetPosEx16(UINT16 wID, LPJOYINFOEX lpInfo)
3148 return joyGetPosEx(wID, lpInfo);
3151 /**************************************************************************
3152 * joyGetPos [MMSYSTEM.103]
3154 MMRESULT16 WINAPI joyGetPos16(UINT16 wID, LPJOYINFO16 lpInfo)
3159 TRACE("(%d, %p);\n", wID, lpInfo);
3161 if ((ret = joyGetPos(wID, &ji)) == JOYERR_NOERROR) {
3162 lpInfo->wXpos = ji.wXpos;
3163 lpInfo->wYpos = ji.wYpos;
3164 lpInfo->wZpos = ji.wZpos;
3165 lpInfo->wButtons = ji.wButtons;
3170 /**************************************************************************
3171 * joyGetThreshold [MMSYSTEM.104]
3173 MMRESULT16 WINAPI joyGetThreshold16(UINT16 wID, LPUINT16 lpThreshold)
3178 ret = joyGetThreshold(wID, &t);
3179 if (ret == JOYERR_NOERROR)
3184 /**************************************************************************
3185 * joyReleaseCapture [MMSYSTEM.105]
3187 MMRESULT16 WINAPI joyReleaseCapture16(UINT16 wID)
3189 return joyReleaseCapture(wID);
3192 /**************************************************************************
3193 * joySetCapture [MMSYSTEM.106]
3195 MMRESULT16 WINAPI joySetCapture16(HWND16 hWnd, UINT16 wID, UINT16 wPeriod, BOOL16 bChanged)
3197 return joySetCapture16(hWnd, wID, wPeriod, bChanged);
3200 /**************************************************************************
3201 * joySetThreshold [MMSYSTEM.107]
3203 MMRESULT16 WINAPI joySetThreshold16(UINT16 wID, UINT16 wThreshold)
3205 return joySetThreshold16(wID,wThreshold);
3208 /**************************************************************************
3209 * joySetCalibration [MMSYSTEM.109]
3211 MMRESULT16 WINAPI joySetCalibration16(UINT16 wID)
3213 FIXME("(%04X): stub.\n", wID);
3214 return JOYERR_NOCANDO;