- revisited mmsystem/winmm loading mechanism
[wine] / dlls / winmm / mmsystem.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4  * MMSYTEM functions
5  *
6  * Copyright 1993      Martin Ayotte
7  *           1998-2002 Eric Pouech
8  *
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.
13  *
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.
18  *
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
22  */
23
24 /*
25  * Eric POUECH :
26  *      99/4    added mmTask and mmThread functions support
27  */
28
29 /* FIXME: I think there are some segmented vs. linear pointer weirdnesses
30  *        and long term pointers to 16 bit space in here
31  */
32
33 #include <string.h>
34
35 #include "mmsystem.h"
36 #include "winbase.h"
37
38 #include "wine/mmsystem16.h"
39 #include "wine/winuser16.h"
40 #include "winemm.h"
41 #include "heap.h"
42
43 #include "wine/debug.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
46
47 /* ### start build ### */
48 extern LONG CALLBACK MMSYSTEM_CallTo16_long_l    (FARPROC16,LONG);
49 extern LONG CALLBACK MMSYSTEM_CallTo16_long_lwll (LPMMIOPROC16,LONG,WORD,LONG,LONG);
50 /* ### stop build ### */
51
52 static WINE_MMTHREAD*   WINMM_GetmmThread(HANDLE16);
53 static LRESULT          MMIO_Callback16(SEGPTR, LPMMIOINFO, UINT, LPARAM, LPARAM);
54
55 /* ###################################################
56  * #                  LIBRARY                        #
57  * ###################################################
58  */
59
60 /**************************************************************************
61  *                      DllEntryPoint (MMSYSTEM.2046)
62  *
63  * MMSYSTEM DLL entry point
64  *
65  */
66 BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
67                              WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
68 {
69     TRACE("0x%x 0x%lx\n", hinstDLL, fdwReason);
70
71     switch (fdwReason) {
72     case DLL_PROCESS_ATTACH:
73         /* need to load WinMM in order to:
74          * - initiate correctly shared variables (WINMM_Init())
75          */
76         if (!GetModuleHandleA("WINMM.DLL") && !LoadLibraryA("WINMM.DLL"))
77         {
78             ERR("Could not load sibling WinMM.dll\n");
79             return FALSE;
80         }
81         WINMM_IData->hWinMM16Instance = hinstDLL;
82         /* hook in our 16 bit function pointers */
83         pFnGetMMThread16  = WINMM_GetmmThread;
84         pFnMmioCallback16 = MMIO_Callback16;
85         break;
86     case DLL_PROCESS_DETACH:
87         WINMM_IData->hWinMM16Instance = 0;
88         pFnGetMMThread16  = NULL;
89         pFnMmioCallback16 = NULL;
90         break;
91     case DLL_THREAD_ATTACH:
92     case DLL_THREAD_DETACH:
93         break;
94     }
95     return TRUE;
96 }
97
98 /**************************************************************************
99  *                              MMSYSTEM_WEP                    [MMSYSTEM.1]
100  */
101 int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
102                         WORD cbHeapSize, LPSTR lpCmdLine)
103 {
104     FIXME("STUB: Unloading MMSystem DLL ... hInst=%04X \n", hInstance);
105     return TRUE;
106 }
107
108 /* ###################################################
109  * #                  PlaySound                      #
110  * ###################################################
111  */
112
113 /**************************************************************************
114  *                              PlaySound               [MMSYSTEM.3]
115  */
116 BOOL16 WINAPI PlaySound16(LPCSTR pszSound, HMODULE16 hmod, DWORD fdwSound)
117 {
118     BOOL16      retv;
119     DWORD       lc;
120
121     ReleaseThunkLock(&lc);
122     retv = PlaySoundA(pszSound, hmod, fdwSound);
123     RestoreThunkLock(lc);
124
125     return retv;
126 }
127
128 /**************************************************************************
129  *                              sndPlaySound            [MMSYSTEM.2]
130  */
131 BOOL16 WINAPI sndPlaySound16(LPCSTR lpszSoundName, UINT16 uFlags)
132 {
133     BOOL16      retv;
134     DWORD       lc;
135
136     ReleaseThunkLock(&lc);
137     retv = sndPlaySoundA(lpszSoundName, uFlags);
138     RestoreThunkLock(lc);
139
140     return retv;
141 }
142
143 /* ###################################################
144  * #                    MISC                         #
145  * ###################################################
146  */
147
148 /**************************************************************************
149  *                              mmsystemGetVersion      [MMSYSTEM.5]
150  *
151  */
152 UINT16 WINAPI mmsystemGetVersion16(void)
153 {
154     return mmsystemGetVersion();
155 }
156
157 /**************************************************************************
158  *                              DriverCallback                  [MMSYSTEM.31]
159  */
160 BOOL16 WINAPI DriverCallback16(DWORD dwCallBack, UINT16 uFlags, HDRVR16 hDev,
161                                WORD wMsg, DWORD dwUser, DWORD dwParam1,
162                                DWORD dwParam2)
163 {
164     return DriverCallback(dwCallBack, uFlags, HDRVR_32(hDev), wMsg, dwUser, dwParam1, dwParam2);
165 }
166
167 /**************************************************************************
168  *                      OutputDebugStr          [MMSYSTEM.30]
169  */
170 void WINAPI OutputDebugStr16(LPCSTR str)
171 {
172     OutputDebugStringA( str );
173 }
174
175
176 /* ###################################################
177  * #                    MIXER                        #
178  * ###################################################
179  */
180
181 /**************************************************************************
182  *      Mixer devices. New to Win95
183  */
184
185 /**************************************************************************
186  *                              mixerGetNumDevs                 [MMSYSTEM.800]
187  */
188 UINT16 WINAPI mixerGetNumDevs16(void)
189 {
190     return MMDRV_GetNum(MMDRV_MIXER);
191 }
192
193 /**************************************************************************
194  *                              mixerGetDevCaps                 [MMSYSTEM.801]
195  */
196 UINT16 WINAPI mixerGetDevCaps16(UINT16 devid, LPMIXERCAPS16 mixcaps,
197                                 UINT16 size)
198 {
199     MIXERCAPSA  micA;
200     UINT        ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
201
202     if (ret == MMSYSERR_NOERROR) {
203         mixcaps->wMid           = micA.wMid;
204         mixcaps->wPid           = micA.wPid;
205         mixcaps->vDriverVersion = micA.vDriverVersion;
206         strcpy(mixcaps->szPname, micA.szPname);
207         mixcaps->fdwSupport     = micA.fdwSupport;
208         mixcaps->cDestinations  = micA.cDestinations;
209     }
210     return ret;
211 }
212
213 /**************************************************************************
214  *                              mixerOpen                       [MMSYSTEM.802]
215  */
216 UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix, UINT16 uDeviceID, DWORD dwCallback,
217                           DWORD dwInstance, DWORD fdwOpen)
218 {
219     HMIXER      hmix;
220     UINT        ret;
221
222     ret = MMSYSTEM_mixerOpen(&hmix, uDeviceID,
223                              dwCallback, dwInstance, fdwOpen, FALSE);
224     if (lphmix) *lphmix = HMIXER_16(hmix);
225     return ret;
226 }
227
228 /**************************************************************************
229  *                              mixerClose                      [MMSYSTEM.803]
230  */
231 UINT16 WINAPI mixerClose16(HMIXER16 hMix)
232 {
233     return mixerClose(HMIXER_32(hMix));
234 }
235
236 /**************************************************************************
237  *                              mixerGetID (MMSYSTEM.806)
238  */
239 UINT16 WINAPI mixerGetID16(HMIXEROBJ16 hmix, LPUINT16 lpid, DWORD fdwID)
240 {
241     UINT        xid;
242     UINT        ret = mixerGetID(HMIXEROBJ_32(hmix), &xid, fdwID);
243
244     if (lpid)
245         *lpid = xid;
246     return ret;
247 }
248
249 /**************************************************************************
250  *                              mixerGetControlDetails  [MMSYSTEM.808]
251  */
252 UINT16 WINAPI mixerGetControlDetails16(HMIXEROBJ16 hmix,
253                                        LPMIXERCONTROLDETAILS16 lpmcd,
254                                        DWORD fdwDetails)
255 {
256     DWORD       ret = MMSYSERR_NOTENABLED;
257     SEGPTR      sppaDetails;
258
259     TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
260
261     if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
262         return MMSYSERR_INVALPARAM;
263
264     sppaDetails = (SEGPTR)lpmcd->paDetails;
265     lpmcd->paDetails = MapSL(sppaDetails);
266     ret = mixerGetControlDetailsA(HMIXEROBJ_32(hmix),
267                                  (LPMIXERCONTROLDETAILS)lpmcd, fdwDetails);
268     lpmcd->paDetails = (LPVOID)sppaDetails;
269
270     return ret;
271 }
272
273 /**************************************************************************
274  *                              mixerGetLineControls            [MMSYSTEM.807]
275  */
276 UINT16 WINAPI mixerGetLineControls16(HMIXEROBJ16 hmix,
277                                      LPMIXERLINECONTROLS16 lpmlc16,
278                                      DWORD fdwControls)
279 {
280     MIXERLINECONTROLSA  mlcA;
281     DWORD               ret;
282     int                 i;
283     LPMIXERCONTROL16    lpmc16;
284
285     TRACE("(%04x, %p, %08lx)\n", hmix, lpmlc16, fdwControls);
286
287     if (lpmlc16 == NULL || lpmlc16->cbStruct != sizeof(*lpmlc16) ||
288         lpmlc16->cbmxctrl != sizeof(MIXERCONTROL16))
289         return MMSYSERR_INVALPARAM;
290
291     mlcA.cbStruct = sizeof(mlcA);
292     mlcA.dwLineID = lpmlc16->dwLineID;
293     mlcA.u.dwControlID = lpmlc16->u.dwControlID;
294     mlcA.u.dwControlType = lpmlc16->u.dwControlType;
295     mlcA.cControls = lpmlc16->cControls;
296     mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
297     mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
298                               mlcA.cControls * mlcA.cbmxctrl);
299
300     ret = mixerGetLineControlsA(HMIXEROBJ_32(hmix), &mlcA, fdwControls);
301
302     if (ret == MMSYSERR_NOERROR) {
303         lpmlc16->dwLineID = mlcA.dwLineID;
304         lpmlc16->u.dwControlID = mlcA.u.dwControlID;
305         lpmlc16->u.dwControlType = mlcA.u.dwControlType;
306         lpmlc16->cControls = mlcA.cControls;
307
308         lpmc16 = MapSL(lpmlc16->pamxctrl);
309
310         for (i = 0; i < mlcA.cControls; i++) {
311             lpmc16[i].cbStruct = sizeof(MIXERCONTROL16);
312             lpmc16[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
313             lpmc16[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
314             lpmc16[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
315             lpmc16[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
316             strcpy(lpmc16[i].szShortName, mlcA.pamxctrl[i].szShortName);
317             strcpy(lpmc16[i].szName, mlcA.pamxctrl[i].szName);
318             /* sizeof(lpmc16[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
319             memcpy(&lpmc16[i].Bounds, &mlcA.pamxctrl[i].Bounds,
320                    sizeof(mlcA.pamxctrl[i].Bounds));
321             /* sizeof(lpmc16[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
322             memcpy(&lpmc16[i].Metrics, &mlcA.pamxctrl[i].Metrics,
323                    sizeof(mlcA.pamxctrl[i].Metrics));
324         }
325     }
326
327     HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
328
329     return ret;
330 }
331
332 /**************************************************************************
333  *                              mixerGetLineInfo        [MMSYSTEM.805]
334  */
335 UINT16 WINAPI mixerGetLineInfo16(HMIXEROBJ16 hmix, LPMIXERLINE16 lpmli16,
336                                  DWORD fdwInfo)
337 {
338     MIXERLINEA          mliA;
339     UINT                ret;
340
341     TRACE("(%04x, %p, %08lx)\n", hmix, lpmli16, fdwInfo);
342
343     if (lpmli16 == NULL || lpmli16->cbStruct != sizeof(*lpmli16))
344         return MMSYSERR_INVALPARAM;
345
346     mliA.cbStruct = sizeof(mliA);
347     switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
348     case MIXER_GETLINEINFOF_COMPONENTTYPE:
349         mliA.dwComponentType = lpmli16->dwComponentType;
350         break;
351     case MIXER_GETLINEINFOF_DESTINATION:
352         mliA.dwDestination = lpmli16->dwDestination;
353         break;
354     case MIXER_GETLINEINFOF_LINEID:
355         mliA.dwLineID = lpmli16->dwLineID;
356         break;
357     case MIXER_GETLINEINFOF_SOURCE:
358         mliA.dwDestination = lpmli16->dwDestination;
359         mliA.dwSource = lpmli16->dwSource;
360         break;
361     case MIXER_GETLINEINFOF_TARGETTYPE:
362         mliA.Target.dwType = lpmli16->Target.dwType;
363         mliA.Target.wMid = lpmli16->Target.wMid;
364         mliA.Target.wPid = lpmli16->Target.wPid;
365         mliA.Target.vDriverVersion = lpmli16->Target.vDriverVersion;
366         strcpy(mliA.Target.szPname, lpmli16->Target.szPname);
367         break;
368     default:
369         FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo);
370     }
371
372     ret = mixerGetLineInfoA(HMIXEROBJ_32(hmix), &mliA, fdwInfo);
373
374     lpmli16->dwDestination      = mliA.dwDestination;
375     lpmli16->dwSource           = mliA.dwSource;
376     lpmli16->dwLineID           = mliA.dwLineID;
377     lpmli16->fdwLine            = mliA.fdwLine;
378     lpmli16->dwUser             = mliA.dwUser;
379     lpmli16->dwComponentType    = mliA.dwComponentType;
380     lpmli16->cChannels          = mliA.cChannels;
381     lpmli16->cConnections       = mliA.cConnections;
382     lpmli16->cControls          = mliA.cControls;
383     strcpy(lpmli16->szShortName, mliA.szShortName);
384     strcpy(lpmli16->szName, mliA.szName);
385     lpmli16->Target.dwType      = mliA.Target.dwType;
386     lpmli16->Target.dwDeviceID  = mliA.Target.dwDeviceID;
387     lpmli16->Target.wMid        = mliA.Target.wMid;
388     lpmli16->Target.wPid        = mliA.Target.wPid;
389     lpmli16->Target.vDriverVersion = mliA.Target.vDriverVersion;
390     strcpy(lpmli16->Target.szPname, mliA.Target.szPname);
391
392     return ret;
393 }
394
395 /**************************************************************************
396  *                              mixerSetControlDetails  [MMSYSTEM.809]
397  */
398 UINT16 WINAPI mixerSetControlDetails16(HMIXEROBJ16 hmix,
399                                        LPMIXERCONTROLDETAILS16 lpmcd,
400                                        DWORD fdwDetails)
401 {
402     TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
403     return MMSYSERR_NOTENABLED;
404 }
405
406 /**************************************************************************
407  *                              mixerMessage            [MMSYSTEM.804]
408  */
409 DWORD WINAPI mixerMessage16(HMIXER16 hmix, UINT16 uMsg, DWORD dwParam1,
410                              DWORD dwParam2)
411 {
412     return mixerMessage(HMIXER_32(hmix), uMsg, dwParam1, dwParam2);
413 }
414
415 /**************************************************************************
416  *                              auxGetNumDevs           [MMSYSTEM.350]
417  */
418 UINT16 WINAPI auxGetNumDevs16(void)
419 {
420     return MMDRV_GetNum(MMDRV_AUX);
421 }
422
423 /* ###################################################
424  * #                     AUX                         #
425  * ###################################################
426  */
427
428 /**************************************************************************
429  *                              auxGetDevCaps           [MMSYSTEM.351]
430  */
431 UINT16 WINAPI auxGetDevCaps16(UINT16 uDeviceID, LPAUXCAPS16 lpCaps, UINT16 uSize)
432 {
433     LPWINE_MLD          wmld;
434
435     TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
436
437     if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
438         return MMSYSERR_INVALHANDLE;
439     return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
440 }
441
442 /**************************************************************************
443  *                              auxGetVolume            [MMSYSTEM.352]
444  */
445 UINT16 WINAPI auxGetVolume16(UINT16 uDeviceID, LPDWORD lpdwVolume)
446 {
447     LPWINE_MLD          wmld;
448
449     TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
450
451     if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
452         return MMSYSERR_INVALHANDLE;
453     return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD)lpdwVolume, 0L, TRUE);
454 }
455
456 /**************************************************************************
457  *                              auxSetVolume            [MMSYSTEM.353]
458  */
459 UINT16 WINAPI auxSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
460 {
461     LPWINE_MLD          wmld;
462
463     TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
464
465     if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
466         return MMSYSERR_INVALHANDLE;
467     return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
468 }
469
470 /**************************************************************************
471  *                              auxOutMessage           [MMSYSTEM.354]
472  */
473 DWORD WINAPI auxOutMessage16(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
474 {
475     LPWINE_MLD          wmld;
476
477     TRACE("(%04X, %04X, %08lX, %08lX)\n", uDeviceID, uMessage, dw1, dw2);
478
479     switch (uMessage) {
480     case AUXDM_GETNUMDEVS:
481     case AUXDM_SETVOLUME:
482         /* no argument conversion needed */
483         break;
484     case AUXDM_GETVOLUME:
485         return auxGetVolume16(uDeviceID, MapSL(dw1));
486     case AUXDM_GETDEVCAPS:
487         return auxGetDevCaps16(uDeviceID, MapSL(dw1), dw2);
488     default:
489         TRACE("(%04x, %04x, %08lx, %08lx): unhandled message\n",
490               uDeviceID, uMessage, dw1, dw2);
491         break;
492     }
493     if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
494         return MMSYSERR_INVALHANDLE;
495
496     return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
497 }
498
499 /* ###################################################
500  * #                     MCI                         #
501  * ###################################################
502  */
503
504 /**************************************************************************
505  *                              mciGetErrorString               [MMSYSTEM.706]
506  */
507 BOOL16 WINAPI mciGetErrorString16(DWORD wError, LPSTR lpstrBuffer, UINT16 uLength)
508 {
509     return mciGetErrorStringA(wError, lpstrBuffer, uLength);
510 }
511
512 /**************************************************************************
513  *                              mciDriverNotify                 [MMSYSTEM.711]
514  */
515 BOOL16 WINAPI mciDriverNotify16(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
516 {
517     TRACE("(%04X, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
518
519     return PostMessageA(HWND_32(hWndCallBack), MM_MCINOTIFY, wStatus, wDevID);
520 }
521
522 /**************************************************************************
523  *                      mciGetDriverData                        [MMSYSTEM.708]
524  */
525 DWORD WINAPI mciGetDriverData16(UINT16 uDeviceID)
526 {
527     return mciGetDriverData(uDeviceID);
528 }
529
530 /**************************************************************************
531  *                      mciSetDriverData                        [MMSYSTEM.707]
532  */
533 BOOL16 WINAPI mciSetDriverData16(UINT16 uDeviceID, DWORD data)
534 {
535     return mciSetDriverData(uDeviceID, data);
536 }
537
538 /**************************************************************************
539  *                              mciSendCommand                  [MMSYSTEM.701]
540  */
541 DWORD WINAPI mciSendCommand16(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
542 {
543     DWORD               dwRet;
544
545     TRACE("(%04X, %s, %08lX, %08lX)\n",
546           wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
547
548     dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, FALSE);
549     dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2, FALSE);
550     TRACE("=> %ld\n", dwRet);
551     return dwRet;
552 }
553
554 /**************************************************************************
555  *                              mciGetDeviceID                  [MMSYSTEM.703]
556  */
557 UINT16 WINAPI mciGetDeviceID16(LPCSTR lpstrName)
558 {
559     TRACE("(\"%s\")\n", lpstrName);
560
561     return MCI_GetDriverFromString(lpstrName);
562 }
563
564 /**************************************************************************
565  *                              mciSetYieldProc                 [MMSYSTEM.714]
566  */
567 BOOL16 WINAPI mciSetYieldProc16(UINT16 uDeviceID, YIELDPROC16 fpYieldProc, DWORD dwYieldData)
568 {
569     LPWINE_MCIDRIVER    wmd;
570
571     TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
572
573     if (!(wmd = MCI_GetDriver(uDeviceID))) {
574         WARN("Bad uDeviceID\n");
575         return FALSE;
576     }
577
578     wmd->lpfnYieldProc = (YIELDPROC)fpYieldProc;
579     wmd->dwYieldData   = dwYieldData;
580     wmd->bIs32         = FALSE;
581
582     return TRUE;
583 }
584
585 /**************************************************************************
586  *                              mciGetDeviceIDFromElementID     [MMSYSTEM.715]
587  */
588 UINT16 WINAPI mciGetDeviceIDFromElementID16(DWORD dwElementID, LPCSTR lpstrType)
589 {
590     FIXME("(%lu, %s) stub\n", dwElementID, lpstrType);
591     return 0;
592 }
593
594 /**************************************************************************
595  *                              mciGetYieldProc                 [MMSYSTEM.716]
596  */
597 YIELDPROC16 WINAPI mciGetYieldProc16(UINT16 uDeviceID, DWORD* lpdwYieldData)
598 {
599     LPWINE_MCIDRIVER    wmd;
600
601     TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
602
603     if (!(wmd = MCI_GetDriver(uDeviceID))) {
604         WARN("Bad uDeviceID\n");
605         return NULL;
606     }
607     if (!wmd->lpfnYieldProc) {
608         WARN("No proc set\n");
609         return NULL;
610     }
611     if (wmd->bIs32) {
612         WARN("Proc is 32 bit\n");
613         return NULL;
614     }
615     return (YIELDPROC16)wmd->lpfnYieldProc;
616 }
617
618 /**************************************************************************
619  *                              mciGetCreatorTask               [MMSYSTEM.717]
620  */
621 HTASK16 WINAPI mciGetCreatorTask16(UINT16 uDeviceID)
622 {
623     LPWINE_MCIDRIVER wmd;
624     HTASK16 ret = 0;
625
626     if ((wmd = MCI_GetDriver(uDeviceID))) ret = K32WOWHandle16(wmd->CreatorThread, WOW_TYPE_HTASK);
627
628     TRACE("(%u) => %04x\n", uDeviceID, ret);
629     return ret;
630 }
631
632 /**************************************************************************
633  *                              mciDriverYield                  [MMSYSTEM.710]
634  */
635 UINT16 WINAPI mciDriverYield16(UINT16 uDeviceID)
636 {
637     LPWINE_MCIDRIVER    wmd;
638     UINT16              ret = 0;
639
640     /*    TRACE("(%04x)\n", uDeviceID); */
641
642     if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || wmd->bIs32) {
643         UserYield16();
644     } else {
645         ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
646     }
647
648     return ret;
649 }
650
651 /* ###################################################
652  * #                     MIDI                        #
653  * ###################################################
654  */
655
656 /**************************************************************************
657  *                              midiOutGetNumDevs       [MMSYSTEM.201]
658  */
659 UINT16 WINAPI midiOutGetNumDevs16(void)
660 {
661     return MMDRV_GetNum(MMDRV_MIDIOUT);
662 }
663
664 /**************************************************************************
665  *                              midiOutGetDevCaps       [MMSYSTEM.202]
666  */
667 UINT16 WINAPI midiOutGetDevCaps16(UINT16 uDeviceID, LPMIDIOUTCAPS16 lpCaps,
668                                   UINT16 uSize)
669 {
670     MIDIOUTCAPSA        capsA;
671     UINT                dwRet;
672
673     if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
674
675     dwRet = midiOutGetDevCapsA(uDeviceID, &capsA, sizeof(capsA));
676     if (dwRet == MMSYSERR_NOERROR) {
677         lpCaps->wMid            = capsA.wMid;
678         lpCaps->wPid            = capsA.wPid;
679         lpCaps->vDriverVersion  = capsA.vDriverVersion;
680         strcpy(lpCaps->szPname, capsA.szPname);
681         lpCaps->wTechnology     = capsA.wTechnology;
682         lpCaps->wVoices         = capsA.wVoices;
683         lpCaps->wNotes          = capsA.wNotes;
684         lpCaps->wChannelMask    = capsA.wChannelMask;
685         lpCaps->dwSupport       = capsA.dwSupport;
686     }
687     return dwRet;
688  }
689
690 /**************************************************************************
691  *                              midiOutGetErrorText     [MMSYSTEM.203]
692  */
693 UINT16 WINAPI midiOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
694 {
695     return midiOutGetErrorTextA(uError, lpText, uSize);
696 }
697
698 /**************************************************************************
699  *                              midiOutOpen             [MMSYSTEM.204]
700  */
701 UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID,
702                             DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
703 {
704     HMIDIOUT    hmo;
705     UINT        ret;
706
707     ret = MMSYSTEM_midiOutOpen(&hmo, uDeviceID, dwCallback, dwInstance,
708                                dwFlags, FALSE);
709
710     if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo);
711     return ret;
712 }
713
714 /**************************************************************************
715  *                              midiOutClose            [MMSYSTEM.205]
716  */
717 UINT16 WINAPI midiOutClose16(HMIDIOUT16 hMidiOut)
718 {
719     return midiOutClose(HMIDIOUT_32(hMidiOut));
720 }
721
722 /**************************************************************************
723  *                              midiOutPrepareHeader    [MMSYSTEM.206]
724  */
725 UINT16 WINAPI midiOutPrepareHeader16(HMIDIOUT16 hMidiOut,         /* [in] */
726                                      SEGPTR lpsegMidiOutHdr,      /* [???] */
727                                      UINT16 uSize)                /* [in] */
728 {
729     LPWINE_MLD          wmld;
730
731     TRACE("(%04X, %08lx, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
732
733     if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
734         return MMSYSERR_INVALHANDLE;
735
736     return MMDRV_Message(wmld, MODM_PREPARE, lpsegMidiOutHdr, uSize, FALSE);
737 }
738
739 /**************************************************************************
740  *                              midiOutUnprepareHeader  [MMSYSTEM.207]
741  */
742 UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut,         /* [in] */
743                                        SEGPTR lpsegMidiOutHdr,      /* [???] */
744                                        UINT16 uSize)                /* [in] */
745 {
746     LPWINE_MLD          wmld;
747     LPMIDIHDR16         lpMidiOutHdr = MapSL(lpsegMidiOutHdr);
748
749     TRACE("(%04X, %08lx, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
750
751     if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
752         return MMSYSERR_NOERROR;
753     }
754
755     if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
756         return MMSYSERR_INVALHANDLE;
757
758     return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD)lpsegMidiOutHdr, uSize, FALSE);
759 }
760
761 /**************************************************************************
762  *                              midiOutShortMsg         [MMSYSTEM.208]
763  */
764 UINT16 WINAPI midiOutShortMsg16(HMIDIOUT16 hMidiOut, DWORD dwMsg)
765 {
766     return midiOutShortMsg(HMIDIOUT_32(hMidiOut), dwMsg);
767 }
768
769 /**************************************************************************
770  *                              midiOutLongMsg          [MMSYSTEM.209]
771  */
772 UINT16 WINAPI midiOutLongMsg16(HMIDIOUT16 hMidiOut,          /* [in] */
773                                LPMIDIHDR16 lpsegMidiOutHdr,  /* [???] NOTE: SEGPTR */
774                                UINT16 uSize)                 /* [in] */
775 {
776     LPWINE_MLD          wmld;
777
778     TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
779
780     if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
781         return MMSYSERR_INVALHANDLE;
782
783     return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD)lpsegMidiOutHdr, uSize, FALSE);
784 }
785
786 /**************************************************************************
787  *                              midiOutReset            [MMSYSTEM.210]
788  */
789 UINT16 WINAPI midiOutReset16(HMIDIOUT16 hMidiOut)
790 {
791     return midiOutReset(HMIDIOUT_32(hMidiOut));
792 }
793
794 /**************************************************************************
795  *                              midiOutGetVolume        [MMSYSTEM.211]
796  */
797 UINT16 WINAPI midiOutGetVolume16(UINT16 uDeviceID, DWORD* lpdwVolume)
798 {
799     return midiOutGetVolume(uDeviceID, lpdwVolume);
800 }
801
802 /**************************************************************************
803  *                              midiOutSetVolume        [MMSYSTEM.212]
804  */
805 UINT16 WINAPI midiOutSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
806 {
807     return midiOutSetVolume(uDeviceID, dwVolume);
808 }
809
810 /**************************************************************************
811  *                              midiOutCachePatches             [MMSYSTEM.213]
812  */
813 UINT16 WINAPI midiOutCachePatches16(HMIDIOUT16 hMidiOut, UINT16 uBank,
814                                     WORD* lpwPatchArray, UINT16 uFlags)
815 {
816     return midiOutCachePatches(HMIDIOUT_32(hMidiOut), uBank, lpwPatchArray,
817                                uFlags);
818 }
819
820 /**************************************************************************
821  *                              midiOutCacheDrumPatches [MMSYSTEM.214]
822  */
823 UINT16 WINAPI midiOutCacheDrumPatches16(HMIDIOUT16 hMidiOut, UINT16 uPatch,
824                                         WORD* lpwKeyArray, UINT16 uFlags)
825 {
826     return midiOutCacheDrumPatches(HMIDIOUT_32(hMidiOut), uPatch, lpwKeyArray, uFlags);
827 }
828
829 /**************************************************************************
830  *                              midiOutGetID            [MMSYSTEM.215]
831  */
832 UINT16 WINAPI midiOutGetID16(HMIDIOUT16 hMidiOut, UINT16* lpuDeviceID)
833 {
834     LPWINE_MLD          wmld;
835
836     TRACE("(%04X, %p)\n", hMidiOut, lpuDeviceID);
837
838     if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
839     if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
840         return MMSYSERR_INVALHANDLE;
841
842     *lpuDeviceID = wmld->uDeviceID;
843     return MMSYSERR_NOERROR;
844 }
845
846 /**************************************************************************
847  *                              midiOutMessage          [MMSYSTEM.216]
848  */
849 DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage,
850                               DWORD dwParam1, DWORD dwParam2)
851 {
852     LPWINE_MLD          wmld;
853
854     TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
855
856     if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL)
857         return MMSYSERR_INVALHANDLE;
858
859     switch (uMessage) {
860     case MODM_OPEN:
861     case MODM_CLOSE:
862         FIXME("can't handle OPEN or CLOSE message!\n");
863         return MMSYSERR_NOTSUPPORTED;
864
865     case MODM_GETVOLUME:
866         return midiOutGetVolume16(hMidiOut, MapSL(dwParam1));
867     case MODM_LONGDATA:
868         return midiOutLongMsg16(hMidiOut, MapSL(dwParam1), dwParam2);
869     case MODM_PREPARE:
870         /* lpMidiOutHdr is still a segmented pointer for this function */
871         return midiOutPrepareHeader16(hMidiOut, dwParam1, dwParam2);
872     case MODM_UNPREPARE:
873         return midiOutUnprepareHeader16(hMidiOut, dwParam1, dwParam2);
874     }
875     return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
876 }
877
878 /**************************************************************************
879  *                              midiInGetNumDevs        [MMSYSTEM.301]
880  */
881 UINT16 WINAPI midiInGetNumDevs16(void)
882 {
883     return MMDRV_GetNum(MMDRV_MIDIIN);
884 }
885
886 /**************************************************************************
887  *                              midiInGetDevCaps        [MMSYSTEM.302]
888  */
889 UINT16 WINAPI midiInGetDevCaps16(UINT16 uDeviceID, LPMIDIINCAPS16 lpCaps,
890                                  UINT16 uSize)
891 {
892     MIDIINCAPSA         micA;
893     UINT                ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
894
895     if (ret == MMSYSERR_NOERROR) {
896         lpCaps->wMid = micA.wMid;
897         lpCaps->wPid = micA.wPid;
898         lpCaps->vDriverVersion = micA.vDriverVersion;
899         strcpy(lpCaps->szPname, micA.szPname);
900         lpCaps->dwSupport = micA.dwSupport;
901     }
902
903     return ret;
904 }
905
906 /**************************************************************************
907  *                              midiInGetErrorText              [MMSYSTEM.303]
908  */
909 UINT16 WINAPI midiInGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
910 {
911     return midiInGetErrorTextA(uError, lpText, uSize);
912 }
913
914 /**************************************************************************
915  *                              midiInOpen              [MMSYSTEM.304]
916  */
917 UINT16 WINAPI midiInOpen16(HMIDIIN16* lphMidiIn, UINT16 uDeviceID,
918                            DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
919 {
920     HMIDIIN     xhmid;
921     UINT        ret;
922
923     ret = MMSYSTEM_midiInOpen(&xhmid, uDeviceID, dwCallback, dwInstance,
924                               dwFlags, FALSE);
925
926     if (lphMidiIn) *lphMidiIn = HMIDIIN_16(xhmid);
927     return ret;
928 }
929
930 /**************************************************************************
931  *                              midiInClose             [MMSYSTEM.305]
932  */
933 UINT16 WINAPI midiInClose16(HMIDIIN16 hMidiIn)
934 {
935     return midiInClose(HMIDIIN_32(hMidiIn));
936 }
937
938 /**************************************************************************
939  *                              midiInPrepareHeader     [MMSYSTEM.306]
940  */
941 UINT16 WINAPI midiInPrepareHeader16(HMIDIIN16 hMidiIn,         /* [in] */
942                                     SEGPTR lpsegMidiInHdr,     /* [???] */
943                                     UINT16 uSize)              /* [in] */
944 {
945     LPWINE_MLD          wmld;
946
947     TRACE("(%04X, %08lx, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
948
949     if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
950         return MMSYSERR_INVALHANDLE;
951
952     return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD)lpsegMidiInHdr, uSize, FALSE);
953 }
954
955 /**************************************************************************
956  *                              midiInUnprepareHeader   [MMSYSTEM.307]
957  */
958 UINT16 WINAPI midiInUnprepareHeader16(HMIDIIN16 hMidiIn,         /* [in] */
959                                       SEGPTR lpsegMidiInHdr,     /* [???] */
960                                       UINT16 uSize)              /* [in] */
961 {
962     LPWINE_MLD          wmld;
963     LPMIDIHDR16         lpMidiInHdr = MapSL(lpsegMidiInHdr);
964
965     TRACE("(%04X, %08lx, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
966
967     if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
968         return MMSYSERR_NOERROR;
969     }
970
971     if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
972         return MMSYSERR_INVALHANDLE;
973
974     return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD)lpsegMidiInHdr, uSize, FALSE);
975 }
976
977 /**************************************************************************
978  *                              midiInAddBuffer         [MMSYSTEM.308]
979  */
980 UINT16 WINAPI midiInAddBuffer16(HMIDIIN16 hMidiIn,         /* [in] */
981                                 MIDIHDR16* lpsegMidiInHdr, /* [???] NOTE: SEGPTR */
982                                 UINT16 uSize)              /* [in] */
983 {
984     LPWINE_MLD          wmld;
985
986     TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
987
988     if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
989         return MMSYSERR_INVALHANDLE;
990
991     return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD)lpsegMidiInHdr, uSize, FALSE);
992 }
993
994 /**************************************************************************
995  *                              midiInStart                     [MMSYSTEM.309]
996  */
997 UINT16 WINAPI midiInStart16(HMIDIIN16 hMidiIn)
998 {
999     return midiInStart(HMIDIIN_32(hMidiIn));
1000 }
1001
1002 /**************************************************************************
1003  *                              midiInStop                      [MMSYSTEM.310]
1004  */
1005 UINT16 WINAPI midiInStop16(HMIDIIN16 hMidiIn)
1006 {
1007     return midiInStop(HMIDIIN_32(hMidiIn));
1008 }
1009
1010 /**************************************************************************
1011  *                              midiInReset                     [MMSYSTEM.311]
1012  */
1013 UINT16 WINAPI midiInReset16(HMIDIIN16 hMidiIn)
1014 {
1015     return midiInReset(HMIDIIN_32(hMidiIn));
1016 }
1017
1018 /**************************************************************************
1019  *                              midiInGetID                     [MMSYSTEM.312]
1020  */
1021 UINT16 WINAPI midiInGetID16(HMIDIIN16 hMidiIn, UINT16* lpuDeviceID)
1022 {
1023     LPWINE_MLD          wmld;
1024
1025     TRACE("(%04X, %p)\n", hMidiIn, lpuDeviceID);
1026
1027     if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1028
1029     if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, TRUE)) == NULL)
1030         return MMSYSERR_INVALHANDLE;
1031
1032     *lpuDeviceID = wmld->uDeviceID;
1033
1034     return MMSYSERR_NOERROR;
1035 }
1036
1037 /**************************************************************************
1038  *                              midiInMessage           [MMSYSTEM.313]
1039  */
1040 DWORD WINAPI midiInMessage16(HMIDIIN16 hMidiIn, UINT16 uMessage,
1041                              DWORD dwParam1, DWORD dwParam2)
1042 {
1043     LPWINE_MLD          wmld;
1044
1045     TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1046
1047     switch (uMessage) {
1048     case MIDM_OPEN:
1049     case MIDM_CLOSE:
1050         FIXME("can't handle OPEN or CLOSE message!\n");
1051         return MMSYSERR_NOTSUPPORTED;
1052
1053     case MIDM_GETDEVCAPS:
1054         return midiInGetDevCaps16(hMidiIn, MapSL(dwParam1), dwParam2);
1055     case MIDM_PREPARE:
1056         return midiInPrepareHeader16(hMidiIn, dwParam1, dwParam2);
1057     case MIDM_UNPREPARE:
1058         return midiInUnprepareHeader16(hMidiIn, dwParam1, dwParam2);
1059     case MIDM_ADDBUFFER:
1060         return midiInAddBuffer16(hMidiIn, MapSL(dwParam1), dwParam2);
1061     }
1062
1063     if ((wmld = MMDRV_Get(HMIDIIN_32(hMidiIn), MMDRV_MIDIIN, FALSE)) == NULL)
1064         return MMSYSERR_INVALHANDLE;
1065
1066     return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1067 }
1068
1069 /**************************************************************************
1070  *                              midiStreamClose                 [MMSYSTEM.252]
1071  */
1072 MMRESULT16 WINAPI midiStreamClose16(HMIDISTRM16 hMidiStrm)
1073 {
1074     return midiStreamClose(HMIDISTRM_32(hMidiStrm));
1075 }
1076
1077 /**************************************************************************
1078  *                              midiStreamOpen                  [MMSYSTEM.251]
1079  */
1080 MMRESULT16 WINAPI midiStreamOpen16(HMIDISTRM16* phMidiStrm, LPUINT16 devid,
1081                                    DWORD cMidi, DWORD dwCallback,
1082                                    DWORD dwInstance, DWORD fdwOpen)
1083 {
1084     HMIDISTRM   hMidiStrm32;
1085     MMRESULT    ret;
1086     UINT        devid32;
1087
1088     if (!phMidiStrm || !devid)
1089         return MMSYSERR_INVALPARAM;
1090     devid32 = *devid;
1091     ret = MMSYSTEM_MidiStream_Open(&hMidiStrm32, &devid32, cMidi, dwCallback,
1092                                    dwInstance, fdwOpen, FALSE);
1093     *phMidiStrm = HMIDISTRM_16(hMidiStrm32);
1094     *devid = devid32;
1095     return ret;
1096 }
1097
1098 /**************************************************************************
1099  *                              midiStreamOut                   [MMSYSTEM.254]
1100  */
1101 MMRESULT16 WINAPI midiStreamOut16(HMIDISTRM16 hMidiStrm, LPMIDIHDR16 lpMidiHdr, UINT16 cbMidiHdr)
1102 {
1103     return midiStreamOut(HMIDISTRM_32(hMidiStrm), (LPMIDIHDR)lpMidiHdr,
1104                          cbMidiHdr);
1105 }
1106
1107 /**************************************************************************
1108  *                              midiStreamPause                 [MMSYSTEM.255]
1109  */
1110 MMRESULT16 WINAPI midiStreamPause16(HMIDISTRM16 hMidiStrm)
1111 {
1112     return midiStreamPause(HMIDISTRM_32(hMidiStrm));
1113 }
1114
1115 /**************************************************************************
1116  *                              midiStreamPosition              [MMSYSTEM.253]
1117  */
1118 MMRESULT16 WINAPI midiStreamPosition16(HMIDISTRM16 hMidiStrm, LPMMTIME16 lpmmt16, UINT16 cbmmt)
1119 {
1120     MMTIME      mmt32;
1121     MMRESULT    ret;
1122
1123     if (!lpmmt16)
1124         return MMSYSERR_INVALPARAM;
1125     MMSYSTEM_MMTIME16to32(&mmt32, lpmmt16);
1126     ret = midiStreamPosition(HMIDISTRM_32(hMidiStrm), &mmt32, sizeof(MMTIME));
1127     MMSYSTEM_MMTIME32to16(lpmmt16, &mmt32);
1128     return ret;
1129 }
1130
1131 /**************************************************************************
1132  *                              midiStreamProperty              [MMSYSTEM.250]
1133  */
1134 MMRESULT16 WINAPI midiStreamProperty16(HMIDISTRM16 hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1135 {
1136     return midiStreamProperty(HMIDISTRM_32(hMidiStrm), lpPropData, dwProperty);
1137 }
1138
1139 /**************************************************************************
1140  *                              midiStreamRestart               [MMSYSTEM.256]
1141  */
1142 MMRESULT16 WINAPI midiStreamRestart16(HMIDISTRM16 hMidiStrm)
1143 {
1144     return midiStreamRestart(HMIDISTRM_32(hMidiStrm));
1145 }
1146
1147 /**************************************************************************
1148  *                              midiStreamStop                  [MMSYSTEM.257]
1149  */
1150 MMRESULT16 WINAPI midiStreamStop16(HMIDISTRM16 hMidiStrm)
1151 {
1152     return midiStreamStop(HMIDISTRM_32(hMidiStrm));
1153 }
1154
1155 /* ###################################################
1156  * #                     WAVE                        #
1157  * ###################################################
1158  */
1159
1160 /**************************************************************************
1161  *                              waveOutGetNumDevs               [MMSYSTEM.401]
1162  */
1163 UINT16 WINAPI waveOutGetNumDevs16(void)
1164 {
1165     return MMDRV_GetNum(MMDRV_WAVEOUT);
1166 }
1167
1168 /**************************************************************************
1169  *                              waveOutGetDevCaps               [MMSYSTEM.402]
1170  */
1171 UINT16 WINAPI waveOutGetDevCaps16(UINT16 uDeviceID,
1172                                   LPWAVEOUTCAPS16 lpCaps, UINT16 uSize)
1173 {
1174     WAVEOUTCAPSA        wocA;
1175     UINT                ret;
1176
1177     TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
1178     if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1179
1180     ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
1181
1182     if (ret == MMSYSERR_NOERROR) {
1183         lpCaps->wMid = wocA.wMid;
1184         lpCaps->wPid = wocA.wPid;
1185         lpCaps->vDriverVersion = wocA.vDriverVersion;
1186         strcpy(lpCaps->szPname, wocA.szPname);
1187         lpCaps->dwFormats = wocA.dwFormats;
1188         lpCaps->wChannels = wocA.wChannels;
1189         lpCaps->dwSupport = wocA.dwSupport;
1190     }
1191     return ret;
1192 }
1193
1194 /**************************************************************************
1195  *                              waveOutGetErrorText     [MMSYSTEM.403]
1196  */
1197 UINT16 WINAPI waveOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
1198 {
1199     return waveOutGetErrorTextA(uError, lpText, uSize);
1200 }
1201
1202 /**************************************************************************
1203  *                      waveOutOpen                     [MMSYSTEM.404]
1204  */
1205 UINT16 WINAPI waveOutOpen16(HWAVEOUT16* lphWaveOut, UINT16 uDeviceID,
1206                             const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
1207                             DWORD dwInstance, DWORD dwFlags)
1208 {
1209     HWAVEOUT            hWaveOut;
1210     UINT                ret;
1211
1212     /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1213      * call the 32 bit version
1214      * however, we need to promote correctly the wave mapper id
1215      * (0xFFFFFFFF and not 0x0000FFFF)
1216      */
1217     ret = MMSYSTEM_waveOpen(&hWaveOut, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1218                             MMDRV_WAVEOUT, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1219
1220     if (lphWaveOut != NULL) *lphWaveOut = HWAVEOUT_16(hWaveOut);
1221     return ret;
1222 }
1223
1224 /**************************************************************************
1225  *                              waveOutClose            [MMSYSTEM.405]
1226  */
1227 UINT16 WINAPI waveOutClose16(HWAVEOUT16 hWaveOut)
1228 {
1229     DWORD       level;
1230     UINT16      ret;
1231
1232     ReleaseThunkLock(&level);
1233     ret = waveOutClose(HWAVEOUT_32(hWaveOut));
1234     RestoreThunkLock(level);
1235     return ret;
1236 }
1237
1238 /**************************************************************************
1239  *                              waveOutPrepareHeader    [MMSYSTEM.406]
1240  */
1241 UINT16 WINAPI waveOutPrepareHeader16(HWAVEOUT16 hWaveOut,      /* [in] */
1242                                      SEGPTR lpsegWaveOutHdr,   /* [???] */
1243                                      UINT16 uSize)             /* [in] */
1244 {
1245     LPWINE_MLD          wmld;
1246     LPWAVEHDR           lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1247
1248     TRACE("(%04X, %08lx, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1249
1250     if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
1251
1252     if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1253         return MMSYSERR_INVALHANDLE;
1254
1255     return MMDRV_Message(wmld, WODM_PREPARE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
1256 }
1257
1258 /**************************************************************************
1259  *                              waveOutUnprepareHeader  [MMSYSTEM.407]
1260  */
1261 UINT16 WINAPI waveOutUnprepareHeader16(HWAVEOUT16 hWaveOut,       /* [in] */
1262                                        SEGPTR lpsegWaveOutHdr,    /* [???] */
1263                                        UINT16 uSize)              /* [in] */
1264 {
1265     LPWINE_MLD          wmld;
1266     LPWAVEHDR           lpWaveOutHdr = MapSL(lpsegWaveOutHdr);
1267
1268     TRACE("(%04X, %08lx, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1269
1270     if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
1271         return MMSYSERR_NOERROR;
1272     }
1273
1274     if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1275         return MMSYSERR_INVALHANDLE;
1276
1277     return MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
1278 }
1279
1280 /**************************************************************************
1281  *                              waveOutWrite            [MMSYSTEM.408]
1282  */
1283 UINT16 WINAPI waveOutWrite16(HWAVEOUT16 hWaveOut,       /* [in] */
1284                              LPWAVEHDR lpsegWaveOutHdr, /* [???] NOTE: SEGPTR */
1285                              UINT16 uSize)              /* [in] */
1286 {
1287     LPWINE_MLD          wmld;
1288
1289     TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
1290
1291     if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1292         return MMSYSERR_INVALHANDLE;
1293
1294     return MMDRV_Message(wmld, WODM_WRITE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
1295 }
1296
1297 /**************************************************************************
1298  *                              waveOutBreakLoop        [MMSYSTEM.419]
1299  */
1300 UINT16 WINAPI waveOutBreakLoop16(HWAVEOUT16 hWaveOut16)
1301 {
1302     DWORD       level;
1303     UINT16      ret;
1304
1305     ReleaseThunkLock(&level);
1306     ret = waveOutBreakLoop(HWAVEOUT_32(hWaveOut16));
1307     RestoreThunkLock(level);
1308     return ret;
1309 }
1310
1311 /**************************************************************************
1312  *                              waveOutPause            [MMSYSTEM.409]
1313  */
1314 UINT16 WINAPI waveOutPause16(HWAVEOUT16 hWaveOut16)
1315 {
1316     DWORD       level;
1317     UINT16      ret;
1318
1319     ReleaseThunkLock(&level);
1320     ret = waveOutPause(HWAVEOUT_32(hWaveOut16));
1321     RestoreThunkLock(level);
1322     return ret;
1323 }
1324
1325 /**************************************************************************
1326  *                              waveOutReset            [MMSYSTEM.411]
1327  */
1328 UINT16 WINAPI waveOutReset16(HWAVEOUT16 hWaveOut16)
1329 {
1330     DWORD       level;
1331     UINT16      ret;
1332
1333     ReleaseThunkLock(&level);
1334     ret = waveOutReset(HWAVEOUT_32(hWaveOut16));
1335     RestoreThunkLock(level);
1336     return ret;
1337 }
1338
1339 /**************************************************************************
1340  *                              waveOutRestart  [MMSYSTEM.410]
1341  */
1342 UINT16 WINAPI waveOutRestart16(HWAVEOUT16 hWaveOut16)
1343 {
1344     DWORD       level;
1345     UINT16      ret;
1346
1347     ReleaseThunkLock(&level);
1348     ret = waveOutRestart(HWAVEOUT_32(hWaveOut16));
1349     RestoreThunkLock(level);
1350     return ret;
1351 }
1352
1353 /**************************************************************************
1354  *                              waveOutGetPosition      [MMSYSTEM.412]
1355  */
1356 UINT16 WINAPI waveOutGetPosition16(HWAVEOUT16 hWaveOut, LPMMTIME16 lpTime,
1357                                    UINT16 uSize)
1358 {
1359     UINT        ret;
1360     MMTIME      mmt;
1361
1362     mmt.wType = lpTime->wType;
1363     ret = waveOutGetPosition(HWAVEOUT_32(hWaveOut), &mmt, sizeof(mmt));
1364     MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1365     return ret;
1366 }
1367
1368 /**************************************************************************
1369  *                              waveOutGetPitch         [MMSYSTEM.413]
1370  */
1371 UINT16 WINAPI waveOutGetPitch16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1372 {
1373     return waveOutGetPitch(HWAVEOUT_32(hWaveOut16), lpdw);
1374 }
1375
1376 /**************************************************************************
1377  *                              waveOutSetPitch         [MMSYSTEM.414]
1378  */
1379 UINT16 WINAPI waveOutSetPitch16(HWAVEOUT16 hWaveOut16, DWORD dw)
1380 {
1381     return waveOutSetPitch(HWAVEOUT_32(hWaveOut16), dw);
1382 }
1383
1384 /**************************************************************************
1385  *                              waveOutGetPlaybackRate  [MMSYSTEM.417]
1386  */
1387 UINT16 WINAPI waveOutGetPlaybackRate16(HWAVEOUT16 hWaveOut16, LPDWORD lpdw)
1388 {
1389     return waveOutGetPlaybackRate(HWAVEOUT_32(hWaveOut16), lpdw);
1390 }
1391
1392 /**************************************************************************
1393  *                              waveOutSetPlaybackRate  [MMSYSTEM.418]
1394  */
1395 UINT16 WINAPI waveOutSetPlaybackRate16(HWAVEOUT16 hWaveOut16, DWORD dw)
1396 {
1397     return waveOutSetPlaybackRate(HWAVEOUT_32(hWaveOut16), dw);
1398 }
1399
1400 /**************************************************************************
1401  *                              waveOutGetVolume        [MMSYSTEM.415]
1402  */
1403 UINT16 WINAPI waveOutGetVolume16(UINT16 devid, LPDWORD lpdw)
1404 {
1405     return waveOutGetVolume(devid, lpdw);
1406 }
1407
1408 /**************************************************************************
1409  *                              waveOutSetVolume        [MMSYSTEM.416]
1410  */
1411 UINT16 WINAPI waveOutSetVolume16(UINT16 devid, DWORD dw)
1412 {
1413     return waveOutSetVolume(devid, dw);
1414 }
1415
1416 /**************************************************************************
1417  *                              waveOutGetID            [MMSYSTEM.420]
1418  */
1419 UINT16 WINAPI waveOutGetID16(HWAVEOUT16 hWaveOut, UINT16* lpuDeviceID)
1420 {
1421     LPWINE_MLD          wmld;
1422
1423     TRACE("(%04X, %p);\n", hWaveOut, lpuDeviceID);
1424
1425     if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1426
1427     if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL)
1428         return MMSYSERR_INVALHANDLE;
1429
1430     *lpuDeviceID = wmld->uDeviceID;
1431     return 0;
1432 }
1433
1434 /**************************************************************************
1435  *                              waveOutMessage          [MMSYSTEM.421]
1436  */
1437 DWORD WINAPI waveOutMessage16(HWAVEOUT16 hWaveOut, UINT16 uMessage,
1438                               DWORD dwParam1, DWORD dwParam2)
1439 {
1440     LPWINE_MLD          wmld;
1441
1442     TRACE("(%04x, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
1443
1444     if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, FALSE)) == NULL) {
1445         if ((wmld = MMDRV_Get(HWAVEOUT_32(hWaveOut), MMDRV_WAVEOUT, TRUE)) != NULL) {
1446             return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1447         }
1448         return MMSYSERR_INVALHANDLE;
1449     }
1450
1451     /* from M$ KB */
1452     if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1453         return MMSYSERR_INVALPARAM;
1454
1455     return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
1456 }
1457
1458 /**************************************************************************
1459  *                              waveInGetNumDevs                [MMSYSTEM.501]
1460  */
1461 UINT16 WINAPI waveInGetNumDevs16(void)
1462 {
1463     return MMDRV_GetNum(MMDRV_WAVEIN);
1464 }
1465
1466 /**************************************************************************
1467  *                              waveInGetDevCaps                [MMSYSTEM.502]
1468  */
1469 UINT16 WINAPI waveInGetDevCaps16(UINT16 uDeviceID, LPWAVEINCAPS16 lpCaps,
1470                                  UINT16 uSize)
1471 {
1472     WAVEINCAPSA wicA;
1473     UINT        ret = waveInGetDevCapsA(uDeviceID, &wicA, sizeof(wicA));
1474
1475     if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1476
1477     if (ret == MMSYSERR_NOERROR) {
1478         lpCaps->wMid = wicA.wMid;
1479         lpCaps->wPid = wicA.wPid;
1480         lpCaps->vDriverVersion = wicA.vDriverVersion;
1481         strcpy(lpCaps->szPname, wicA.szPname);
1482         lpCaps->dwFormats = wicA.dwFormats;
1483         lpCaps->wChannels = wicA.wChannels;
1484     }
1485     return ret;
1486 }
1487
1488 /**************************************************************************
1489  *                              waveInGetErrorText      [MMSYSTEM.503]
1490  */
1491 UINT16 WINAPI waveInGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
1492 {
1493     return waveInGetErrorTextA(uError, lpText, uSize);
1494 }
1495
1496 /**************************************************************************
1497  *                              waveInOpen                      [MMSYSTEM.504]
1498  */
1499 UINT16 WINAPI waveInOpen16(HWAVEIN16* lphWaveIn, UINT16 uDeviceID,
1500                            const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
1501                            DWORD dwInstance, DWORD dwFlags)
1502 {
1503     HWAVEIN             hWaveIn;
1504     UINT                ret;
1505
1506     /* since layout of WAVEFORMATEX is the same for 16/32 bits, we directly
1507      * call the 32 bit version
1508      * however, we need to promote correctly the wave mapper id
1509      * (0xFFFFFFFF and not 0x0000FFFF)
1510      */
1511     ret = MMSYSTEM_waveOpen(&hWaveIn, (uDeviceID == (UINT16)-1) ? (UINT)-1 : uDeviceID,
1512                             MMDRV_WAVEIN, lpFormat, dwCallback, dwInstance, dwFlags, FALSE);
1513
1514     if (lphWaveIn != NULL) *lphWaveIn = HWAVEIN_16(hWaveIn);
1515     return ret;
1516 }
1517
1518 /**************************************************************************
1519  *                              waveInClose                     [MMSYSTEM.505]
1520  */
1521 UINT16 WINAPI waveInClose16(HWAVEIN16 hWaveIn)
1522 {
1523     DWORD       level;
1524     UINT16      ret;
1525
1526     ReleaseThunkLock(&level);
1527     ret = waveInClose(HWAVEIN_32(hWaveIn));
1528     RestoreThunkLock(level);
1529     return ret;
1530 }
1531
1532 /**************************************************************************
1533  *                              waveInPrepareHeader             [MMSYSTEM.506]
1534  */
1535 UINT16 WINAPI waveInPrepareHeader16(HWAVEIN16 hWaveIn,       /* [in] */
1536                                     SEGPTR lpsegWaveInHdr,   /* [???] */
1537                                     UINT16 uSize)            /* [in] */
1538 {
1539     LPWINE_MLD          wmld;
1540     LPWAVEHDR           lpWaveInHdr = MapSL(lpsegWaveInHdr);
1541     UINT16              ret;
1542
1543     TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
1544
1545     if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
1546     if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1547         return MMSYSERR_INVALHANDLE;
1548
1549     lpWaveInHdr->dwBytesRecorded = 0;
1550
1551     ret = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD)lpsegWaveInHdr, uSize, FALSE);
1552     return ret;
1553 }
1554
1555 /**************************************************************************
1556  *                              waveInUnprepareHeader   [MMSYSTEM.507]
1557  */
1558 UINT16 WINAPI waveInUnprepareHeader16(HWAVEIN16 hWaveIn,       /* [in] */
1559                                       SEGPTR lpsegWaveInHdr,   /* [???] */
1560                                       UINT16 uSize)            /* [in] */
1561 {
1562     LPWINE_MLD          wmld;
1563     LPWAVEHDR           lpWaveInHdr = MapSL(lpsegWaveInHdr);
1564
1565     TRACE("(%04X, %08lx, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1566
1567     if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1568
1569     if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
1570         return MMSYSERR_NOERROR;
1571     }
1572
1573     if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1574         return MMSYSERR_INVALHANDLE;
1575
1576     return MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD)lpsegWaveInHdr, uSize, FALSE);
1577 }
1578
1579 /**************************************************************************
1580  *                              waveInAddBuffer         [MMSYSTEM.508]
1581  */
1582 UINT16 WINAPI waveInAddBuffer16(HWAVEIN16 hWaveIn,       /* [in] */
1583                                 WAVEHDR* lpsegWaveInHdr, /* [???] NOTE: SEGPTR */
1584                                 UINT16 uSize)            /* [in] */
1585 {
1586     LPWINE_MLD          wmld;
1587
1588     TRACE("(%04X, %p, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
1589
1590     if (lpsegWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
1591     if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1592         return MMSYSERR_INVALHANDLE;
1593
1594     return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD)lpsegWaveInHdr, uSize, FALSE);
1595 }
1596
1597 /**************************************************************************
1598  *                              waveInReset             [MMSYSTEM.511]
1599  */
1600 UINT16 WINAPI waveInReset16(HWAVEIN16 hWaveIn16)
1601 {
1602     DWORD       level;
1603     UINT16      ret;
1604
1605     ReleaseThunkLock(&level);
1606     ret = waveInReset(HWAVEIN_32(hWaveIn16));
1607     RestoreThunkLock(level);
1608     return ret;
1609 }
1610
1611 /**************************************************************************
1612  *                              waveInStart             [MMSYSTEM.509]
1613  */
1614 UINT16 WINAPI waveInStart16(HWAVEIN16 hWaveIn16)
1615 {
1616     DWORD       level;
1617     UINT16      ret;
1618
1619     ReleaseThunkLock(&level);
1620     ret = waveInStart(HWAVEIN_32(hWaveIn16));
1621     RestoreThunkLock(level);
1622     return ret;
1623 }
1624
1625 /**************************************************************************
1626  *                              waveInStop              [MMSYSTEM.510]
1627  */
1628 UINT16 WINAPI waveInStop16(HWAVEIN16 hWaveIn16)
1629 {
1630     DWORD       level;
1631     UINT16      ret;
1632
1633     ReleaseThunkLock(&level);
1634     ret = waveInStop(HWAVEIN_32(hWaveIn16));
1635     RestoreThunkLock(level);
1636     return ret;
1637 }
1638
1639 /**************************************************************************
1640  *                              waveInGetPosition       [MMSYSTEM.512]
1641  */
1642 UINT16 WINAPI waveInGetPosition16(HWAVEIN16 hWaveIn, LPMMTIME16 lpTime,
1643                                   UINT16 uSize)
1644 {
1645     UINT        ret;
1646     MMTIME      mmt;
1647
1648     mmt.wType = lpTime->wType;
1649     ret = waveInGetPosition(HWAVEIN_32(hWaveIn), &mmt, sizeof(mmt));
1650     MMSYSTEM_MMTIME32to16(lpTime, &mmt);
1651     return ret;
1652 }
1653
1654 /**************************************************************************
1655  *                              waveInGetID                     [MMSYSTEM.513]
1656  */
1657 UINT16 WINAPI waveInGetID16(HWAVEIN16 hWaveIn, UINT16* lpuDeviceID)
1658 {
1659     LPWINE_MLD          wmld;
1660
1661     TRACE("(%04X, %p);\n", hWaveIn, lpuDeviceID);
1662
1663     if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
1664
1665     if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1666         return MMSYSERR_INVALHANDLE;
1667
1668     *lpuDeviceID = wmld->uDeviceID;
1669     return MMSYSERR_NOERROR;
1670 }
1671
1672 /**************************************************************************
1673  *                              waveInMessage           [MMSYSTEM.514]
1674  */
1675 DWORD WINAPI waveInMessage16(HWAVEIN16 hWaveIn, UINT16 uMessage,
1676                              DWORD dwParam1, DWORD dwParam2)
1677 {
1678     LPWINE_MLD          wmld;
1679
1680     TRACE("(%04x, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
1681
1682     /* from M$ KB */
1683     if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
1684         return MMSYSERR_INVALPARAM;
1685
1686     if ((wmld = MMDRV_Get(HWAVEIN_32(hWaveIn), MMDRV_WAVEIN, FALSE)) == NULL)
1687         return MMSYSERR_INVALHANDLE;
1688
1689     return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1690 }
1691
1692 /* ###################################################
1693  * #                     TASK                        #
1694  * ###################################################
1695  */
1696
1697 /*#define USE_MM_TSK_WINE*/
1698
1699 /**************************************************************************
1700  *                              mmTaskCreate            [MMSYSTEM.900]
1701  *
1702  * Creates a 16 bit MM task. It's entry point is lpFunc, and it should be
1703  * called upon creation with dwPmt as parameter.
1704  */
1705 HINSTANCE16 WINAPI mmTaskCreate16(SEGPTR spProc, HINSTANCE16 *lphMmTask, DWORD dwPmt)
1706 {
1707     HINSTANCE16         ret;
1708     HINSTANCE16         handle;
1709     char cmdline[16];
1710     DWORD showCmd = 0x40002;
1711     LOADPARAMS16 lp;
1712
1713     TRACE("(%08lx, %p, %08lx);\n", spProc, lphMmTask, dwPmt);
1714     /* This to work requires NE modules to be started with a binary command line
1715      * which is not currently the case. A patch exists but has never been committed.
1716      * A workaround would be to integrate code for mmtask.tsk into Wine, but
1717      * this requires tremendous work (starting with patching tools/build to
1718      * create NE executables (and not only DLLs) for builtins modules.
1719      * EP 99/04/25
1720      */
1721     FIXME("This is currently broken. It will fail\n");
1722
1723     cmdline[0] = 0x0d;
1724     *(LPDWORD)(cmdline + 1) = (DWORD)spProc;
1725     *(LPDWORD)(cmdline + 5) = dwPmt;
1726     *(LPDWORD)(cmdline + 9) = 0;
1727
1728     lp.hEnvironment = 0;
1729     lp.cmdLine = MapLS(cmdline);
1730     lp.showCmd = MapLS(&showCmd);
1731     lp.reserved = 0;
1732
1733 #ifndef USE_MM_TSK_WINE
1734     handle = LoadModule16("c:\\windows\\system\\mmtask.tsk", &lp);
1735 #else
1736     handle = LoadModule16("mmtask.tsk", &lp);
1737 #endif
1738     if (handle < 32) {
1739         ret = (handle) ? 1 : 2;
1740         handle = 0;
1741     } else {
1742         ret = 0;
1743     }
1744     if (lphMmTask)
1745         *lphMmTask = handle;
1746
1747     UnMapLS( lp.cmdLine );
1748     UnMapLS( lp.showCmd );
1749     TRACE("=> 0x%04x/%d\n", handle, ret);
1750     return ret;
1751 }
1752
1753 #ifdef USE_MM_TSK_WINE
1754 /* C equivalent to mmtask.tsk binary content */
1755 void    mmTaskEntryPoint16(LPSTR cmdLine, WORD di, WORD si)
1756 {
1757     int len = cmdLine[0x80];
1758
1759     if (len / 2 == 6) {
1760         void    (*fpProc)(DWORD) = MapSL(*((DWORD*)(cmdLine + 1)));
1761         DWORD   dwPmt  = *((DWORD*)(cmdLine + 5));
1762
1763 #if 0
1764         InitTask16(); /* FIXME: pmts / from context ? */
1765         InitApp(di);
1766 #endif
1767         if (SetMessageQueue16(0x40)) {
1768             WaitEvent16(0);
1769             if (HIWORD(fpProc)) {
1770                 OldYield16();
1771 /* EPP          StackEnter16(); */
1772                 (fpProc)(dwPmt);
1773             }
1774         }
1775     }
1776     OldYield16();
1777     OldYield16();
1778     OldYield16();
1779     ExitProcess(0);
1780 }
1781 #endif
1782
1783 /**************************************************************************
1784  *                              mmTaskBlock             [MMSYSTEM.902]
1785  */
1786 void    WINAPI  mmTaskBlock16(HINSTANCE16 WINE_UNUSED hInst)
1787 {
1788     MSG         msg;
1789
1790     do {
1791         GetMessageA(&msg, 0, 0, 0);
1792         if (msg.hwnd) {
1793             TranslateMessage(&msg);
1794             DispatchMessageA(&msg);
1795         }
1796     } while (msg.message < 0x3A0);
1797 }
1798
1799 /**************************************************************************
1800  *                              mmTaskSignal            [MMSYSTEM.903]
1801  */
1802 LRESULT WINAPI mmTaskSignal16(HTASK16 ht)
1803 {
1804     TRACE("(%04x);\n", ht);
1805     return PostAppMessage16(ht, WM_USER, 0, 0);
1806 }
1807
1808 /**************************************************************************
1809  *                              mmGetCurrentTask        [MMSYSTEM.904]
1810  */
1811 HTASK16 WINAPI mmGetCurrentTask16(void)
1812 {
1813     return GetCurrentTask();
1814 }
1815
1816 /**************************************************************************
1817  *                              mmTaskYield             [MMSYSTEM.905]
1818  */
1819 void    WINAPI  mmTaskYield16(void)
1820 {
1821     MSG         msg;
1822
1823     if (PeekMessageA(&msg, 0, 0, 0, 0)) {
1824         K32WOWYield16();
1825     }
1826 }
1827
1828 extern DWORD    WINAPI  GetProcessFlags(DWORD);
1829
1830 /******************************************************************
1831  *              WINMM_GetmmThread
1832  *
1833  *
1834  */
1835 static  WINE_MMTHREAD*  WINMM_GetmmThread(HANDLE16 h)
1836 {
1837     return (WINE_MMTHREAD*)MapSL( MAKESEGPTR(h, 0) );
1838 }
1839
1840 void WINAPI WINE_mmThreadEntryPoint(DWORD);
1841
1842 /**************************************************************************
1843  *                              mmThreadCreate          [MMSYSTEM.1120]
1844  *
1845  * undocumented
1846  * Creates a MM thread, calling fpThreadAddr(dwPmt).
1847  * dwFlags:
1848  *      bit.0 set means create a 16 bit task instead of thread calling a 16 bit proc
1849  *      bit.1 set means to open a VxD for this thread (unsupported)
1850  */
1851 LRESULT WINAPI mmThreadCreate16(FARPROC16 fpThreadAddr, LPHANDLE lpHndl, DWORD dwPmt, DWORD dwFlags)
1852 {
1853     HANDLE16            hndl;
1854     LRESULT             ret;
1855
1856     TRACE("(%p, %p, %08lx, %08lx)!\n", fpThreadAddr, lpHndl, dwPmt, dwFlags);
1857
1858     hndl = GlobalAlloc16(sizeof(WINE_MMTHREAD), GMEM_SHARE|GMEM_ZEROINIT);
1859
1860     if (hndl == 0) {
1861         ret = 2;
1862     } else {
1863         WINE_MMTHREAD*  lpMMThd = WINMM_GetmmThread(hndl);
1864
1865 #if 0
1866         /* force mmtask routines even if mmthread is required */
1867         /* this will work only if the patch about binary cmd line and NE tasks
1868          * is committed
1869          */
1870         dwFlags |= 1;
1871 #endif
1872
1873         lpMMThd->dwSignature    = WINE_MMTHREAD_CREATED;
1874         lpMMThd->dwCounter      = 0;
1875         lpMMThd->hThread        = 0;
1876         lpMMThd->dwThreadID     = 0;
1877         lpMMThd->fpThread       = fpThreadAddr;
1878         lpMMThd->dwThreadPmt    = dwPmt;
1879         lpMMThd->dwSignalCount  = 0;
1880         lpMMThd->hEvent         = 0;
1881         lpMMThd->hVxD           = 0;
1882         lpMMThd->dwStatus       = 0;
1883         lpMMThd->dwFlags        = dwFlags;
1884         lpMMThd->hTask          = 0;
1885
1886         if ((dwFlags & 1) == 0 && (GetProcessFlags(GetCurrentThreadId()) & 8) == 0) {
1887             lpMMThd->hEvent = CreateEventA(0, 0, 1, 0);
1888
1889             TRACE("Let's go crazy... trying new MM thread. lpMMThd=%p\n", lpMMThd);
1890             if (lpMMThd->dwFlags & 2) {
1891                 /* as long as we don't support MM VxD in wine, we don't need
1892                  * to care about this flag
1893                  */
1894                 /* FIXME("Don't know how to properly open VxD handles\n"); */
1895                 /* lpMMThd->hVxD = OpenVxDHandle(lpMMThd->hEvent); */
1896             }
1897
1898             lpMMThd->hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)WINE_mmThreadEntryPoint,
1899                                             (LPVOID)(DWORD)hndl, CREATE_SUSPENDED, &lpMMThd->dwThreadID);
1900             if (lpMMThd->hThread == 0) {
1901                 WARN("Couldn't create thread\n");
1902                 /* clean-up(VxDhandle...); devicedirectio... */
1903                 if (lpMMThd->hEvent != 0)
1904                     CloseHandle(lpMMThd->hEvent);
1905                 ret = 2;
1906             } else {
1907                 TRACE("Got a nice thread hndl=0x%04x id=0x%08lx\n", lpMMThd->hThread, lpMMThd->dwThreadID);
1908                 ret = 0;
1909             }
1910         } else {
1911             /* get WINE_mmThreadEntryPoint()
1912              * 2047 is its ordinal in mmsystem.spec
1913              */
1914             FARPROC16   fp = GetProcAddress16(GetModuleHandle16("MMSYSTEM"), (LPCSTR)2047);
1915
1916             TRACE("farproc seg=0x%08lx lin=%p\n", (DWORD)fp, MapSL((SEGPTR)fp));
1917
1918             ret = (fp == 0) ? 2 : mmTaskCreate16((DWORD)fp, 0, hndl);
1919         }
1920
1921         if (ret == 0) {
1922             if (lpMMThd->hThread && !ResumeThread(lpMMThd->hThread))
1923                 WARN("Couldn't resume thread\n");
1924
1925             while (lpMMThd->dwStatus != 0x10) { /* test also HIWORD of dwStatus */
1926                 UserYield16();
1927             }
1928         }
1929     }
1930
1931     if (ret != 0) {
1932         GlobalFree16(hndl);
1933         hndl = 0;
1934     }
1935
1936     if (lpHndl)
1937         *lpHndl = hndl;
1938
1939     TRACE("ok => %ld\n", ret);
1940     return ret;
1941 }
1942
1943 /**************************************************************************
1944  *                              mmThreadSignal          [MMSYSTEM.1121]
1945  */
1946 void WINAPI mmThreadSignal16(HANDLE16 hndl)
1947 {
1948     TRACE("(%04x)!\n", hndl);
1949
1950     if (hndl) {
1951         WINE_MMTHREAD*  lpMMThd = WINMM_GetmmThread(hndl);
1952
1953         lpMMThd->dwCounter++;
1954         if (lpMMThd->hThread != 0) {
1955             InterlockedIncrement(&lpMMThd->dwSignalCount);
1956             SetEvent(lpMMThd->hEvent);
1957         } else {
1958             mmTaskSignal16(lpMMThd->hTask);
1959         }
1960         lpMMThd->dwCounter--;
1961     }
1962 }
1963
1964 static  void    MMSYSTEM_ThreadBlock(WINE_MMTHREAD* lpMMThd)
1965 {
1966     MSG         msg;
1967     DWORD       ret;
1968
1969     if (lpMMThd->dwThreadID != GetCurrentThreadId())
1970         ERR("Not called by thread itself\n");
1971
1972     for (;;) {
1973         ResetEvent(lpMMThd->hEvent);
1974         if (InterlockedDecrement(&lpMMThd->dwSignalCount) >= 0)
1975             break;
1976         InterlockedIncrement(&lpMMThd->dwSignalCount);
1977
1978         TRACE("S1\n");
1979
1980         ret = MsgWaitForMultipleObjects(1, &lpMMThd->hEvent, FALSE, INFINITE, QS_ALLINPUT);
1981         switch (ret) {
1982         case WAIT_OBJECT_0:     /* Event */
1983             TRACE("S2.1\n");
1984             break;
1985         case WAIT_OBJECT_0 + 1: /* Msg */
1986             TRACE("S2.2\n");
1987             if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1988                 TranslateMessage(&msg);
1989                 DispatchMessageA(&msg);
1990             }
1991             break;
1992         default:
1993             WARN("S2.x unsupported ret val 0x%08lx\n", ret);
1994         }
1995         TRACE("S3\n");
1996     }
1997 }
1998
1999 /**************************************************************************
2000  *                              mmThreadBlock           [MMSYSTEM.1122]
2001  */
2002 void    WINAPI mmThreadBlock16(HANDLE16 hndl)
2003 {
2004     TRACE("(%04x)!\n", hndl);
2005
2006     if (hndl) {
2007         WINE_MMTHREAD*  lpMMThd = WINMM_GetmmThread(hndl);
2008
2009         if (lpMMThd->hThread != 0) {
2010             DWORD       lc;
2011
2012             ReleaseThunkLock(&lc);
2013             MMSYSTEM_ThreadBlock(lpMMThd);
2014             RestoreThunkLock(lc);
2015         } else {
2016             mmTaskBlock16(lpMMThd->hTask);
2017         }
2018     }
2019     TRACE("done\n");
2020 }
2021
2022 /**************************************************************************
2023  *                              mmThreadIsCurrent       [MMSYSTEM.1123]
2024  */
2025 BOOL16  WINAPI mmThreadIsCurrent16(HANDLE16 hndl)
2026 {
2027     BOOL16              ret = FALSE;
2028
2029     TRACE("(%04x)!\n", hndl);
2030
2031     if (hndl && mmThreadIsValid16(hndl)) {
2032         WINE_MMTHREAD*  lpMMThd = WINMM_GetmmThread(hndl);
2033         ret = (GetCurrentThreadId() == lpMMThd->dwThreadID);
2034     }
2035     TRACE("=> %d\n", ret);
2036     return ret;
2037 }
2038
2039 /**************************************************************************
2040  *                              mmThreadIsValid         [MMSYSTEM.1124]
2041  */
2042 BOOL16  WINAPI  mmThreadIsValid16(HANDLE16 hndl)
2043 {
2044     BOOL16              ret = FALSE;
2045
2046     TRACE("(%04x)!\n", hndl);
2047
2048     if (hndl) {
2049         WINE_MMTHREAD*  lpMMThd = WINMM_GetmmThread(hndl);
2050
2051         if (!IsBadWritePtr(lpMMThd, sizeof(WINE_MMTHREAD)) &&
2052             lpMMThd->dwSignature == WINE_MMTHREAD_CREATED &&
2053             IsTask16(lpMMThd->hTask)) {
2054             lpMMThd->dwCounter++;
2055             if (lpMMThd->hThread != 0) {
2056                 DWORD   dwThreadRet;
2057                 if (GetExitCodeThread(lpMMThd->hThread, &dwThreadRet) &&
2058                     dwThreadRet == STATUS_PENDING) {
2059                     ret = TRUE;
2060                 }
2061             } else {
2062                 ret = TRUE;
2063             }
2064             lpMMThd->dwCounter--;
2065         }
2066     }
2067     TRACE("=> %d\n", ret);
2068     return ret;
2069 }
2070
2071 /**************************************************************************
2072  *                              mmThreadGetTask         [MMSYSTEM.1125]
2073  */
2074 HANDLE16 WINAPI mmThreadGetTask16(HANDLE16 hndl)
2075 {
2076     HANDLE16    ret = 0;
2077
2078     TRACE("(%04x)\n", hndl);
2079
2080     if (mmThreadIsValid16(hndl)) {
2081         WINE_MMTHREAD*  lpMMThd = WINMM_GetmmThread(hndl);
2082         ret = lpMMThd->hTask;
2083     }
2084     return ret;
2085 }
2086
2087 /**************************************************************************
2088  *                              WINE_mmThreadEntryPoint (MMSYSTEM.2047)
2089  */
2090 void WINAPI WINE_mmThreadEntryPoint(DWORD _pmt)
2091 {
2092     HANDLE16            hndl = (HANDLE16)_pmt;
2093     WINE_MMTHREAD*      lpMMThd = WINMM_GetmmThread(hndl);
2094
2095     TRACE("(%04x %p)\n", hndl, lpMMThd);
2096
2097     lpMMThd->hTask = LOWORD(GetCurrentTask());
2098     TRACE("[10-%08x] setting hTask to 0x%08x\n", lpMMThd->hThread, lpMMThd->hTask);
2099     lpMMThd->dwStatus = 0x10;
2100     MMSYSTEM_ThreadBlock(lpMMThd);
2101     TRACE("[20-%08x]\n", lpMMThd->hThread);
2102     lpMMThd->dwStatus = 0x20;
2103     if (lpMMThd->fpThread) {
2104         MMSYSTEM_CallTo16_long_l(lpMMThd->fpThread, lpMMThd->dwThreadPmt);
2105     }
2106     lpMMThd->dwStatus = 0x30;
2107     TRACE("[30-%08x]\n", lpMMThd->hThread);
2108     while (lpMMThd->dwCounter) {
2109         Sleep(1);
2110         /* K32WOWYield16();*/
2111     }
2112     TRACE("[XX-%08x]\n", lpMMThd->hThread);
2113     /* paranoia */
2114     lpMMThd->dwSignature = WINE_MMTHREAD_DELETED;
2115     /* close lpMMThread->hVxD directIO */
2116     if (lpMMThd->hEvent)
2117         CloseHandle(lpMMThd->hEvent);
2118     GlobalFree16(hndl);
2119     TRACE("done\n");
2120 }
2121
2122 typedef BOOL16 (WINAPI *MMCPLCALLBACK)(HWND, LPCSTR, LPCSTR, LPCSTR);
2123
2124 /**************************************************************************
2125  *                      mmShowMMCPLPropertySheet        [MMSYSTEM.1150]
2126  */
2127 BOOL16  WINAPI  mmShowMMCPLPropertySheet16(HWND hWnd, LPCSTR lpStrDevice,
2128                                            LPCSTR lpStrTab, LPCSTR lpStrTitle)
2129 {
2130     HANDLE      hndl;
2131     BOOL16      ret = FALSE;
2132
2133     TRACE("(%04x \"%s\" \"%s\" \"%s\")\n", hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2134
2135     hndl = LoadLibraryA("MMSYS.CPL");
2136     if (hndl != 0) {
2137         MMCPLCALLBACK   fp = (MMCPLCALLBACK)GetProcAddress(hndl, "ShowMMCPLPropertySheet");
2138         if (fp != NULL) {
2139             DWORD       lc;
2140             ReleaseThunkLock(&lc);
2141             ret = (fp)(hWnd, lpStrDevice, lpStrTab, lpStrTitle);
2142             RestoreThunkLock(lc);
2143         }
2144         FreeLibrary(hndl);
2145     }
2146
2147     return ret;
2148 }
2149
2150 /**************************************************************************
2151  *                      StackEnter              [MMSYSTEM.32]
2152  */
2153 void WINAPI StackEnter16(void)
2154 {
2155 #ifdef __i386__
2156     /* mmsystem.dll from Win 95 does only this: so does Wine */
2157     __asm__("stc");
2158 #endif
2159 }
2160
2161 /**************************************************************************
2162  *                      StackLeave              [MMSYSTEM.33]
2163  */
2164 void WINAPI StackLeave16(void)
2165 {
2166 #ifdef __i386__
2167     /* mmsystem.dll from Win 95 does only this: so does Wine */
2168     __asm__("stc");
2169 #endif
2170 }
2171
2172 /**************************************************************************
2173  *                      WMMMidiRunOnce          [MMSYSTEM.8]
2174  */
2175 void WINAPI WMMMidiRunOnce16(void)
2176 {
2177     FIXME("(), stub!\n");
2178 }
2179
2180 /* ###################################################
2181  * #                    DRIVER                       #
2182  * ###################################################
2183  */
2184
2185 /**************************************************************************
2186  *                              DRIVER_MapMsg32To16             [internal]
2187  *
2188  * Map a 32 bit driver message to a 16 bit driver message.
2189  */
2190 WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lParam2)
2191 {
2192     WINMM_MapType       ret = WINMM_MAP_MSGERROR;
2193
2194     switch (wMsg) {
2195     case DRV_LOAD:
2196     case DRV_ENABLE:
2197     case DRV_DISABLE:
2198     case DRV_FREE:
2199     case DRV_QUERYCONFIGURE:
2200     case DRV_REMOVE:
2201     case DRV_EXITSESSION:
2202     case DRV_EXITAPPLICATION:
2203     case DRV_POWER:
2204     case DRV_CLOSE:     /* should be 0/0 */
2205     case DRV_OPEN:      /* pass through */
2206         /* lParam1 and lParam2 are not used */
2207         ret = WINMM_MAP_OK;
2208         break;
2209     case DRV_CONFIGURE:
2210     case DRV_INSTALL:
2211         /* lParam1 is a handle to a window (conf) or to a driver (inst) or not used,
2212          * lParam2 is a pointer to DRVCONFIGINFO
2213          */
2214         if (*lParam2) {
2215             LPDRVCONFIGINFO16 dci16 = HeapAlloc( GetProcessHeap(), 0, sizeof(*dci16) );
2216             LPDRVCONFIGINFO     dci32 = (LPDRVCONFIGINFO)(*lParam2);
2217
2218             if (dci16) {
2219                 LPSTR str1;
2220
2221                 dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
2222
2223                 if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCISectionName)) != NULL)
2224                 {
2225                     dci16->lpszDCISectionName = MapLS( str1 );
2226                 } else {
2227                     return WINMM_MAP_NOMEM;
2228                 }
2229                 if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCIAliasName)) != NULL)
2230                 {
2231                     dci16->lpszDCIAliasName = MapLS( str1 );
2232                 } else {
2233                     return WINMM_MAP_NOMEM;
2234                 }
2235             } else {
2236                 return WINMM_MAP_NOMEM;
2237             }
2238             *lParam2 = MapLS( dci16 );
2239             ret = WINMM_MAP_OKMEM;
2240         } else {
2241             ret = WINMM_MAP_OK;
2242         }
2243         break;
2244     default:
2245         if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2246            FIXME("Unknown message 0x%04x\n", wMsg);
2247         }
2248         ret = WINMM_MAP_OK;
2249     }
2250     return ret;
2251 }
2252
2253 /**************************************************************************
2254  *                              DRIVER_UnMapMsg32To16           [internal]
2255  *
2256  * UnMap a 32 bit driver message to a 16 bit driver message.
2257  */
2258 WINMM_MapType DRIVER_UnMapMsg32To16(WORD wMsg, DWORD lParam1, DWORD lParam2)
2259 {
2260     WINMM_MapType       ret = WINMM_MAP_MSGERROR;
2261
2262     switch (wMsg) {
2263     case DRV_LOAD:
2264     case DRV_ENABLE:
2265     case DRV_DISABLE:
2266     case DRV_FREE:
2267     case DRV_QUERYCONFIGURE:
2268     case DRV_REMOVE:
2269     case DRV_EXITSESSION:
2270     case DRV_EXITAPPLICATION:
2271     case DRV_POWER:
2272     case DRV_OPEN:
2273     case DRV_CLOSE:
2274         /* lParam1 and lParam2 are not used */
2275         break;
2276     case DRV_CONFIGURE:
2277     case DRV_INSTALL:
2278         /* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
2279         if (lParam2) {
2280             LPDRVCONFIGINFO16   dci16 = MapSL(lParam2);
2281             HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCISectionName) );
2282             HeapFree( GetProcessHeap(), 0, MapSL(dci16->lpszDCIAliasName) );
2283             UnMapLS( lParam2 );
2284             UnMapLS( dci16->lpszDCISectionName );
2285             UnMapLS( dci16->lpszDCIAliasName );
2286             HeapFree( GetProcessHeap(), 0, dci16 );
2287         }
2288         ret = WINMM_MAP_OK;
2289         break;
2290     default:
2291         if (!((wMsg >= 0x800 && wMsg < 0x900) || (wMsg >= 0x4000 && wMsg < 0x4100))) {
2292             FIXME("Unknown message 0x%04x\n", wMsg);
2293         }
2294         ret = WINMM_MAP_OK;
2295     }
2296     return ret;
2297 }
2298
2299 /**************************************************************************
2300  *                              DrvOpen                 [MMSYSTEM.1100]
2301  */
2302 HDRVR16 WINAPI DrvOpen16(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
2303 {
2304     return OpenDriver16(lpDriverName, lpSectionName, lParam);
2305 }
2306
2307 /**************************************************************************
2308  *                              DrvClose                [MMSYSTEM.1101]
2309  */
2310 LRESULT WINAPI DrvClose16(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
2311 {
2312     return CloseDriver16(hDrv, lParam1, lParam2);
2313 }
2314
2315 /**************************************************************************
2316  *                              DrvSendMessage          [MMSYSTEM.1102]
2317  */
2318 LRESULT WINAPI DrvSendMessage16(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
2319                                 LPARAM lParam2)
2320 {
2321     return SendDriverMessage16(hDrv, msg, lParam1, lParam2);
2322 }
2323
2324 /**************************************************************************
2325  *                              DrvGetModuleHandle      [MMSYSTEM.1103]
2326  */
2327 HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
2328 {
2329     return GetDriverModuleHandle16(hDrv);
2330 }
2331
2332 /**************************************************************************
2333  *                              DrvDefDriverProc        [MMSYSTEM.1104]
2334  */
2335 LRESULT WINAPI DrvDefDriverProc16(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg,
2336                                   DWORD dwParam1, DWORD dwParam2)
2337 {
2338     return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
2339 }
2340
2341 /**************************************************************************
2342  *                              DriverProc                      [MMSYSTEM.6]
2343  */
2344 LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
2345                             DWORD dwParam1, DWORD dwParam2)
2346 {
2347     TRACE("dwDevID=%08lx hDrv=%04x wMsg=%04x dwParam1=%08lx dwParam2=%08lx\n",
2348           dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2349
2350     return DrvDefDriverProc16(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
2351 }
2352
2353 /* ###################################################
2354  * #                     TIME                        #
2355  * ###################################################
2356  */
2357
2358 /**************************************************************************
2359  *                              timeGetSystemTime       [MMSYSTEM.601]
2360  */
2361 MMRESULT16 WINAPI timeGetSystemTime16(LPMMTIME16 lpTime, UINT16 wSize)
2362 {
2363     TRACE("(%p, %u);\n", lpTime, wSize);
2364
2365     if (wSize >= sizeof(*lpTime)) {
2366         lpTime->wType = TIME_MS;
2367         TIME_MMTimeStart();
2368         lpTime->u.ms = WINMM_IData->mmSysTimeMS;
2369
2370         TRACE("=> %lu\n", lpTime->u.ms);
2371     }
2372
2373     return 0;
2374 }
2375
2376 /**************************************************************************
2377  *                              timeSetEvent            [MMSYSTEM.602]
2378  */
2379 MMRESULT16 WINAPI timeSetEvent16(UINT16 wDelay, UINT16 wResol, LPTIMECALLBACK16 lpFunc,
2380                                  DWORD dwUser, UINT16 wFlags)
2381 {
2382     if (wFlags & WINE_TIMER_IS32)
2383         WARN("Unknown windows flag... wine internally used.. ooch\n");
2384
2385     return timeSetEventInternal(wDelay, wResol, (FARPROC16)lpFunc,
2386                                 dwUser, wFlags & ~WINE_TIMER_IS32);
2387 }
2388
2389 /**************************************************************************
2390  *                              timeKillEvent           [MMSYSTEM.603]
2391  */
2392 MMRESULT16 WINAPI timeKillEvent16(UINT16 wID)
2393 {
2394     return timeKillEvent(wID);
2395 }
2396
2397 /**************************************************************************
2398  *                              timeGetDevCaps          [MMSYSTEM.604]
2399  */
2400 MMRESULT16 WINAPI timeGetDevCaps16(LPTIMECAPS16 lpCaps, UINT16 wSize)
2401 {
2402     TIMECAPS    caps;
2403     MMRESULT    ret;
2404
2405     TRACE("(%p, %u) !\n", lpCaps, wSize);
2406
2407     ret = timeGetDevCaps(&caps, sizeof(caps));
2408     lpCaps->wPeriodMin = caps.wPeriodMin;
2409     lpCaps->wPeriodMax = caps.wPeriodMax;
2410     return 0;
2411 }
2412
2413 /**************************************************************************
2414  *                              timeBeginPeriod [MMSYSTEM.605]
2415  */
2416 MMRESULT16 WINAPI timeBeginPeriod16(UINT16 wPeriod)
2417 {
2418     TRACE("(%u) !\n", wPeriod);
2419
2420     return timeBeginPeriod(wPeriod);
2421 }
2422
2423 /**************************************************************************
2424  *                              timeEndPeriod           [MMSYSTEM.606]
2425  */
2426 MMRESULT16 WINAPI timeEndPeriod16(UINT16 wPeriod)
2427 {
2428     TRACE("(%u) !\n", wPeriod);
2429
2430     return timeEndPeriod(wPeriod);
2431 }
2432
2433 /**************************************************************************
2434  *                              mciSendString                   [MMSYSTEM.702]
2435  */
2436 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
2437                              UINT16 uRetLen, HWND16 hwndCallback)
2438 {
2439     return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback));
2440 }
2441
2442 /**************************************************************************
2443  *                      mciLoadCommandResource                  [MMSYSTEM.705]
2444  */
2445 UINT16 WINAPI mciLoadCommandResource16(HANDLE16 hInst, LPCSTR resname, UINT16 type)
2446 {
2447     LPCWSTR     ptr = HEAP_strdupAtoW(GetProcessHeap(), 0, resname);
2448     UINT        ret = mciLoadCommandResource(hInst, ptr, type);
2449     HeapFree(GetProcessHeap(), 0, (LPWSTR)ptr);
2450     return ret;
2451 }
2452
2453 /**************************************************************************
2454  *                      mciFreeCommandResource                  [MMSYSTEM.713]
2455  */
2456 BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
2457 {
2458     TRACE("(%04x)!\n", uTable);
2459
2460     return mciFreeCommandResource(uTable);
2461 }
2462
2463 /* ###################################################
2464  * #                     MMIO                        #
2465  * ###################################################
2466  */
2467
2468 /****************************************************************
2469  *                      MMIO_Map32To16                  [INTERNAL]
2470  */
2471 static LRESULT  MMIO_Map32To16(DWORD wMsg, LPARAM* lp1, LPARAM* lp2)
2472 {
2473     switch (wMsg) {
2474     case MMIOM_CLOSE:
2475     case MMIOM_SEEK:
2476         /* nothing to do */
2477         break;
2478     case MMIOM_OPEN:
2479     case MMIOM_READ:
2480     case MMIOM_WRITE:
2481     case MMIOM_WRITEFLUSH:
2482         *lp1 = MapLS( (void *)*lp1 );
2483         break;
2484     case MMIOM_RENAME:
2485         *lp1 = MapLS( (void *)*lp1 );
2486         *lp2 = MapLS( (void *)*lp2 );
2487         break;
2488     default:
2489         if (wMsg < MMIOM_USER)
2490             TRACE("Not a mappable message (%ld)\n", wMsg);
2491     }
2492     return MMSYSERR_NOERROR;
2493 }
2494
2495 /****************************************************************
2496  *              MMIO_UnMap32To16                        [INTERNAL]
2497  */
2498 static LRESULT  MMIO_UnMap32To16(DWORD wMsg, LPARAM lParam1, LPARAM lParam2,
2499                                  LPARAM lp1, LPARAM lp2)
2500 {
2501     switch (wMsg) {
2502     case MMIOM_CLOSE:
2503     case MMIOM_SEEK:
2504         /* nothing to do */
2505         break;
2506     case MMIOM_OPEN:
2507     case MMIOM_READ:
2508     case MMIOM_WRITE:
2509     case MMIOM_WRITEFLUSH:
2510         UnMapLS( lp1 );
2511         break;
2512     case MMIOM_RENAME:
2513         UnMapLS( lp1 );
2514         UnMapLS( lp2 );
2515         break;
2516     default:
2517         if (wMsg < MMIOM_USER)
2518             TRACE("Not a mappable message (%ld)\n", wMsg);
2519     }
2520     return MMSYSERR_NOERROR;
2521 }
2522
2523 /******************************************************************
2524  *              MMIO_Callback16
2525  *
2526  *
2527  */
2528 static LRESULT MMIO_Callback16(SEGPTR cb16, LPMMIOINFO lpmmioinfo, UINT uMessage,
2529                                LPARAM lParam1, LPARAM lParam2)
2530 {
2531     LRESULT             result;
2532     MMIOINFO16          mmioInfo16;
2533     SEGPTR              segmmioInfo16;
2534     LPARAM              lp1 = lParam1, lp2 = lParam2;
2535
2536     memset(&mmioInfo16, 0, sizeof(MMIOINFO16));
2537     mmioInfo16.lDiskOffset = lpmmioinfo->lDiskOffset;
2538     mmioInfo16.adwInfo[0]  = lpmmioinfo->adwInfo[0];
2539     mmioInfo16.adwInfo[1]  = lpmmioinfo->adwInfo[1];
2540     mmioInfo16.adwInfo[2]  = lpmmioinfo->adwInfo[2];
2541     mmioInfo16.adwInfo[3]  = lpmmioinfo->adwInfo[3];
2542     /* map (lParam1, lParam2) into (lp1, lp2) 32=>16 */
2543     if ((result = MMIO_Map32To16(uMessage, &lp1, &lp2)) != MMSYSERR_NOERROR)
2544         return result;
2545     
2546     segmmioInfo16 = MapLS(&mmioInfo16);
2547     
2548     result = MMSYSTEM_CallTo16_long_lwll((LPMMIOPROC16)cb16, segmmioInfo16, uMessage, lp1, lp2);
2549     UnMapLS(segmmioInfo16);
2550     MMIO_UnMap32To16(uMessage, lParam1, lParam2, lp1, lp2);
2551
2552     lpmmioinfo->lDiskOffset = mmioInfo16.lDiskOffset;
2553     lpmmioinfo->adwInfo[0]  = mmioInfo16.adwInfo[0];
2554     lpmmioinfo->adwInfo[1]  = mmioInfo16.adwInfo[1];
2555     lpmmioinfo->adwInfo[2]  = mmioInfo16.adwInfo[2];
2556     lpmmioinfo->adwInfo[3]  = mmioInfo16.adwInfo[3];
2557
2558     return result;
2559 }
2560
2561 /******************************************************************
2562  *             MMIO_ResetSegmentedData
2563  *
2564  */
2565 static LRESULT     MMIO_SetSegmentedBuffer(HMMIO hmmio, SEGPTR ptr)
2566 {
2567     LPWINE_MMIO         wm;
2568
2569     if ((wm = MMIO_Get(hmmio)) == NULL)
2570         return MMSYSERR_INVALHANDLE;
2571     wm->segBuffer16 = ptr;
2572     return MMSYSERR_NOERROR;
2573 }
2574
2575 /**************************************************************************
2576  *                              mmioOpen                [MMSYSTEM.1210]
2577  */
2578 HMMIO16 WINAPI mmioOpen16(LPSTR szFileName, MMIOINFO16* lpmmioinfo16,
2579                           DWORD dwOpenFlags)
2580 {
2581     HMMIO       ret;
2582
2583     if (lpmmioinfo16) {
2584         MMIOINFO        mmioinfo;
2585
2586         memset(&mmioinfo, 0, sizeof(mmioinfo));
2587
2588         mmioinfo.dwFlags     = lpmmioinfo16->dwFlags;
2589         mmioinfo.fccIOProc   = lpmmioinfo16->fccIOProc;
2590         mmioinfo.pIOProc     = (LPMMIOPROC)lpmmioinfo16->pIOProc;
2591         mmioinfo.cchBuffer   = lpmmioinfo16->cchBuffer;
2592         mmioinfo.pchBuffer   = MapSL((DWORD)lpmmioinfo16->pchBuffer);
2593         mmioinfo.adwInfo[0]  = lpmmioinfo16->adwInfo[0];
2594         /* if we don't have a file name, it's likely a passed open file descriptor */
2595         if (!szFileName) 
2596             mmioinfo.adwInfo[0] = DosFileHandleToWin32Handle(mmioinfo.adwInfo[0]);
2597         mmioinfo.adwInfo[1]  = lpmmioinfo16->adwInfo[1];
2598         mmioinfo.adwInfo[2]  = lpmmioinfo16->adwInfo[2];
2599         mmioinfo.adwInfo[3]  = lpmmioinfo16->adwInfo[3];
2600
2601         ret = MMIO_Open(szFileName, &mmioinfo, dwOpenFlags, MMIO_PROC_16);
2602         MMIO_SetSegmentedBuffer(mmioinfo.hmmio, (SEGPTR)lpmmioinfo16->pchBuffer);
2603
2604         lpmmioinfo16->wErrorRet = mmioinfo.wErrorRet;
2605         lpmmioinfo16->hmmio     = HMMIO_16(mmioinfo.hmmio);
2606     } else {
2607         ret = MMIO_Open(szFileName, NULL, dwOpenFlags, MMIO_PROC_32A);
2608     }
2609     return HMMIO_16(ret);
2610 }
2611
2612 /**************************************************************************
2613  *                              mmioClose               [MMSYSTEM.1211]
2614  */
2615 MMRESULT16 WINAPI mmioClose16(HMMIO16 hmmio, UINT16 uFlags)
2616 {
2617     return mmioClose(HMMIO_32(hmmio), uFlags);
2618 }
2619
2620 /**************************************************************************
2621  *                              mmioRead                [MMSYSTEM.1212]
2622  */
2623 LONG WINAPI mmioRead16(HMMIO16 hmmio, HPSTR pch, LONG cch)
2624 {
2625     return mmioRead(HMMIO_32(hmmio), pch, cch);
2626 }
2627
2628 /**************************************************************************
2629  *                              mmioWrite               [MMSYSTEM.1213]
2630  */
2631 LONG WINAPI mmioWrite16(HMMIO16 hmmio, HPCSTR pch, LONG cch)
2632 {
2633     return mmioWrite(HMMIO_32(hmmio),pch,cch);
2634 }
2635
2636 /**************************************************************************
2637  *                              mmioSeek                [MMSYSTEM.1214]
2638  */
2639 LONG WINAPI mmioSeek16(HMMIO16 hmmio, LONG lOffset, INT16 iOrigin)
2640 {
2641     return mmioSeek(HMMIO_32(hmmio), lOffset, iOrigin);
2642 }
2643
2644 /**************************************************************************
2645  *                              mmioGetInfo             [MMSYSTEM.1215]
2646  */
2647 MMRESULT16 WINAPI mmioGetInfo16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2648 {
2649     MMIOINFO            mmioinfo;
2650     MMRESULT            ret;
2651     LPWINE_MMIO         wm;
2652
2653     TRACE("(0x%04x,%p,0x%08x)\n", hmmio, lpmmioinfo, uFlags);
2654
2655     if ((wm = MMIO_Get(hmmio)) == NULL)
2656         return MMSYSERR_INVALHANDLE;
2657
2658     ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2659     if (ret != MMSYSERR_NOERROR) return ret;
2660
2661     lpmmioinfo->dwFlags     = mmioinfo.dwFlags;
2662     lpmmioinfo->fccIOProc   = mmioinfo.fccIOProc;
2663     lpmmioinfo->pIOProc     = (wm->ioProc->type == MMIO_PROC_16) ?
2664         (LPMMIOPROC16)wm->ioProc->pIOProc : NULL;
2665     lpmmioinfo->wErrorRet   = mmioinfo.wErrorRet;
2666     lpmmioinfo->hTask       = mmioinfo.hTask;
2667     lpmmioinfo->cchBuffer   = mmioinfo.cchBuffer;
2668     lpmmioinfo->pchBuffer   = (void*)wm->segBuffer16;
2669     lpmmioinfo->pchNext     = (void*)(wm->segBuffer16 + (mmioinfo.pchNext - mmioinfo.pchBuffer));
2670     lpmmioinfo->pchEndRead  = (void*)(wm->segBuffer16 + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
2671     lpmmioinfo->pchEndWrite = (void*)(wm->segBuffer16 + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
2672     lpmmioinfo->lBufOffset  = mmioinfo.lBufOffset;
2673     lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
2674     lpmmioinfo->adwInfo[0]  = mmioinfo.adwInfo[0];
2675     lpmmioinfo->adwInfo[1]  = mmioinfo.adwInfo[1];
2676     lpmmioinfo->adwInfo[2]  = mmioinfo.adwInfo[2];
2677     lpmmioinfo->adwInfo[3]  = mmioinfo.adwInfo[3];
2678     lpmmioinfo->dwReserved1 = 0;
2679     lpmmioinfo->dwReserved2 = 0;
2680     lpmmioinfo->hmmio = HMMIO_16(mmioinfo.hmmio);
2681
2682     return MMSYSERR_NOERROR;
2683 }
2684
2685 /**************************************************************************
2686  *                              mmioSetInfo             [MMSYSTEM.1216]
2687  */
2688 MMRESULT16 WINAPI mmioSetInfo16(HMMIO16 hmmio, const MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2689 {
2690     MMIOINFO            mmioinfo;
2691     MMRESULT            ret;
2692
2693     TRACE("(0x%04x,%p,0x%08x)\n",hmmio,lpmmioinfo,uFlags);
2694
2695     ret = mmioGetInfo(HMMIO_32(hmmio), &mmioinfo, 0);
2696     if (ret != MMSYSERR_NOERROR) return ret;
2697
2698     /* check if seg and lin buffers are the same */
2699     if (mmioinfo.cchBuffer != lpmmioinfo->cchBuffer  ||
2700         mmioinfo.pchBuffer != MapSL((DWORD)lpmmioinfo->pchBuffer)) 
2701         return MMSYSERR_INVALPARAM;
2702
2703     /* check pointers coherence */
2704     if (lpmmioinfo->pchNext < lpmmioinfo->pchBuffer ||
2705         lpmmioinfo->pchNext > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2706         lpmmioinfo->pchEndRead < lpmmioinfo->pchBuffer ||
2707         lpmmioinfo->pchEndRead > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer ||
2708         lpmmioinfo->pchEndWrite < lpmmioinfo->pchBuffer ||
2709         lpmmioinfo->pchEndWrite > lpmmioinfo->pchBuffer + lpmmioinfo->cchBuffer)
2710         return MMSYSERR_INVALPARAM;
2711
2712     mmioinfo.pchNext     = mmioinfo.pchBuffer + (lpmmioinfo->pchNext     - lpmmioinfo->pchBuffer);
2713     mmioinfo.pchEndRead  = mmioinfo.pchBuffer + (lpmmioinfo->pchEndRead  - lpmmioinfo->pchBuffer);
2714     mmioinfo.pchEndWrite = mmioinfo.pchBuffer + (lpmmioinfo->pchEndWrite - lpmmioinfo->pchBuffer);
2715
2716     return mmioSetInfo(HMMIO_32(hmmio), &mmioinfo, uFlags);
2717 }
2718
2719 /**************************************************************************
2720  *                              mmioSetBuffer           [MMSYSTEM.1217]
2721  */
2722 MMRESULT16 WINAPI mmioSetBuffer16(HMMIO16 hmmio, LPSTR pchBuffer,
2723                                   LONG cchBuffer, UINT16 uFlags)
2724 {
2725     MMRESULT    ret = mmioSetBuffer(HMMIO_32(hmmio), MapSL((DWORD)pchBuffer), 
2726                                     cchBuffer, uFlags);
2727
2728     if (ret == MMSYSERR_NOERROR)
2729         MMIO_SetSegmentedBuffer(HMMIO_32(hmmio), (DWORD)pchBuffer);
2730     return ret;
2731 }
2732
2733 /**************************************************************************
2734  *                              mmioFlush               [MMSYSTEM.1218]
2735  */
2736 MMRESULT16 WINAPI mmioFlush16(HMMIO16 hmmio, UINT16 uFlags)
2737 {
2738     return mmioFlush(HMMIO_32(hmmio), uFlags);
2739 }
2740
2741 /***********************************************************************
2742  *                              mmioAdvance             [MMSYSTEM.1219]
2743  */
2744 MMRESULT16 WINAPI mmioAdvance16(HMMIO16 hmmio, MMIOINFO16* lpmmioinfo, UINT16 uFlags)
2745 {
2746     MMIOINFO    mmioinfo;
2747     LRESULT     ret;
2748
2749     /* WARNING: this heavily relies on mmioAdvance implementation (for choosing which
2750      * fields to init
2751      */
2752     if (lpmmioinfo)
2753     {
2754         mmioinfo.pchBuffer = MapSL((DWORD)lpmmioinfo->pchBuffer);
2755         mmioinfo.pchNext = MapSL((DWORD)lpmmioinfo->pchNext);
2756         mmioinfo.dwFlags = lpmmioinfo->dwFlags;
2757         mmioinfo.lBufOffset = lpmmioinfo->lBufOffset;
2758         ret = mmioAdvance(HMMIO_32(hmmio), &mmioinfo, uFlags);
2759     }
2760     else
2761         ret = mmioAdvance(HMMIO_32(hmmio), NULL, uFlags);
2762         
2763     if (ret != MMSYSERR_NOERROR) return ret;
2764
2765     if (lpmmioinfo)
2766     {
2767         lpmmioinfo->dwFlags = mmioinfo.dwFlags;
2768         lpmmioinfo->pchNext     = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchNext - mmioinfo.pchBuffer));
2769         lpmmioinfo->pchEndRead  = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndRead - mmioinfo.pchBuffer));
2770         lpmmioinfo->pchEndWrite = (void*)(lpmmioinfo->pchBuffer + (mmioinfo.pchEndWrite - mmioinfo.pchBuffer));
2771         lpmmioinfo->lBufOffset  = mmioinfo.lBufOffset;
2772         lpmmioinfo->lDiskOffset = mmioinfo.lDiskOffset;
2773     }
2774
2775     return MMSYSERR_NOERROR;
2776 }
2777
2778 /**************************************************************************
2779  *                              mmioStringToFOURCC      [MMSYSTEM.1220]
2780  */
2781 FOURCC WINAPI mmioStringToFOURCC16(LPCSTR sz, UINT16 uFlags)
2782 {
2783     return mmioStringToFOURCCA(sz, uFlags);
2784 }
2785
2786 /**************************************************************************
2787  *              mmioInstallIOProc    [MMSYSTEM.1221]
2788  */
2789 LPMMIOPROC16 WINAPI mmioInstallIOProc16(FOURCC fccIOProc, LPMMIOPROC16 pIOProc,
2790                                         DWORD dwFlags)
2791 {
2792     return (LPMMIOPROC16)MMIO_InstallIOProc(fccIOProc, (LPMMIOPROC)pIOProc,
2793                                             dwFlags, MMIO_PROC_16);
2794 }
2795
2796 /**************************************************************************
2797  *                              mmioSendMessage [MMSYSTEM.1222]
2798  */
2799 LRESULT WINAPI mmioSendMessage16(HMMIO16 hmmio, UINT16 uMessage,
2800                                  LPARAM lParam1, LPARAM lParam2)
2801 {
2802     return MMIO_SendMessage(HMMIO_32(hmmio), uMessage, 
2803                             lParam1, lParam2, MMIO_PROC_16);
2804 }
2805
2806 /**************************************************************************
2807  *                              mmioDescend             [MMSYSTEM.1223]
2808  */
2809 MMRESULT16 WINAPI mmioDescend16(HMMIO16 hmmio, LPMMCKINFO lpck,
2810                                 const MMCKINFO* lpckParent, UINT16 uFlags)
2811 {
2812     return mmioDescend(HMMIO_32(hmmio), lpck, lpckParent, uFlags);
2813 }
2814
2815 /**************************************************************************
2816  *                              mmioAscend              [MMSYSTEM.1224]
2817  */
2818 MMRESULT16 WINAPI mmioAscend16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
2819 {
2820     return mmioAscend(HMMIO_32(hmmio),lpck,uFlags);
2821 }
2822
2823 /**************************************************************************
2824  *                              mmioCreateChunk         [MMSYSTEM.1225]
2825  */
2826 MMRESULT16 WINAPI mmioCreateChunk16(HMMIO16 hmmio, MMCKINFO* lpck, UINT16 uFlags)
2827 {
2828     return mmioCreateChunk(HMMIO_32(hmmio), lpck, uFlags);
2829 }
2830
2831 /**************************************************************************
2832  *                              mmioRename              [MMSYSTEM.1226]
2833  */
2834 MMRESULT16 WINAPI mmioRename16(LPCSTR szFileName, LPCSTR szNewFileName,
2835                                MMIOINFO16* lpmmioinfo, DWORD dwRenameFlags)
2836 {
2837     BOOL        inst = FALSE;
2838     MMRESULT    ret;
2839     MMIOINFO    mmioinfo;
2840
2841     if (lpmmioinfo != NULL && lpmmioinfo->pIOProc != NULL && 
2842         lpmmioinfo->fccIOProc == 0) {
2843         FIXME("Can't handle this case yet\n");
2844         return MMSYSERR_ERROR;
2845     }
2846      
2847     /* this is a bit hacky, but it'll work if we get a fourCC code or nothing.
2848      * but a non installed ioproc without a fourcc won't do
2849      */
2850     if (lpmmioinfo && lpmmioinfo->fccIOProc && lpmmioinfo->pIOProc) {
2851         MMIO_InstallIOProc(lpmmioinfo->fccIOProc, (LPMMIOPROC)lpmmioinfo->pIOProc,
2852                            MMIO_INSTALLPROC, MMIO_PROC_16);
2853         inst = TRUE;
2854     }
2855     memset(&mmioinfo, 0, sizeof(mmioinfo));
2856     mmioinfo.fccIOProc = lpmmioinfo->fccIOProc;
2857     ret = mmioRenameA(szFileName, szNewFileName, &mmioinfo, dwRenameFlags);
2858     if (inst) {
2859         MMIO_InstallIOProc(lpmmioinfo->fccIOProc, NULL,
2860                            MMIO_REMOVEPROC, MMIO_PROC_16);
2861     }
2862     return ret;
2863 }