msvfw32: Replace long with LONG.
[wine/hacks.git] / dlls / mmsystem.dll16 / mmsystem.c
blob66311bb71cc1051efe29f63157e5a100a682e5d6
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MMSYSTEM functions
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
25 * Eric POUECH :
26 * 99/4 added mmTask and mmThread functions support
29 #include <stdarg.h>
30 #include <string.h>
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
34 #include "windef.h"
35 #include "winbase.h"
36 #include "mmsystem.h"
37 #include "winternl.h"
38 #include "wownt32.h"
39 #include "winnls.h"
41 #include "wine/list.h"
42 #include "wine/winuser16.h"
43 #include "winemm16.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
50 static CRITICAL_SECTION_DEBUG mmdrv_critsect_debug =
52 0, 0, &mmdrv_cs,
53 { &mmdrv_critsect_debug.ProcessLocksList, &mmdrv_critsect_debug.ProcessLocksList },
54 0, 0, { (DWORD_PTR)(__FILE__ ": mmsystem_mmdrv_cs") }
56 CRITICAL_SECTION mmdrv_cs = { &mmdrv_critsect_debug, -1, 0, 0, 0, 0 };
58 /* ###################################################
59 * # LIBRARY #
60 * ###################################################
63 /**************************************************************************
64 * DllEntryPoint (MMSYSTEM.4)
66 * MMSYSTEM DLL entry point
69 BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
70 WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
72 static int done;
74 if (!done++) LoadLibrary16( "sound.drv" );
75 return TRUE;
78 /**************************************************************************
79 * WEP [MMSYSTEM.1]
81 int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
82 WORD cbHeapSize, LPSTR lpCmdLine)
84 TRACE("STUB: Unloading MMSystem DLL ... hInst=%04X\n", hInstance);
85 return TRUE;
88 /* ###################################################
89 * # TIME #
90 * ###################################################
93 /******************************************************************
94 * MMSYSTEM_MMTIME32to16
98 void MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16, const MMTIME* mmt32)
100 mmt16->wType = mmt32->wType;
101 /* layout of rest is the same for 32/16,
102 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
104 memcpy(&(mmt16->u), &(mmt32->u), sizeof(mmt16->u));
107 /******************************************************************
108 * MMSYSTEM_MMTIME16to32
112 static void MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16)
114 mmt32->wType = mmt16->wType;
115 /* layout of rest is the same for 32/16,
116 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
118 memcpy(&(mmt32->u), &(mmt16->u), sizeof(mmt16->u));
121 /**************************************************************************
122 * timeGetSystemTime [MMSYSTEM.601]
124 MMRESULT16 WINAPI timeGetSystemTime16(LPMMTIME16 lpTime, UINT16 wSize)
126 if (wSize >= sizeof(*lpTime)) {
127 lpTime->wType = TIME_MS;
128 lpTime->u.ms = GetTickCount();
130 TRACE("=> %u\n", lpTime->u.ms);
133 return 0;
136 struct timer_entry {
137 struct list entry;
138 UINT id;
139 LPTIMECALLBACK16 func16;
140 DWORD user;
143 static struct list timer_list = LIST_INIT(timer_list);
145 static void CALLBACK timeCB3216(UINT id, UINT uMsg, DWORD_PTR user, DWORD_PTR dw1, DWORD_PTR dw2)
147 struct timer_entry* te = (void*)user;
148 WORD args[8];
149 DWORD ret;
151 args[7] = LOWORD(id);
152 args[6] = LOWORD(uMsg);
153 args[5] = HIWORD(te->user);
154 args[4] = LOWORD(te->user);
155 args[3] = HIWORD(dw1);
156 args[2] = LOWORD(dw2);
157 args[1] = HIWORD(dw2);
158 args[0] = LOWORD(dw2);
159 WOWCallback16Ex((DWORD)te->func16, WCB16_PASCAL, sizeof(args), args, &ret);
162 /**************************************************************************
163 * timeSetEvent [MMSYSTEM.602]
165 MMRESULT16 WINAPI timeSetEvent16(UINT16 wDelay, UINT16 wResol, LPTIMECALLBACK16 lpFunc,
166 DWORD dwUser, UINT16 wFlags)
168 MMRESULT16 id;
169 struct timer_entry* te;
171 switch (wFlags & (TIME_CALLBACK_EVENT_SET|TIME_CALLBACK_EVENT_PULSE))
173 case TIME_CALLBACK_EVENT_SET:
174 case TIME_CALLBACK_EVENT_PULSE:
175 id = timeSetEvent(wDelay, wResol, (LPTIMECALLBACK)lpFunc, dwUser, wFlags);
176 break;
177 case TIME_CALLBACK_FUNCTION:
178 te = HeapAlloc(GetProcessHeap(), 0, sizeof(*te));
179 if (!te) return 0;
180 te->func16 = lpFunc;
181 te->user = dwUser;
182 id = te->id = timeSetEvent(wDelay, wResol, timeCB3216, (DWORD_PTR)te, wFlags);
183 if (id)
185 EnterCriticalSection(&mmdrv_cs);
186 list_add_tail(&timer_list, &te->entry);
187 LeaveCriticalSection(&mmdrv_cs);
189 else HeapFree(GetProcessHeap(), 0, te);
190 break;
191 default:
192 id = 0;
193 break;
195 return id;
198 /**************************************************************************
199 * timeKillEvent [MMSYSTEM.603]
201 MMRESULT16 WINAPI timeKillEvent16(UINT16 wID)
203 MMRESULT16 ret = timeKillEvent(wID);
204 struct timer_entry* te;
206 if (ret == TIMERR_NOERROR)
208 EnterCriticalSection(&mmdrv_cs);
209 LIST_FOR_EACH_ENTRY(te, &timer_list, struct timer_entry, entry)
211 if (wID == te->id)
213 list_remove(&te->entry);
214 HeapFree(GetProcessHeap(), 0, te);
215 break;
218 LeaveCriticalSection(&mmdrv_cs);
220 return ret;
223 /**************************************************************************
224 * timeGetDevCaps [MMSYSTEM.604]
226 MMRESULT16 WINAPI timeGetDevCaps16(LPTIMECAPS16 lpCaps, UINT16 wSize)
228 TIMECAPS caps;
229 MMRESULT ret;
230 TRACE("(%p, %u) !\n", lpCaps, wSize);
232 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
234 ret = timeGetDevCaps(&caps, sizeof(caps));
235 if (ret == MMSYSERR_NOERROR) {
236 TIMECAPS16 tc16;
237 tc16.wPeriodMin = caps.wPeriodMin;
238 tc16.wPeriodMax = caps.wPeriodMax;
239 memcpy(lpCaps, &tc16, min(wSize, sizeof(tc16)));
241 return ret;
244 /**************************************************************************
245 * timeBeginPeriod [MMSYSTEM.605]
247 MMRESULT16 WINAPI timeBeginPeriod16(UINT16 wPeriod)
249 TRACE("(%u) !\n", wPeriod);
251 return timeBeginPeriod(wPeriod);
254 /**************************************************************************
255 * timeEndPeriod [MMSYSTEM.606]
257 MMRESULT16 WINAPI timeEndPeriod16(UINT16 wPeriod)
259 TRACE("(%u) !\n", wPeriod);
261 return timeEndPeriod(wPeriod);
264 /**************************************************************************
265 * timeGetTime [MMSYSTEM.607]
267 DWORD WINAPI timeGetTime16(void)
269 return timeGetTime();
272 /* ###################################################
273 * # PlaySound #
274 * ###################################################
277 /**************************************************************************
278 * PlaySound [MMSYSTEM.3]
280 BOOL16 WINAPI PlaySound16(LPCSTR pszSound, HMODULE16 hmod, DWORD fdwSound)
282 BOOL16 retv;
283 DWORD lc;
285 if ((fdwSound & SND_RESOURCE) == SND_RESOURCE)
287 HGLOBAL16 handle;
288 HRSRC16 res;
290 if (!(res = FindResource16( hmod, pszSound, "WAVE" ))) return FALSE;
291 if (!(handle = LoadResource16( hmod, res ))) return FALSE;
292 pszSound = LockResource16(handle);
293 fdwSound = (fdwSound & ~SND_RESOURCE) | SND_MEMORY;
294 /* FIXME: FreeResource16 */
297 ReleaseThunkLock(&lc);
298 retv = PlaySoundA(pszSound, 0, fdwSound);
299 RestoreThunkLock(lc);
301 return retv;
304 /**************************************************************************
305 * sndPlaySound [MMSYSTEM.2]
307 BOOL16 WINAPI sndPlaySound16(LPCSTR lpszSoundName, UINT16 uFlags)
309 BOOL16 retv;
310 DWORD lc;
312 ReleaseThunkLock(&lc);
313 retv = sndPlaySoundA(lpszSoundName, uFlags);
314 RestoreThunkLock(lc);
316 return retv;
319 /* ###################################################
320 * # MISC #
321 * ###################################################
324 /**************************************************************************
325 * mmsystemGetVersion [MMSYSTEM.5]
328 UINT16 WINAPI mmsystemGetVersion16(void)
330 return mmsystemGetVersion();
333 /**************************************************************************
334 * DriverCallback [MMSYSTEM.31]
336 BOOL16 WINAPI DriverCallback16(DWORD dwCallBack, UINT16 uFlags, HDRVR16 hDev,
337 WORD wMsg, DWORD dwUser, DWORD dwParam1,
338 DWORD dwParam2)
340 return DriverCallback(dwCallBack, uFlags, HDRVR_32(hDev), wMsg, dwUser, dwParam1, dwParam2);
343 /**************************************************************************
344 * OutputDebugStr [MMSYSTEM.30]
346 void WINAPI OutputDebugStr16(LPCSTR str)
348 OutputDebugStringA( str );
351 /* ###################################################
352 * # MIXER #
353 * ###################################################
356 /**************************************************************************
357 * Mixer devices. New to Win95
360 /**************************************************************************
361 * mixerGetNumDevs [MMSYSTEM.800]
363 UINT16 WINAPI mixerGetNumDevs16(void)
365 return mixerGetNumDevs();
368 /**************************************************************************
369 * mixerGetDevCaps [MMSYSTEM.801]
371 UINT16 WINAPI mixerGetDevCaps16(UINT16 uDeviceID, LPMIXERCAPS16 lpCaps,
372 UINT16 uSize)
374 MIXERCAPSA micA;
375 UINT ret;
377 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
379 ret = mixerGetDevCapsA(uDeviceID, &micA, sizeof(micA));
380 if (ret == MMSYSERR_NOERROR) {
381 MIXERCAPS16 mic16;
382 mic16.wMid = micA.wMid;
383 mic16.wPid = micA.wPid;
384 mic16.vDriverVersion = micA.vDriverVersion;
385 strcpy(mic16.szPname, micA.szPname);
386 mic16.fdwSupport = micA.fdwSupport;
387 mic16.cDestinations = micA.cDestinations;
388 memcpy(lpCaps, &mic16, min(uSize, sizeof(mic16)));
390 return ret;
393 /**************************************************************************
394 * mixerOpen [MMSYSTEM.802]
396 UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix, UINT16 uDeviceID, DWORD dwCallback,
397 DWORD dwInstance, DWORD fdwOpen)
399 HMIXER hmix;
400 UINT ret;
401 struct mmsystdrv_thunk* thunk;
403 if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIXER)))
405 return MMSYSERR_NOMEM;
407 if ((fdwOpen & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION)
409 dwCallback = (DWORD)thunk;
412 ret = mixerOpen(&hmix, uDeviceID, dwCallback, dwInstance, fdwOpen);
413 if (ret == MMSYSERR_NOERROR)
415 if (lphmix) *lphmix = HMIXER_16(hmix);
416 if (thunk) MMSYSTDRV_SetHandle(thunk, hmix);
418 else MMSYSTDRV_DeleteThunk(thunk);
419 return ret;
422 /**************************************************************************
423 * mixerClose [MMSYSTEM.803]
425 UINT16 WINAPI mixerClose16(HMIXER16 hMix)
427 UINT ret = mixerClose(HMIXER_32(hMix));
429 if (ret == MMSYSERR_NOERROR)
430 MMSYSTDRV_CloseHandle((void*)HMIXER_32(hMix));
431 return ret;
434 /**************************************************************************
435 * mixerGetID (MMSYSTEM.806)
437 UINT16 WINAPI mixerGetID16(HMIXEROBJ16 hmix, LPUINT16 lpid, DWORD fdwID)
439 UINT xid;
440 UINT ret = mixerGetID(HMIXEROBJ_32(hmix), &xid, fdwID);
442 if (lpid)
443 *lpid = xid;
444 return ret;
447 /**************************************************************************
448 * mixerGetControlDetails [MMSYSTEM.808]
450 UINT16 WINAPI mixerGetControlDetails16(HMIXEROBJ16 hmix,
451 LPMIXERCONTROLDETAILS16 lpmcd,
452 DWORD fdwDetails)
454 DWORD ret = MMSYSERR_NOTENABLED;
455 SEGPTR sppaDetails;
457 TRACE("(%04x, %p, %08x)\n", hmix, lpmcd, fdwDetails);
459 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
460 return MMSYSERR_INVALPARAM;
462 sppaDetails = (SEGPTR)lpmcd->paDetails;
463 lpmcd->paDetails = MapSL(sppaDetails);
464 ret = mixerGetControlDetailsA(HMIXEROBJ_32(hmix),
465 (LPMIXERCONTROLDETAILS)lpmcd, fdwDetails);
466 lpmcd->paDetails = (LPVOID)sppaDetails;
468 return ret;
471 /**************************************************************************
472 * mixerGetLineControls [MMSYSTEM.807]
474 UINT16 WINAPI mixerGetLineControls16(HMIXEROBJ16 hmix,
475 LPMIXERLINECONTROLS16 lpmlc16,
476 DWORD fdwControls)
478 MIXERLINECONTROLSA mlcA;
479 DWORD ret;
480 unsigned int i;
481 LPMIXERCONTROL16 lpmc16;
483 TRACE("(%04x, %p, %08x)\n", hmix, lpmlc16, fdwControls);
485 if (lpmlc16 == NULL || lpmlc16->cbStruct != sizeof(*lpmlc16) ||
486 lpmlc16->cbmxctrl != sizeof(MIXERCONTROL16))
487 return MMSYSERR_INVALPARAM;
489 mlcA.cbStruct = sizeof(mlcA);
490 mlcA.dwLineID = lpmlc16->dwLineID;
491 mlcA.u.dwControlID = lpmlc16->u.dwControlID;
492 mlcA.u.dwControlType = lpmlc16->u.dwControlType;
493 mlcA.cControls = lpmlc16->cControls;
494 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
495 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
496 mlcA.cControls * mlcA.cbmxctrl);
498 ret = mixerGetLineControlsA(HMIXEROBJ_32(hmix), &mlcA, fdwControls);
500 if (ret == MMSYSERR_NOERROR) {
501 lpmlc16->dwLineID = mlcA.dwLineID;
502 lpmlc16->u.dwControlID = mlcA.u.dwControlID;
503 lpmlc16->u.dwControlType = mlcA.u.dwControlType;
504 lpmlc16->cControls = mlcA.cControls;
506 lpmc16 = MapSL(lpmlc16->pamxctrl);
508 for (i = 0; i < mlcA.cControls; i++) {
509 lpmc16[i].cbStruct = sizeof(MIXERCONTROL16);
510 lpmc16[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
511 lpmc16[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
512 lpmc16[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
513 lpmc16[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
514 strcpy(lpmc16[i].szShortName, mlcA.pamxctrl[i].szShortName);
515 strcpy(lpmc16[i].szName, mlcA.pamxctrl[i].szName);
516 /* sizeof(lpmc16[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
517 memcpy(&lpmc16[i].Bounds, &mlcA.pamxctrl[i].Bounds,
518 sizeof(mlcA.pamxctrl[i].Bounds));
519 /* sizeof(lpmc16[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
520 memcpy(&lpmc16[i].Metrics, &mlcA.pamxctrl[i].Metrics,
521 sizeof(mlcA.pamxctrl[i].Metrics));
525 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
527 return ret;
530 /**************************************************************************
531 * mixerGetLineInfo [MMSYSTEM.805]
533 UINT16 WINAPI mixerGetLineInfo16(HMIXEROBJ16 hmix, LPMIXERLINE16 lpmli16,
534 DWORD fdwInfo)
536 MIXERLINEA mliA;
537 UINT ret;
539 TRACE("(%04x, %p, %08x)\n", hmix, lpmli16, fdwInfo);
541 if (lpmli16 == NULL || lpmli16->cbStruct != sizeof(*lpmli16))
542 return MMSYSERR_INVALPARAM;
544 mliA.cbStruct = sizeof(mliA);
545 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
546 case MIXER_GETLINEINFOF_COMPONENTTYPE:
547 mliA.dwComponentType = lpmli16->dwComponentType;
548 break;
549 case MIXER_GETLINEINFOF_DESTINATION:
550 mliA.dwDestination = lpmli16->dwDestination;
551 break;
552 case MIXER_GETLINEINFOF_LINEID:
553 mliA.dwLineID = lpmli16->dwLineID;
554 break;
555 case MIXER_GETLINEINFOF_SOURCE:
556 mliA.dwDestination = lpmli16->dwDestination;
557 mliA.dwSource = lpmli16->dwSource;
558 break;
559 case MIXER_GETLINEINFOF_TARGETTYPE:
560 mliA.Target.dwType = lpmli16->Target.dwType;
561 mliA.Target.wMid = lpmli16->Target.wMid;
562 mliA.Target.wPid = lpmli16->Target.wPid;
563 mliA.Target.vDriverVersion = lpmli16->Target.vDriverVersion;
564 strcpy(mliA.Target.szPname, lpmli16->Target.szPname);
565 break;
566 default:
567 FIXME("Unsupported fdwControls=0x%08x\n", fdwInfo);
570 ret = mixerGetLineInfoA(HMIXEROBJ_32(hmix), &mliA, fdwInfo);
572 lpmli16->dwDestination = mliA.dwDestination;
573 lpmli16->dwSource = mliA.dwSource;
574 lpmli16->dwLineID = mliA.dwLineID;
575 lpmli16->fdwLine = mliA.fdwLine;
576 lpmli16->dwUser = mliA.dwUser;
577 lpmli16->dwComponentType = mliA.dwComponentType;
578 lpmli16->cChannels = mliA.cChannels;
579 lpmli16->cConnections = mliA.cConnections;
580 lpmli16->cControls = mliA.cControls;
581 strcpy(lpmli16->szShortName, mliA.szShortName);
582 strcpy(lpmli16->szName, mliA.szName);
583 lpmli16->Target.dwType = mliA.Target.dwType;
584 lpmli16->Target.dwDeviceID = mliA.Target.dwDeviceID;
585 lpmli16->Target.wMid = mliA.Target.wMid;
586 lpmli16->Target.wPid = mliA.Target.wPid;
587 lpmli16->Target.vDriverVersion = mliA.Target.vDriverVersion;
588 strcpy(lpmli16->Target.szPname, mliA.Target.szPname);
590 return ret;
593 /**************************************************************************
594 * mixerSetControlDetails [MMSYSTEM.809]
596 UINT16 WINAPI mixerSetControlDetails16(HMIXEROBJ16 hmix,
597 LPMIXERCONTROLDETAILS16 lpmcd,
598 DWORD fdwDetails)
600 TRACE("(%04x, %p, %08x)\n", hmix, lpmcd, fdwDetails);
601 return MMSYSERR_NOTENABLED;
604 /**************************************************************************
605 * mixerMessage [MMSYSTEM.804]
607 DWORD WINAPI mixerMessage16(HMIXER16 hmix, UINT16 uMsg, DWORD dwParam1,
608 DWORD dwParam2)
610 return mixerMessage(HMIXER_32(hmix), uMsg, dwParam1, dwParam2);
613 /* ###################################################
614 * # AUX #
615 * ###################################################
618 /**************************************************************************
619 * auxGetNumDevs [MMSYSTEM.350]
621 UINT16 WINAPI auxGetNumDevs16(void)
623 return auxGetNumDevs();
626 /**************************************************************************
627 * auxGetDevCaps [MMSYSTEM.351]
629 UINT16 WINAPI auxGetDevCaps16(UINT16 uDeviceID, LPAUXCAPS16 lpCaps, UINT16 uSize)
631 AUXCAPSA acA;
632 UINT ret;
634 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
636 ret = auxGetDevCapsA(uDeviceID, &acA, sizeof(acA));
637 if (ret == MMSYSERR_NOERROR) {
638 AUXCAPS16 ac16;
639 ac16.wMid = acA.wMid;
640 ac16.wPid = acA.wPid;
641 ac16.vDriverVersion = acA.vDriverVersion;
642 strcpy(ac16.szPname, acA.szPname);
643 ac16.wTechnology = acA.wTechnology;
644 ac16.dwSupport = acA.dwSupport;
645 memcpy(lpCaps, &ac16, min(uSize, sizeof(ac16)));
647 return ret;
650 /**************************************************************************
651 * auxGetVolume [MMSYSTEM.352]
653 UINT16 WINAPI auxGetVolume16(UINT16 uDeviceID, LPDWORD lpdwVolume)
655 return auxGetVolume(uDeviceID, lpdwVolume);
658 /**************************************************************************
659 * auxSetVolume [MMSYSTEM.353]
661 UINT16 WINAPI auxSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
663 return auxSetVolume(uDeviceID, dwVolume);
666 /**************************************************************************
667 * auxOutMessage [MMSYSTEM.354]
669 DWORD WINAPI auxOutMessage16(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
671 TRACE("(%04X, %04X, %08X, %08X)\n", uDeviceID, uMessage, dw1, dw2);
673 switch (uMessage) {
674 case AUXDM_GETNUMDEVS:
675 case AUXDM_SETVOLUME:
676 /* no argument conversion needed */
677 break;
678 case AUXDM_GETVOLUME:
679 return auxGetVolume(uDeviceID, MapSL(dw1));
680 case AUXDM_GETDEVCAPS:
681 return auxGetDevCaps16(uDeviceID, MapSL(dw1), dw2);
682 default:
683 TRACE("(%04x, %04x, %08x, %08x): unhandled message\n",
684 uDeviceID, uMessage, dw1, dw2);
685 break;
687 return auxOutMessage(uDeviceID, uMessage, dw1, dw2);
690 /* ###################################################
691 * # MIDI #
692 * ###################################################
695 /**************************************************************************
696 * midiOutGetNumDevs [MMSYSTEM.201]
698 UINT16 WINAPI midiOutGetNumDevs16(void)
700 return midiOutGetNumDevs();
703 /**************************************************************************
704 * midiOutGetDevCaps [MMSYSTEM.202]
706 UINT16 WINAPI midiOutGetDevCaps16(UINT16 uDeviceID, LPMIDIOUTCAPS16 lpCaps,
707 UINT16 uSize)
709 MIDIOUTCAPSA mocA;
710 UINT ret;
712 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
714 ret = midiOutGetDevCapsA(uDeviceID, &mocA, sizeof(mocA));
715 if (ret == MMSYSERR_NOERROR) {
716 MIDIOUTCAPS16 moc16;
717 moc16.wMid = mocA.wMid;
718 moc16.wPid = mocA.wPid;
719 moc16.vDriverVersion = mocA.vDriverVersion;
720 strcpy(moc16.szPname, mocA.szPname);
721 moc16.wTechnology = mocA.wTechnology;
722 moc16.wVoices = mocA.wVoices;
723 moc16.wNotes = mocA.wNotes;
724 moc16.wChannelMask = mocA.wChannelMask;
725 moc16.dwSupport = mocA.dwSupport;
726 memcpy(lpCaps, &moc16, min(uSize, sizeof(moc16)));
728 return ret;
731 /**************************************************************************
732 * midiOutGetErrorText [MMSYSTEM.203]
733 * midiInGetErrorText [MMSYSTEM.303]
735 UINT16 WINAPI midiOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
737 return midiOutGetErrorTextA(uError, lpText, uSize);
740 /**************************************************************************
741 * midiOutOpen [MMSYSTEM.204]
743 UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID,
744 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
746 HMIDIOUT hmo;
747 UINT ret;
748 struct mmsystdrv_thunk* thunk;
750 if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIDIOUT)))
752 return MMSYSERR_NOMEM;
754 if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION)
756 dwCallback = (DWORD)thunk;
758 ret = midiOutOpen(&hmo, uDeviceID, dwCallback, dwInstance, dwFlags);
759 if (ret == MMSYSERR_NOERROR)
761 if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo);
762 MMSYSTDRV_SetHandle(thunk, (void*)hmo);
764 else MMSYSTDRV_DeleteThunk(thunk);
765 return ret;
768 /**************************************************************************
769 * midiOutClose [MMSYSTEM.205]
771 UINT16 WINAPI midiOutClose16(HMIDIOUT16 hMidiOut)
773 UINT ret = midiOutClose(HMIDIOUT_32(hMidiOut));
775 if (ret == MMSYSERR_NOERROR)
776 MMSYSTDRV_CloseHandle((void*)HMIDIOUT_32(hMidiOut));
777 return ret;
780 /**************************************************************************
781 * midiOutPrepareHeader [MMSYSTEM.206]
783 UINT16 WINAPI midiOutPrepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
784 SEGPTR lpsegMidiOutHdr, /* [???] */
785 UINT16 uSize) /* [in] */
787 TRACE("(%04X, %08x, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
789 return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), MODM_PREPARE, lpsegMidiOutHdr, uSize);
792 /**************************************************************************
793 * midiOutUnprepareHeader [MMSYSTEM.207]
795 UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */
796 SEGPTR lpsegMidiOutHdr, /* [???] */
797 UINT16 uSize) /* [in] */
799 LPMIDIHDR16 lpMidiOutHdr = MapSL(lpsegMidiOutHdr);
801 TRACE("(%04X, %08x, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
803 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
804 return MMSYSERR_NOERROR;
807 return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), MODM_UNPREPARE, lpsegMidiOutHdr, uSize);
810 /**************************************************************************
811 * midiOutShortMsg [MMSYSTEM.208]
813 UINT16 WINAPI midiOutShortMsg16(HMIDIOUT16 hMidiOut, DWORD dwMsg)
815 return midiOutShortMsg(HMIDIOUT_32(hMidiOut), dwMsg);
818 /**************************************************************************
819 * midiOutLongMsg [MMSYSTEM.209]
821 UINT16 WINAPI midiOutLongMsg16(HMIDIOUT16 hMidiOut, /* [in] */
822 LPMIDIHDR16 lpsegMidiOutHdr, /* [???] NOTE: SEGPTR */
823 UINT16 uSize) /* [in] */
825 TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
827 return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), MODM_LONGDATA, (DWORD_PTR)lpsegMidiOutHdr, uSize);
830 /**************************************************************************
831 * midiOutReset [MMSYSTEM.210]
833 UINT16 WINAPI midiOutReset16(HMIDIOUT16 hMidiOut)
835 return midiOutReset(HMIDIOUT_32(hMidiOut));
838 /**************************************************************************
839 * midiOutGetVolume [MMSYSTEM.211]
841 UINT16 WINAPI midiOutGetVolume16(UINT16 uDeviceID, DWORD* lpdwVolume)
843 return midiOutGetVolume(HMIDIOUT_32(uDeviceID), lpdwVolume);
846 /**************************************************************************
847 * midiOutSetVolume [MMSYSTEM.212]
849 UINT16 WINAPI midiOutSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
851 return midiOutSetVolume(HMIDIOUT_32(uDeviceID), dwVolume);
854 /**************************************************************************
855 * midiOutCachePatches [MMSYSTEM.213]
857 UINT16 WINAPI midiOutCachePatches16(HMIDIOUT16 hMidiOut, UINT16 uBank,
858 WORD* lpwPatchArray, UINT16 uFlags)
860 return midiOutCachePatches(HMIDIOUT_32(hMidiOut), uBank, lpwPatchArray,
861 uFlags);
864 /**************************************************************************
865 * midiOutCacheDrumPatches [MMSYSTEM.214]
867 UINT16 WINAPI midiOutCacheDrumPatches16(HMIDIOUT16 hMidiOut, UINT16 uPatch,
868 WORD* lpwKeyArray, UINT16 uFlags)
870 return midiOutCacheDrumPatches(HMIDIOUT_32(hMidiOut), uPatch, lpwKeyArray, uFlags);
873 /**************************************************************************
874 * midiOutGetID [MMSYSTEM.215]
876 UINT16 WINAPI midiOutGetID16(HMIDIOUT16 hMidiOut, UINT16* lpuDeviceID)
878 UINT devid;
879 UINT16 ret;
881 ret = midiOutGetID(HMIDIOUT_32(hMidiOut), &devid);
882 if (ret != MMSYSERR_NOERROR) return ret;
883 *lpuDeviceID = devid;
884 return ret;
887 /**************************************************************************
888 * midiOutMessage [MMSYSTEM.216]
890 DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage,
891 DWORD dwParam1, DWORD dwParam2)
893 TRACE("(%04X, %04X, %08X, %08X)\n", hMidiOut, uMessage, dwParam1, dwParam2);
895 switch (uMessage) {
896 case MODM_OPEN:
897 case MODM_CLOSE:
898 FIXME("can't handle OPEN or CLOSE message!\n");
899 return MMSYSERR_NOTSUPPORTED;
901 case MODM_GETVOLUME:
902 return midiOutGetVolume16(hMidiOut, MapSL(dwParam1));
903 case MODM_LONGDATA:
904 return midiOutLongMsg16(hMidiOut, MapSL(dwParam1), dwParam2);
905 case MODM_PREPARE:
906 /* lpMidiOutHdr is still a segmented pointer for this function */
907 return midiOutPrepareHeader16(hMidiOut, dwParam1, dwParam2);
908 case MODM_UNPREPARE:
909 return midiOutUnprepareHeader16(hMidiOut, dwParam1, dwParam2);
911 return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), uMessage, dwParam1, dwParam2);
914 /**************************************************************************
915 * midiInGetNumDevs [MMSYSTEM.301]
917 UINT16 WINAPI midiInGetNumDevs16(void)
919 return midiInGetNumDevs();
922 /**************************************************************************
923 * midiInGetDevCaps [MMSYSTEM.302]
925 UINT16 WINAPI midiInGetDevCaps16(UINT16 uDeviceID, LPMIDIINCAPS16 lpCaps,
926 UINT16 uSize)
928 MIDIINCAPSA micA;
929 UINT ret;
931 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
933 ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
934 if (ret == MMSYSERR_NOERROR) {
935 MIDIINCAPS16 mic16;
936 mic16.wMid = micA.wMid;
937 mic16.wPid = micA.wPid;
938 mic16.vDriverVersion = micA.vDriverVersion;
939 strcpy(mic16.szPname, micA.szPname);
940 mic16.dwSupport = micA.dwSupport;
941 memcpy(lpCaps, &mic16, min(uSize, sizeof(mic16)));
943 return ret;
946 /**************************************************************************
947 * midiInOpen [MMSYSTEM.304]
949 UINT16 WINAPI midiInOpen16(HMIDIIN16* lphMidiIn, UINT16 uDeviceID,
950 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
952 HMIDIIN hmid;
953 UINT ret;
954 struct mmsystdrv_thunk* thunk;
956 if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIDIIN)))
958 return MMSYSERR_NOMEM;
960 if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION)
962 dwCallback = (DWORD)thunk;
964 ret = midiInOpen(&hmid, uDeviceID, dwCallback, dwInstance, dwFlags);
965 if (ret == MMSYSERR_NOERROR)
967 if (lphMidiIn) *lphMidiIn = HMIDIIN_16(hmid);
968 MMSYSTDRV_SetHandle(thunk, (void*)hmid);
970 else MMSYSTDRV_DeleteThunk(thunk);
971 return ret;
974 /**************************************************************************
975 * midiInClose [MMSYSTEM.305]
977 UINT16 WINAPI midiInClose16(HMIDIIN16 hMidiIn)
979 UINT ret = midiInClose(HMIDIIN_32(hMidiIn));
981 if (ret == MMSYSERR_NOERROR)
982 MMSYSTDRV_CloseHandle((void*)HMIDIIN_32(hMidiIn));
983 return ret;
986 /**************************************************************************
987 * midiInPrepareHeader [MMSYSTEM.306]
989 UINT16 WINAPI midiInPrepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
990 SEGPTR lpsegMidiInHdr, /* [???] */
991 UINT16 uSize) /* [in] */
993 TRACE("(%04X, %08x, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
995 return MMSYSTDRV_Message(HMIDIIN_32(hMidiIn), MIDM_PREPARE, lpsegMidiInHdr, uSize);
998 /**************************************************************************
999 * midiInUnprepareHeader [MMSYSTEM.307]
1001 UINT16 WINAPI midiInUnprepareHeader16(HMIDIIN16 hMidiIn, /* [in] */
1002 SEGPTR lpsegMidiInHdr, /* [???] */
1003 UINT16 uSize) /* [in] */
1005 LPMIDIHDR16 lpMidiInHdr = MapSL(lpsegMidiInHdr);
1007 TRACE("(%04X, %08x, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
1009 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1010 return MMSYSERR_NOERROR;
1013 return MMSYSTDRV_Message(HMIDIIN_32(hMidiIn), MIDM_UNPREPARE, lpsegMidiInHdr, uSize);
1016 /**************************************************************************
1017 * midiInAddBuffer [MMSYSTEM.308]
1019 UINT16 WINAPI midiInAddBuffer16(HMIDIIN16 hMidiIn, /* [in] */
1020 MIDIHDR16* lpsegMidiInHdr, /* [???] NOTE: SEGPTR */
1021 UINT16 uSize) /* [in] */
1023 TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
1025 return MMSYSTDRV_Message(HMIDIIN_32(hMidiIn), MIDM_ADDBUFFER, (DWORD_PTR)lpsegMidiInHdr, uSize);
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)
1057 UINT devid;
1058 UINT16 ret;
1060 ret = midiInGetID(HMIDIIN_32(hMidiIn), &devid);
1061 if (ret != MMSYSERR_NOERROR) return ret;
1062 *lpuDeviceID = devid;
1063 return ret;
1066 /**************************************************************************
1067 * midiInMessage [MMSYSTEM.313]
1069 DWORD WINAPI midiInMessage16(HMIDIIN16 hMidiIn, UINT16 uMessage,
1070 DWORD dwParam1, DWORD dwParam2)
1072 TRACE("(%04X, %04X, %08X, %08X)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1074 switch (uMessage) {
1075 case MIDM_OPEN:
1076 case MIDM_CLOSE:
1077 FIXME("can't handle OPEN or CLOSE message!\n");
1078 return MMSYSERR_NOTSUPPORTED;
1080 case MIDM_GETDEVCAPS:
1081 return midiInGetDevCaps16(hMidiIn, MapSL(dwParam1), dwParam2);
1082 case MIDM_PREPARE:
1083 return midiInPrepareHeader16(hMidiIn, dwParam1, dwParam2);
1084 case MIDM_UNPREPARE:
1085 return midiInUnprepareHeader16(hMidiIn, dwParam1, dwParam2);
1086 case MIDM_ADDBUFFER:
1087 return midiInAddBuffer16(hMidiIn, MapSL(dwParam1), dwParam2);
1089 return MMSYSTDRV_Message(HMIDIIN_32(hMidiIn), uMessage, dwParam1, dwParam2);
1092 /**************************************************************************
1093 * midiStreamClose [MMSYSTEM.252]
1095 MMRESULT16 WINAPI midiStreamClose16(HMIDISTRM16 hMidiStrm)
1097 UINT ret = midiStreamClose(HMIDISTRM_32(hMidiStrm));
1098 if (ret == MMSYSERR_NOERROR)
1099 MMSYSTDRV_CloseHandle((void*)HMIDISTRM_32(hMidiStrm));
1100 return ret;
1103 /**************************************************************************
1104 * midiStreamOpen [MMSYSTEM.251]
1106 MMRESULT16 WINAPI midiStreamOpen16(HMIDISTRM16* phMidiStrm, LPUINT16 devid,
1107 DWORD cMidi, DWORD dwCallback,
1108 DWORD dwInstance, DWORD fdwOpen)
1110 HMIDISTRM hMidiStrm32;
1111 MMRESULT ret;
1112 UINT devid32;
1113 struct mmsystdrv_thunk* thunk;
1115 if (!phMidiStrm || !devid)
1116 return MMSYSERR_INVALPARAM;
1117 devid32 = *devid;
1119 if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIDIOUT)))
1121 return MMSYSERR_NOMEM;
1123 if ((fdwOpen & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION)
1125 dwCallback = (DWORD)thunk;
1127 ret = midiStreamOpen(&hMidiStrm32, &devid32, cMidi, dwCallback, dwInstance, fdwOpen);
1128 if (ret == MMSYSERR_NOERROR)
1130 *phMidiStrm = HMIDISTRM_16(hMidiStrm32);
1131 *devid = devid32;
1132 MMSYSTDRV_SetHandle(thunk, hMidiStrm32);
1134 else MMSYSTDRV_DeleteThunk(thunk);
1135 return ret;
1138 /**************************************************************************
1139 * midiStreamOut [MMSYSTEM.254]
1141 MMRESULT16 WINAPI midiStreamOut16(HMIDISTRM16 hMidiStrm, LPMIDIHDR16 lpMidiHdr, UINT16 cbMidiHdr)
1143 return midiStreamOut(HMIDISTRM_32(hMidiStrm), (LPMIDIHDR)lpMidiHdr,
1144 cbMidiHdr);
1147 /**************************************************************************
1148 * midiStreamPause [MMSYSTEM.255]
1150 MMRESULT16 WINAPI midiStreamPause16(HMIDISTRM16 hMidiStrm)
1152 return midiStreamPause(HMIDISTRM_32(hMidiStrm));
1155 /**************************************************************************
1156 * midiStreamPosition [MMSYSTEM.253]
1158 MMRESULT16 WINAPI midiStreamPosition16(HMIDISTRM16 hMidiStrm, LPMMTIME16 lpmmt16, UINT16 cbmmt)
1160 MMTIME mmt32;
1161 MMRESULT ret;
1163 if (!lpmmt16)
1164 return MMSYSERR_INVALPARAM;
1165 MMSYSTEM_MMTIME16to32(&mmt32, lpmmt16);
1166 ret = midiStreamPosition(HMIDISTRM_32(hMidiStrm), &mmt32, sizeof(MMTIME));
1167 MMSYSTEM_MMTIME32to16(lpmmt16, &mmt32);
1168 return ret;
1171 /**************************************************************************
1172 * midiStreamProperty [MMSYSTEM.250]
1174 MMRESULT16 WINAPI midiStreamProperty16(HMIDISTRM16 hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1176 return midiStreamProperty(HMIDISTRM_32(hMidiStrm), lpPropData, dwProperty);
1179 /**************************************************************************
1180 * midiStreamRestart [MMSYSTEM.256]
1182 MMRESULT16 WINAPI midiStreamRestart16(HMIDISTRM16 hMidiStrm)
1184 return midiStreamRestart(HMIDISTRM_32(hMidiStrm));
1187 /**************************************************************************
1188 * midiStreamStop [MMSYSTEM.257]
1190 MMRESULT16 WINAPI midiStreamStop16(HMIDISTRM16 hMidiStrm)
1192 return midiStreamStop(HMIDISTRM_32(hMidiStrm));
1195 /* ###################################################
1196 * # WAVE #
1197 * ###################################################
1200 /**************************************************************************
1201 * waveOutGetNumDevs [MMSYSTEM.401]
1203 UINT16 WINAPI waveOutGetNumDevs16(void)
1205 return waveOutGetNumDevs();
1208 /**************************************************************************
1209 * waveOutGetDevCaps [MMSYSTEM.402]
1211 UINT16 WINAPI waveOutGetDevCaps16(UINT16 uDeviceID,
1212 LPWAVEOUTCAPS16 lpCaps, UINT16 uSize)
1214 WAVEOUTCAPSA wocA;
1215 UINT ret;
1216 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
1218 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1220 ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
1221 if (ret == MMSYSERR_NOERROR) {
1222 WAVEOUTCAPS16 woc16;
1223 woc16.wMid = wocA.wMid;
1224 woc16.wPid = wocA.wPid;
1225 woc16.vDriverVersion = wocA.vDriverVersion;
1226 strcpy(woc16.szPname, wocA.szPname);
1227 woc16.dwFormats = wocA.dwFormats;
1228 woc16.wChannels = wocA.wChannels;
1229 woc16.dwSupport = wocA.dwSupport;
1230 memcpy(lpCaps, &woc16, min(uSize, sizeof(woc16)));
1232 return ret;
1235 /**************************************************************************
1236 * waveOutGetErrorText [MMSYSTEM.403]
1237 * waveInGetErrorText [MMSYSTEM.503]
1239 UINT16 WINAPI waveOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
1241 return waveOutGetErrorTextA(uError, lpText, uSize);
1244 /**************************************************************************
1245 * waveOutOpen [MMSYSTEM.404]
1247 UINT16 WINAPI waveOutOpen16(HWAVEOUT16* lphWaveOut, UINT16 uDeviceID,
1248 LPCWAVEFORMATEX lpFormat, DWORD dwCallback,
1249 DWORD dwInstance, DWORD dwFlags)
1251 HWAVEOUT hWaveOut;
1252 UINT ret;
1253 struct mmsystdrv_thunk* thunk;
1255 if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_WAVEOUT)))
1257 return MMSYSERR_NOMEM;
1259 if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION)
1261 dwCallback = (DWORD)thunk;
1263 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1264 * call the 32 bit version
1265 * however, we need to promote correctly the wave mapper id
1266 * (0xFFFFFFFF and not 0x0000FFFF)
1268 ret = waveOutOpen(&hWaveOut, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1269 lpFormat, dwCallback, dwInstance, dwFlags);
1271 if (ret == MMSYSERR_NOERROR)
1273 if (lphWaveOut != NULL) *lphWaveOut = HWAVEOUT_16(hWaveOut);
1274 MMSYSTDRV_SetHandle(thunk, (void*)hWaveOut);
1276 else MMSYSTDRV_DeleteThunk(thunk);
1277 return ret;
1280 /**************************************************************************
1281 * waveOutClose [MMSYSTEM.405]
1283 UINT16 WINAPI waveOutClose16(HWAVEOUT16 hWaveOut)
1285 DWORD level;
1286 UINT16 ret;
1288 ReleaseThunkLock(&level);
1289 ret = waveOutClose(HWAVEOUT_32(hWaveOut));
1290 RestoreThunkLock(level);
1291 if (ret == MMSYSERR_NOERROR)
1292 MMSYSTDRV_CloseHandle((void*)HWAVEOUT_32(hWaveOut));
1293 return ret;
1296 /**************************************************************************
1297 * waveOutPrepareHeader [MMSYSTEM.406]
1299 UINT16 WINAPI waveOutPrepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1300 SEGPTR lpsegWaveOutHdr, /* [???] */
1301 UINT16 uSize) /* [in] */
1303 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1304 UINT16 result;
1306 TRACE("(%04X, %08x, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1308 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
1310 if ((result = MMSYSTDRV_Message(HWAVEOUT_32(hWaveOut), WODM_PREPARE, lpsegWaveOutHdr,
1311 uSize)) != MMSYSERR_NOTSUPPORTED)
1312 return result;
1314 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
1315 return WAVERR_STILLPLAYING;
1317 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
1318 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
1320 return MMSYSERR_NOERROR;
1323 /**************************************************************************
1324 * waveOutUnprepareHeader [MMSYSTEM.407]
1326 UINT16 WINAPI waveOutUnprepareHeader16(HWAVEOUT16 hWaveOut, /* [in] */
1327 SEGPTR lpsegWaveOutHdr, /* [???] */
1328 UINT16 uSize) /* [in] */
1330 LPWAVEHDR lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1332 TRACE("(%04X, %08x, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1334 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
1335 return MMSYSERR_NOERROR;
1338 return MMSYSTDRV_Message(HWAVEOUT_32(hWaveOut), WODM_UNPREPARE, lpsegWaveOutHdr, uSize);
1341 /**************************************************************************
1342 * waveOutWrite [MMSYSTEM.408]
1344 UINT16 WINAPI waveOutWrite16(HWAVEOUT16 hWaveOut, /* [in] */
1345 LPWAVEHDR lpsegWaveOutHdr, /* [???] NOTE: SEGPTR */
1346 UINT16 uSize) /* [in] */
1348 TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1350 return MMSYSTDRV_Message(HWAVEOUT_32(hWaveOut), WODM_WRITE, (DWORD_PTR)lpsegWaveOutHdr, uSize);
1353 /**************************************************************************
1354 * waveOutBreakLoop [MMSYSTEM.419]
1356 UINT16 WINAPI waveOutBreakLoop16(HWAVEOUT16 hWaveOut16)
1358 DWORD level;
1359 UINT16 ret;
1361 ReleaseThunkLock(&level);
1362 ret = waveOutBreakLoop(HWAVEOUT_32(hWaveOut16));
1363 RestoreThunkLock(level);
1364 return ret;
1367 /**************************************************************************
1368 * waveOutPause [MMSYSTEM.409]
1370 UINT16 WINAPI waveOutPause16(HWAVEOUT16 hWaveOut16)
1372 DWORD level;
1373 UINT16 ret;
1375 ReleaseThunkLock(&level);
1376 ret = waveOutPause(HWAVEOUT_32(hWaveOut16));
1377 RestoreThunkLock(level);
1378 return ret;
1381 /**************************************************************************
1382 * waveOutReset [MMSYSTEM.411]
1384 UINT16 WINAPI waveOutReset16(HWAVEOUT16 hWaveOut16)
1386 DWORD level;
1387 UINT16 ret;
1389 ReleaseThunkLock(&level);
1390 ret = waveOutReset(HWAVEOUT_32(hWaveOut16));
1391 RestoreThunkLock(level);
1392 return ret;
1395 /**************************************************************************
1396 * waveOutRestart [MMSYSTEM.410]
1398 UINT16 WINAPI waveOutRestart16(HWAVEOUT16 hWaveOut16)
1400 DWORD level;
1401 UINT16 ret;
1403 ReleaseThunkLock(&level);
1404 ret = waveOutRestart(HWAVEOUT_32(hWaveOut16));
1405 RestoreThunkLock(level);
1406 return ret;
1409 /**************************************************************************
1410 * waveOutGetPosition [MMSYSTEM.412]
1412 UINT16 WINAPI waveOutGetPosition16(HWAVEOUT16 hWaveOut, LPMMTIME16 lpTime,
1413 UINT16 uSize)
1415 UINT ret;
1416 MMTIME mmt;
1418 mmt.wType = lpTime->wType;
1419 ret = waveOutGetPosition(HWAVEOUT_32(hWaveOut), &mmt, sizeof(mmt));
1420 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1421 return ret;
1424 /**************************************************************************
1425 * waveOutGetPitch [MMSYSTEM.413]
1427 UINT16 WINAPI waveOutGetPitch16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1429 return waveOutGetPitch(HWAVEOUT_32(hWaveOut16), lpdw);
1432 /**************************************************************************
1433 * waveOutSetPitch [MMSYSTEM.414]
1435 UINT16 WINAPI waveOutSetPitch16(HWAVEOUT16 hWaveOut16, DWORD dw)
1437 return waveOutSetPitch(HWAVEOUT_32(hWaveOut16), dw);
1440 /**************************************************************************
1441 * waveOutGetPlaybackRate [MMSYSTEM.417]
1443 UINT16 WINAPI waveOutGetPlaybackRate16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1445 return waveOutGetPlaybackRate(HWAVEOUT_32(hWaveOut16), lpdw);
1448 /**************************************************************************
1449 * waveOutSetPlaybackRate [MMSYSTEM.418]
1451 UINT16 WINAPI waveOutSetPlaybackRate16(HWAVEOUT16 hWaveOut16, DWORD dw)
1453 return waveOutSetPlaybackRate(HWAVEOUT_32(hWaveOut16), dw);
1456 /**************************************************************************
1457 * waveOutGetVolume [MMSYSTEM.415]
1459 UINT16 WINAPI waveOutGetVolume16(UINT16 devid, LPDWORD lpdw)
1461 return waveOutGetVolume(HWAVEOUT_32(devid), lpdw);
1464 /**************************************************************************
1465 * waveOutSetVolume [MMSYSTEM.416]
1467 UINT16 WINAPI waveOutSetVolume16(UINT16 devid, DWORD dw)
1469 return waveOutSetVolume(HWAVEOUT_32(devid), dw);
1472 /**************************************************************************
1473 * waveOutGetID [MMSYSTEM.420]
1475 UINT16 WINAPI waveOutGetID16(HWAVEOUT16 hWaveOut, UINT16* lpuDeviceID)
1477 UINT devid;
1478 UINT16 ret;
1480 ret = waveOutGetID(HWAVEOUT_32(hWaveOut), &devid);
1481 if (ret != MMSYSERR_NOERROR) return ret;
1482 *lpuDeviceID = devid;
1483 return ret;
1486 /**************************************************************************
1487 * waveOutMessage [MMSYSTEM.421]
1489 DWORD WINAPI waveOutMessage16(HWAVEOUT16 hWaveOut, UINT16 uMessage,
1490 DWORD dwParam1, DWORD dwParam2)
1492 TRACE("(%04x, %u, %d, %d)\n", hWaveOut, uMessage, dwParam1, dwParam2);
1494 if ((DWORD_PTR)hWaveOut < waveOutGetNumDevs())
1496 if (uMessage == DRV_QUERYDRVENTRY || uMessage == DRV_QUERYDEVNODE)
1497 dwParam1 = (DWORD)MapSL(dwParam1);
1499 else if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1500 /* from M$ KB */
1501 return MMSYSERR_INVALPARAM;
1503 return MMSYSTDRV_Message(HWAVEOUT_32(hWaveOut), uMessage, dwParam1, dwParam2);
1506 /**************************************************************************
1507 * waveInGetNumDevs [MMSYSTEM.501]
1509 UINT16 WINAPI waveInGetNumDevs16(void)
1511 return waveInGetNumDevs();
1514 /**************************************************************************
1515 * waveInGetDevCaps [MMSYSTEM.502]
1517 UINT16 WINAPI waveInGetDevCaps16(UINT16 uDeviceID, LPWAVEINCAPS16 lpCaps,
1518 UINT16 uSize)
1520 WAVEINCAPSA wicA;
1521 UINT ret;
1523 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1525 ret = waveInGetDevCapsA(uDeviceID, &wicA, sizeof(wicA));
1526 if (ret == MMSYSERR_NOERROR) {
1527 WAVEINCAPS16 wic16;
1528 wic16.wMid = wicA.wMid;
1529 wic16.wPid = wicA.wPid;
1530 wic16.vDriverVersion = wicA.vDriverVersion;
1531 strcpy(wic16.szPname, wicA.szPname);
1532 wic16.dwFormats = wicA.dwFormats;
1533 wic16.wChannels = wicA.wChannels;
1534 memcpy(lpCaps, &wic16, min(uSize, sizeof(wic16)));
1536 return ret;
1539 /**************************************************************************
1540 * waveInOpen [MMSYSTEM.504]
1542 UINT16 WINAPI waveInOpen16(HWAVEIN16* lphWaveIn, UINT16 uDeviceID,
1543 LPCWAVEFORMATEX lpFormat, DWORD dwCallback,
1544 DWORD dwInstance, DWORD dwFlags)
1546 HWAVEIN hWaveIn;
1547 UINT ret;
1548 struct mmsystdrv_thunk* thunk;
1550 if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_WAVEIN)))
1552 return MMSYSERR_NOMEM;
1554 if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION)
1556 dwCallback = (DWORD)thunk;
1558 /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1559 * call the 32 bit version
1560 * however, we need to promote correctly the wave mapper id
1561 * (0xFFFFFFFF and not 0x0000FFFF)
1563 ret = waveInOpen(&hWaveIn, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1564 lpFormat, dwCallback, dwInstance, dwFlags);
1566 if (ret == MMSYSERR_NOERROR)
1568 if (lphWaveIn != NULL) *lphWaveIn = HWAVEIN_16(hWaveIn);
1569 MMSYSTDRV_SetHandle(thunk, (void*)hWaveIn);
1571 else MMSYSTDRV_DeleteThunk(thunk);
1572 return ret;
1575 /**************************************************************************
1576 * waveInClose [MMSYSTEM.505]
1578 UINT16 WINAPI waveInClose16(HWAVEIN16 hWaveIn)
1580 DWORD level;
1581 UINT16 ret;
1583 ReleaseThunkLock(&level);
1584 ret = waveInClose(HWAVEIN_32(hWaveIn));
1585 RestoreThunkLock(level);
1586 if (ret == MMSYSERR_NOERROR)
1587 MMSYSTDRV_CloseHandle((void*)HWAVEIN_32(hWaveIn));
1588 return ret;
1591 /**************************************************************************
1592 * waveInPrepareHeader [MMSYSTEM.506]
1594 UINT16 WINAPI waveInPrepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1595 SEGPTR lpsegWaveInHdr, /* [???] */
1596 UINT16 uSize) /* [in] */
1598 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1599 UINT16 ret;
1601 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
1603 if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
1604 lpWaveInHdr->dwBytesRecorded = 0;
1606 ret = MMSYSTDRV_Message(HWAVEIN_32(hWaveIn), WIDM_PREPARE, lpsegWaveInHdr, uSize);
1607 return ret;
1610 /**************************************************************************
1611 * waveInUnprepareHeader [MMSYSTEM.507]
1613 UINT16 WINAPI waveInUnprepareHeader16(HWAVEIN16 hWaveIn, /* [in] */
1614 SEGPTR lpsegWaveInHdr, /* [???] */
1615 UINT16 uSize) /* [in] */
1617 LPWAVEHDR lpWaveInHdr = MapSL(lpsegWaveInHdr);
1619 TRACE("(%04X, %08x, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1621 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1623 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
1624 return MMSYSERR_NOERROR;
1627 return MMSYSTDRV_Message(HWAVEIN_32(hWaveIn), WIDM_UNPREPARE, lpsegWaveInHdr, uSize);
1630 /**************************************************************************
1631 * waveInAddBuffer [MMSYSTEM.508]
1633 UINT16 WINAPI waveInAddBuffer16(HWAVEIN16 hWaveIn, /* [in] */
1634 WAVEHDR* lpsegWaveInHdr, /* [???] NOTE: SEGPTR */
1635 UINT16 uSize) /* [in] */
1637 TRACE("(%04X, %p, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1639 if (lpsegWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1641 return MMSYSTDRV_Message(HWAVEIN_32(hWaveIn), WIDM_ADDBUFFER, (DWORD_PTR)lpsegWaveInHdr, uSize);
1644 /**************************************************************************
1645 * waveInReset [MMSYSTEM.511]
1647 UINT16 WINAPI waveInReset16(HWAVEIN16 hWaveIn16)
1649 DWORD level;
1650 UINT16 ret;
1652 ReleaseThunkLock(&level);
1653 ret = waveInReset(HWAVEIN_32(hWaveIn16));
1654 RestoreThunkLock(level);
1655 return ret;
1658 /**************************************************************************
1659 * waveInStart [MMSYSTEM.509]
1661 UINT16 WINAPI waveInStart16(HWAVEIN16 hWaveIn16)
1663 DWORD level;
1664 UINT16 ret;
1666 ReleaseThunkLock(&level);
1667 ret = waveInStart(HWAVEIN_32(hWaveIn16));
1668 RestoreThunkLock(level);
1669 return ret;
1672 /**************************************************************************
1673 * waveInStop [MMSYSTEM.510]
1675 UINT16 WINAPI waveInStop16(HWAVEIN16 hWaveIn16)
1677 DWORD level;
1678 UINT16 ret;
1680 ReleaseThunkLock(&level);
1681 ret = waveInStop(HWAVEIN_32(hWaveIn16));
1682 RestoreThunkLock(level);
1683 return ret;
1686 /**************************************************************************
1687 * waveInGetPosition [MMSYSTEM.512]
1689 UINT16 WINAPI waveInGetPosition16(HWAVEIN16 hWaveIn, LPMMTIME16 lpTime,
1690 UINT16 uSize)
1692 UINT ret;
1693 MMTIME mmt;
1695 mmt.wType = lpTime->wType;
1696 ret = waveInGetPosition(HWAVEIN_32(hWaveIn), &mmt, sizeof(mmt));
1697 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1698 return ret;
1701 /**************************************************************************
1702 * waveInGetID [MMSYSTEM.513]
1704 UINT16 WINAPI waveInGetID16(HWAVEIN16 hWaveIn, UINT16* lpuDeviceID)
1706 UINT devid;
1707 UINT16 ret;
1709 ret = waveInGetID(HWAVEIN_32(hWaveIn), &devid);
1710 if (ret != MMSYSERR_NOERROR) return ret;
1711 *lpuDeviceID = devid;
1712 return ret;
1715 /**************************************************************************
1716 * waveInMessage [MMSYSTEM.514]
1718 DWORD WINAPI waveInMessage16(HWAVEIN16 hWaveIn, UINT16 uMessage,
1719 DWORD dwParam1, DWORD dwParam2)
1721 TRACE("(%04x, %u, %d, %d)\n", hWaveIn, uMessage, dwParam1, dwParam2);
1723 if ((DWORD_PTR)hWaveIn < waveInGetNumDevs())
1725 if (uMessage == DRV_QUERYDRVENTRY || uMessage == DRV_QUERYDEVNODE)
1726 dwParam1 = (DWORD)MapSL(dwParam1);
1728 else if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1729 /* from M$ KB */
1730 return MMSYSERR_INVALPARAM;
1732 return MMSYSTDRV_Message(HWAVEIN_32(hWaveIn), uMessage, dwParam1, dwParam2);
1735 /* ###################################################
1736 * # TASK #
1737 * ###################################################
1740 /*#define USE_MM_TSK_WINE*/
1742 /**************************************************************************
1743 * mmTaskCreate [MMSYSTEM.900]
1745 * Creates a 16 bit MM task. It's entry point is lpFunc, and it should be
1746 * called upon creation with dwPmt as parameter.
1748 HINSTANCE16 WINAPI mmTaskCreate16(SEGPTR spProc, HINSTANCE16 *lphMmTask, DWORD dwPmt)
1750 HINSTANCE16 ret;
1751 HINSTANCE16 handle;
1752 char cmdline[16];
1753 DWORD showCmd = 0x40002;
1754 LOADPARAMS16 lp;
1756 TRACE("(%08x, %p, %08x);\n", spProc, lphMmTask, dwPmt);
1757 /* This to work requires NE modules to be started with a binary command line
1758 * which is not currently the case. A patch exists but has never been committed.
1759 * A workaround would be to integrate code for mmtask.tsk into Wine, but
1760 * this requires tremendous work (starting with patching tools/build to
1761 * create NE executables (and not only DLLs) for builtins modules.
1762 * EP 99/04/25
1764 FIXME("This is currently broken. It will fail\n");
1766 cmdline[0] = 0x0d;
1767 *(LPDWORD)(cmdline + 1) = (DWORD)spProc;
1768 *(LPDWORD)(cmdline + 5) = dwPmt;
1769 *(LPDWORD)(cmdline + 9) = 0;
1771 lp.hEnvironment = 0;
1772 lp.cmdLine = MapLS(cmdline);
1773 lp.showCmd = MapLS(&showCmd);
1774 lp.reserved = 0;
1776 #ifndef USE_MM_TSK_WINE
1777 handle = LoadModule16("c:\\windows\\system\\mmtask.tsk", &lp);
1778 #else
1779 handle = LoadModule16("mmtask.tsk", &lp);
1780 #endif
1781 if (handle < 32) {
1782 ret = (handle) ? 1 : 2;
1783 handle = 0;
1784 } else {
1785 ret = 0;
1787 if (lphMmTask)
1788 *lphMmTask = handle;
1790 UnMapLS( lp.cmdLine );
1791 UnMapLS( lp.showCmd );
1792 TRACE("=> 0x%04x/%d\n", handle, ret);
1793 return ret;
1796 #ifdef USE_MM_TSK_WINE
1797 /* C equivalent to mmtask.tsk binary content */
1798 void mmTaskEntryPoint16(LPSTR cmdLine, WORD di, WORD si)
1800 int len = cmdLine[0x80];
1802 if (len / 2 == 6) {
1803 void (*fpProc)(DWORD) = MapSL(*((DWORD*)(cmdLine + 1)));
1804 DWORD dwPmt = *((DWORD*)(cmdLine + 5));
1806 #if 0
1807 InitTask16(); /* FIXME: pmts / from context ? */
1808 InitApp(di);
1809 #endif
1810 if (SetMessageQueue16(0x40)) {
1811 WaitEvent16(0);
1812 if (HIWORD(fpProc)) {
1813 OldYield16();
1814 /* EPP StackEnter16(); */
1815 (fpProc)(dwPmt);
1819 OldYield16();
1820 OldYield16();
1821 OldYield16();
1822 ExitProcess(0);
1824 #endif
1826 /**************************************************************************
1827 * mmTaskBlock [MMSYSTEM.902]
1829 void WINAPI mmTaskBlock16(HINSTANCE16 hInst)
1831 MSG msg;
1833 do {
1834 GetMessageA(&msg, 0, 0, 0);
1835 if (msg.hwnd) {
1836 TranslateMessage(&msg);
1837 DispatchMessageA(&msg);
1839 } while (msg.message < 0x3A0);
1842 /**************************************************************************
1843 * mmTaskSignal [MMSYSTEM.903]
1845 LRESULT WINAPI mmTaskSignal16(HTASK16 ht)
1847 TRACE("(%04x);\n", ht);
1848 return PostThreadMessageW( HTASK_32(ht), WM_USER, 0, 0 );
1851 /**************************************************************************
1852 * mmGetCurrentTask [MMSYSTEM.904]
1854 HTASK16 WINAPI mmGetCurrentTask16(void)
1856 return GetCurrentTask();
1859 /**************************************************************************
1860 * mmTaskYield [MMSYSTEM.905]
1862 void WINAPI mmTaskYield16(void)
1864 MSG msg;
1866 if (PeekMessageA(&msg, 0, 0, 0, 0)) {
1867 WOWYield16();
1871 /******************************************************************
1872 * WINMM_GetmmThread
1876 static WINE_MMTHREAD* WINMM_GetmmThread(HANDLE16 h)
1878 return MapSL(MAKESEGPTR(h, 0));
1881 static void MMSYSTEM_ThreadBlock(WINE_MMTHREAD* lpMMThd)
1883 MSG msg;
1884 DWORD ret;
1886 if (lpMMThd->dwThreadID != GetCurrentThreadId())
1887 ERR("Not called by thread itself\n");
1889 for (;;) {
1890 ResetEvent(lpMMThd->hEvent);
1891 if (InterlockedDecrement(&lpMMThd->dwSignalCount) >= 0)
1892 break;
1893 InterlockedIncrement(&lpMMThd->dwSignalCount);
1895 TRACE("S1\n");
1897 ret = MsgWaitForMultipleObjects(1, &lpMMThd->hEvent, FALSE, INFINITE, QS_ALLINPUT);
1898 switch (ret) {
1899 case WAIT_OBJECT_0: /* Event */
1900 TRACE("S2.1\n");
1901 break;
1902 case WAIT_OBJECT_0 + 1: /* Msg */
1903 TRACE("S2.2\n");
1904 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1905 TranslateMessage(&msg);
1906 DispatchMessageA(&msg);
1908 break;
1909 default:
1910 WARN("S2.x unsupported ret val 0x%08x\n", ret);
1912 TRACE("S3\n");
1916 /**************************************************************************
1917 * mmThreadBlock [MMSYSTEM.1122]
1919 void WINAPI mmThreadBlock16(HANDLE16 hndl)
1921 TRACE("(%04x)!\n", hndl);
1923 if (hndl) {
1924 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
1926 if (lpMMThd->hThread != 0) {
1927 DWORD lc;
1929 ReleaseThunkLock(&lc);
1930 MMSYSTEM_ThreadBlock(lpMMThd);
1931 RestoreThunkLock(lc);
1932 } else {
1933 mmTaskBlock16(lpMMThd->hTask);
1936 TRACE("done\n");
1939 /**************************************************************************
1940 * __wine_mmThreadEntryPoint (MMSYSTEM.2047)
1942 DWORD WINAPI WINE_mmThreadEntryPoint(LPVOID p)
1944 HANDLE16 hndl = (HANDLE16)(DWORD_PTR)p;
1945 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
1947 TRACE("(%04x %p)\n", hndl, lpMMThd);
1949 lpMMThd->hTask = LOWORD(GetCurrentTask());
1950 TRACE("[10-%p] setting hTask to 0x%08x\n", lpMMThd->hThread, lpMMThd->hTask);
1951 lpMMThd->dwStatus = 0x10;
1952 MMSYSTEM_ThreadBlock(lpMMThd);
1953 TRACE("[20-%p]\n", lpMMThd->hThread);
1954 lpMMThd->dwStatus = 0x20;
1955 if (lpMMThd->fpThread) {
1956 WOWCallback16(lpMMThd->fpThread, lpMMThd->dwThreadPmt);
1958 lpMMThd->dwStatus = 0x30;
1959 TRACE("[30-%p]\n", lpMMThd->hThread);
1960 while (lpMMThd->dwCounter) {
1961 Sleep(1);
1962 /* WOWYield16();*/
1964 TRACE("[XX-%p]\n", lpMMThd->hThread);
1965 /* paranoia */
1966 lpMMThd->dwSignature = WINE_MMTHREAD_DELETED;
1967 /* close lpMMThread->hVxD directIO */
1968 if (lpMMThd->hEvent)
1969 CloseHandle(lpMMThd->hEvent);
1970 GlobalFree16(hndl);
1971 TRACE("done\n");
1973 return 0;
1976 extern DWORD WINAPI GetProcessFlags(DWORD);
1978 /**************************************************************************
1979 * mmThreadCreate [MMSYSTEM.1120]
1981 * undocumented
1982 * Creates a MM thread, calling fpThreadAddr(dwPmt).
1983 * dwFlags:
1984 * bit.0 set means create a 16 bit task instead of thread calling a 16 bit proc
1985 * bit.1 set means to open a VxD for this thread (unsupported)
1987 LRESULT WINAPI mmThreadCreate16(FARPROC16 fpThreadAddr, LPHANDLE16 lpHndl, DWORD dwPmt, DWORD dwFlags)
1989 HANDLE16 hndl;
1990 LRESULT ret;
1992 TRACE("(%p, %p, %08x, %08x)!\n", fpThreadAddr, lpHndl, dwPmt, dwFlags);
1994 hndl = GlobalAlloc16(sizeof(WINE_MMTHREAD), GMEM_SHARE|GMEM_ZEROINIT);
1996 if (hndl == 0) {
1997 ret = 2;
1998 } else {
1999 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2001 #if 0
2002 /* force mmtask routines even if mmthread is required */
2003 /* this will work only if the patch about binary cmd line and NE tasks
2004 * is committed
2006 dwFlags |= 1;
2007 #endif
2009 lpMMThd->dwSignature = WINE_MMTHREAD_CREATED;
2010 lpMMThd->dwCounter = 0;
2011 lpMMThd->hThread = 0;
2012 lpMMThd->dwThreadID = 0;
2013 lpMMThd->fpThread = (DWORD)fpThreadAddr;
2014 lpMMThd->dwThreadPmt = dwPmt;
2015 lpMMThd->dwSignalCount = 0;
2016 lpMMThd->hEvent = 0;
2017 lpMMThd->hVxD = 0;
2018 lpMMThd->dwStatus = 0;
2019 lpMMThd->dwFlags = dwFlags;
2020 lpMMThd->hTask = 0;
2022 if ((dwFlags & 1) == 0 && (GetProcessFlags(GetCurrentThreadId()) & 8) == 0) {
2023 lpMMThd->hEvent = CreateEventW(NULL, FALSE, TRUE, NULL);
2025 TRACE("Let's go crazy... trying new MM thread. lpMMThd=%p\n", lpMMThd);
2026 if (lpMMThd->dwFlags & 2) {
2027 /* as long as we don't support MM VxD in wine, we don't need
2028 * to care about this flag
2030 /* FIXME("Don't know how to properly open VxD handles\n"); */
2031 /* lpMMThd->hVxD = OpenVxDHandle(lpMMThd->hEvent); */
2034 lpMMThd->hThread = CreateThread(0, 0, WINE_mmThreadEntryPoint,
2035 (LPVOID)(DWORD_PTR)hndl, CREATE_SUSPENDED, &lpMMThd->dwThreadID);
2036 if (lpMMThd->hThread == 0) {
2037 WARN("Couldn't create thread\n");
2038 /* clean-up(VxDhandle...); devicedirectio... */
2039 if (lpMMThd->hEvent != 0)
2040 CloseHandle(lpMMThd->hEvent);
2041 ret = 2;
2042 } else {
2043 SetThreadPriority(lpMMThd->hThread, THREAD_PRIORITY_TIME_CRITICAL);
2044 TRACE("Got a nice thread hndl=%p id=0x%08x\n", lpMMThd->hThread, lpMMThd->dwThreadID);
2045 ret = 0;
2047 } else {
2048 /* get WINE_mmThreadEntryPoint()
2049 * 2047 is its ordinal in mmsystem.spec
2051 FARPROC16 fp = GetProcAddress16(GetModuleHandle16("MMSYSTEM"), (LPCSTR)2047);
2053 TRACE("farproc seg=0x%p lin=%p\n", fp, MapSL((SEGPTR)fp));
2055 ret = (fp == 0) ? 2 : mmTaskCreate16((DWORD)fp, 0, hndl);
2058 if (ret == 0) {
2059 if (lpMMThd->hThread && !ResumeThread(lpMMThd->hThread))
2060 WARN("Couldn't resume thread\n");
2062 while (lpMMThd->dwStatus != 0x10) { /* test also HIWORD of dwStatus */
2063 MSG msg;
2064 PeekMessageW( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
2069 if (ret != 0) {
2070 GlobalFree16(hndl);
2071 hndl = 0;
2074 if (lpHndl)
2075 *lpHndl = hndl;
2077 TRACE("ok => %ld\n", ret);
2078 return ret;
2081 /**************************************************************************
2082 * mmThreadSignal [MMSYSTEM.1121]
2084 void WINAPI mmThreadSignal16(HANDLE16 hndl)
2086 TRACE("(%04x)!\n", hndl);
2088 if (hndl) {
2089 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2091 lpMMThd->dwCounter++;
2092 if (lpMMThd->hThread != 0) {
2093 InterlockedIncrement(&lpMMThd->dwSignalCount);
2094 SetEvent(lpMMThd->hEvent);
2095 } else {
2096 mmTaskSignal16(lpMMThd->hTask);
2098 lpMMThd->dwCounter--;
2102 /**************************************************************************
2103 * mmThreadIsCurrent [MMSYSTEM.1123]
2105 BOOL16 WINAPI mmThreadIsCurrent16(HANDLE16 hndl)
2107 BOOL16 ret = FALSE;
2109 TRACE("(%04x)!\n", hndl);
2111 if (hndl && mmThreadIsValid16(hndl)) {
2112 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2113 ret = (GetCurrentThreadId() == lpMMThd->dwThreadID);
2115 TRACE("=> %d\n", ret);
2116 return ret;
2119 /**************************************************************************
2120 * mmThreadIsValid [MMSYSTEM.1124]
2122 BOOL16 WINAPI mmThreadIsValid16(HANDLE16 hndl)
2124 BOOL16 ret = FALSE;
2126 TRACE("(%04x)!\n", hndl);
2128 if (hndl) {
2129 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2131 if (!IsBadWritePtr(lpMMThd, sizeof(WINE_MMTHREAD)) &&
2132 lpMMThd->dwSignature == WINE_MMTHREAD_CREATED &&
2133 IsTask16(lpMMThd->hTask)) {
2134 lpMMThd->dwCounter++;
2135 if (lpMMThd->hThread != 0) {
2136 DWORD dwThreadRet;
2137 if (GetExitCodeThread(lpMMThd->hThread, &dwThreadRet) &&
2138 dwThreadRet == STATUS_PENDING) {
2139 ret = TRUE;
2141 } else {
2142 ret = TRUE;
2144 lpMMThd->dwCounter--;
2147 TRACE("=> %d\n", ret);
2148 return ret;
2151 /**************************************************************************
2152 * mmThreadGetTask [MMSYSTEM.1125]
2154 HANDLE16 WINAPI mmThreadGetTask16(HANDLE16 hndl)
2156 HANDLE16 ret = 0;
2158 TRACE("(%04x)\n", hndl);
2160 if (mmThreadIsValid16(hndl)) {
2161 WINE_MMTHREAD* lpMMThd = WINMM_GetmmThread(hndl);
2162 ret = lpMMThd->hTask;
2164 return ret;
2167 typedef BOOL16 (WINAPI *MMCPLCALLBACK)(HWND, LPCSTR, LPCSTR, LPCSTR);
2169 /**************************************************************************
2170 * mmShowMMCPLPropertySheet [MMSYSTEM.1150]
2172 BOOL16 WINAPI mmShowMMCPLPropertySheet16(HWND hWnd, LPCSTR lpStrDevice,
2173 LPCSTR lpStrTab, LPCSTR lpStrTitle)
2175 HANDLE hndl;
2176 BOOL16 ret = FALSE;
2178 TRACE("(%p \"%s\" \"%s\" \"%s\")\n", hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2180 hndl = LoadLibraryA("MMSYS.CPL");
2181 if (hndl != 0) {
2182 MMCPLCALLBACK fp = (MMCPLCALLBACK)GetProcAddress(hndl, "ShowMMCPLPropertySheet");
2183 if (fp != NULL) {
2184 DWORD lc;
2185 ReleaseThunkLock(&lc);
2186 ret = (fp)(hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2187 RestoreThunkLock(lc);
2189 FreeLibrary(hndl);
2192 return ret;
2195 /**************************************************************************
2196 * StackEnter [MMSYSTEM.32]
2198 void WINAPI StackEnter16(void)
2200 #ifdef __i386__
2201 /* mmsystem.dll from Win 95 does only this: so does Wine */
2202 __asm__("stc");
2203 #endif
2206 /**************************************************************************
2207 * StackLeave [MMSYSTEM.33]
2209 void WINAPI StackLeave16(void)
2211 #ifdef __i386__
2212 /* mmsystem.dll from Win 95 does only this: so does Wine */
2213 __asm__("stc");
2214 #endif
2217 /**************************************************************************
2218 * WMMMidiRunOnce [MMSYSTEM.8]
2220 void WINAPI WMMMidiRunOnce16(void)
2222 FIXME("(), stub!\n");
2227 /* ###################################################
2228 * # JOYSTICK #
2229 * ###################################################
2232 /**************************************************************************
2233 * joyGetNumDevs [MMSYSTEM.101]
2235 UINT16 WINAPI joyGetNumDevs16(void)
2237 return joyGetNumDevs();
2240 /**************************************************************************
2241 * joyGetDevCaps [MMSYSTEM.102]
2243 MMRESULT16 WINAPI joyGetDevCaps16(UINT16 wID, LPJOYCAPS16 lpCaps, UINT16 wSize)
2245 JOYCAPSA jca;
2246 MMRESULT ret;
2248 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2250 ret = joyGetDevCapsA(wID, &jca, sizeof(jca));
2252 if (ret != JOYERR_NOERROR) return ret;
2253 lpCaps->wMid = jca.wMid;
2254 lpCaps->wPid = jca.wPid;
2255 strcpy(lpCaps->szPname, jca.szPname);
2256 lpCaps->wXmin = jca.wXmin;
2257 lpCaps->wXmax = jca.wXmax;
2258 lpCaps->wYmin = jca.wYmin;
2259 lpCaps->wYmax = jca.wYmax;
2260 lpCaps->wZmin = jca.wZmin;
2261 lpCaps->wZmax = jca.wZmax;
2262 lpCaps->wNumButtons = jca.wNumButtons;
2263 lpCaps->wPeriodMin = jca.wPeriodMin;
2264 lpCaps->wPeriodMax = jca.wPeriodMax;
2266 if (wSize >= sizeof(JOYCAPS16)) { /* Win95 extensions ? */
2267 lpCaps->wRmin = jca.wRmin;
2268 lpCaps->wRmax = jca.wRmax;
2269 lpCaps->wUmin = jca.wUmin;
2270 lpCaps->wUmax = jca.wUmax;
2271 lpCaps->wVmin = jca.wVmin;
2272 lpCaps->wVmax = jca.wVmax;
2273 lpCaps->wCaps = jca.wCaps;
2274 lpCaps->wMaxAxes = jca.wMaxAxes;
2275 lpCaps->wNumAxes = jca.wNumAxes;
2276 lpCaps->wMaxButtons = jca.wMaxButtons;
2277 strcpy(lpCaps->szRegKey, jca.szRegKey);
2278 strcpy(lpCaps->szOEMVxD, jca.szOEMVxD);
2281 return ret;
2284 /**************************************************************************
2285 * joyGetPosEx [MMSYSTEM.110]
2287 MMRESULT16 WINAPI joyGetPosEx16(UINT16 wID, LPJOYINFOEX lpInfo)
2289 return joyGetPosEx(wID, lpInfo);
2292 /**************************************************************************
2293 * joyGetPos [MMSYSTEM.103]
2295 MMRESULT16 WINAPI joyGetPos16(UINT16 wID, LPJOYINFO16 lpInfo)
2297 JOYINFO ji;
2298 MMRESULT ret;
2300 TRACE("(%d, %p);\n", wID, lpInfo);
2302 if ((ret = joyGetPos(wID, &ji)) == JOYERR_NOERROR) {
2303 lpInfo->wXpos = ji.wXpos;
2304 lpInfo->wYpos = ji.wYpos;
2305 lpInfo->wZpos = ji.wZpos;
2306 lpInfo->wButtons = ji.wButtons;
2308 return ret;
2311 /**************************************************************************
2312 * joyGetThreshold [MMSYSTEM.104]
2314 MMRESULT16 WINAPI joyGetThreshold16(UINT16 wID, LPUINT16 lpThreshold)
2316 UINT t;
2317 MMRESULT ret;
2319 ret = joyGetThreshold(wID, &t);
2320 if (ret == JOYERR_NOERROR)
2321 *lpThreshold = t;
2322 return ret;
2325 /**************************************************************************
2326 * joyReleaseCapture [MMSYSTEM.105]
2328 MMRESULT16 WINAPI joyReleaseCapture16(UINT16 wID)
2330 return joyReleaseCapture(wID);
2333 /**************************************************************************
2334 * joySetCapture [MMSYSTEM.106]
2336 MMRESULT16 WINAPI joySetCapture16(HWND16 hWnd, UINT16 wID, UINT16 wPeriod, BOOL16 bChanged)
2338 return joySetCapture(HWND_32(hWnd), wID, wPeriod, bChanged);
2341 /**************************************************************************
2342 * joySetThreshold [MMSYSTEM.107]
2344 MMRESULT16 WINAPI joySetThreshold16(UINT16 wID, UINT16 wThreshold)
2346 return joySetThreshold(wID,wThreshold);
2349 /**************************************************************************
2350 * joySetCalibration [MMSYSTEM.109]
2352 MMRESULT16 WINAPI joySetCalibration16(UINT16 wID)
2354 FIXME("(%04X): stub.\n", wID);
2355 return JOYERR_NOCANDO;