1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1993 Martin Ayotte
11 * 98/9 added Win32 MCI support
12 * 99/4 added mmTask and mmThread functions support
13 * added midiStream support
16 /* FIXME: I think there are some segmented vs. linear pointer weirdnesses
17 * and long term pointers to 16 bit space in here
23 #include "wine/winbase16.h"
27 #include "multimedia.h"
30 #include "selectors.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(mmsys
)
36 UINT16 WINAPI
midiGetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
);
37 static UINT16
waveGetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
);
38 LONG WINAPI
DrvDefDriverProc(DWORD dwDevID
, HDRVR16 hDrv
, WORD wMsg
,
39 DWORD dwParam1
, DWORD dwParam2
);
41 static LPWINE_MM_IDATA lpFirstIData
= NULL
;
43 /**************************************************************************
44 * MULTIMEDIA_GetIData [internal]
46 LPWINE_MM_IDATA
MULTIMEDIA_GetIData(void)
48 DWORD pid
= GetCurrentProcessId();
49 LPWINE_MM_IDATA iData
;
51 for (iData
= lpFirstIData
; iData
; iData
= iData
->lpNextIData
) {
52 if (iData
->dwThisProcess
== pid
)
58 /**************************************************************************
59 * WINMM_LibMain [EntryPoint]
61 * WINMM DLL entry point
64 BOOL WINAPI
WINMM_LibMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
66 static BOOL bInitDone
= FALSE
;
67 LPWINE_MM_IDATA iData
;
69 TRACE("0x%x 0x%lx %p\n", hinstDLL
, fdwReason
, fImpLoad
);
72 case DLL_PROCESS_ATTACH
:
73 if (!bInitDone
) { /* to be done only once */
74 if (!MULTIMEDIA_MidiInit() || !MULTIMEDIA_MciInit()) {
79 iData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MM_IDATA
));
82 iData
->hWinMM32Instance
= hinstDLL
;
83 iData
->dwThisProcess
= GetCurrentProcessId();
84 iData
->lpNextIData
= lpFirstIData
;
87 case DLL_PROCESS_DETACH
:
88 iData
= MULTIMEDIA_GetIData();
90 LPWINE_MM_IDATA
* ppid
;
92 for (ppid
= &lpFirstIData
; *ppid
; ppid
= &(*ppid
)->lpNextIData
) {
94 *ppid
= iData
->lpNextIData
;
99 ERR("Idata is NULL, please report\n");
102 /* FIXME: should also free content and resources allocated inside iData */
103 HeapFree(GetProcessHeap(), 0, iData
);
105 case DLL_THREAD_ATTACH
:
106 case DLL_THREAD_DETACH
:
112 /**************************************************************************
113 * MMSYSTEM_LibMain [EntryPoint]
115 * MMSYSTEM DLL entry point
118 BOOL WINAPI
MMSYSTEM_LibMain(DWORD fdwReason
, HINSTANCE hinstDLL
, WORD ds
,
119 WORD wHeapSize
, DWORD dwReserved1
, WORD wReserved2
)
122 LPWINE_MM_IDATA iData
;
124 TRACE("0x%x 0x%lx\n", hinstDLL
, fdwReason
);
127 case DLL_PROCESS_ATTACH
:
128 /* need to load WinMM in order to:
129 * - correctly initiates shared variables (MULTIMEDIA_Init())
130 * - correctly creates the per process WINE_MM_IDATA chunk
132 hndl
= LoadLibraryA("WINMM.DLL");
135 ERR("Could not load sibling WinMM.dll\n");
138 iData
= MULTIMEDIA_GetIData();
139 if (!iData
) {ERR("Idata is NULL, please report\n"); return FALSE
;}
140 iData
->hWinMM16Instance
= hinstDLL
;
141 iData
->h16Module32
= hndl
;
143 case DLL_PROCESS_DETACH
:
144 iData
= MULTIMEDIA_GetIData();
146 ERR("Idata is NULL, please report\n");
149 FreeLibrary(iData
->h16Module32
);
151 case DLL_THREAD_ATTACH
:
152 case DLL_THREAD_DETACH
:
158 /**************************************************************************
159 * MMSYSTEM_WEP [MMSYSTEM.1]
161 int WINAPI
MMSYSTEM_WEP(HINSTANCE16 hInstance
, WORD wDataSeg
,
162 WORD cbHeapSize
, LPSTR lpCmdLine
)
164 FIXME("STUB: Unloading MMSystem DLL ... hInst=%04X \n", hInstance
);
168 static void MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16
, const MMTIME
* mmt32
)
170 mmt16
->wType
= mmt32
->wType
;
171 /* layout of rest is the same for 32/16,
172 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
174 memcpy(&(mmt16
->u
), &(mmt32
->u
), sizeof(mmt16
->u
));
177 static void MMSYSTEM_MMTIME16to32(LPMMTIME mmt32
, const MMTIME16
* mmt16
)
179 mmt32
->wType
= mmt16
->wType
;
180 /* layout of rest is the same for 32/16,
181 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
183 memcpy(&(mmt32
->u
), &(mmt16
->u
), sizeof(mmt16
->u
));
186 static HANDLE PlaySound_hThread
= 0;
187 static HANDLE PlaySound_hPlayEvent
= 0;
188 static HANDLE PlaySound_hReadyEvent
= 0;
189 static HANDLE PlaySound_hMiddleEvent
= 0;
190 static BOOL PlaySound_Result
= FALSE
;
191 static int PlaySound_Stop
= FALSE
;
192 static int PlaySound_Playing
= FALSE
;
194 static LPCSTR PlaySound_pszSound
= NULL
;
195 static HMODULE PlaySound_hmod
= 0;
196 static DWORD PlaySound_fdwSound
= 0;
197 static int PlaySound_Loop
= FALSE
;
198 static int PlaySound_SearchMode
= 0; /* 1 - sndPlaySound search order
199 2 - PlaySound order */
201 static HMMIO16
get_mmioFromFile(LPCSTR lpszName
)
203 return mmioOpen16((LPSTR
)lpszName
, NULL
,
204 MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
207 static HMMIO16
get_mmioFromProfile(UINT uFlags
, LPCSTR lpszName
)
213 TRACE("searching in SystemSound List !\n");
214 GetProfileStringA("Sounds", (LPSTR
)lpszName
, "", str
, sizeof(str
));
215 if (strlen(str
) == 0) {
216 if (uFlags
& SND_NODEFAULT
) return 0;
217 GetProfileStringA("Sounds", "Default", "", str
, sizeof(str
));
218 if (strlen(str
) == 0) return 0;
220 if ((ptr
= (LPSTR
)strchr(str
, ',')) != NULL
) *ptr
= '\0';
221 hmmio
= get_mmioFromFile(str
);
223 WARN("can't find SystemSound='%s' !\n", str
);
229 static BOOL16 WINAPI
proc_PlaySound(LPCSTR lpszSoundName
, UINT uFlags
)
235 TRACE("SoundName='%s' uFlags=%04X !\n", lpszSoundName
, uFlags
);
236 if (lpszSoundName
== NULL
) {
240 if (uFlags
& SND_MEMORY
) {
242 memset(&mminfo
, 0, sizeof(mminfo
));
243 mminfo
.fccIOProc
= FOURCC_MEM
;
244 mminfo
.pchBuffer
= (LPSTR
)lpszSoundName
;
245 mminfo
.cchBuffer
= -1;
246 TRACE("Memory sound %p\n", lpszSoundName
);
247 hmmio
= mmioOpen16(NULL
, &mminfo
, MMIO_READ
);
250 if (uFlags
& SND_ALIAS
)
251 if ((hmmio
=get_mmioFromProfile(uFlags
, lpszSoundName
)) == 0)
254 if (uFlags
& SND_FILENAME
)
255 if ((hmmio
=get_mmioFromFile(lpszSoundName
)) == 0) return FALSE
;
257 if (PlaySound_SearchMode
== 1) {
258 PlaySound_SearchMode
= 0;
259 if ((hmmio
=get_mmioFromFile(lpszSoundName
)) == 0)
260 if ((hmmio
=get_mmioFromProfile(uFlags
, lpszSoundName
)) == 0)
264 if (PlaySound_SearchMode
== 2) {
265 PlaySound_SearchMode
= 0;
266 if ((hmmio
=get_mmioFromProfile(uFlags
| SND_NODEFAULT
, lpszSoundName
)) == 0)
267 if ((hmmio
=get_mmioFromFile(lpszSoundName
)) == 0)
268 if ((hmmio
=get_mmioFromProfile(uFlags
, lpszSoundName
)) == 0) return FALSE
;
272 if (mmioDescend(hmmio
, &ckMainRIFF
, NULL
, 0) == 0) {
273 DWORD dwPos
= mmioSeek(hmmio
, 0, SEEK_CUR
);
275 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
276 (LPSTR
)&ckMainRIFF
.ckid
, (LPSTR
)&ckMainRIFF
.fccType
,
279 mmioSeek(hmmio
, dwPos
, SEEK_SET
);
281 if ((ckMainRIFF
.ckid
== FOURCC_RIFF
) &&
282 (ckMainRIFF
.fccType
== mmioFOURCC('W', 'A', 'V', 'E'))) {
285 mmckInfo
.ckid
= mmioFOURCC('f', 'm', 't', ' ');
287 if (mmioDescend(hmmio
, &mmckInfo
, &ckMainRIFF
, MMIO_FINDCHUNK
) == 0) {
288 PCMWAVEFORMAT pcmWaveFormat
;
290 TRACE("Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
291 (LPSTR
)&mmckInfo
.ckid
, (LPSTR
)&mmckInfo
.fccType
, mmckInfo
.cksize
);
293 if (mmioRead(hmmio
, (HPSTR
)&pcmWaveFormat
,
294 (long) sizeof(PCMWAVEFORMAT
)) == (long) sizeof(PCMWAVEFORMAT
)) {
295 TRACE("wFormatTag=%04X !\n", pcmWaveFormat
.wf
.wFormatTag
);
296 TRACE("nChannels=%d \n", pcmWaveFormat
.wf
.nChannels
);
297 TRACE("nSamplesPerSec=%ld\n", pcmWaveFormat
.wf
.nSamplesPerSec
);
298 TRACE("nAvgBytesPerSec=%ld\n", pcmWaveFormat
.wf
.nAvgBytesPerSec
);
299 TRACE("nBlockAlign=%d \n", pcmWaveFormat
.wf
.nBlockAlign
);
300 TRACE("wBitsPerSample=%u !\n", pcmWaveFormat
.wBitsPerSample
);
302 mmckInfo
.ckid
= mmioFOURCC('d', 'a', 't', 'a');
303 /* move to end of 'fmt ' chunk */
304 mmioSeek(hmmio
, mmckInfo
.dwDataOffset
+ ((mmckInfo
.cksize
+ 1) & ~1), SEEK_SET
);
306 if (mmioDescend(hmmio
, &mmckInfo
, &ckMainRIFF
, MMIO_FINDCHUNK
) == 0) {
307 WAVEOPENDESC waveDesc
;
310 TRACE("Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX\n",
311 (LPSTR
)&mmckInfo
.ckid
, (LPSTR
)&mmckInfo
.fccType
, mmckInfo
.cksize
);
313 pcmWaveFormat
.wf
.nAvgBytesPerSec
= pcmWaveFormat
.wf
.nSamplesPerSec
*
314 pcmWaveFormat
.wf
.nBlockAlign
;
316 waveDesc
.lpFormat
= (LPWAVEFORMAT
)&pcmWaveFormat
;
318 dwRet
= wodMessage(0, WODM_OPEN
, 0, (DWORD
)&waveDesc
, CALLBACK_NULL
);
319 if (dwRet
== MMSYSERR_NOERROR
) {
322 INT count
, bufsize
, left
= mmckInfo
.cksize
;
325 hData
= GlobalAlloc16(GMEM_MOVEABLE
, bufsize
);
326 waveHdr
.lpData
= (LPSTR
)GlobalLock16(hData
);
327 waveHdr
.dwBufferLength
= bufsize
;
329 waveHdr
.dwFlags
= 0L;
330 waveHdr
.dwLoops
= 0L;
332 dwRet
= wodMessage(0, WODM_PREPARE
, 0, (DWORD
)&waveHdr
, sizeof(WAVEHDR
));
333 if (dwRet
== MMSYSERR_NOERROR
) {
335 if (PlaySound_Stop
) {
336 PlaySound_Stop
= FALSE
;
337 PlaySound_Loop
= FALSE
;
340 if (bufsize
> left
) bufsize
= left
;
341 count
= mmioRead(hmmio
, waveHdr
.lpData
,bufsize
);
342 if (count
< 1) break;
344 waveHdr
.dwBufferLength
= count
;
346 waveHdr
.reserved
= (DWORD
)&waveHdr
;
347 /* waveHdr.dwBytesRecorded = count; */
348 /* FIXME: doesn't expect async ops */
349 wodMessage(0, WODM_WRITE
, 0, (DWORD
)&waveHdr
, sizeof(WAVEHDR
));
350 while (!(waveHdr
.dwFlags
& WHDR_DONE
))
353 wodMessage(0, WODM_UNPREPARE
, 0, (DWORD
)&waveHdr
, sizeof(WAVEHDR
));
354 while (wodMessage(0, WODM_CLOSE
, 0, 0L, 0L) == WAVERR_STILLPLAYING
)
359 WARN("can't prepare WaveOut device !\n");
361 GlobalUnlock16(hData
);
368 } while (PlaySound_Loop
);
371 if (hmmio
!= 0) mmioClose(hmmio
, 0);
375 static DWORD WINAPI
PlaySound_Thread(LPVOID arg
)
380 PlaySound_Playing
= FALSE
;
381 SetEvent(PlaySound_hReadyEvent
);
382 res
= WaitForSingleObject(PlaySound_hPlayEvent
, INFINITE
);
383 ResetEvent(PlaySound_hReadyEvent
);
384 SetEvent(PlaySound_hMiddleEvent
);
385 if (res
== WAIT_FAILED
) ExitThread(2);
386 if (res
!= WAIT_OBJECT_0
) continue;
387 PlaySound_Playing
= TRUE
;
389 if ((PlaySound_fdwSound
& SND_RESOURCE
) == SND_RESOURCE
) {
394 if ((hRES
= FindResourceA(PlaySound_hmod
, PlaySound_pszSound
, "WAVE")) == 0) {
395 PlaySound_Result
= FALSE
;
398 if ((hGLOB
= LoadResource(PlaySound_hmod
, hRES
)) == 0) {
399 PlaySound_Result
= FALSE
;
402 if ((ptr
= LockResource(hGLOB
)) == NULL
) {
404 PlaySound_Result
= FALSE
;
407 PlaySound_Result
= proc_PlaySound(ptr
,
408 ((UINT16
)PlaySound_fdwSound
^ SND_RESOURCE
) | SND_MEMORY
);
412 PlaySound_Result
= proc_PlaySound(PlaySound_pszSound
, (UINT16
)PlaySound_fdwSound
);
416 /**************************************************************************
417 * PlaySoundA [WINMM.1]
419 BOOL WINAPI
PlaySoundA(LPCSTR pszSound
, HMODULE hmod
, DWORD fdwSound
)
421 static LPSTR StrDup
= NULL
;
423 TRACE("pszSound='%p' hmod=%04X fdwSound=%08lX\n",
424 pszSound
, hmod
, fdwSound
);
426 if (PlaySound_hThread
== 0) { /* This is the first time they called us */
428 if ((PlaySound_hReadyEvent
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
)) == 0)
430 if ((PlaySound_hMiddleEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
)) == 0)
432 if ((PlaySound_hPlayEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
)) == 0)
434 if ((PlaySound_hThread
= CreateThread(NULL
, 0, PlaySound_Thread
, 0, 0, &id
)) == 0)
438 /* FIXME? I see no difference between SND_WAIT and SND_NOSTOP ! */
439 if ((fdwSound
& (SND_NOWAIT
| SND_NOSTOP
)) && PlaySound_Playing
)
442 /* Trying to stop if playing */
443 if (PlaySound_Playing
) PlaySound_Stop
= TRUE
;
445 /* Waiting playing thread to get ready. I think 10 secs is ok & if not then leave*/
446 if (WaitForSingleObject(PlaySound_hReadyEvent
, 1000*10) != WAIT_OBJECT_0
)
449 if (!pszSound
|| (fdwSound
& SND_PURGE
))
450 return FALSE
; /* We stoped playing so leaving */
452 if (PlaySound_SearchMode
!= 1) PlaySound_SearchMode
= 2;
453 if (!(fdwSound
& SND_ASYNC
)) {
454 if (fdwSound
& SND_LOOP
)
456 PlaySound_pszSound
= pszSound
;
457 PlaySound_hmod
= hmod
;
458 PlaySound_fdwSound
= fdwSound
;
459 PlaySound_Result
= FALSE
;
460 SetEvent(PlaySound_hPlayEvent
);
461 if (WaitForSingleObject(PlaySound_hMiddleEvent
, INFINITE
) != WAIT_OBJECT_0
)
463 if (WaitForSingleObject(PlaySound_hReadyEvent
, INFINITE
) != WAIT_OBJECT_0
)
465 return PlaySound_Result
;
467 PlaySound_hmod
= hmod
;
468 PlaySound_fdwSound
= fdwSound
;
469 PlaySound_Result
= FALSE
;
471 HeapFree(GetProcessHeap(), 0, StrDup
);
474 if (!((fdwSound
& SND_MEMORY
) || ((fdwSound
& SND_RESOURCE
) &&
475 !((DWORD
)pszSound
>> 16)) || !pszSound
)) {
476 StrDup
= HEAP_strdupA(GetProcessHeap(), 0,pszSound
);
477 PlaySound_pszSound
= StrDup
;
478 } else PlaySound_pszSound
= pszSound
;
479 PlaySound_Loop
= fdwSound
& SND_LOOP
;
480 SetEvent(PlaySound_hPlayEvent
);
481 ResetEvent(PlaySound_hMiddleEvent
);
487 /**************************************************************************
488 * PlaySoundW [WINMM.18]
490 BOOL WINAPI
PlaySoundW(LPCWSTR pszSound
, HMODULE hmod
, DWORD fdwSound
)
495 if (!((fdwSound
& SND_MEMORY
) || ((fdwSound
& SND_RESOURCE
) &&
496 !((DWORD
)pszSound
>> 16)) || !pszSound
)) {
497 pszSoundA
= HEAP_strdupWtoA(GetProcessHeap(), 0,pszSound
);
498 bSound
= PlaySoundA(pszSoundA
, hmod
, fdwSound
);
499 HeapFree(GetProcessHeap(), 0,pszSoundA
);
501 bSound
= PlaySoundA((LPCSTR
)pszSound
, hmod
, fdwSound
);
506 /**************************************************************************
507 * PlaySound16 [MMSYSTEM.3]
509 BOOL16 WINAPI
PlaySound16(LPCSTR pszSound
, HMODULE16 hmod
, DWORD fdwSound
)
513 SYSLEVEL_ReleaseWin16Lock();
514 retv
= PlaySoundA( pszSound
, hmod
, fdwSound
);
515 SYSLEVEL_RestoreWin16Lock();
520 /**************************************************************************
521 * sndPlaySoundA [WINMM135]
523 BOOL WINAPI
sndPlaySoundA(LPCSTR lpszSoundName
, UINT uFlags
)
525 PlaySound_SearchMode
= 1;
526 return PlaySoundA(lpszSoundName
, 0, uFlags
);
529 /**************************************************************************
530 * sndPlaySoundW [WINMM.136]
532 BOOL WINAPI
sndPlaySoundW(LPCWSTR lpszSoundName
, UINT uFlags
)
534 PlaySound_SearchMode
= 1;
535 return PlaySoundW(lpszSoundName
, 0, uFlags
);
538 /**************************************************************************
539 * sndPlaySound16 [MMSYSTEM.2]
541 BOOL16 WINAPI
sndPlaySound16(LPCSTR lpszSoundName
, UINT16 uFlags
)
545 SYSLEVEL_ReleaseWin16Lock();
546 retv
= sndPlaySoundA( lpszSoundName
, uFlags
);
547 SYSLEVEL_RestoreWin16Lock();
553 /**************************************************************************
554 * mmsystemGetVersion [WINMM.134]
556 UINT WINAPI
mmsystemGetVersion(void)
558 return mmsystemGetVersion16();
561 /**************************************************************************
562 * mmsystemGetVersion [MMSYSTEM.5]
563 * return value borrowed from Win95 winmm.dll ;)
565 UINT16 WINAPI
mmsystemGetVersion16(void)
567 TRACE("3.10 (Win95?)\n");
571 /**************************************************************************
572 * DriverProc [MMSYSTEM.6]
574 LRESULT WINAPI
DriverProc16(DWORD dwDevID
, HDRVR16 hDrv
, WORD wMsg
,
575 DWORD dwParam1
, DWORD dwParam2
)
577 return DrvDefDriverProc(dwDevID
, hDrv
, wMsg
, dwParam1
, dwParam2
);
580 /**************************************************************************
581 * DriverCallback [MMSYSTEM.31]
583 BOOL16 WINAPI
DriverCallback16(DWORD dwCallBack
, UINT16 uFlags
, HANDLE16 hDev
,
584 WORD wMsg
, DWORD dwUser
, DWORD dwParam1
, DWORD dwParam2
)
586 TRACE("(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n",
587 dwCallBack
, uFlags
, hDev
, wMsg
, dwUser
, dwParam1
, dwParam2
);
589 switch (uFlags
& DCB_TYPEMASK
) {
594 TRACE("Window(%04lX) handle=%04X!\n", dwCallBack
, hDev
);
595 if (!IsWindow(dwCallBack
) || USER_HEAP_LIN_ADDR(hDev
) == NULL
)
597 Callout
.PostMessageA((HWND16
)dwCallBack
, wMsg
, hDev
, dwParam1
);
599 case DCB_TASK
: /* aka DCB_THREAD */
600 TRACE("Task(%04lx) !\n", dwCallBack
);
601 Callout
.PostThreadMessageA(dwCallBack
, wMsg
, hDev
, dwParam1
);
604 TRACE("Function (16bit) !\n");
605 Callbacks
->CallDriverCallback((FARPROC16
)dwCallBack
, hDev
, wMsg
, dwUser
,
608 case DCB_FUNC32
: /* This is a Wine only value - AKAIF not used yet by MS */
609 TRACE("Function (32bit) !\n");
610 ((LPDRVCALLBACK
)dwCallBack
)(hDev
, wMsg
, dwUser
, dwParam1
, dwParam2
);
613 TRACE("Event(%08lx) !\n", dwCallBack
);
614 SetEvent((HANDLE
)dwCallBack
);
616 case 6: /* I would dub it DCB_MMTHREADSIGNAL */
617 /* this is an undocumented DCB_ value used for mmThreads
618 * loword of dwCallBack contains the handle of the lpMMThd block
619 * which dwSignalCount has to be incremented
622 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(LOWORD(dwCallBack
), 0);
624 TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack
), lpMMThd
);
625 /* same as mmThreadSignal16 */
626 InterlockedIncrement(&lpMMThd
->dwSignalCount
);
627 SetEvent(lpMMThd
->hEvent
);
628 /* some other stuff on lpMMThd->hVxD */
633 /* this is an undocumented DCB_ value for... I don't know */
637 WARN("Unknown callback type %d\n", uFlags
& DCB_TYPEMASK
);
644 /**************************************************************************
645 * Mixer devices. New to Win95
648 /**************************************************************************
649 * find out the real mixer ID depending on hmix (depends on dwFlags)
650 * FIXME: also fix dwInstance passing to mixMessage
652 static UINT
MIXER_GetDevID(HMIXEROBJ hmix
, DWORD dwFlags
)
654 /* FIXME: Check dwFlags for MIXER_OBJSECTF_xxxx entries and modify hmix
655 * accordingly. For now we always use mixerdevice 0.
660 /**************************************************************************
661 * mixerGetNumDevs [WINMM.108]
663 UINT WINAPI
mixerGetNumDevs(void)
665 UINT16 count
= mixMessage(0, MXDM_GETNUMDEVS
, 0L, 0L, 0L);
667 TRACE("mixerGetNumDevs returns %d\n", count
);
671 /**************************************************************************
672 * mixerGetNumDevs [MMSYSTEM.800]
674 UINT16 WINAPI
mixerGetNumDevs16(void)
676 return mixerGetNumDevs();
679 /**************************************************************************
680 * mixerGetDevCapsA [WINMM.101]
682 UINT WINAPI
mixerGetDevCapsA(UINT devid
, LPMIXERCAPSA mixcaps
, UINT size
)
684 return mixMessage(devid
, MXDM_GETDEVCAPS
, 0L, (DWORD
)mixcaps
, (DWORD
)size
);
687 /**************************************************************************
688 * mixerGetDevCapsW [WINMM.102]
690 UINT WINAPI
mixerGetDevCapsW(UINT devid
, LPMIXERCAPSW mixcaps
, UINT size
)
693 UINT ret
= mixerGetDevCapsA(devid
, &micA
, sizeof(micA
));
695 if (ret
== MMSYSERR_NOERROR
) {
696 mixcaps
->wMid
= micA
.wMid
;
697 mixcaps
->wPid
= micA
.wPid
;
698 mixcaps
->vDriverVersion
= micA
.vDriverVersion
;
699 lstrcpyAtoW(mixcaps
->szPname
, micA
.szPname
);
700 mixcaps
->fdwSupport
= micA
.fdwSupport
;
701 mixcaps
->cDestinations
= micA
.cDestinations
;
706 /**************************************************************************
707 * mixerGetDevCaps [MMSYSTEM.801]
709 UINT16 WINAPI
mixerGetDevCaps16(UINT16 devid
, LPMIXERCAPS16 mixcaps
, UINT16 size
)
712 UINT ret
= mixerGetDevCapsA(devid
, &micA
, sizeof(micA
));
714 if (ret
== MMSYSERR_NOERROR
) {
715 mixcaps
->wMid
= micA
.wMid
;
716 mixcaps
->wPid
= micA
.wPid
;
717 mixcaps
->vDriverVersion
= micA
.vDriverVersion
;
718 strcpy(mixcaps
->szPname
, micA
.szPname
);
719 mixcaps
->fdwSupport
= micA
.fdwSupport
;
720 mixcaps
->cDestinations
= micA
.cDestinations
;
725 /**************************************************************************
726 * mixerOpen [WINMM.110]
728 UINT WINAPI
mixerOpen(LPHMIXER lphmix
, UINT uDeviceID
, DWORD dwCallback
,
729 DWORD dwInstance
, DWORD fdwOpen
)
734 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
735 lphmix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
);
736 ret
= mixerOpen16(&hmix16
, uDeviceID
, dwCallback
, dwInstance
,fdwOpen
);
737 if (lphmix
) *lphmix
= hmix16
;
741 /**************************************************************************
742 * mixerOpen [MMSYSTEM.803]
744 UINT16 WINAPI
mixerOpen16(LPHMIXER16 lphmix
, UINT16 uDeviceID
, DWORD dwCallback
,
745 DWORD dwInstance
, DWORD fdwOpen
)
748 LPMIXEROPENDESC lpmod
;
749 BOOL mapperflag
= (uDeviceID
== 0);
752 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
753 lphmix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
);
754 hmix
= USER_HEAP_ALLOC(sizeof(MIXEROPENDESC
));
755 if (lphmix
) *lphmix
= hmix
;
756 lpmod
= (LPMIXEROPENDESC
)USER_HEAP_LIN_ADDR(hmix
);
758 lpmod
->dwCallback
= dwCallback
;
759 lpmod
->dwInstance
= dwInstance
;
760 if (uDeviceID
>= MAXMIXERDRIVERS
)
762 while (uDeviceID
< MAXMIXERDRIVERS
) {
763 dwRet
= mixMessage(uDeviceID
, MXDM_OPEN
, dwInstance
, (DWORD
)lpmod
, fdwOpen
);
764 if (dwRet
== MMSYSERR_NOERROR
) break;
765 if (!mapperflag
) break;
768 lpmod
->uDeviceID
= uDeviceID
;
770 if (dwRet
!= MMSYSERR_NOERROR
) {
771 USER_HEAP_FREE(hmix
);
772 if (lphmix
) *lphmix
= 0;
778 /**************************************************************************
779 * mixerClose [WINMM.98]
781 UINT WINAPI
mixerClose(HMIXER hmix
)
783 LPMIXEROPENDESC lpmod
;
786 TRACE("(%04x)\n", hmix
);
788 lpmod
= (LPMIXEROPENDESC
)USER_HEAP_LIN_ADDR(hmix
);
789 if (lpmod
== NULL
) return MMSYSERR_INVALHANDLE
;
790 dwRet
= mixMessage(lpmod
->uDeviceID
, MXDM_CLOSE
, lpmod
->dwInstance
, 0L, 0L);
791 USER_HEAP_FREE(hmix
);
795 /**************************************************************************
796 * mixerClose [MMSYSTEM.803]
798 UINT16 WINAPI
mixerClose16(HMIXER16 hmix
)
800 return mixerClose(hmix
);
803 /**************************************************************************
804 * mixerGetID [WINMM.103]
806 UINT WINAPI
mixerGetID(HMIXEROBJ hmix
, LPUINT lpid
, DWORD fdwID
)
808 FIXME("(%04x %p %08lx): semi-stub\n", hmix
, lpid
, fdwID
);
811 *lpid
= MIXER_GetDevID(hmix
, fdwID
);
813 return MMSYSERR_NOERROR
; /* FIXME: many error possibilities */
816 /**************************************************************************
819 UINT16 WINAPI
mixerGetID16(HMIXEROBJ16 hmix
, LPUINT16 lpid
, DWORD fdwID
)
822 UINT ret
= mixerGetID(hmix
, &xid
, fdwID
);
829 /**************************************************************************
830 * mixerGetControlDetailsA [WINMM.99]
832 UINT WINAPI
mixerGetControlDetailsA(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
, DWORD fdwDetails
)
836 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmcdA
, fdwDetails
);
838 if (lpmcdA
== NULL
|| lpmcdA
->cbStruct
!= sizeof(*lpmcdA
))
839 return MMSYSERR_INVALPARAM
;
841 uDevID
= MIXER_GetDevID(hmix
, fdwDetails
);
843 return mixMessage(uDevID
, MXDM_GETCONTROLDETAILS
, 0, (DWORD
)lpmcdA
, fdwDetails
);
846 /**************************************************************************
847 * mixerGetControlDetailsW [WINMM.100]
849 UINT WINAPI
mixerGetControlDetailsW(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcd
, DWORD fdwDetails
)
851 DWORD ret
= MMSYSERR_NOTENABLED
;
853 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmcd
, fdwDetails
);
855 if (lpmcd
== NULL
|| lpmcd
->cbStruct
!= sizeof(*lpmcd
))
856 return MMSYSERR_INVALPARAM
;
858 switch (fdwDetails
& MIXER_GETCONTROLDETAILSF_QUERYMASK
) {
859 case MIXER_GETCONTROLDETAILSF_VALUE
:
860 /* can savely use W structure as it is, no string inside */
861 ret
= mixerGetControlDetailsA(hmix
, lpmcd
, fdwDetails
);
863 case MIXER_GETCONTROLDETAILSF_LISTTEXT
:
865 LPVOID paDetailsW
= lpmcd
->paDetails
;
866 int size
= MAX(1, lpmcd
->cChannels
) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
868 if (lpmcd
->u
.cMultipleItems
!= 0 && lpmcd
->u
.cMultipleItems
!= lpmcd
->u
.hwndOwner
) {
869 size
*= lpmcd
->u
.cMultipleItems
;
871 lpmcd
->paDetails
= HeapAlloc(GetProcessHeap(), 0, size
);
872 /* set up lpmcd->paDetails */
873 ret
= mixerGetControlDetailsA(hmix
, lpmcd
, fdwDetails
);
874 /* copy from lpmcd->paDetails back to paDetailsW; */
875 HeapFree(GetProcessHeap(), 0, lpmcd
->paDetails
);
876 lpmcd
->paDetails
= paDetailsW
;
880 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails
);
886 /**************************************************************************
887 * mixerGetControlDetails [MMSYSTEM.808]
889 UINT16 WINAPI
mixerGetControlDetails16(HMIXEROBJ16 hmix
, LPMIXERCONTROLDETAILS16 lpmcd
, DWORD fdwDetails
)
891 DWORD ret
= MMSYSERR_NOTENABLED
;
894 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmcd
, fdwDetails
);
896 if (lpmcd
== NULL
|| lpmcd
->cbStruct
!= sizeof(*lpmcd
))
897 return MMSYSERR_INVALPARAM
;
899 sppaDetails
= (SEGPTR
)lpmcd
->paDetails
;
900 lpmcd
->paDetails
= PTR_SEG_TO_LIN(sppaDetails
);
901 ret
= mixerGetControlDetailsA(hmix
, (LPMIXERCONTROLDETAILS
)lpmcd
, fdwDetails
);
902 lpmcd
->paDetails
= (LPVOID
)sppaDetails
;
907 /**************************************************************************
908 * mixerGetLineControlsA [WINMM.104]
910 UINT WINAPI
mixerGetLineControlsA(HMIXEROBJ hmix
, LPMIXERLINECONTROLSA lpmlcA
, DWORD fdwControls
)
914 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmlcA
, fdwControls
);
916 if (lpmlcA
== NULL
|| lpmlcA
->cbStruct
!= sizeof(*lpmlcA
))
917 return MMSYSERR_INVALPARAM
;
919 uDevID
= MIXER_GetDevID(hmix
, 0);
921 return mixMessage(uDevID
, MXDM_GETLINECONTROLS
, 0, (DWORD
)lpmlcA
, fdwControls
);
924 /**************************************************************************
925 * mixerGetLineControlsW [WINMM.105]
927 UINT WINAPI
mixerGetLineControlsW(HMIXEROBJ hmix
, LPMIXERLINECONTROLSW lpmlcW
, DWORD fdwControls
)
929 MIXERLINECONTROLSA mlcA
;
933 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmlcW
, fdwControls
);
935 if (lpmlcW
== NULL
|| lpmlcW
->cbStruct
!= sizeof(*lpmlcW
) || lpmlcW
->cbmxctrl
!= sizeof(MIXERCONTROLW
))
936 return MMSYSERR_INVALPARAM
;
938 mlcA
.cbStruct
= sizeof(mlcA
);
939 mlcA
.dwLineID
= lpmlcW
->dwLineID
;
940 mlcA
.u
.dwControlID
= lpmlcW
->u
.dwControlID
;
941 mlcA
.u
.dwControlType
= lpmlcW
->u
.dwControlType
;
942 mlcA
.cControls
= lpmlcW
->cControls
;
943 mlcA
.cbmxctrl
= sizeof(MIXERCONTROLA
);
944 mlcA
.pamxctrl
= HeapAlloc(GetProcessHeap(), 0, mlcA
.cControls
* mlcA
.cbmxctrl
);
946 ret
= mixerGetLineControlsA(hmix
, &mlcA
, fdwControls
);
948 if (ret
== MMSYSERR_NOERROR
) {
949 lpmlcW
->dwLineID
= mlcA
.dwLineID
;
950 lpmlcW
->u
.dwControlID
= mlcA
.u
.dwControlID
;
951 lpmlcW
->u
.dwControlType
= mlcA
.u
.dwControlType
;
952 lpmlcW
->cControls
= mlcA
.cControls
;
954 for (i
= 0; i
< mlcA
.cControls
; i
++) {
955 lpmlcW
->pamxctrl
[i
].cbStruct
= sizeof(MIXERCONTROLW
);
956 lpmlcW
->pamxctrl
[i
].dwControlID
= mlcA
.pamxctrl
[i
].dwControlID
;
957 lpmlcW
->pamxctrl
[i
].dwControlType
= mlcA
.pamxctrl
[i
].dwControlType
;
958 lpmlcW
->pamxctrl
[i
].fdwControl
= mlcA
.pamxctrl
[i
].fdwControl
;
959 lpmlcW
->pamxctrl
[i
].cMultipleItems
= mlcA
.pamxctrl
[i
].cMultipleItems
;
960 lstrcpyAtoW(lpmlcW
->pamxctrl
[i
].szShortName
, mlcA
.pamxctrl
[i
].szShortName
);
961 lstrcpyAtoW(lpmlcW
->pamxctrl
[i
].szName
, mlcA
.pamxctrl
[i
].szName
);
962 /* sizeof(lpmlcW->pamxctrl[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
963 memcpy(&lpmlcW
->pamxctrl
[i
].Bounds
, &mlcA
.pamxctrl
[i
].Bounds
, sizeof(mlcA
.pamxctrl
[i
].Bounds
));
964 /* sizeof(lpmlcW->pamxctrl[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
965 memcpy(&lpmlcW
->pamxctrl
[i
].Metrics
, &mlcA
.pamxctrl
[i
].Metrics
, sizeof(mlcA
.pamxctrl
[i
].Metrics
));
969 HeapFree(GetProcessHeap(), 0, mlcA
.pamxctrl
);
974 /**************************************************************************
975 * mixerGetLineControls [MMSYSTEM.807]
977 UINT16 WINAPI
mixerGetLineControls16(HMIXEROBJ16 hmix
, LPMIXERLINECONTROLS16 lpmlc16
, DWORD fdwControls
)
979 MIXERLINECONTROLSA mlcA
;
982 LPMIXERCONTROL16 lpmc16
;
984 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmlc16
, fdwControls
);
986 if (lpmlc16
== NULL
|| lpmlc16
->cbStruct
!= sizeof(*lpmlc16
) || lpmlc16
->cbmxctrl
!= sizeof(MIXERCONTROL16
))
987 return MMSYSERR_INVALPARAM
;
989 mlcA
.cbStruct
= sizeof(mlcA
);
990 mlcA
.dwLineID
= lpmlc16
->dwLineID
;
991 mlcA
.u
.dwControlID
= lpmlc16
->u
.dwControlID
;
992 mlcA
.u
.dwControlType
= lpmlc16
->u
.dwControlType
;
993 mlcA
.cControls
= lpmlc16
->cControls
;
994 mlcA
.cbmxctrl
= sizeof(MIXERCONTROLA
);
995 mlcA
.pamxctrl
= HeapAlloc(GetProcessHeap(), 0, mlcA
.cControls
* mlcA
.cbmxctrl
);
997 ret
= mixerGetLineControlsA(hmix
, &mlcA
, fdwControls
);
999 if (ret
== MMSYSERR_NOERROR
) {
1000 lpmlc16
->dwLineID
= mlcA
.dwLineID
;
1001 lpmlc16
->u
.dwControlID
= mlcA
.u
.dwControlID
;
1002 lpmlc16
->u
.dwControlType
= mlcA
.u
.dwControlType
;
1003 lpmlc16
->cControls
= mlcA
.cControls
;
1005 lpmc16
= PTR_SEG_TO_LIN(lpmlc16
->pamxctrl
);
1007 for (i
= 0; i
< mlcA
.cControls
; i
++) {
1008 lpmc16
[i
].cbStruct
= sizeof(MIXERCONTROL16
);
1009 lpmc16
[i
].dwControlID
= mlcA
.pamxctrl
[i
].dwControlID
;
1010 lpmc16
[i
].dwControlType
= mlcA
.pamxctrl
[i
].dwControlType
;
1011 lpmc16
[i
].fdwControl
= mlcA
.pamxctrl
[i
].fdwControl
;
1012 lpmc16
[i
].cMultipleItems
= mlcA
.pamxctrl
[i
].cMultipleItems
;
1013 strcpy(lpmc16
[i
].szShortName
, mlcA
.pamxctrl
[i
].szShortName
);
1014 strcpy(lpmc16
[i
].szName
, mlcA
.pamxctrl
[i
].szName
);
1015 /* sizeof(lpmc16[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
1016 memcpy(&lpmc16
[i
].Bounds
, &mlcA
.pamxctrl
[i
].Bounds
, sizeof(mlcA
.pamxctrl
[i
].Bounds
));
1017 /* sizeof(lpmc16[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
1018 memcpy(&lpmc16
[i
].Metrics
, &mlcA
.pamxctrl
[i
].Metrics
, sizeof(mlcA
.pamxctrl
[i
].Metrics
));
1022 HeapFree(GetProcessHeap(), 0, mlcA
.pamxctrl
);
1027 /**************************************************************************
1028 * mixerGetLineInfoA [WINMM.106]
1030 UINT WINAPI
mixerGetLineInfoA(HMIXEROBJ hmix
, LPMIXERLINEA lpmliW
, DWORD fdwInfo
)
1034 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmliW
, fdwInfo
);
1036 /* FIXME: I'm not sure of the flags */
1037 devid
= MIXER_GetDevID(hmix
, fdwInfo
);
1038 return mixMessage(devid
, MXDM_GETLINEINFO
, 0, (DWORD
)lpmliW
, fdwInfo
);
1041 /**************************************************************************
1042 * mixerGetLineInfoW [WINMM.107]
1044 UINT WINAPI
mixerGetLineInfoW(HMIXEROBJ hmix
, LPMIXERLINEW lpmliW
, DWORD fdwInfo
)
1049 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmliW
, fdwInfo
);
1051 if (lpmliW
== NULL
|| lpmliW
->cbStruct
!= sizeof(*lpmliW
))
1052 return MMSYSERR_INVALPARAM
;
1054 mliA
.cbStruct
= sizeof(mliA
);
1055 switch (fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
) {
1056 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
1057 mliA
.dwComponentType
= lpmliW
->dwComponentType
;
1059 case MIXER_GETLINEINFOF_DESTINATION
:
1060 mliA
.dwDestination
= lpmliW
->dwDestination
;
1062 case MIXER_GETLINEINFOF_LINEID
:
1063 mliA
.dwLineID
= lpmliW
->dwLineID
;
1065 case MIXER_GETLINEINFOF_SOURCE
:
1066 mliA
.dwDestination
= lpmliW
->dwDestination
;
1067 mliA
.dwSource
= lpmliW
->dwSource
;
1069 case MIXER_GETLINEINFOF_TARGETTYPE
:
1070 mliA
.Target
.dwType
= lpmliW
->Target
.dwType
;
1071 mliA
.Target
.wMid
= lpmliW
->Target
.wMid
;
1072 mliA
.Target
.wPid
= lpmliW
->Target
.wPid
;
1073 mliA
.Target
.vDriverVersion
= lpmliW
->Target
.vDriverVersion
;
1074 lstrcpyWtoA(mliA
.Target
.szPname
, lpmliW
->Target
.szPname
);
1077 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo
);
1080 ret
= mixerGetLineInfoA(hmix
, &mliA
, fdwInfo
);
1082 lpmliW
->dwDestination
= mliA
.dwDestination
;
1083 lpmliW
->dwSource
= mliA
.dwSource
;
1084 lpmliW
->dwLineID
= mliA
.dwLineID
;
1085 lpmliW
->fdwLine
= mliA
.fdwLine
;
1086 lpmliW
->dwUser
= mliA
.dwUser
;
1087 lpmliW
->dwComponentType
= mliA
.dwComponentType
;
1088 lpmliW
->cChannels
= mliA
.cChannels
;
1089 lpmliW
->cConnections
= mliA
.cConnections
;
1090 lpmliW
->cControls
= mliA
.cControls
;
1091 lstrcpyAtoW(lpmliW
->szShortName
, mliA
.szShortName
);
1092 lstrcpyAtoW(lpmliW
->szName
, mliA
.szName
);
1093 lpmliW
->Target
.dwType
= mliA
.Target
.dwType
;
1094 lpmliW
->Target
.dwDeviceID
= mliA
.Target
.dwDeviceID
;
1095 lpmliW
->Target
.wMid
= mliA
.Target
.wMid
;
1096 lpmliW
->Target
.wPid
= mliA
.Target
.wPid
;
1097 lpmliW
->Target
.vDriverVersion
= mliA
.Target
.vDriverVersion
;
1098 lstrcpyAtoW(lpmliW
->Target
.szPname
, mliA
.Target
.szPname
);
1103 /**************************************************************************
1104 * mixerGetLineInfo [MMSYSTEM.805]
1106 UINT16 WINAPI
mixerGetLineInfo16(HMIXEROBJ16 hmix
, LPMIXERLINE16 lpmli16
, DWORD fdwInfo
)
1111 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmli16
, fdwInfo
);
1113 if (lpmli16
== NULL
|| lpmli16
->cbStruct
!= sizeof(*lpmli16
))
1114 return MMSYSERR_INVALPARAM
;
1116 mliA
.cbStruct
= sizeof(mliA
);
1117 switch (fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
) {
1118 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
1119 mliA
.dwComponentType
= lpmli16
->dwComponentType
;
1121 case MIXER_GETLINEINFOF_DESTINATION
:
1122 mliA
.dwDestination
= lpmli16
->dwDestination
;
1124 case MIXER_GETLINEINFOF_LINEID
:
1125 mliA
.dwLineID
= lpmli16
->dwLineID
;
1127 case MIXER_GETLINEINFOF_SOURCE
:
1128 mliA
.dwDestination
= lpmli16
->dwDestination
;
1129 mliA
.dwSource
= lpmli16
->dwSource
;
1131 case MIXER_GETLINEINFOF_TARGETTYPE
:
1132 mliA
.Target
.dwType
= lpmli16
->Target
.dwType
;
1133 mliA
.Target
.wMid
= lpmli16
->Target
.wMid
;
1134 mliA
.Target
.wPid
= lpmli16
->Target
.wPid
;
1135 mliA
.Target
.vDriverVersion
= lpmli16
->Target
.vDriverVersion
;
1136 strcpy(mliA
.Target
.szPname
, lpmli16
->Target
.szPname
);
1139 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo
);
1142 ret
= mixerGetLineInfoA(hmix
, &mliA
, fdwInfo
);
1144 lpmli16
->dwDestination
= mliA
.dwDestination
;
1145 lpmli16
->dwSource
= mliA
.dwSource
;
1146 lpmli16
->dwLineID
= mliA
.dwLineID
;
1147 lpmli16
->fdwLine
= mliA
.fdwLine
;
1148 lpmli16
->dwUser
= mliA
.dwUser
;
1149 lpmli16
->dwComponentType
= mliA
.dwComponentType
;
1150 lpmli16
->cChannels
= mliA
.cChannels
;
1151 lpmli16
->cConnections
= mliA
.cConnections
;
1152 lpmli16
->cControls
= mliA
.cControls
;
1153 strcpy(lpmli16
->szShortName
, mliA
.szShortName
);
1154 strcpy(lpmli16
->szName
, mliA
.szName
);
1155 lpmli16
->Target
.dwType
= mliA
.Target
.dwType
;
1156 lpmli16
->Target
.dwDeviceID
= mliA
.Target
.dwDeviceID
;
1157 lpmli16
->Target
.wMid
= mliA
.Target
.wMid
;
1158 lpmli16
->Target
.wPid
= mliA
.Target
.wPid
;
1159 lpmli16
->Target
.vDriverVersion
= mliA
.Target
.vDriverVersion
;
1160 strcpy(lpmli16
->Target
.szPname
, mliA
.Target
.szPname
);
1165 /**************************************************************************
1166 * mixerSetControlDetails [WINMM.111]
1168 UINT WINAPI
mixerSetControlDetails(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
, DWORD fdwDetails
)
1172 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmcdA
, fdwDetails
);
1174 uDevID
= MIXER_GetDevID(hmix
, fdwDetails
);
1176 return mixMessage(uDevID
, MXDM_SETCONTROLDETAILS
, 0, (DWORD
)lpmcdA
, fdwDetails
);
1179 /**************************************************************************
1180 * mixerSetControlDetails [MMSYSTEM.809]
1182 UINT16 WINAPI
mixerSetControlDetails16(HMIXEROBJ16 hmix
, LPMIXERCONTROLDETAILS16 lpmcd
, DWORD fdwDetails
)
1184 TRACE("(%04x, %p, %08lx)\n", hmix
, lpmcd
, fdwDetails
);
1185 return MMSYSERR_NOTENABLED
;
1188 /**************************************************************************
1189 * mixerMessage [WINMM.109]
1191 UINT WINAPI
mixerMessage(HMIXER hmix
, UINT uMsg
, DWORD dwParam1
, DWORD dwParam2
)
1193 LPMIXEROPENDESC lpmod
;
1196 lpmod
= (LPMIXEROPENDESC
)USER_HEAP_LIN_ADDR(hmix
);
1198 uDeviceID
= lpmod
->uDeviceID
;
1201 FIXME("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
1202 (DWORD
)hmix
, uMsg
, dwParam1
, dwParam2
);
1203 return mixMessage(uDeviceID
, uMsg
, 0L, dwParam1
, dwParam2
);
1206 /**************************************************************************
1207 * mixerMessage [MMSYSTEM.804]
1209 UINT16 WINAPI
mixerMessage16(HMIXER16 hmix
, UINT16 uMsg
, DWORD dwParam1
, DWORD dwParam2
)
1211 LPMIXEROPENDESC lpmod
;
1214 lpmod
= (LPMIXEROPENDESC
)USER_HEAP_LIN_ADDR(hmix
);
1215 uDeviceID
= (lpmod
) ? lpmod
->uDeviceID
: 0;
1216 FIXME("(%04x, %d, %08lx, %08lx) - semi-stub?\n",
1217 hmix
, uMsg
, dwParam1
, dwParam2
);
1218 return mixMessage(uDeviceID
, uMsg
, 0L, dwParam1
, dwParam2
);
1221 /**************************************************************************
1222 * auxGetNumDevs [WINMM.22]
1224 UINT WINAPI
auxGetNumDevs(void)
1226 return auxGetNumDevs16();
1229 /**************************************************************************
1230 * auxGetNumDevs [MMSYSTEM.350]
1232 UINT16 WINAPI
auxGetNumDevs16(void)
1237 count
= auxMessage(0, AUXDM_GETNUMDEVS
, 0L, 0L, 0L);
1238 TRACE("=> %u\n", count
);
1242 /**************************************************************************
1243 * auxGetDevCaps [WINMM.20]
1245 UINT WINAPI
auxGetDevCapsW(UINT uDeviceID
, LPAUXCAPSW lpCaps
, UINT uSize
)
1248 UINT ret
= auxGetDevCaps16(uDeviceID
, &ac16
, sizeof(ac16
));
1250 lpCaps
->wMid
= ac16
.wMid
;
1251 lpCaps
->wPid
= ac16
.wPid
;
1252 lpCaps
->vDriverVersion
= ac16
.vDriverVersion
;
1253 lstrcpyAtoW(lpCaps
->szPname
, ac16
.szPname
);
1254 lpCaps
->wTechnology
= ac16
.wTechnology
;
1255 lpCaps
->dwSupport
= ac16
.dwSupport
;
1259 /**************************************************************************
1260 * auxGetDevCaps [WINMM.21]
1262 UINT WINAPI
auxGetDevCapsA(UINT uDeviceID
, LPAUXCAPSA lpCaps
, UINT uSize
)
1265 UINT ret
= auxGetDevCaps16(uDeviceID
, &ac16
, sizeof(ac16
));
1267 lpCaps
->wMid
= ac16
.wMid
;
1268 lpCaps
->wPid
= ac16
.wPid
;
1269 lpCaps
->vDriverVersion
= ac16
.vDriverVersion
;
1270 strcpy(lpCaps
->szPname
, ac16
.szPname
);
1271 lpCaps
->wTechnology
= ac16
.wTechnology
;
1272 lpCaps
->dwSupport
= ac16
.dwSupport
;
1276 /**************************************************************************
1277 * auxGetDevCaps [MMSYSTEM.351]
1279 UINT16 WINAPI
auxGetDevCaps16(UINT16 uDeviceID
, LPAUXCAPS16 lpCaps
, UINT16 uSize
)
1281 TRACE("(%04X, %p, %d) !\n", uDeviceID
, lpCaps
, uSize
);
1283 return auxMessage(uDeviceID
, AUXDM_GETDEVCAPS
,
1284 0L, (DWORD
)lpCaps
, (DWORD
)uSize
);
1287 /**************************************************************************
1288 * auxGetVolume [WINM.23]
1290 UINT WINAPI
auxGetVolume(UINT uDeviceID
, DWORD
* lpdwVolume
)
1292 return auxGetVolume16(uDeviceID
, lpdwVolume
);
1295 /**************************************************************************
1296 * auxGetVolume [MMSYSTEM.352]
1298 UINT16 WINAPI
auxGetVolume16(UINT16 uDeviceID
, DWORD
* lpdwVolume
)
1300 TRACE("(%04X, %p) !\n", uDeviceID
, lpdwVolume
);
1302 return auxMessage(uDeviceID
, AUXDM_GETVOLUME
, 0L, (DWORD
)lpdwVolume
, 0L);
1305 /**************************************************************************
1306 * auxSetVolume [WINMM.25]
1308 UINT WINAPI
auxSetVolume(UINT uDeviceID
, DWORD dwVolume
)
1310 return auxSetVolume16(uDeviceID
, dwVolume
);
1313 /**************************************************************************
1314 * auxSetVolume [MMSYSTEM.353]
1316 UINT16 WINAPI
auxSetVolume16(UINT16 uDeviceID
, DWORD dwVolume
)
1318 TRACE("(%04X, %08lX) !\n", uDeviceID
, dwVolume
);
1320 return auxMessage(uDeviceID
, AUXDM_SETVOLUME
, 0L, dwVolume
, 0L);
1323 /**************************************************************************
1324 * auxOutMessage [MMSYSTEM.354]
1326 DWORD WINAPI
auxOutMessage(UINT uDeviceID
, UINT uMessage
, DWORD dw1
, DWORD dw2
)
1329 case AUXDM_GETNUMDEVS
:
1330 case AUXDM_GETVOLUME
:
1331 case AUXDM_SETVOLUME
:
1332 /* no argument conversion needed */
1334 case AUXDM_GETDEVCAPS
:
1335 return auxGetDevCapsA(uDeviceID
, (LPAUXCAPSA
)dw1
, dw2
);
1337 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
1338 uDeviceID
, uMessage
, dw1
, dw2
);
1341 return auxMessage(uDeviceID
, uMessage
, 0L, dw1
, dw2
);
1344 /**************************************************************************
1345 * auxOutMessage [MMSYSTEM.354]
1347 DWORD WINAPI
auxOutMessage16(UINT16 uDeviceID
, UINT16 uMessage
, DWORD dw1
, DWORD dw2
)
1349 TRACE("(%04X, %04X, %08lX, %08lX)\n", uDeviceID
, uMessage
, dw1
, dw2
);
1352 case AUXDM_GETNUMDEVS
:
1353 case AUXDM_SETVOLUME
:
1354 /* no argument conversion needed */
1356 case AUXDM_GETVOLUME
:
1357 return auxGetVolume16(uDeviceID
, (LPDWORD
)PTR_SEG_TO_LIN(dw1
));
1358 case AUXDM_GETDEVCAPS
:
1359 return auxGetDevCaps16(uDeviceID
, (LPAUXCAPS16
)PTR_SEG_TO_LIN(dw1
), dw2
);
1361 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
1362 uDeviceID
, uMessage
, dw1
, dw2
);
1365 return auxMessage(uDeviceID
, uMessage
, 0L, dw1
, dw2
);
1368 /**************************************************************************
1369 * mciGetErrorStringW [WINMM.46]
1371 BOOL WINAPI
mciGetErrorStringW(DWORD wError
, LPWSTR lpstrBuffer
, UINT uLength
)
1373 LPSTR bufstr
= HeapAlloc(GetProcessHeap(), 0, uLength
);
1374 BOOL ret
= mciGetErrorStringA(wError
, bufstr
, uLength
);
1376 lstrcpyAtoW(lpstrBuffer
, bufstr
);
1377 HeapFree(GetProcessHeap(), 0, bufstr
);
1381 /**************************************************************************
1382 * mciGetErrorStringA [WINMM.45]
1384 BOOL WINAPI
mciGetErrorStringA(DWORD wError
, LPSTR lpstrBuffer
, UINT uLength
)
1386 return mciGetErrorString16(wError
, lpstrBuffer
, uLength
);
1389 /**************************************************************************
1390 * mciGetErrorString [MMSYSTEM.706]
1392 BOOL16 WINAPI
mciGetErrorString16(DWORD dwError
, LPSTR lpstrBuffer
, UINT16 uLength
)
1394 LPSTR msgptr
= NULL
;
1396 TRACE("(%08lX, %p, %d);\n", dwError
, lpstrBuffer
, uLength
);
1398 if ((lpstrBuffer
== NULL
) || (uLength
< 1))
1401 lpstrBuffer
[0] = '\0';
1405 msgptr
= "The specified command has been executed.";
1407 case MCIERR_INVALID_DEVICE_ID
:
1408 msgptr
= "Invalid MCI device ID. Use the ID returned when opening the MCI device.";
1410 case MCIERR_UNRECOGNIZED_KEYWORD
:
1411 msgptr
= "The driver cannot recognize the specified command parameter.";
1413 case MCIERR_UNRECOGNIZED_COMMAND
:
1414 msgptr
= "The driver cannot recognize the specified command.";
1416 case MCIERR_HARDWARE
:
1417 msgptr
= "There is a problem with your media device. Make sure it is working correctly or contact the device manufacturer.";
1419 case MCIERR_INVALID_DEVICE_NAME
:
1420 msgptr
= "The specified device is not open or is not recognized by MCI.";
1422 case MCIERR_OUT_OF_MEMORY
:
1423 msgptr
= "Not enough memory available for this task. \nQuit one or more applications to increase available memory, and then try again.";
1425 case MCIERR_DEVICE_OPEN
:
1426 msgptr
= "The device name is already being used as an alias by this application. Use a unique alias.";
1428 case MCIERR_CANNOT_LOAD_DRIVER
:
1429 msgptr
= "There is an undetectable problem in loading the specified device driver.";
1431 case MCIERR_MISSING_COMMAND_STRING
:
1432 msgptr
= "No command was specified.";
1434 case MCIERR_PARAM_OVERFLOW
:
1435 msgptr
= "The output string was to large to fit in the return buffer. Increase the size of the buffer.";
1437 case MCIERR_MISSING_STRING_ARGUMENT
:
1438 msgptr
= "The specified command requires a character-string parameter. Please provide one.";
1440 case MCIERR_BAD_INTEGER
:
1441 msgptr
= "The specified integer is invalid for this command.";
1443 case MCIERR_PARSER_INTERNAL
:
1444 msgptr
= "The device driver returned an invalid return type. Check with the device manufacturer about obtaining a new driver.";
1446 case MCIERR_DRIVER_INTERNAL
:
1447 msgptr
= "There is a problem with the device driver. Check with the device manufacturer about obtaining a new driver.";
1449 case MCIERR_MISSING_PARAMETER
:
1450 msgptr
= "The specified command requires a parameter. Please supply one.";
1452 case MCIERR_UNSUPPORTED_FUNCTION
:
1453 msgptr
= "The MCI device you are using does not support the specified command.";
1455 case MCIERR_FILE_NOT_FOUND
:
1456 msgptr
= "Cannot find the specified file. Make sure the path and filename are correct.";
1458 case MCIERR_DEVICE_NOT_READY
:
1459 msgptr
= "The device driver is not ready.";
1461 case MCIERR_INTERNAL
:
1462 msgptr
= "A problem occurred in initializing MCI. Try restarting Windows.";
1465 msgptr
= "There is a problem with the device driver. The driver has closed. Cannot access error.";
1467 case MCIERR_CANNOT_USE_ALL
:
1468 msgptr
= "Cannot use 'all' as the device name with the specified command.";
1470 case MCIERR_MULTIPLE
:
1471 msgptr
= "Errors occurred in more than one device. Specify each command and device separately to determine which devices caused the error";
1473 case MCIERR_EXTENSION_NOT_FOUND
:
1474 msgptr
= "Cannot determine the device type from the given filename extension.";
1476 case MCIERR_OUTOFRANGE
:
1477 msgptr
= "The specified parameter is out of range for the specified command.";
1479 case MCIERR_FLAGS_NOT_COMPATIBLE
:
1480 msgptr
= "The specified parameters cannot be used together.";
1482 case MCIERR_FILE_NOT_SAVED
:
1483 msgptr
= "Cannot save the specified file. Make sure you have enough disk space or are still connected to the network.";
1485 case MCIERR_DEVICE_TYPE_REQUIRED
:
1486 msgptr
= "Cannot find the specified device. Make sure it is installed or that the device name is spelled correctly.";
1488 case MCIERR_DEVICE_LOCKED
:
1489 msgptr
= "The specified device is now being closed. Wait a few seconds, and then try again.";
1491 case MCIERR_DUPLICATE_ALIAS
:
1492 msgptr
= "The specified alias is already being used in this application. Use a unique alias.";
1494 case MCIERR_BAD_CONSTANT
:
1495 msgptr
= "The specified parameter is invalid for this command.";
1497 case MCIERR_MUST_USE_SHAREABLE
:
1498 msgptr
= "The device driver is already in use. To share it, use the 'shareable' parameter with each 'open' command.";
1500 case MCIERR_MISSING_DEVICE_NAME
:
1501 msgptr
= "The specified command requires an alias, file, driver, or device name. Please supply one.";
1503 case MCIERR_BAD_TIME_FORMAT
:
1504 msgptr
= "The specified value for the time format is invalid. Refer to the MCI documentation for valid formats.";
1506 case MCIERR_NO_CLOSING_QUOTE
:
1507 msgptr
= "A closing double-quotation mark is missing from the parameter value. Please supply one.";
1509 case MCIERR_DUPLICATE_FLAGS
:
1510 msgptr
= "A parameter or value was specified twice. Only specify it once.";
1512 case MCIERR_INVALID_FILE
:
1513 msgptr
= "The specified file cannot be played on the specified MCI device. The file may be corrupt, or not in the correct format.";
1515 case MCIERR_NULL_PARAMETER_BLOCK
:
1516 msgptr
= "A null parameter block was passed to MCI.";
1518 case MCIERR_UNNAMED_RESOURCE
:
1519 msgptr
= "Cannot save an unnamed file. Supply a filename.";
1521 case MCIERR_NEW_REQUIRES_ALIAS
:
1522 msgptr
= "You must specify an alias when using the 'new' parameter.";
1524 case MCIERR_NOTIFY_ON_AUTO_OPEN
:
1525 msgptr
= "Cannot use the 'notify' flag with auto-opened devices.";
1527 case MCIERR_NO_ELEMENT_ALLOWED
:
1528 msgptr
= "Cannot use a filename with the specified device.";
1530 case MCIERR_NONAPPLICABLE_FUNCTION
:
1531 msgptr
= "Cannot carry out the commands in the order specified. Correct the command sequence, and then try again.";
1533 case MCIERR_ILLEGAL_FOR_AUTO_OPEN
:
1534 msgptr
= "Cannot carry out the specified command on an auto-opened device. Wait until the device is closed, and then try again.";
1536 case MCIERR_FILENAME_REQUIRED
:
1537 msgptr
= "The filename is invalid. Make sure the filename is not longer than 8 characters, followed by a period and an extension.";
1539 case MCIERR_EXTRA_CHARACTERS
:
1540 msgptr
= "Cannot specify extra characters after a string enclosed in quotation marks.";
1542 case MCIERR_DEVICE_NOT_INSTALLED
:
1543 msgptr
= "The specified device is not installed on the system. Use the Drivers option in Control Panel to install the device.";
1546 msgptr
= "Cannot access the specified file or MCI device. Try changing directories or restarting your computer.";
1549 msgptr
= "Cannot access the specified file or MCI device because the application cannot change directories.";
1551 case MCIERR_SET_DRIVE
:
1552 msgptr
= "Cannot access specified file or MCI device because the application cannot change drives.";
1554 case MCIERR_DEVICE_LENGTH
:
1555 msgptr
= "Specify a device or driver name that is less than 79 characters.";
1557 case MCIERR_DEVICE_ORD_LENGTH
:
1558 msgptr
= "Specify a device or driver name that is less than 69 characters.";
1560 case MCIERR_NO_INTEGER
:
1561 msgptr
= "The specified command requires an integer parameter. Please provide one.";
1563 case MCIERR_WAVE_OUTPUTSINUSE
:
1564 msgptr
= "All wave devices that can play files in the current format are in use. Wait until a wave device is free, and then try again.";
1566 case MCIERR_WAVE_SETOUTPUTINUSE
:
1567 msgptr
= "Cannot set the current wave device for play back because it is in use. Wait until the device is free, and then try again.";
1569 case MCIERR_WAVE_INPUTSINUSE
:
1570 msgptr
= "All wave devices that can record files in the current format are in use. Wait until a wave device is free, and then try again.";
1572 case MCIERR_WAVE_SETINPUTINUSE
:
1573 msgptr
= "Cannot set the current wave device for recording because it is in use. Wait until the device is free, and then try again.";
1575 case MCIERR_WAVE_OUTPUTUNSPECIFIED
:
1576 msgptr
= "Any compatible waveform playback device may be used.";
1578 case MCIERR_WAVE_INPUTUNSPECIFIED
:
1579 msgptr
= "Any compatible waveform recording device may be used.";
1581 case MCIERR_WAVE_OUTPUTSUNSUITABLE
:
1582 msgptr
= "No wave device that can play files in the current format is installed. Use the Drivers option to install the wave device.";
1584 case MCIERR_WAVE_SETOUTPUTUNSUITABLE
:
1585 msgptr
= "The device you are trying to play to cannot recognize the current file format.";
1587 case MCIERR_WAVE_INPUTSUNSUITABLE
:
1588 msgptr
= "No wave device that can record files in the current format is installed. Use the Drivers option to install the wave device.";
1590 case MCIERR_WAVE_SETINPUTUNSUITABLE
:
1591 msgptr
= "The device you are trying to record from cannot recognize the current file format.";
1593 case MCIERR_NO_WINDOW
:
1594 msgptr
= "There is no display window.";
1596 case MCIERR_CREATEWINDOW
:
1597 msgptr
= "Could not create or use window.";
1599 case MCIERR_FILE_READ
:
1600 msgptr
= "Cannot read the specified file. Make sure the file is still present, or check your disk or network connection.";
1602 case MCIERR_FILE_WRITE
:
1603 msgptr
= "Cannot write to the specified file. Make sure you have enough disk space or are still connected to the network.";
1605 case MCIERR_SEQ_DIV_INCOMPATIBLE
:
1606 msgptr
= "The time formats of the \"song pointer\" and SMPTE are mutually exclusive. You can't use them together.";
1608 case MCIERR_SEQ_NOMIDIPRESENT
:
1609 msgptr
= "The system has no installed MIDI devices. Use the Drivers option from the Control Panel to install a MIDI driver.";
1611 case MCIERR_SEQ_PORT_INUSE
:
1612 msgptr
= "The specified MIDI port is already in use. Wait until it is free; the try again.";
1614 case MCIERR_SEQ_PORT_MAPNODEVICE
:
1615 msgptr
= "The current MIDI Mapper setup refers to a MIDI device that is not installed on the system. Use the MIDI Mapper option from the Control Panel to edit the setup.";
1617 case MCIERR_SEQ_PORT_MISCERROR
:
1618 msgptr
= "An error occurred with the specified port.";
1620 case MCIERR_SEQ_PORT_NONEXISTENT
:
1621 msgptr
= "The specified MIDI device is not installed on the system. Use the Drivers option from the Control Panel to install a MIDI device.";
1623 case MCIERR_SEQ_PORTUNSPECIFIED
:
1624 msgptr
= "The system doesnot have a current MIDI port specified.";
1626 case MCIERR_SEQ_TIMER
:
1627 msgptr
= "All multimedia timers are being used by other applications. Quit one of these applications; then, try again.";
1632 msg# 514 : videodisc
1637 msg# 519 : animation
1638 msg# 520 : digitalvideo
1640 msg# 522 : waveaudio
1641 msg# 523 : sequencer
1642 msg# 524 : not ready
1645 msg# 527 : recording
1651 msg# 533 : milliseconds
1658 msg# 540 : smpte 30 drop
1664 TRACE("Unknown MCI Error %ld!\n", dwError
);
1667 lstrcpynA(lpstrBuffer
, msgptr
, uLength
);
1668 TRACE("msg = \"%s\";\n", lpstrBuffer
);
1672 /**************************************************************************
1673 * mciDriverNotify [MMSYSTEM.711]
1675 BOOL16 WINAPI
mciDriverNotify16(HWND16 hWndCallBack
, UINT16 wDevID
, UINT16 wStatus
)
1677 TRACE("(%04X, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
1679 if (!IsWindow(hWndCallBack
)) {
1680 WARN("bad hWnd for call back (0x%04x)\n", hWndCallBack
);
1683 TRACE("before PostMessage\n");
1684 Callout
.PostMessageA(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
1688 /**************************************************************************
1689 * mciDriverNotify [WINMM.36]
1691 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, UINT wDevID
, UINT wStatus
)
1694 TRACE("(%08X, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
1696 if (!IsWindow(hWndCallBack
)) {
1697 WARN("bad hWnd for call back (0x%04x)\n", hWndCallBack
);
1700 TRACE("before PostMessage\n");
1701 Callout
.PostMessageA(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
1705 /**************************************************************************
1706 * mciGetDriverData [MMSYSTEM.708]
1708 DWORD WINAPI
mciGetDriverData16(UINT16 uDeviceID
)
1710 return mciGetDriverData(uDeviceID
);
1713 /**************************************************************************
1714 * mciGetDriverData [WINMM.44]
1716 DWORD WINAPI
mciGetDriverData(UINT uDeviceID
)
1718 LPWINE_MCIDRIVER wmd
;
1720 TRACE("(%04x)\n", uDeviceID
);
1722 wmd
= MCI_GetDriver(uDeviceID
);
1725 WARN("Bad uDeviceID\n");
1729 return wmd
->dwPrivate
;
1732 /**************************************************************************
1733 * mciSetDriverData [MMSYSTEM.707]
1735 BOOL16 WINAPI
mciSetDriverData16(UINT16 uDeviceID
, DWORD data
)
1737 return mciSetDriverData(uDeviceID
, data
);
1740 /**************************************************************************
1741 * mciSetDriverData [WINMM.53]
1743 BOOL WINAPI
mciSetDriverData(UINT uDeviceID
, DWORD data
)
1745 LPWINE_MCIDRIVER wmd
;
1747 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
1749 wmd
= MCI_GetDriver(uDeviceID
);
1752 WARN("Bad uDeviceID\n");
1756 wmd
->dwPrivate
= data
;
1760 /**************************************************************************
1761 * mciLoadCommandResource [MMSYSTEM.705]
1763 UINT16 WINAPI
mciLoadCommandResource16(HANDLE16 hinst
, LPCSTR resname
, UINT16 type
)
1771 FIXME("(%04x, %s, %d): stub!\n", hinst
, resname
, type
);
1772 if (!lstrcmpiA(resname
, "core")) {
1773 FIXME("(...,\"core\",...), have to use internal tables... (not there yet)\n");
1776 /* if file exists "resname.mci", then load resource "resname" from it
1777 * otherwise directly from driver
1779 strcpy(buf
, resname
);
1780 strcat(buf
, ".mci");
1781 segstr
= SEGPTR_STRDUP(resname
);
1783 if (!type
&& OpenFile(buf
, &ofs
, OF_EXIST
) != HFILE_ERROR
) {
1784 HANDLE16 xhinst
= LoadLibrary16(buf
);
1787 hrsrc
= FindResource16(xhinst
, SEGPTR_GET(segstr
), 0x800a);
1791 hrsrc
= FindResource16(hinst
, SEGPTR_GET(segstr
), 0x800a);
1793 SEGPTR_FREE(segstr
);
1795 WARN("no special commandlist found in resource (hinst=%04x)\n", hinst
);
1796 return MCI_NO_COMMAND_TABLE
;
1798 hmem
= LoadResource16(hinst
, hrsrc
);
1800 WARN("couldn't load resource??\n");
1801 return MCI_NO_COMMAND_TABLE
;
1803 if (TRACE_ON(mmsys
)) {
1807 xmem
= WIN16_LockResource16(hmem
);
1809 WARN("couldn't lock resource??\n");
1811 lmem
= PTR_SEG_TO_LIN(xmem
);
1812 TRACE("first resource entry is %s\n", (char*)lmem
);
1813 /* parse resource, register stuff, return unique id */
1818 lmem
+= strlen(lmem
) + 1;
1819 TRACE("cmd='%s' %08lx %04x\n", cmd
, *(LPDWORD
)lmem
, *(LPWORD
)(lmem
+ sizeof(DWORD
)));
1820 lmem
+= sizeof(DWORD
) + sizeof(WORD
);
1823 TRACE("eoc %08lx %04x\n", *(LPDWORD
)lmem
, *(LPWORD
)(lmem
+ sizeof(DWORD
)));
1831 /**************************************************************************
1832 * mciFreeCommandResource [MMSYSTEM.713]
1834 BOOL16 WINAPI
mciFreeCommandResource16(UINT16 uTable
)
1836 FIXME("(%04x) stub\n", uTable
);
1838 FreeResource16((HANDLE16
)uTable
);
1842 /**************************************************************************
1843 * mciFreeCommandResource [WINMM.39]
1845 BOOL WINAPI
mciFreeCommandResource(UINT uTable
)
1847 FIXME("(%08x) stub\n", uTable
);
1851 /**************************************************************************
1852 * mciLoadCommandResource [WINMM.48]
1854 UINT WINAPI
mciLoadCommandResource(HANDLE hinst
, LPCWSTR resname
, UINT type
)
1856 FIXME("(%04x, %s, %d): stub!\n", hinst
, debugstr_w(resname
), type
);
1860 /**************************************************************************
1861 * mciSendCommandA [WINMM.49]
1863 DWORD WINAPI
mciSendCommandA(UINT wDevID
, UINT wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1867 TRACE("(%08x, %s, %08lx, %08lx)\n", wDevID
, MCI_CommandToString(wMsg
), dwParam1
, dwParam2
);
1871 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1874 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1877 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1880 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1882 /* FIXME: it seems that MCI_BREAK and MCI_SOUND need the same handling */
1884 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1885 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1886 dwRet
= MCIERR_CANNOT_USE_ALL
;
1888 dwRet
= MCI_SendCommandFrom32(wDevID
, wMsg
, dwParam1
, dwParam2
);
1892 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
, TRUE
);
1893 TRACE("=> %08lx\n", dwRet
);
1897 /**************************************************************************
1898 * mciSendCommandW [WINMM.50]
1900 DWORD WINAPI
mciSendCommandW(UINT wDevID
, UINT wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1902 FIXME("(%08x, %s, %08lx, %08lx): stub\n", wDevID
, MCI_CommandToString(wMsg
), dwParam1
, dwParam2
);
1903 return MCIERR_UNSUPPORTED_FUNCTION
;
1906 /**************************************************************************
1907 * mciSendCommand [MMSYSTEM.701]
1909 DWORD WINAPI
mciSendCommand16(UINT16 wDevID
, UINT16 wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1911 DWORD dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
1912 LPWINE_MCIDRIVER wmd
;
1914 TRACE("(%04X, %s, %08lX, %08lX)\n",
1915 wDevID
, MCI_CommandToString(wMsg
), dwParam1
, dwParam2
);
1919 switch (MCI_MapMsg16To32A(0, wMsg
, &dwParam2
)) {
1922 dwRet
= MCI_Open(dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
1923 MCI_UnMapMsg16To32A(0, wMsg
, dwParam2
);
1925 default: break; /* so that gcc does not bark */
1929 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1930 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1931 dwRet
= MCIERR_CANNOT_USE_ALL
;
1932 } else if (!(wmd
= MCI_GetDriver(wDevID
))) {
1933 dwRet
= MCIERR_INVALID_DEVICE_ID
;
1935 switch (MCI_MapMsg16To32A(wmd
->wType
, wMsg
, &dwParam2
)) {
1938 dwRet
= MCI_Close(wDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1939 MCI_UnMapMsg16To32A(wmd
->wType
, wMsg
, dwParam2
);
1941 default: break; /* so that gcc does not bark */
1946 switch (MCI_MapMsg16To32A(0, wDevID
, &dwParam2
)) {
1949 dwRet
= MCI_SysInfo(wDevID
, dwParam1
, (LPMCI_SYSINFO_PARMSA
)dwParam2
);
1950 MCI_UnMapMsg16To32A(0, wDevID
, dwParam2
);
1952 default: break; /* so that gcc doesnot bark */
1956 switch (MCI_MapMsg16To32A(0, wDevID
, &dwParam2
)) {
1959 dwRet
= MCI_Break(wDevID
, dwParam1
, (LPMCI_BREAK_PARMS
)dwParam2
);
1960 MCI_UnMapMsg16To32A(0, wDevID
, dwParam2
);
1962 default: break; /* so that gcc does not bark */
1966 /* FIXME: it seems that MCI_BREAK and MCI_SOUND need the same handling */
1968 if (wDevID
== MCI_ALL_DEVICE_ID
) {
1969 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
1970 dwRet
= MCIERR_CANNOT_USE_ALL
;
1972 dwRet
= MCI_SendCommandFrom16(wDevID
, wMsg
, dwParam1
, dwParam2
);
1976 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
, FALSE
);
1977 TRACE("=> %ld\n", dwRet
);
1981 /**************************************************************************
1982 * mciGetDeviceID [MMSYSTEM.703]
1984 UINT16 WINAPI
mciGetDeviceID16(LPCSTR lpstrName
)
1986 TRACE("(\"%s\")\n", lpstrName
);
1988 return MCI_GetDriverFromString(lpstrName
);
1991 /**************************************************************************
1992 * mciGetDeviceIDA [WINMM.41]
1994 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
1996 return MCI_GetDriverFromString(lpstrName
);
1999 /**************************************************************************
2000 * mciGetDeviceIDW [WINMM.43]
2002 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
2007 lpstrName
= HEAP_strdupWtoA(GetProcessHeap(), 0, lpwstrName
);
2008 ret
= MCI_GetDriverFromString(lpstrName
);
2009 HeapFree(GetProcessHeap(), 0, lpstrName
);
2013 /**************************************************************************
2014 * MCI_DefYieldProc [internal]
2016 UINT16 WINAPI
MCI_DefYieldProc(UINT16 wDevID
, DWORD data
)
2020 TRACE("(0x%04x, 0x%08lx)\n", wDevID
, data
);
2022 if ((HIWORD(data
) != 0 && GetActiveWindow16() != HIWORD(data
)) ||
2023 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
2029 msg
.hwnd
= HIWORD(data
);
2030 while (!PeekMessageA(&msg
, HIWORD(data
), WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
2036 /**************************************************************************
2037 * mciSetYieldProc [MMSYSTEM.714]
2039 BOOL16 WINAPI
mciSetYieldProc16(UINT16 uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2041 LPWINE_MCIDRIVER wmd
;
2043 TRACE("(%u, %p, %08lx)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2045 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2046 WARN("Bad uDeviceID\n");
2050 wmd
->lpfnYieldProc
= fpYieldProc
;
2051 wmd
->dwYieldData
= dwYieldData
;
2057 /**************************************************************************
2058 * mciSetYieldProc [WINMM.54]
2060 BOOL WINAPI
mciSetYieldProc(UINT uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
2062 LPWINE_MCIDRIVER wmd
;
2064 TRACE("(%u, %p, %08lx)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
2066 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2067 WARN("Bad uDeviceID\n");
2071 wmd
->lpfnYieldProc
= fpYieldProc
;
2072 wmd
->dwYieldData
= dwYieldData
;
2078 /**************************************************************************
2079 * mciGetDeviceIDFromElementID [MMSYSTEM.715]
2081 UINT16 WINAPI
mciGetDeviceIDFromElementID16(DWORD dwElementID
, LPCSTR lpstrType
)
2083 FIXME("(%lu, %s) stub\n", dwElementID
, lpstrType
);
2087 /**************************************************************************
2088 * mciGetDeviceIDFromElementIDW [WINMM.42]
2090 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
2092 /* FIXME: that's rather strange, there is no
2093 * mciGetDeviceIDFromElementID32A in winmm.spec
2095 FIXME("(%lu, %p) stub\n", dwElementID
, lpstrType
);
2099 /**************************************************************************
2100 * mciGetYieldProc [MMSYSTEM.716]
2102 YIELDPROC WINAPI
mciGetYieldProc16(UINT16 uDeviceID
, DWORD
* lpdwYieldData
)
2104 LPWINE_MCIDRIVER wmd
;
2106 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2108 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2109 WARN("Bad uDeviceID\n");
2112 if (!wmd
->lpfnYieldProc
) {
2113 WARN("No proc set\n");
2117 WARN("Proc is 32 bit\n");
2120 return wmd
->lpfnYieldProc
;
2123 /**************************************************************************
2124 * mciGetYieldProc [WINMM.47]
2126 YIELDPROC WINAPI
mciGetYieldProc(UINT uDeviceID
, DWORD
* lpdwYieldData
)
2128 LPWINE_MCIDRIVER wmd
;
2130 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
2132 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
2133 WARN("Bad uDeviceID\n");
2136 if (!wmd
->lpfnYieldProc
) {
2137 WARN("No proc set\n");
2141 WARN("Proc is 32 bit\n");
2144 return wmd
->lpfnYieldProc
;
2147 /**************************************************************************
2148 * mciGetCreatorTask [MMSYSTEM.717]
2150 HTASK16 WINAPI
mciGetCreatorTask16(UINT16 uDeviceID
)
2152 return mciGetCreatorTask(uDeviceID
);
2155 /**************************************************************************
2156 * mciGetCreatorTask [WINMM.40]
2158 HTASK WINAPI
mciGetCreatorTask(UINT uDeviceID
)
2160 LPWINE_MCIDRIVER wmd
;
2163 TRACE("(%u)\n", uDeviceID
);
2165 ret
= (!(wmd
= MCI_GetDriver(uDeviceID
))) ? 0 : wmd
->hCreatorTask
;
2167 TRACE("=> %04x\n", ret
);
2171 /**************************************************************************
2172 * mciDriverYield [MMSYSTEM.710]
2174 UINT16 WINAPI
mciDriverYield16(UINT16 uDeviceID
)
2176 LPWINE_MCIDRIVER wmd
;
2179 /* TRACE("(%04x)\n", uDeviceID); */
2181 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || wmd
->lpfnYieldProc
|| wmd
->bIs32
) {
2184 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);
2190 /**************************************************************************
2191 * mciDriverYield [WINMM.37]
2193 UINT WINAPI
mciDriverYield(UINT uDeviceID
)
2195 LPWINE_MCIDRIVER wmd
;
2198 TRACE("(%04x)\n", uDeviceID
);
2200 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || wmd
->lpfnYieldProc
|| wmd
->bIs32
) {
2203 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);
2209 /**************************************************************************
2210 * midiOutGetNumDevs [WINMM.80]
2212 UINT WINAPI
midiOutGetNumDevs(void)
2214 return midiOutGetNumDevs16();
2217 /**************************************************************************
2218 * midiOutGetNumDevs [MMSYSTEM.201]
2220 UINT16 WINAPI
midiOutGetNumDevs16(void)
2222 UINT16 count
= modMessage(0, MODM_GETNUMDEVS
, 0L, 0L, 0L);
2224 TRACE("returns %u\n", count
);
2228 /**************************************************************************
2229 * midiOutGetDevCapsW [WINMM.76]
2231 UINT WINAPI
midiOutGetDevCapsW(UINT uDeviceID
, LPMIDIOUTCAPSW lpCaps
, UINT uSize
)
2233 MIDIOUTCAPS16 moc16
;
2236 ret
= midiOutGetDevCaps16(uDeviceID
, &moc16
, sizeof(moc16
));
2237 lpCaps
->wMid
= moc16
.wMid
;
2238 lpCaps
->wPid
= moc16
.wPid
;
2239 lpCaps
->vDriverVersion
= moc16
.vDriverVersion
;
2240 lstrcpyAtoW(lpCaps
->szPname
, moc16
.szPname
);
2241 lpCaps
->wTechnology
= moc16
.wTechnology
;
2242 lpCaps
->wVoices
= moc16
.wVoices
;
2243 lpCaps
->wNotes
= moc16
.wNotes
;
2244 lpCaps
->wChannelMask
= moc16
.wChannelMask
;
2245 lpCaps
->dwSupport
= moc16
.dwSupport
;
2249 /**************************************************************************
2250 * midiOutGetDevCapsA [WINMM.75]
2252 UINT WINAPI
midiOutGetDevCapsA(UINT uDeviceID
, LPMIDIOUTCAPSA lpCaps
, UINT uSize
)
2254 MIDIOUTCAPS16 moc16
;
2257 ret
= midiOutGetDevCaps16(uDeviceID
, &moc16
, sizeof(moc16
));
2258 lpCaps
->wMid
= moc16
.wMid
;
2259 lpCaps
->wPid
= moc16
.wPid
;
2260 lpCaps
->vDriverVersion
= moc16
.vDriverVersion
;
2261 strcpy(lpCaps
->szPname
, moc16
.szPname
);
2262 lpCaps
->wTechnology
= moc16
.wTechnology
;
2263 lpCaps
->wVoices
= moc16
.wVoices
;
2264 lpCaps
->wNotes
= moc16
.wNotes
;
2265 lpCaps
->wChannelMask
= moc16
.wChannelMask
;
2266 lpCaps
->dwSupport
= moc16
.dwSupport
;
2270 /**************************************************************************
2271 * midiOutGetDevCaps [MMSYSTEM.202]
2273 UINT16 WINAPI
midiOutGetDevCaps16(UINT16 uDeviceID
, LPMIDIOUTCAPS16 lpCaps
, UINT16 uSize
)
2275 TRACE("midiOutGetDevCaps\n");
2276 return modMessage(uDeviceID
, MODM_GETDEVCAPS
, 0, (DWORD
)lpCaps
, uSize
);
2279 /**************************************************************************
2280 * midiOutGetErrorTextA [WINMM.77]
2282 UINT WINAPI
midiOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2284 TRACE("midiOutGetErrorText\n");
2285 return midiGetErrorText(uError
, lpText
, uSize
);
2288 /**************************************************************************
2289 * midiOutGetErrorTextW [WINMM.78]
2291 UINT WINAPI
midiOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2293 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
2296 TRACE("midiOutGetErrorText\n");
2297 ret
= midiGetErrorText(uError
, xstr
, uSize
);
2298 lstrcpyAtoW(lpText
, xstr
);
2299 HeapFree(GetProcessHeap(), 0, xstr
);
2303 /**************************************************************************
2304 * midiOutGetErrorText [MMSYSTEM.203]
2306 UINT16 WINAPI
midiOutGetErrorText16(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
2308 TRACE("midiOutGetErrorText\n");
2309 return midiGetErrorText(uError
, lpText
, uSize
);
2312 /**************************************************************************
2313 * midiGetErrorText [internal]
2315 UINT16 WINAPI
midiGetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
2318 if ((lpText
== NULL
) || (uSize
< 1)) return(FALSE
);
2321 case MIDIERR_UNPREPARED
:
2322 msgptr
= "The MIDI header was not prepared. Use the Prepare function to prepare the header, and then try again.";
2324 case MIDIERR_STILLPLAYING
:
2325 msgptr
= "Cannot perform this operation while media data is still playing. Reset the device, or wait until the data is finished playing.";
2328 msgptr
= "A MIDI map was not found. There may be a problem with the driver, or the MIDIMAP.CFG file may be corrupt or missing.";
2330 case MIDIERR_NOTREADY
:
2331 msgptr
= "The port is transmitting data to the device. Wait until the data has been transmitted, and then try again.";
2333 case MIDIERR_NODEVICE
:
2334 msgptr
= "The current MIDI Mapper setup refers to a MIDI device that is not installed on the system. Use MIDI Mapper to edit the setup.";
2336 case MIDIERR_INVALIDSETUP
:
2337 msgptr
= "The current MIDI setup is damaged. Copy the original MIDIMAP.CFG file to the Windows SYSTEM directory, and then try again.";
2340 msg# 336 : Cannot use the song-pointer time format and the SMPTE time-format together.
2341 msg# 337 : The specified MIDI device is already in use. Wait until it is free, and then try again.
2342 msg# 338 : The specified MIDI device is not installed on the system. Use the Drivers option in Control Panel to install the driver.
2343 msg# 339 : The current MIDI Mapper setup refers to a MIDI device that is not installed on the system. Use MIDI Mapper to edit the setup.
2344 msg# 340 : An error occurred using the specified port.
2345 msg# 341 : All multimedia timers are being used by other applications. Quit one of these applications, and then try again.
2346 msg# 342 : There is no current MIDI port.
2347 msg# 343 : There are no MIDI devices installed on the system. Use the Drivers option in Control Panel to install the driver.
2350 msgptr
= "Unknown MIDI Error !\n";
2353 lstrcpynA(lpText
, msgptr
, uSize
);
2357 static LPMIDIOPENDESC
MIDI_OutAlloc(HMIDIOUT16
* lphMidiOut
, DWORD dwCallback
,
2358 DWORD dwInstance
, DWORD cIDs
, MIDIOPENSTRMID
* lpIDs
)
2361 LPMIDIOPENDESC lpDesc
;
2363 hMidiOut
= USER_HEAP_ALLOC(sizeof(MIDIOPENDESC
) + (cIDs
? (cIDs
- 1) : 0) * sizeof(MIDIOPENSTRMID
));
2365 if (lphMidiOut
!= NULL
)
2366 *lphMidiOut
= hMidiOut
;
2367 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2370 lpDesc
->hMidi
= hMidiOut
;
2371 lpDesc
->dwCallback
= dwCallback
;
2372 lpDesc
->dwInstance
= dwInstance
;
2373 lpDesc
->dnDevNode
= 0;
2374 lpDesc
->cIds
= cIDs
;
2376 memcpy(&(lpDesc
->rgIds
), lpIDs
, cIDs
* sizeof(MIDIOPENSTRMID
));
2381 /**************************************************************************
2382 * midiOutOpen [WINM.84]
2384 UINT WINAPI
midiOutOpen(HMIDIOUT
* lphMidiOut
, UINT uDeviceID
,
2385 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
2390 ret
= midiOutOpen16(&hmo16
, uDeviceID
, dwCallback
, dwInstance
,
2391 CALLBACK32CONV(dwFlags
));
2392 if (lphMidiOut
) *lphMidiOut
= hmo16
;
2396 /**************************************************************************
2397 * midiOutOpen [MMSYSTEM.204]
2399 UINT16 WINAPI
midiOutOpen16(HMIDIOUT16
* lphMidiOut
, UINT16 uDeviceID
,
2400 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
2402 HMIDIOUT16 hMidiOut
;
2403 LPMIDIOPENDESC lpDesc
;
2405 BOOL bMapperFlg
= FALSE
;
2407 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
2408 lphMidiOut
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
2410 if (lphMidiOut
!= NULL
) *lphMidiOut
= 0;
2412 if (uDeviceID
== (UINT16
)MIDI_MAPPER
) {
2413 TRACE("MIDI_MAPPER mode requested !\n");
2418 lpDesc
= MIDI_OutAlloc(&hMidiOut
, dwCallback
, dwInstance
, 0, NULL
);
2421 return MMSYSERR_NOMEM
;
2423 while (uDeviceID
< MAXMIDIDRIVERS
) {
2424 ret
= modMessage(uDeviceID
, MODM_OPEN
,
2425 lpDesc
->dwInstance
, (DWORD
)lpDesc
, dwFlags
);
2426 if (ret
== MMSYSERR_NOERROR
) break;
2427 if (!bMapperFlg
) break;
2429 TRACE("MIDI_MAPPER mode ! try next driver...\n");
2431 TRACE("=> wDevID=%u (%d)\n", uDeviceID
, ret
);
2432 if (ret
!= MMSYSERR_NOERROR
) {
2433 USER_HEAP_FREE(hMidiOut
);
2434 if (lphMidiOut
) *lphMidiOut
= 0;
2436 lpDesc
->wDevID
= uDeviceID
;
2437 if (lphMidiOut
) *lphMidiOut
= hMidiOut
;
2443 /**************************************************************************
2444 * midiOutClose [WINMM.74]
2446 UINT WINAPI
midiOutClose(HMIDIOUT hMidiOut
)
2448 return midiOutClose16(hMidiOut
);
2451 /**************************************************************************
2452 * midiOutClose [MMSYSTEM.205]
2454 UINT16 WINAPI
midiOutClose16(HMIDIOUT16 hMidiOut
)
2456 LPMIDIOPENDESC lpDesc
;
2459 TRACE("(%04X)\n", hMidiOut
);
2461 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2463 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2464 dwRet
= modMessage(lpDesc
->wDevID
, MODM_CLOSE
, lpDesc
->dwInstance
, 0L, 0L);
2465 USER_HEAP_FREE(hMidiOut
);
2469 /**************************************************************************
2470 * midiOutPrepareHeader [WINMM.85]
2472 UINT WINAPI
midiOutPrepareHeader(HMIDIOUT hMidiOut
,
2473 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
2475 LPMIDIOPENDESC lpDesc
;
2477 TRACE("(%04X, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
2479 lpDesc
= (LPMIDIOPENDESC
)USER_HEAP_LIN_ADDR(hMidiOut
);
2481 return MMSYSERR_INVALHANDLE
;
2482 lpMidiOutHdr
->reserved
= (DWORD
)lpMidiOutHdr
;
2483 return modMessage(lpDesc
->wDevID
, MODM_PREPARE
, lpDesc
->dwInstance
,
2484 (DWORD
)lpMidiOutHdr
, (DWORD
)uSize
);
2487 /**************************************************************************
2488 * midiOutPrepareHeader [MMSYSTEM.206]
2490 UINT16 WINAPI
midiOutPrepareHeader16(HMIDIOUT16 hMidiOut
,
2491 LPMIDIHDR16
/*SEGPTR*/ _lpMidiOutHdr
, UINT16 uSize
)
2493 LPMIDIOPENDESC lpDesc
;
2494 LPMIDIHDR16 lpMidiOutHdr
= (LPMIDIHDR16
)PTR_SEG_TO_LIN(_lpMidiOutHdr
);
2496 TRACE("(%04X, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
2498 lpDesc
= (LPMIDIOPENDESC
)USER_HEAP_LIN_ADDR(hMidiOut
);
2500 return MMSYSERR_INVALHANDLE
;
2501 lpMidiOutHdr
->reserved
= (DWORD
)_lpMidiOutHdr
;
2502 return modMessage(lpDesc
->wDevID
, MODM_PREPARE
, lpDesc
->dwInstance
,
2503 (DWORD
)lpMidiOutHdr
, (DWORD
)uSize
);
2506 /**************************************************************************
2507 * midiOutUnprepareHeader [WINMM.89]
2509 UINT WINAPI
midiOutUnprepareHeader(HMIDIOUT hMidiOut
,
2510 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
2512 return midiOutUnprepareHeader16(hMidiOut
, (MIDIHDR16
*)lpMidiOutHdr
, uSize
);
2515 /**************************************************************************
2516 * midiOutUnprepareHeader [MMSYSTEM.207]
2518 UINT16 WINAPI
midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut
,
2519 MIDIHDR16
* lpMidiOutHdr
, UINT16 uSize
)
2521 LPMIDIOPENDESC lpDesc
;
2523 TRACE("(%04X, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
2525 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2526 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2527 return modMessage(lpDesc
->wDevID
, MODM_UNPREPARE
, lpDesc
->dwInstance
,
2528 (DWORD
)lpMidiOutHdr
, (DWORD
)uSize
);
2531 /**************************************************************************
2532 * midiOutShortMsg [WINMM.88]
2534 UINT WINAPI
midiOutShortMsg(HMIDIOUT hMidiOut
, DWORD dwMsg
)
2536 return midiOutShortMsg16(hMidiOut
, dwMsg
);
2539 /**************************************************************************
2540 * midiOutShortMsg [MMSYSTEM.208]
2542 UINT16 WINAPI
midiOutShortMsg16(HMIDIOUT16 hMidiOut
, DWORD dwMsg
)
2544 LPMIDIOPENDESC lpDesc
;
2546 TRACE("(%04X, %08lX)\n", hMidiOut
, dwMsg
);
2548 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2549 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2550 return modMessage(lpDesc
->wDevID
, MODM_DATA
, lpDesc
->dwInstance
, dwMsg
, 0L);
2553 /**************************************************************************
2554 * midiOutLongMsg [WINMM.82]
2556 UINT WINAPI
midiOutLongMsg(HMIDIOUT hMidiOut
,
2557 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
2559 return midiOutLongMsg16(hMidiOut
, (MIDIHDR16
*)lpMidiOutHdr
, uSize
);
2562 /**************************************************************************
2563 * midiOutLongMsg [MMSYSTEM.209]
2565 UINT16 WINAPI
midiOutLongMsg16(HMIDIOUT16 hMidiOut
,
2566 MIDIHDR16
* lpMidiOutHdr
, UINT16 uSize
)
2568 LPMIDIOPENDESC lpDesc
;
2570 TRACE("(%04X, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
2572 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2573 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2574 return modMessage(lpDesc
->wDevID
, MODM_LONGDATA
, lpDesc
->dwInstance
,
2575 (DWORD
)lpMidiOutHdr
, (DWORD
)uSize
);
2578 /**************************************************************************
2579 * midiOutReset [WINMM.86]
2581 UINT WINAPI
midiOutReset(HMIDIOUT hMidiOut
)
2583 return midiOutReset16(hMidiOut
);
2586 /**************************************************************************
2587 * midiOutReset [MMSYSTEM.210]
2589 UINT16 WINAPI
midiOutReset16(HMIDIOUT16 hMidiOut
)
2591 LPMIDIOPENDESC lpDesc
;
2593 TRACE("(%04X)\n", hMidiOut
);
2595 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2596 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2597 return modMessage(lpDesc
->wDevID
, MODM_RESET
, lpDesc
->dwInstance
, 0L, 0L);
2600 /**************************************************************************
2601 * midiOutGetVolume [WINM.81]
2603 UINT WINAPI
midiOutGetVolume(UINT uDeviceID
, DWORD
* lpdwVolume
)
2605 return midiOutGetVolume16(uDeviceID
, lpdwVolume
);
2608 /**************************************************************************
2609 * midiOutGetVolume [MMSYSTEM.211]
2611 UINT16 WINAPI
midiOutGetVolume16(UINT16 uDeviceID
, DWORD
* lpdwVolume
)
2613 TRACE("(%04X, %p);\n", uDeviceID
, lpdwVolume
);
2614 return modMessage(uDeviceID
, MODM_GETVOLUME
, 0L, (DWORD
)lpdwVolume
, 0L);
2617 /**************************************************************************
2618 * midiOutSetVolume [WINMM.87]
2620 UINT WINAPI
midiOutSetVolume(UINT uDeviceID
, DWORD dwVolume
)
2622 return midiOutSetVolume16(uDeviceID
, dwVolume
);
2625 /**************************************************************************
2626 * midiOutSetVolume [MMSYSTEM.212]
2628 UINT16 WINAPI
midiOutSetVolume16(UINT16 uDeviceID
, DWORD dwVolume
)
2630 TRACE("(%04X, %08lX);\n", uDeviceID
, dwVolume
);
2631 return modMessage(uDeviceID
, MODM_SETVOLUME
, 0L, dwVolume
, 0L);
2634 /**************************************************************************
2635 * midiOutCachePatches [WINMM.73]
2637 UINT WINAPI
midiOutCachePatches(HMIDIOUT hMidiOut
, UINT uBank
,
2638 WORD
* lpwPatchArray
, UINT uFlags
)
2640 return midiOutCachePatches16(hMidiOut
, uBank
, lpwPatchArray
, uFlags
);
2643 /**************************************************************************
2644 * midiOutCachePatches [MMSYSTEM.213]
2646 UINT16 WINAPI
midiOutCachePatches16(HMIDIOUT16 hMidiOut
, UINT16 uBank
,
2647 WORD
* lpwPatchArray
, UINT16 uFlags
)
2649 /* not really necessary to support this */
2650 FIXME("not supported yet\n");
2651 return MMSYSERR_NOTSUPPORTED
;
2654 /**************************************************************************
2655 * midiOutCacheDrumPatches [WINMM.72]
2657 UINT WINAPI
midiOutCacheDrumPatches(HMIDIOUT hMidiOut
, UINT uPatch
,
2658 WORD
* lpwKeyArray
, UINT uFlags
)
2660 return midiOutCacheDrumPatches16(hMidiOut
, uPatch
, lpwKeyArray
, uFlags
);
2663 /**************************************************************************
2664 * midiOutCacheDrumPatches [MMSYSTEM.214]
2666 UINT16 WINAPI
midiOutCacheDrumPatches16(HMIDIOUT16 hMidiOut
, UINT16 uPatch
,
2667 WORD
* lpwKeyArray
, UINT16 uFlags
)
2669 FIXME("not supported yet\n");
2670 return MMSYSERR_NOTSUPPORTED
;
2673 /**************************************************************************
2674 * midiOutGetID [WINMM.79]
2676 UINT WINAPI
midiOutGetID(HMIDIOUT hMidiOut
, UINT
* lpuDeviceID
)
2681 ret
= midiOutGetID16(hMidiOut
, &xid
);
2686 /**************************************************************************
2687 * midiOutGetID [MMSYSTEM.215]
2689 UINT16 WINAPI
midiOutGetID16(HMIDIOUT16 hMidiOut
, UINT16
* lpuDeviceID
)
2691 TRACE("midiOutGetID\n");
2695 /**************************************************************************
2696 * midiOutMessage [WINMM.83]
2698 DWORD WINAPI
midiOutMessage(HMIDIOUT hMidiOut
, UINT uMessage
,
2699 DWORD dwParam1
, DWORD dwParam2
)
2701 LPMIDIOPENDESC lpDesc
;
2703 /* Shouldn't we anyway use the functions midiOutXXX ?
2704 * M$ doc says: This function is used only for driver-specific
2705 * messages that are not supported by the MIDI API.
2706 * Clearly not what we are currently doing
2709 TRACE("(%04X, %04X, %08lX, %08lX)\n",
2710 hMidiOut
, uMessage
, dwParam1
, dwParam2
);
2712 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2713 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2716 FIXME("can't handle MODM_OPEN!\n");
2718 case MODM_GETDEVCAPS
:
2719 return midiOutGetDevCapsA(hMidiOut
, (LPMIDIOUTCAPSA
)dwParam1
, dwParam2
);
2720 case MODM_GETNUMDEVS
:
2723 case MODM_GETVOLUME
:
2724 case MODM_SETVOLUME
:
2727 case MODM_UNPREPARE
:
2728 /* no argument conversion needed */
2731 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
2732 hMidiOut
, uMessage
, dwParam1
, dwParam2
);
2735 return modMessage(lpDesc
->wDevID
, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
2738 /**************************************************************************
2739 * midiOutMessage [MMSYSTEM.216]
2741 DWORD WINAPI
midiOutMessage16(HMIDIOUT16 hMidiOut
, UINT16 uMessage
,
2742 DWORD dwParam1
, DWORD dwParam2
)
2744 LPMIDIOPENDESC lpDesc
;
2746 TRACE("(%04X, %04X, %08lX, %08lX)\n",
2747 hMidiOut
, uMessage
, dwParam1
, dwParam2
);
2748 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiOut
);
2749 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2752 FIXME("can't handle MODM_OPEN!\n");
2754 case MODM_GETNUMDEVS
:
2757 case MODM_SETVOLUME
:
2758 /* no argument conversion needed */
2760 case MODM_GETVOLUME
:
2761 return midiOutGetVolume16(hMidiOut
, (LPDWORD
)PTR_SEG_TO_LIN(dwParam1
));
2763 return midiOutLongMsg16(hMidiOut
, (LPMIDIHDR16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
2765 /* lpMidiOutHdr is still a segmented pointer for this function */
2766 return midiOutPrepareHeader16(hMidiOut
, (LPMIDIHDR16
)dwParam1
, dwParam2
);
2767 case MODM_UNPREPARE
:
2768 return midiOutUnprepareHeader16(hMidiOut
, (LPMIDIHDR16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
2770 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
2771 hMidiOut
, uMessage
, dwParam1
, dwParam2
);
2774 return modMessage(lpDesc
->wDevID
, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
2777 /**************************************************************************
2778 * midiInGetNumDevs [WINMM.64]
2780 UINT WINAPI
midiInGetNumDevs(void)
2782 return midiInGetNumDevs16();
2785 /**************************************************************************
2786 * midiInGetNumDevs [MMSYSTEM.301]
2788 UINT16 WINAPI
midiInGetNumDevs16(void)
2791 TRACE("midiInGetNumDevs\n");
2792 count
+= midMessage(0, MIDM_GETNUMDEVS
, 0L, 0L, 0L);
2793 TRACE("midiInGetNumDevs return %u \n", count
);
2797 /**************************************************************************
2798 * midiInGetDevCaps [WINMM.60]
2800 UINT WINAPI
midiInGetDevCapsW(UINT uDeviceID
, LPMIDIINCAPSW lpCaps
, UINT uSize
)
2803 UINT ret
= midiInGetDevCaps16(uDeviceID
, &mic16
, uSize
);
2805 lpCaps
->wMid
= mic16
.wMid
;
2806 lpCaps
->wPid
= mic16
.wPid
;
2807 lpCaps
->vDriverVersion
= mic16
.vDriverVersion
;
2808 lstrcpyAtoW(lpCaps
->szPname
, mic16
.szPname
);
2809 lpCaps
->dwSupport
= mic16
.dwSupport
;
2813 /**************************************************************************
2814 * midiInGetDevCaps [WINMM.59]
2816 UINT WINAPI
midiInGetDevCapsA(UINT uDeviceID
, LPMIDIINCAPSA lpCaps
, UINT uSize
)
2819 UINT ret
= midiInGetDevCaps16(uDeviceID
, &mic16
, uSize
);
2821 lpCaps
->wMid
= mic16
.wMid
;
2822 lpCaps
->wPid
= mic16
.wPid
;
2823 lpCaps
->vDriverVersion
= mic16
.vDriverVersion
;
2824 strcpy(lpCaps
->szPname
, mic16
.szPname
);
2825 lpCaps
->dwSupport
= mic16
.dwSupport
;
2829 /**************************************************************************
2830 * midiInGetDevCaps [MMSYSTEM.302]
2832 UINT16 WINAPI
midiInGetDevCaps16(UINT16 uDeviceID
,
2833 LPMIDIINCAPS16 lpCaps
, UINT16 uSize
)
2835 TRACE("midiInGetDevCaps\n");
2836 return midMessage(uDeviceID
, MIDM_GETDEVCAPS
, 0, (DWORD
)lpCaps
, uSize
);
2839 /**************************************************************************
2840 * midiInGetErrorText [WINMM.62]
2842 UINT WINAPI
midiInGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2844 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
2845 UINT ret
= midiInGetErrorText16(uError
, xstr
, uSize
);
2846 lstrcpyAtoW(lpText
, xstr
);
2847 HeapFree(GetProcessHeap(), 0, xstr
);
2851 /**************************************************************************
2852 * midiInGetErrorText [WINMM.61]
2854 UINT WINAPI
midiInGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2856 return midiInGetErrorText16(uError
, lpText
, uSize
);
2859 /**************************************************************************
2860 * midiInGetErrorText [MMSYSTEM.303]
2862 UINT16 WINAPI
midiInGetErrorText16(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
2864 TRACE("midiInGetErrorText\n");
2865 return (midiGetErrorText(uError
, lpText
, uSize
));
2868 /**************************************************************************
2869 * midiInOpen [WINMM.66]
2871 UINT WINAPI
midiInOpen(HMIDIIN
* lphMidiIn
, UINT uDeviceID
,
2872 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
2875 UINT ret
= midiInOpen16(&xhmid16
, uDeviceID
, dwCallback
, dwInstance
,
2876 CALLBACK32CONV(dwFlags
));
2878 *lphMidiIn
= xhmid16
;
2882 /**************************************************************************
2883 * midiInOpen [MMSYSTEM.304]
2885 UINT16 WINAPI
midiInOpen16(HMIDIIN16
* lphMidiIn
, UINT16 uDeviceID
,
2886 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
2889 LPMIDIOPENDESC lpDesc
;
2891 BOOL bMapperFlg
= FALSE
;
2893 if (lphMidiIn
!= NULL
)
2895 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
2896 lphMidiIn
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
2897 if (uDeviceID
== (UINT16
)MIDI_MAPPER
) {
2898 TRACE("MIDI_MAPPER mode requested !\n");
2902 hMidiIn
= USER_HEAP_ALLOC(sizeof(MIDIOPENDESC
));
2903 if (lphMidiIn
!= NULL
)
2904 *lphMidiIn
= hMidiIn
;
2905 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
2907 return MMSYSERR_NOMEM
;
2908 lpDesc
->hMidi
= hMidiIn
;
2909 lpDesc
->dwCallback
= dwCallback
;
2910 lpDesc
->dwInstance
= dwInstance
;
2912 while (uDeviceID
< MAXMIDIDRIVERS
) {
2913 dwRet
= midMessage(uDeviceID
, MIDM_OPEN
,
2914 lpDesc
->dwInstance
, (DWORD
)lpDesc
, dwFlags
);
2915 if (dwRet
== MMSYSERR_NOERROR
)
2920 TRACE("MIDI_MAPPER mode ! try next driver...\n");
2922 lpDesc
->wDevID
= uDeviceID
;
2924 if (dwRet
!= MMSYSERR_NOERROR
) {
2925 USER_HEAP_FREE(hMidiIn
);
2926 if (lphMidiIn
) *lphMidiIn
= 0;
2932 /**************************************************************************
2933 * midiInClose [WINMM.58]
2935 UINT WINAPI
midiInClose(HMIDIIN hMidiIn
)
2937 return midiInClose16(hMidiIn
);
2940 /**************************************************************************
2941 * midiInClose [MMSYSTEM.305]
2943 UINT16 WINAPI
midiInClose16(HMIDIIN16 hMidiIn
)
2945 LPMIDIOPENDESC lpDesc
;
2948 TRACE("(%04X)\n", hMidiIn
);
2949 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
2951 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
2952 dwRet
= midMessage(lpDesc
->wDevID
, MIDM_CLOSE
, lpDesc
->dwInstance
, 0L, 0L);
2953 USER_HEAP_FREE(hMidiIn
);
2957 /**************************************************************************
2958 * midiInPrepareHeader [WINMM.67]
2960 UINT WINAPI
midiInPrepareHeader(HMIDIIN hMidiIn
,
2961 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
2963 LPMIDIOPENDESC lpDesc
;
2965 TRACE("(%04X, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
2967 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
2969 return MMSYSERR_INVALHANDLE
;
2970 lpMidiInHdr
->reserved
= (DWORD
)lpMidiInHdr
;
2971 return midMessage(lpDesc
->wDevID
, MIDM_PREPARE
, lpDesc
->dwInstance
,
2972 (DWORD
)lpMidiInHdr
, (DWORD
)uSize
);
2975 /**************************************************************************
2976 * midiInPrepareHeader [MMSYSTEM.306]
2978 UINT16 WINAPI
midiInPrepareHeader16(HMIDIIN16 hMidiIn
,
2979 MIDIHDR16
* /*SEGPTR*/ _lpMidiInHdr
, UINT16 uSize
)
2981 LPMIDIOPENDESC lpDesc
;
2982 LPMIDIHDR16 lpMidiInHdr
= (LPMIDIHDR16
)PTR_SEG_TO_LIN(_lpMidiInHdr
);
2984 TRACE("(%04X, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
2986 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
2988 return MMSYSERR_INVALHANDLE
;
2989 lpMidiInHdr
->reserved
= (DWORD
)_lpMidiInHdr
;
2990 return midMessage(lpDesc
->wDevID
, MIDM_PREPARE
, lpDesc
->dwInstance
,
2991 (DWORD
)lpMidiInHdr
, (DWORD
)uSize
);
2994 /**************************************************************************
2995 * midiInUnprepareHeader [WINMM.71]
2997 UINT WINAPI
midiInUnprepareHeader(HMIDIIN hMidiIn
,
2998 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
3000 return midiInUnprepareHeader16(hMidiIn
, (MIDIHDR16
*)lpMidiInHdr
, uSize
);
3003 /**************************************************************************
3004 * midiInUnprepareHeader [MMSYSTEM.307]
3006 UINT16 WINAPI
midiInUnprepareHeader16(HMIDIIN16 hMidiIn
,
3007 MIDIHDR16
* lpMidiInHdr
, UINT16 uSize
)
3009 LPMIDIOPENDESC lpDesc
;
3011 TRACE("(%04X, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
3013 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3015 return MMSYSERR_INVALHANDLE
;
3016 return midMessage(lpDesc
->wDevID
, MIDM_UNPREPARE
, lpDesc
->dwInstance
,
3017 (DWORD
)lpMidiInHdr
, (DWORD
)uSize
);
3020 /**************************************************************************
3021 * midiInAddBuffer [WINMM.57]
3023 UINT WINAPI
midiInAddBuffer(HMIDIIN hMidiIn
,
3024 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
3026 return midiInAddBuffer16(hMidiIn
, (MIDIHDR16
*)lpMidiInHdr
, uSize
);
3029 /**************************************************************************
3030 * midiInAddBuffer [MMSYSTEM.308]
3032 UINT16 WINAPI
midiInAddBuffer16(HMIDIIN16 hMidiIn
,
3033 MIDIHDR16
* lpMidiInHdr
, UINT16 uSize
)
3035 TRACE("midiInAddBuffer\n");
3039 /**************************************************************************
3040 * midiInStart [WINMM.69]
3042 UINT WINAPI
midiInStart(HMIDIIN hMidiIn
)
3044 return midiInStart16(hMidiIn
);
3047 /**************************************************************************
3048 * midiInStart [MMSYSTEM.309]
3050 UINT16 WINAPI
midiInStart16(HMIDIIN16 hMidiIn
)
3052 LPMIDIOPENDESC lpDesc
;
3054 TRACE("(%04X)\n", hMidiIn
);
3055 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3057 return MMSYSERR_INVALHANDLE
;
3058 return midMessage(lpDesc
->wDevID
, MIDM_START
, lpDesc
->dwInstance
, 0L, 0L);
3061 /**************************************************************************
3062 * midiInStop [WINMM.70]
3064 UINT WINAPI
midiInStop(HMIDIIN hMidiIn
)
3066 return midiInStop16(hMidiIn
);
3069 /**************************************************************************
3070 * midiInStop [MMSYSTEM.310]
3072 UINT16 WINAPI
midiInStop16(HMIDIIN16 hMidiIn
)
3074 LPMIDIOPENDESC lpDesc
;
3076 TRACE("(%04X)\n", hMidiIn
);
3077 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3079 return MMSYSERR_INVALHANDLE
;
3080 return midMessage(lpDesc
->wDevID
, MIDM_STOP
, lpDesc
->dwInstance
, 0L, 0L);
3083 /**************************************************************************
3084 * midiInReset [WINMM.68]
3086 UINT WINAPI
midiInReset(HMIDIIN hMidiIn
)
3088 return midiInReset16(hMidiIn
);
3091 /**************************************************************************
3092 * midiInReset [MMSYSTEM.311]
3094 UINT16 WINAPI
midiInReset16(HMIDIIN16 hMidiIn
)
3096 LPMIDIOPENDESC lpDesc
;
3098 TRACE("(%04X)\n", hMidiIn
);
3099 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3101 return MMSYSERR_INVALHANDLE
;
3102 return midMessage(lpDesc
->wDevID
, MIDM_RESET
, lpDesc
->dwInstance
, 0L, 0L);
3105 /**************************************************************************
3106 * midiInGetID [WINMM.63]
3108 UINT WINAPI
midiInGetID(HMIDIIN hMidiIn
, UINT
* lpuDeviceID
)
3110 LPMIDIOPENDESC lpDesc
;
3112 TRACE("(%04X, %p)\n", hMidiIn
, lpuDeviceID
);
3113 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3115 return MMSYSERR_INVALHANDLE
;
3116 if (lpuDeviceID
== NULL
)
3117 return MMSYSERR_INVALPARAM
;
3118 *lpuDeviceID
= lpDesc
->wDevID
;
3120 return MMSYSERR_NOERROR
;
3123 /**************************************************************************
3124 * midiInGetID [MMSYSTEM.312]
3126 UINT16 WINAPI
midiInGetID16(HMIDIIN16 hMidiIn
, UINT16
* lpuDeviceID
)
3128 LPMIDIOPENDESC lpDesc
;
3130 TRACE("(%04X, %p)\n", hMidiIn
, lpuDeviceID
);
3131 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3133 return MMSYSERR_INVALHANDLE
;
3134 if (lpuDeviceID
== NULL
)
3135 return MMSYSERR_INVALPARAM
;
3136 *lpuDeviceID
= lpDesc
->wDevID
;
3138 return MMSYSERR_NOERROR
;
3141 /**************************************************************************
3142 * midiInMessage [WINMM.65]
3144 DWORD WINAPI
midiInMessage(HMIDIIN hMidiIn
, UINT uMessage
,
3145 DWORD dwParam1
, DWORD dwParam2
)
3147 LPMIDIOPENDESC lpDesc
;
3149 TRACE("(%04X, %04X, %08lX, %08lX)\n",
3150 hMidiIn
, uMessage
, dwParam1
, dwParam2
);
3151 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3153 return MMSYSERR_INVALHANDLE
;
3157 FIXME("can't handle MIDM_OPEN!\n");
3159 case MIDM_GETDEVCAPS
:
3160 return midiInGetDevCapsA(hMidiIn
, (LPMIDIINCAPSA
)dwParam1
, dwParam2
);
3161 case MIDM_GETNUMDEVS
:
3166 /* no argument conversion needed */
3169 return midiInPrepareHeader(hMidiIn
, (LPMIDIHDR
)dwParam1
, dwParam2
);
3170 case MIDM_UNPREPARE
:
3171 return midiInUnprepareHeader(hMidiIn
, (LPMIDIHDR
)dwParam1
, dwParam2
);
3172 case MIDM_ADDBUFFER
:
3173 return midiInAddBuffer(hMidiIn
, (LPMIDIHDR
)dwParam1
, dwParam2
);
3175 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
3176 hMidiIn
, uMessage
, dwParam1
, dwParam2
);
3179 return midMessage(0, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
3182 /**************************************************************************
3183 * midiInMessage [MMSYSTEM.313]
3185 DWORD WINAPI
midiInMessage16(HMIDIIN16 hMidiIn
, UINT16 uMessage
,
3186 DWORD dwParam1
, DWORD dwParam2
)
3188 LPMIDIOPENDESC lpDesc
;
3190 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiIn
, uMessage
, dwParam1
, dwParam2
);
3192 lpDesc
= (LPMIDIOPENDESC
) USER_HEAP_LIN_ADDR(hMidiIn
);
3193 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
3196 WARN("can't handle MIDM_OPEN!\n");
3198 case MIDM_GETDEVCAPS
:
3199 return midiInGetDevCaps16(hMidiIn
, (LPMIDIINCAPS16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
3200 case MIDM_GETNUMDEVS
:
3205 /* no argument conversion needed */
3208 return midiInPrepareHeader16(hMidiIn
, (LPMIDIHDR16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
3209 case MIDM_UNPREPARE
:
3210 return midiInUnprepareHeader16(hMidiIn
, (LPMIDIHDR16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
3211 case MIDM_ADDBUFFER
:
3212 return midiInAddBuffer16(hMidiIn
, (LPMIDIHDR16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
3214 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
3215 hMidiIn
, uMessage
, dwParam1
, dwParam2
);
3218 return midMessage(0, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
3221 typedef struct WINE_MIDIStream
{
3232 LPMIDIHDR lpMidiHdr
;
3235 #define WINE_MSM_HEADER (WM_USER+0)
3236 #define WINE_MSM_STOP (WM_USER+1)
3238 /**************************************************************************
3239 * MMSYSTEM_GetMidiStream [internal]
3241 static BOOL
MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm
, WINE_MIDIStream
** lpMidiStrm
, MIDIOPENDESC
** lplpDesc
)
3243 MIDIOPENDESC
* lpDesc
= (LPMIDIOPENDESC
)USER_HEAP_LIN_ADDR(hMidiStrm
);
3248 if (lpDesc
== NULL
) {
3252 *lpMidiStrm
= (WINE_MIDIStream
*)lpDesc
->rgIds
.dwStreamID
;
3254 return *lpMidiStrm
!= NULL
;
3257 /**************************************************************************
3258 * MMSYSTEM_MidiStream_Convert [internal]
3260 static DWORD
MMSYSTEM_MidiStream_Convert(WINE_MIDIStream
* lpMidiStrm
, DWORD pulse
)
3264 if (lpMidiStrm
->dwTimeDiv
== 0) {
3265 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
3266 } else if (lpMidiStrm
->dwTimeDiv
> 0x8000) { /* SMPTE, unchecked FIXME? */
3267 int nf
= -(char)HIBYTE(lpMidiStrm
->dwTimeDiv
); /* number of frames */
3268 int nsf
= LOBYTE(lpMidiStrm
->dwTimeDiv
); /* number of sub-frames */
3269 ret
= (pulse
* 1000) / (nf
* nsf
);
3271 ret
= (DWORD
)((double)pulse
* ((double)lpMidiStrm
->dwTempo
/ 1000) /
3272 (double)lpMidiStrm
->dwTimeDiv
);
3278 /**************************************************************************
3279 * MMSYSTEM_MidiStream_MessageHandler [internal]
3281 static BOOL
MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream
* lpMidiStrm
, LPMIDIOPENDESC lpDesc
, LPMSG msg
)
3283 LPMIDIHDR lpMidiHdr
;
3287 switch (msg
->message
) {
3289 SetEvent(lpMidiStrm
->hEvent
);
3293 /* this is not quite what MS doc says... */
3294 midiOutReset(lpMidiStrm
->hDevice
);
3295 /* empty list of already submitted buffers */
3296 for (lpMidiHdr
= lpMidiStrm
->lpMidiHdr
; lpMidiHdr
; lpMidiHdr
= (LPMIDIHDR
)lpMidiHdr
->lpNext
) {
3297 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
3298 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
3300 DriverCallback16(lpDesc
->dwCallback
, lpMidiStrm
->wFlags
, lpMidiStrm
->hDevice
,
3301 MM_MOM_DONE
, lpDesc
->dwInstance
, lpMidiHdr
->reserved
, 0L);
3303 lpMidiStrm
->lpMidiHdr
= 0;
3304 SetEvent(lpMidiStrm
->hEvent
);
3306 case WINE_MSM_HEADER
:
3307 /* sets initial tick count for first MIDIHDR */
3308 if (!lpMidiStrm
->dwStartTicks
)
3309 lpMidiStrm
->dwStartTicks
= GetTickCount();
3311 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
3312 * by native mcimidi, it doesn't look like a correct one".
3313 * this trick allows to throw it away... but I don't like it.
3314 * It looks like part of the file I'm trying to play and definitively looks
3315 * like raw midi content
3316 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
3317 * synchronization issue where native mcimidi is still processing raw MIDI
3318 * content before generating MIDIEVENTs ?
3320 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
3321 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
3322 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
3323 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
3324 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
3325 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
3326 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
3327 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
3328 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
3329 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
3330 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
3331 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
3332 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
3333 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
3334 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
3335 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
3336 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
3338 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
3339 lpData
= ((DWORD
)lpMidiHdr
== lpMidiHdr
->reserved
) ?
3340 (LPBYTE
)lpMidiHdr
->lpData
: (LPBYTE
)PTR_SEG_TO_LIN(lpMidiHdr
->lpData
);
3341 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
3342 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular", lpMidiHdr
,
3343 lpMidiHdr
->reserved
, lpMidiHdr
->dwBufferLength
, lpMidiHdr
->dwBytesRecorded
,
3344 lpMidiHdr
->dwFlags
, msg
->wParam
);
3346 /* dumps content of lpMidiHdr->lpData
3347 * FIXME: there should be a debug routine somewhere that already does this
3348 * I hate spreading this type of shit all around the code
3350 for (dwToGo
= 0; dwToGo
< lpMidiHdr
->dwBufferLength
; dwToGo
+= 16) {
3354 for (i
= 0; i
< MIN(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++)
3355 printf("%02x ", lpData
[dwToGo
+ i
]);
3358 for (i
= 0; i
< MIN(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++) {
3359 ch
= lpData
[dwToGo
+ i
];
3360 printf("%c", (ch
>= 0x20 && ch
<= 0x7F) ? ch
: '.');
3365 if (((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0 &&
3366 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0xFFFFFFFF &&
3367 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= (DWORD
)lpMidiStrm
) {
3368 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
3369 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular",
3370 ((LPMIDIEVENT
)lpData
)->dwStreamID
);
3371 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
3372 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
3374 DriverCallback16(lpDesc
->dwCallback
, lpMidiStrm
->wFlags
, lpMidiStrm
->hDevice
,
3375 MM_MOM_DONE
, lpDesc
->dwInstance
, lpMidiHdr
->reserved
, 0L);
3379 for (lpmh
= &lpMidiStrm
->lpMidiHdr
; *lpmh
; lpmh
= (LPMIDIHDR
*)&((*lpmh
)->lpNext
));
3381 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
3382 lpMidiHdr
->lpNext
= 0;
3383 lpMidiHdr
->dwFlags
|= MHDR_INQUEUE
;
3384 lpMidiHdr
->dwFlags
&= MHDR_DONE
;
3385 lpMidiHdr
->dwOffset
= 0;
3389 FIXME("Unknown message %d\n", msg
->message
);
3395 /**************************************************************************
3396 * MMSYSTEM_MidiStream_Player [internal]
3398 static DWORD CALLBACK
MMSYSTEM_MidiStream_Player(LPVOID pmt
)
3400 WINE_MIDIStream
* lpMidiStrm
= pmt
;
3401 MIDIOPENDESC
* lpDesc
= USER_HEAP_LIN_ADDR(lpMidiStrm
->hDevice
);
3405 LPMIDIHDR lpMidiHdr
;
3409 TRACE("(%p)!\n", lpMidiStrm
);
3411 /* force thread's queue creation */
3412 /* Used to be InitThreadInput16(0, 5); */
3413 /* but following works also with hack in midiStreamOpen */
3414 Callout
.PeekMessageA(&msg
, 0, 0, 0, 0);
3416 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
3417 SetEvent(lpMidiStrm
->hEvent
);
3418 TRACE("Ready to go 1\n");
3419 /* thread is started in paused mode */
3420 SuspendThread(lpMidiStrm
->hThread
);
3421 TRACE("Ready to go 2\n");
3423 lpMidiStrm
->dwStartTicks
= 0;
3424 lpMidiStrm
->dwPulses
= 0;
3426 lpMidiStrm
->lpMidiHdr
= 0;
3429 lpMidiHdr
= lpMidiStrm
->lpMidiHdr
;
3431 /* for first message, block until one arrives, then process all that are available */
3432 Callout
.GetMessageA(&msg
, 0, 0, 0);
3434 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpDesc
, &msg
))
3436 } while (Callout
.PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
));
3442 * midiOutPrepareHeader(), in Wine, sets the 'reserved' field of MIDIHDR to the
3443 * 16 or 32 bit address of lpMidiHdr (depending if called from 16 to 32 bit code)
3446 lpData
= ((DWORD
)lpMidiHdr
== lpMidiHdr
->reserved
) ?
3447 (LPBYTE
)lpMidiHdr
->lpData
: (LPBYTE
)PTR_SEG_TO_LIN(lpMidiHdr
->lpData
);
3449 me
= (LPMIDIEVENT
)(lpData
+ lpMidiHdr
->dwOffset
);
3451 /* do we have to wait ? */
3452 if (me
->dwDeltaTime
) {
3453 lpMidiStrm
->dwPositionMS
+= MMSYSTEM_MidiStream_Convert(lpMidiStrm
, me
->dwDeltaTime
);
3454 lpMidiStrm
->dwPulses
+= me
->dwDeltaTime
;
3456 dwToGo
= lpMidiStrm
->dwStartTicks
+ lpMidiStrm
->dwPositionMS
;
3458 TRACE("%ld/%ld/%ld\n", dwToGo
, GetTickCount(), me
->dwDeltaTime
);
3459 while ((dwCurrTC
= GetTickCount()) < dwToGo
) {
3460 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, dwToGo
- dwCurrTC
, QS_ALLINPUT
) == WAIT_OBJECT_0
) {
3461 /* got a message, handle it */
3462 while (Callout
.PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) {
3463 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpDesc
, &msg
))
3468 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
3473 switch (MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
)) {
3475 FIXME("NIY: MEVT_COMMENT\n");
3476 /* do nothing, skip bytes */
3479 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
3484 midiOutShortMsg(lpMidiStrm
->hDevice
, MEVT_EVENTPARM(me
->dwEvent
));
3487 lpMidiStrm
->dwTempo
= MEVT_EVENTPARM(me
->dwEvent
);
3492 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
));
3495 if (me
->dwEvent
& MEVT_F_CALLBACK
) {
3496 DriverCallback16(lpDesc
->dwCallback
, lpMidiStrm
->wFlags
, lpMidiStrm
->hDevice
,
3497 MM_MOM_POSITIONCB
, lpDesc
->dwInstance
, (LPARAM
)lpMidiHdr
, 0L);
3499 lpMidiHdr
->dwOffset
+= sizeof(MIDIEVENT
);
3500 if (me
->dwEvent
& MEVT_F_LONG
)
3501 lpMidiHdr
->dwOffset
+= (MEVT_EVENTPARM(me
->dwEvent
) + 3) & ~3;
3502 if (lpMidiHdr
->dwOffset
>= lpMidiHdr
->dwBufferLength
) {
3503 /* done with this header */
3504 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
3505 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
3507 lpMidiStrm
->lpMidiHdr
= (LPMIDIHDR
)lpMidiHdr
->lpNext
;
3508 DriverCallback16(lpDesc
->dwCallback
, lpMidiStrm
->wFlags
, lpMidiStrm
->hDevice
,
3509 MM_MOM_DONE
, lpDesc
->dwInstance
, lpMidiHdr
->reserved
, 0L);
3514 TRACE("End of thread\n");
3516 return 0; /* for removing the warning, never executed */
3519 /**************************************************************************
3520 * MMSYSTEM_MidiStream_PostMessage [internal]
3522 static BOOL
MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream
* lpMidiStrm
, WORD msg
, DWORD pmt1
, DWORD pmt2
)
3524 if (Callout
.PostThreadMessageA(lpMidiStrm
->dwThreadID
, msg
, pmt1
, pmt2
)) {
3528 /* FIXME: should use the new syslevel APIs */
3529 if ((bHasWin16Lock
= _ConfirmWin16Lock()) != 0) {
3530 ReleaseThunkLock(&count
);
3532 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
3533 if (bHasWin16Lock
) {
3534 RestoreThunkLock(count
);
3537 WARN("bad PostThreadMessageA\n");
3543 /**************************************************************************
3544 * midiStreamClose [WINMM.90]
3546 MMRESULT WINAPI
midiStreamClose(HMIDISTRM hMidiStrm
)
3548 WINE_MIDIStream
* lpMidiStrm
;
3550 TRACE("(%08x)!\n", hMidiStrm
);
3552 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
))
3553 return MMSYSERR_INVALHANDLE
;
3555 midiStreamStop(hMidiStrm
);
3556 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WM_QUIT
, 0, 0);
3557 HeapFree(GetProcessHeap(), 0, lpMidiStrm
);
3558 CloseHandle(lpMidiStrm
->hEvent
);
3560 return midiOutClose(hMidiStrm
);
3563 /**************************************************************************
3564 * MMSYSTEM_MidiStream_Open [internal]
3566 static MMRESULT WINAPI
MMSYSTEM_MidiStream_Open(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
,
3567 DWORD cMidi
, DWORD dwCallback
,
3568 DWORD dwInstance
, DWORD fdwOpen
)
3570 WINE_MIDIStream
* lpMidiStrm
;
3572 MIDIOPENSTRMID mosm
;
3573 MIDIOPENDESC
* lpDesc
;
3574 HMIDIOUT16 hMidiOut16
;
3576 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
3577 lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
, dwInstance
, fdwOpen
);
3579 if (cMidi
!= 1 || lphMidiStrm
== NULL
|| lpuDeviceID
== NULL
)
3580 return MMSYSERR_INVALPARAM
;
3582 if (*lpuDeviceID
== (UINT16
)MIDI_MAPPER
) {
3583 FIXME("MIDI_MAPPER mode requested ! => forcing devID to 0\n");
3587 lpMidiStrm
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream
));
3589 return MMSYSERR_NOMEM
;
3591 lpMidiStrm
->dwTempo
= 500000;
3592 lpMidiStrm
->dwTimeDiv
= 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
3593 lpMidiStrm
->dwPositionMS
= 0;
3595 mosm
.dwStreamID
= (DWORD
)lpMidiStrm
;
3596 /* FIXME: the correct value is not allocated yet for MAPPER */
3597 mosm
.wDeviceID
= *lpuDeviceID
;
3598 lpDesc
= MIDI_OutAlloc(&hMidiOut16
, dwCallback
, dwInstance
, 1, &mosm
);
3599 lpMidiStrm
->hDevice
= hMidiOut16
;
3601 *lphMidiStrm
= hMidiOut16
;
3603 lpDesc
->wDevID
= *lpuDeviceID
;
3604 ret
= modMessage(lpDesc
->wDevID
, MODM_OPEN
,
3605 lpDesc
->dwInstance
, (DWORD
)lpDesc
, fdwOpen
);
3606 lpMidiStrm
->hEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
3607 lpMidiStrm
->wFlags
= HIWORD(fdwOpen
);
3609 lpMidiStrm
->hThread
= CreateThread(NULL
, 0, MMSYSTEM_MidiStream_Player
,
3610 lpMidiStrm
, 0, &(lpMidiStrm
->dwThreadID
));
3612 if (!lpMidiStrm
->hThread
) {
3613 midiStreamClose((HMIDISTRM
)hMidiOut16
);
3614 return MMSYSERR_NOMEM
;
3617 /* wait for thread to have started, and for it's queue to be created */
3622 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
3623 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
3624 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
3626 if ((bHasWin16Lock
= _ConfirmWin16Lock()) != 0) {
3627 ReleaseThunkLock(&count
);
3629 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
3630 if (bHasWin16Lock
) {
3631 RestoreThunkLock(count
);
3635 TRACE("=> (%u/%d) hMidi=0x%04x ret=%d lpMidiStrm=%p\n", *lpuDeviceID
, lpDesc
->wDevID
, *lphMidiStrm
, ret
, lpMidiStrm
);
3639 /**************************************************************************
3640 * midiStreamOpen [WINMM.91]
3642 MMRESULT WINAPI
midiStreamOpen(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
,
3643 DWORD cMidi
, DWORD dwCallback
,
3644 DWORD dwInstance
, DWORD fdwOpen
)
3646 return MMSYSTEM_MidiStream_Open(lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
, dwInstance
, CALLBACK32CONV(fdwOpen
));
3649 /**************************************************************************
3650 * midiStreamOut [WINMM.92]
3652 MMRESULT WINAPI
midiStreamOut(HMIDISTRM hMidiStrm
, LPMIDIHDR lpMidiHdr
, UINT cbMidiHdr
)
3654 WINE_MIDIStream
* lpMidiStrm
;
3655 DWORD ret
= MMSYSERR_NOERROR
;
3657 TRACE("(%08x, %p, %u)!\n", hMidiStrm
, lpMidiHdr
, cbMidiHdr
);
3659 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
3660 ret
= MMSYSERR_INVALHANDLE
;
3662 if (!Callout
.PostThreadMessageA(lpMidiStrm
->dwThreadID
, WINE_MSM_HEADER
, cbMidiHdr
, (DWORD
)lpMidiHdr
)) {
3663 WARN("bad PostThreadMessageA\n");
3664 ret
= MMSYSERR_ERROR
;
3670 /**************************************************************************
3671 * midiStreamPause [WINMM.93]
3673 MMRESULT WINAPI
midiStreamPause(HMIDISTRM hMidiStrm
)
3675 WINE_MIDIStream
* lpMidiStrm
;
3676 DWORD ret
= MMSYSERR_NOERROR
;
3678 TRACE("(%08x)!\n", hMidiStrm
);
3680 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
3681 ret
= MMSYSERR_INVALHANDLE
;
3683 if (SuspendThread(lpMidiStrm
->hThread
) == 0xFFFFFFFF) {
3684 WARN("bad Suspend (%ld)\n", GetLastError());
3685 ret
= MMSYSERR_ERROR
;
3691 /**************************************************************************
3692 * midiStreamPosition [WINMM.94]
3694 MMRESULT WINAPI
midiStreamPosition(HMIDISTRM hMidiStrm
, LPMMTIME lpMMT
, UINT cbmmt
)
3696 WINE_MIDIStream
* lpMidiStrm
;
3697 DWORD ret
= MMSYSERR_NOERROR
;
3699 TRACE("(%08x, %p, %u)!\n", hMidiStrm
, lpMMT
, cbmmt
);
3701 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
3702 ret
= MMSYSERR_INVALHANDLE
;
3703 } else if (lpMMT
== NULL
|| cbmmt
!= sizeof(MMTIME
)) {
3704 ret
= MMSYSERR_INVALPARAM
;
3706 switch (lpMMT
->wType
) {
3708 lpMMT
->u
.ms
= lpMidiStrm
->dwPositionMS
;
3709 TRACE("=> %ld ms\n", lpMMT
->u
.ms
);
3712 lpMMT
->u
.ticks
= lpMidiStrm
->dwPulses
;
3713 TRACE("=> %ld ticks\n", lpMMT
->u
.ticks
);
3716 WARN("Unsupported time type %d\n", lpMMT
->wType
);
3717 lpMMT
->wType
= TIME_MS
;
3718 ret
= MMSYSERR_INVALPARAM
;
3725 /**************************************************************************
3726 * midiStreamProperty [WINMM.95]
3728 MMRESULT WINAPI
midiStreamProperty(HMIDISTRM hMidiStrm
, LPBYTE lpPropData
, DWORD dwProperty
)
3730 WINE_MIDIStream
* lpMidiStrm
;
3731 MMRESULT ret
= MMSYSERR_NOERROR
;
3733 TRACE("(%08x, %p, %lx)\n", hMidiStrm
, lpPropData
, dwProperty
);
3735 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
3736 ret
= MMSYSERR_INVALHANDLE
;
3737 } else if ((dwProperty
& (MIDIPROP_GET
|MIDIPROP_SET
)) == 0) {
3738 ret
= MMSYSERR_INVALPARAM
;
3739 } else if (dwProperty
& MIDIPROP_TEMPO
) {
3740 MIDIPROPTEMPO
* mpt
= (MIDIPROPTEMPO
*)lpPropData
;
3742 if (sizeof(MIDIPROPTEMPO
) != mpt
->cbStruct
) {
3743 ret
= MMSYSERR_INVALPARAM
;
3744 } else if (dwProperty
& MIDIPROP_SET
) {
3745 lpMidiStrm
->dwTempo
= mpt
->dwTempo
;
3746 TRACE("Setting tempo to %ld\n", mpt
->dwTempo
);
3747 } else if (dwProperty
& MIDIPROP_GET
) {
3748 mpt
->dwTempo
= lpMidiStrm
->dwTempo
;
3749 TRACE("Getting tempo <= %ld\n", mpt
->dwTempo
);
3751 } else if (dwProperty
& MIDIPROP_TIMEDIV
) {
3752 MIDIPROPTIMEDIV
* mptd
= (MIDIPROPTIMEDIV
*)lpPropData
;
3754 if (sizeof(MIDIPROPTIMEDIV
) != mptd
->cbStruct
) {
3755 ret
= MMSYSERR_INVALPARAM
;
3756 } else if (dwProperty
& MIDIPROP_SET
) {
3757 lpMidiStrm
->dwTimeDiv
= mptd
->dwTimeDiv
;
3758 TRACE("Setting time div to %ld\n", mptd
->dwTimeDiv
);
3759 } else if (dwProperty
& MIDIPROP_GET
) {
3760 mptd
->dwTimeDiv
= lpMidiStrm
->dwTimeDiv
;
3761 TRACE("Getting time div <= %ld\n", mptd
->dwTimeDiv
);
3764 ret
= MMSYSERR_INVALPARAM
;
3770 /**************************************************************************
3771 * midiStreamRestart [WINMM.96]
3773 MMRESULT WINAPI
midiStreamRestart(HMIDISTRM hMidiStrm
)
3775 WINE_MIDIStream
* lpMidiStrm
;
3776 MMRESULT ret
= MMSYSERR_NOERROR
;
3778 TRACE("(%08x)!\n", hMidiStrm
);
3780 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
3781 ret
= MMSYSERR_INVALHANDLE
;
3783 if (ResumeThread(lpMidiStrm
->hThread
) == 0xFFFFFFFF) {
3784 WARN("bad Resume (%ld)\n", GetLastError());
3785 ret
= MMSYSERR_ERROR
;
3787 lpMidiStrm
->dwStartTicks
= GetTickCount() - lpMidiStrm
->dwPositionMS
;
3793 /**************************************************************************
3794 * midiStreamStop [WINMM.97]
3796 MMRESULT WINAPI
midiStreamStop(HMIDISTRM hMidiStrm
)
3798 WINE_MIDIStream
* lpMidiStrm
;
3799 MMRESULT ret
= MMSYSERR_NOERROR
;
3801 TRACE("(%08x)!\n", hMidiStrm
);
3803 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
3804 ret
= MMSYSERR_INVALHANDLE
;
3806 /* in case stream has been paused... FIXME is the current state correct ? */
3807 midiStreamRestart(hMidiStrm
);
3808 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WINE_MSM_STOP
, 0, 0);
3813 /**************************************************************************
3814 * midiStreamClose [MMSYSTEM.252]
3816 MMRESULT16 WINAPI
midiStreamClose16(HMIDISTRM16 hMidiStrm
)
3818 return midiStreamClose(hMidiStrm
);
3821 /**************************************************************************
3822 * midiStreamOpen [MMSYSTEM.251]
3824 MMRESULT16 WINAPI
midiStreamOpen16(HMIDISTRM16
* phMidiStrm
, LPUINT16 devid
,
3825 DWORD cMidi
, DWORD dwCallback
,
3826 DWORD dwInstance
, DWORD fdwOpen
)
3828 HMIDISTRM hMidiStrm32
;
3832 if (!phMidiStrm
|| !devid
)
3833 return MMSYSERR_INVALPARAM
;
3835 ret
= MMSYSTEM_MidiStream_Open(&hMidiStrm32
, &devid32
, cMidi
, dwCallback
, dwInstance
, fdwOpen
);
3836 *phMidiStrm
= hMidiStrm32
;
3841 /**************************************************************************
3842 * midiStreamOut [MMSYSTEM.254]
3844 MMRESULT16 WINAPI
midiStreamOut16(HMIDISTRM16 hMidiStrm
, LPMIDIHDR16 lpMidiHdr
, UINT16 cbMidiHdr
)
3846 return midiStreamOut(hMidiStrm
, (LPMIDIHDR
)lpMidiHdr
, cbMidiHdr
);
3849 /**************************************************************************
3850 * midiStreamPause [MMSYSTEM.255]
3852 MMRESULT16 WINAPI
midiStreamPause16(HMIDISTRM16 hMidiStrm
)
3854 return midiStreamPause(hMidiStrm
);
3857 /**************************************************************************
3858 * midiStreamPosition [MMSYSTEM.253]
3860 MMRESULT16 WINAPI
midiStreamPosition16(HMIDISTRM16 hMidiStrm
, LPMMTIME16 lpmmt16
, UINT16 cbmmt
)
3866 return MMSYSERR_INVALPARAM
;
3867 MMSYSTEM_MMTIME16to32(&mmt32
, lpmmt16
);
3868 ret
= midiStreamPosition(hMidiStrm
, &mmt32
, sizeof(MMTIME
));
3869 MMSYSTEM_MMTIME32to16(lpmmt16
, &mmt32
);
3873 /**************************************************************************
3874 * midiStreamProperty [MMSYSTEM.250]
3876 MMRESULT16 WINAPI
midiStreamProperty16(HMIDISTRM16 hMidiStrm
, LPBYTE lpPropData
, DWORD dwProperty
)
3878 return midiStreamProperty(hMidiStrm
, lpPropData
, dwProperty
);
3881 /**************************************************************************
3882 * midiStreamRestart [MMSYSTEM.256]
3884 MMRESULT16 WINAPI
midiStreamRestart16(HMIDISTRM16 hMidiStrm
)
3886 return midiStreamRestart(hMidiStrm
);
3889 /**************************************************************************
3890 * midiStreamStop [MMSYSTEM.257]
3892 MMRESULT16 WINAPI
midiStreamStop16(HMIDISTRM16 hMidiStrm
)
3894 return midiStreamStop(hMidiStrm
);
3897 /**************************************************************************
3898 * waveOutGetNumDevs [MMSYSTEM.401]
3900 UINT WINAPI
waveOutGetNumDevs(void)
3902 return waveOutGetNumDevs16();
3905 /**************************************************************************
3906 * waveOutGetNumDevs [WINMM.167]
3908 UINT16 WINAPI
waveOutGetNumDevs16(void)
3911 TRACE("waveOutGetNumDevs\n");
3912 count
+= wodMessage(0, WODM_GETNUMDEVS
, 0L, 0L, 0L);
3913 TRACE("waveOutGetNumDevs return %u \n", count
);
3917 /**************************************************************************
3918 * waveOutGetDevCaps [MMSYSTEM.402]
3920 UINT16 WINAPI
waveOutGetDevCaps16(UINT16 uDeviceID
, LPWAVEOUTCAPS16 lpCaps
,
3923 TRACE("waveOutGetDevCaps\n");
3925 /* FIXME: do we have a wave mapper ? */
3926 if (uDeviceID
== (UINT16
)WAVE_MAPPER
)
3928 /* return MMSYSERR_BADDEVICEID; */
3930 if (uDeviceID
>= waveOutGetNumDevs16()) return MMSYSERR_BADDEVICEID
;
3932 return wodMessage(uDeviceID
, WODM_GETDEVCAPS
, 0L, (DWORD
)lpCaps
, uSize
);
3935 /**************************************************************************
3936 * waveOutGetDevCapsA [WINMM.162]
3938 UINT WINAPI
waveOutGetDevCapsA(UINT uDeviceID
, LPWAVEOUTCAPSA lpCaps
,
3941 WAVEOUTCAPS16 woc16
;
3942 UINT16 ret
= waveOutGetDevCaps16(uDeviceID
, &woc16
, sizeof(woc16
));
3944 lpCaps
->wMid
= woc16
.wMid
;
3945 lpCaps
->wPid
= woc16
.wPid
;
3946 lpCaps
->vDriverVersion
= woc16
.vDriverVersion
;
3947 strcpy(lpCaps
->szPname
, woc16
.szPname
);
3948 lpCaps
->dwFormats
= woc16
.dwFormats
;
3949 lpCaps
->wChannels
= woc16
.wChannels
;
3950 lpCaps
->dwSupport
= woc16
.dwSupport
;
3954 /**************************************************************************
3955 * waveOutGetDevCapsW [WINMM.163]
3957 UINT WINAPI
waveOutGetDevCapsW(UINT uDeviceID
, LPWAVEOUTCAPSW lpCaps
,
3960 WAVEOUTCAPS16 woc16
;
3961 UINT ret
= waveOutGetDevCaps16(uDeviceID
, &woc16
, sizeof(woc16
));
3963 lpCaps
->wMid
= woc16
.wMid
;
3964 lpCaps
->wPid
= woc16
.wPid
;
3965 lpCaps
->vDriverVersion
= woc16
.vDriverVersion
;
3966 lstrcpyAtoW(lpCaps
->szPname
, woc16
.szPname
);
3967 lpCaps
->dwFormats
= woc16
.dwFormats
;
3968 lpCaps
->wChannels
= woc16
.wChannels
;
3969 lpCaps
->dwSupport
= woc16
.dwSupport
;
3973 /**************************************************************************
3974 * waveOutGetErrorText [MMSYSTEM.403]
3976 UINT16 WINAPI
waveOutGetErrorText16(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
3978 TRACE("waveOutGetErrorText\n");
3979 return waveGetErrorText(uError
, lpText
, uSize
);
3982 /**************************************************************************
3983 * waveOutGetErrorTextA [WINMM.164]
3985 UINT WINAPI
waveOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
3987 return waveOutGetErrorText16(uError
, lpText
, uSize
);
3990 /**************************************************************************
3991 * waveOutGetErrorTextW [WINMM.165]
3993 UINT WINAPI
waveOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
3995 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
3996 UINT ret
= waveOutGetErrorTextA(uError
, xstr
, uSize
);
3998 lstrcpyAtoW(lpText
, xstr
);
3999 HeapFree(GetProcessHeap(), 0, xstr
);
4003 /**************************************************************************
4004 * waveGetErrorText [internal]
4006 static UINT16
waveGetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
4009 TRACE("(%04X, %p, %d);\n", uError
, lpText
, uSize
);
4011 if ((lpText
== NULL
) || (uSize
< 1)) return FALSE
;
4015 case MMSYSERR_NOERROR
:
4016 msgptr
= "The specified command was carried out.";
4018 case MMSYSERR_ERROR
:
4019 msgptr
= "Undefined external error.";
4021 case MMSYSERR_BADDEVICEID
:
4022 msgptr
= "A device ID has been used that is out of range for your system.";
4024 case MMSYSERR_NOTENABLED
:
4025 msgptr
= "The driver was not enabled.";
4027 case MMSYSERR_ALLOCATED
:
4028 msgptr
= "The specified device is already in use. Wait until it is free, and then try again.";
4030 case MMSYSERR_INVALHANDLE
:
4031 msgptr
= "The specified device handle is invalid.";
4033 case MMSYSERR_NODRIVER
:
4034 msgptr
= "There is no driver installed on your system !\n";
4036 case MMSYSERR_NOMEM
:
4037 msgptr
= "Not enough memory available for this task. Quit one or more applications to increase available memory, and then try again.";
4039 case MMSYSERR_NOTSUPPORTED
:
4040 msgptr
= "This function is not supported. Use the Capabilities function to determine which functions and messages the driver supports.";
4042 case MMSYSERR_BADERRNUM
:
4043 msgptr
= "An error number was specified that is not defined in the system.";
4045 case MMSYSERR_INVALFLAG
:
4046 msgptr
= "An invalid flag was passed to a system function.";
4048 case MMSYSERR_INVALPARAM
:
4049 msgptr
= "An invalid parameter was passed to a system function.";
4051 case WAVERR_BADFORMAT
:
4052 msgptr
= "The specified format is not supported or cannot be translated. Use the Capabilities function to determine the supported formats";
4054 case WAVERR_STILLPLAYING
:
4055 msgptr
= "Cannot perform this operation while media data is still playing. Reset the device, or wait until the data is finished playing.";
4057 case WAVERR_UNPREPARED
:
4058 msgptr
= "The wave header was not prepared. Use the Prepare function to prepare the header, and then try again.";
4061 msgptr
= "Cannot open the device without using the WAVE_ALLOWSYNC flag. Use the flag, and then try again.";
4064 msgptr
= "Unknown MMSYSTEM Error !\n";
4067 lstrcpynA(lpText
, msgptr
, uSize
);
4071 /**************************************************************************
4072 * waveOutOpen [WINMM.173]
4073 * All the args/structs have the same layout as the win16 equivalents
4075 UINT WINAPI
waveOutOpen(HWAVEOUT
* lphWaveOut
, UINT uDeviceID
,
4076 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
4077 DWORD dwInstance
, DWORD dwFlags
)
4080 UINT ret
= waveOutOpen16(&hwo16
, uDeviceID
, lpFormat
, dwCallback
, dwInstance
,
4081 CALLBACK32CONV(dwFlags
));
4083 if (lphWaveOut
) *lphWaveOut
= hwo16
;
4087 /**************************************************************************
4088 * waveOutOpen [MMSYSTEM.404]
4090 UINT16 WINAPI
waveOutOpen16(HWAVEOUT16
* lphWaveOut
, UINT16 uDeviceID
,
4091 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
4092 DWORD dwInstance
, DWORD dwFlags
)
4094 HWAVEOUT16 hWaveOut
;
4095 LPWAVEOPENDESC lpDesc
;
4096 DWORD dwRet
= MMSYSERR_NOERROR
;
4097 BOOL bMapperFlg
= FALSE
;
4099 TRACE("(%p, %d, %p, %08lX, %08lX, %08lX);\n",
4100 lphWaveOut
, uDeviceID
, lpFormat
, dwCallback
, dwInstance
, dwFlags
);
4101 if (dwFlags
& WAVE_FORMAT_QUERY
)
4102 TRACE("WAVE_FORMAT_QUERY requested !\n");
4103 if (uDeviceID
== (UINT16
)WAVE_MAPPER
) {
4104 TRACE("WAVE_MAPPER mode requested !\n");
4108 if (lpFormat
== NULL
) return WAVERR_BADFORMAT
;
4110 hWaveOut
= USER_HEAP_ALLOC(sizeof(WAVEOPENDESC
));
4111 if (hWaveOut
== 0) return MMSYSERR_NOMEM
;
4112 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4113 if (lpDesc
== NULL
) return MMSYSERR_NOMEM
;
4114 lpDesc
->hWave
= hWaveOut
;
4115 lpDesc
->lpFormat
= (LPWAVEFORMAT
)lpFormat
; /* should the struct be copied iso pointer? */
4116 lpDesc
->dwCallBack
= dwCallback
;
4117 lpDesc
->dwInstance
= dwInstance
;
4118 if (uDeviceID
>= MAXWAVEDRIVERS
)
4120 while (uDeviceID
< MAXWAVEDRIVERS
) {
4121 /* FIXME: dwUser parameter is wrong, it's not lpDesc->dwInstancen but
4122 * a pointer to a DWORD (see ms/ddkdoc/s2abc.htm)
4124 dwRet
= wodMessage(uDeviceID
, WODM_OPEN
,
4125 lpDesc
->dwInstance
, (DWORD
)lpDesc
, dwFlags
);
4126 if (dwRet
== MMSYSERR_NOERROR
) break;
4127 if (!bMapperFlg
) break;
4129 TRACE("WAVE_MAPPER mode ! try next driver...\n");
4131 lpDesc
->uDeviceID
= uDeviceID
; /* save physical Device ID */
4132 if (dwFlags
& WAVE_FORMAT_QUERY
) {
4133 TRACE("End of WAVE_FORMAT_QUERY !\n");
4134 USER_HEAP_FREE(hWaveOut
);
4137 else if (dwRet
!= MMSYSERR_NOERROR
)
4139 USER_HEAP_FREE(hWaveOut
);
4142 if (lphWaveOut
!= NULL
) *lphWaveOut
= hWaveOut
;
4143 TRACE("=> %ld\n", dwRet
);
4147 /**************************************************************************
4148 * waveOutClose [WINMM.161]
4150 UINT WINAPI
waveOutClose(HWAVEOUT hWaveOut
)
4152 return waveOutClose16(hWaveOut
);
4155 /**************************************************************************
4156 * waveOutClose [MMSYSTEM.405]
4158 UINT16 WINAPI
waveOutClose16(HWAVEOUT16 hWaveOut
)
4160 LPWAVEOPENDESC lpDesc
;
4163 TRACE("(%04X)\n", hWaveOut
);
4165 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4166 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4167 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4168 dwRet
= wodMessage(lpDesc
->uDeviceID
, WODM_CLOSE
, lpDesc
->dwInstance
, 0L, 0L);
4169 USER_HEAP_FREE(hWaveOut
);
4173 /**************************************************************************
4174 * waveOutPrepareHeader [WINMM.175]
4176 UINT WINAPI
waveOutPrepareHeader(HWAVEOUT hWaveOut
,
4177 WAVEHDR
* lpWaveOutHdr
, UINT uSize
)
4179 LPWAVEOPENDESC lpDesc
;
4181 TRACE("(%04X, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
4183 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4185 return MMSYSERR_INVALHANDLE
;
4186 lpWaveOutHdr
->reserved
= (DWORD
)lpWaveOutHdr
;
4187 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4188 return wodMessage(lpDesc
->uDeviceID
, WODM_PREPARE
, lpDesc
->dwInstance
,
4189 (DWORD
)lpWaveOutHdr
, uSize
);
4192 /**************************************************************************
4193 * waveOutPrepareHeader [MMSYSTEM.406]
4195 UINT16 WINAPI
waveOutPrepareHeader16(HWAVEOUT16 hWaveOut
,
4196 WAVEHDR
* /*SEGPTR*/ _lpWaveOutHdr
, UINT16 uSize
)
4198 LPWAVEOPENDESC lpDesc
;
4199 LPWAVEHDR lpWaveOutHdr
= (LPWAVEHDR
)PTR_SEG_TO_LIN(_lpWaveOutHdr
);
4202 TRACE("(%04X, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
4204 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4206 return MMSYSERR_INVALHANDLE
;
4207 lpWaveOutHdr
->reserved
= (DWORD
)_lpWaveOutHdr
;
4208 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4209 ret
= wodMessage(lpDesc
->uDeviceID
, WODM_PREPARE
, lpDesc
->dwInstance
,
4210 (DWORD
)lpWaveOutHdr
, uSize
);
4214 /**************************************************************************
4215 * waveOutUnprepareHeader [WINMM.181]
4217 UINT WINAPI
waveOutUnprepareHeader(HWAVEOUT hWaveOut
,
4218 WAVEHDR
* lpWaveOutHdr
, UINT uSize
)
4220 LPWAVEOPENDESC lpDesc
;
4222 TRACE("(%04X, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
4224 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4225 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4226 lpWaveOutHdr
->reserved
= (DWORD
)lpWaveOutHdr
;
4227 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4228 return wodMessage(lpDesc
->uDeviceID
, WODM_UNPREPARE
, lpDesc
->dwInstance
,
4229 (DWORD
)lpWaveOutHdr
, uSize
);
4232 /**************************************************************************
4233 * waveOutUnprepareHeader [MMSYSTEM.407]
4235 UINT16 WINAPI
waveOutUnprepareHeader16(HWAVEOUT16 hWaveOut
,
4236 WAVEHDR
* lpWaveOutHdr
, UINT16 uSize
)
4238 LPWAVEOPENDESC lpDesc
;
4241 TRACE("(%04X, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
4243 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4245 return MMSYSERR_INVALHANDLE
;
4246 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4247 ret
= wodMessage(lpDesc
->uDeviceID
, WODM_UNPREPARE
, lpDesc
->dwInstance
,
4248 (DWORD
)lpWaveOutHdr
, uSize
);
4252 /**************************************************************************
4253 * waveOutWrite [MMSYSTEM.408]
4255 UINT WINAPI
waveOutWrite(HWAVEOUT hWaveOut
, WAVEHDR
* lpWaveOutHdr
,
4258 LPWAVEOPENDESC lpDesc
;
4260 TRACE("(%04X, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
4262 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4264 return MMSYSERR_INVALHANDLE
;
4265 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4266 return wodMessage(lpDesc
->uDeviceID
, WODM_WRITE
, lpDesc
->dwInstance
,
4267 (DWORD
)lpWaveOutHdr
, uSize
);
4270 /**************************************************************************
4271 * waveOutWrite [MMSYSTEM.408]
4273 UINT16 WINAPI
waveOutWrite16(HWAVEOUT16 hWaveOut
, WAVEHDR
* lpWaveOutHdr
,
4276 LPWAVEOPENDESC lpDesc
;
4279 TRACE("(%04X, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
4281 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4283 return MMSYSERR_INVALHANDLE
;
4284 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4285 ret
= wodMessage(lpDesc
->uDeviceID
, WODM_WRITE
, lpDesc
->dwInstance
,
4286 (DWORD
)lpWaveOutHdr
, uSize
);
4290 /**************************************************************************
4291 * waveOutPause [WINMM.174]
4293 UINT WINAPI
waveOutPause(HWAVEOUT hWaveOut
)
4295 return waveOutPause16(hWaveOut
);
4298 /**************************************************************************
4299 * waveOutPause [MMSYSTEM.409]
4301 UINT16 WINAPI
waveOutPause16(HWAVEOUT16 hWaveOut
)
4303 LPWAVEOPENDESC lpDesc
;
4305 TRACE("(%04X)\n", hWaveOut
);
4307 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4308 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4309 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4310 return wodMessage(lpDesc
->uDeviceID
, WODM_PAUSE
, lpDesc
->dwInstance
, 0L, 0L);
4313 /**************************************************************************
4314 * waveOutRestart [WINMM.177]
4316 UINT WINAPI
waveOutRestart(HWAVEOUT hWaveOut
)
4318 return waveOutRestart16(hWaveOut
);
4321 /**************************************************************************
4322 * waveOutRestart [MMSYSTEM.410]
4324 UINT16 WINAPI
waveOutRestart16(HWAVEOUT16 hWaveOut
)
4326 LPWAVEOPENDESC lpDesc
;
4328 TRACE("(%04X)\n", hWaveOut
);
4330 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4331 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4332 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4333 return wodMessage(lpDesc
->uDeviceID
, WODM_RESTART
, lpDesc
->dwInstance
, 0L, 0L);
4336 /**************************************************************************
4337 * waveOutReset [WINMM.176]
4339 UINT WINAPI
waveOutReset(HWAVEOUT hWaveOut
)
4341 return waveOutReset16(hWaveOut
);
4344 /**************************************************************************
4345 * waveOutReset [MMSYSTEM.411]
4347 UINT16 WINAPI
waveOutReset16(HWAVEOUT16 hWaveOut
)
4349 LPWAVEOPENDESC lpDesc
;
4351 TRACE("(%04X)\n", hWaveOut
);
4353 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4354 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4355 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4356 return wodMessage(lpDesc
->uDeviceID
, WODM_RESET
, lpDesc
->dwInstance
, 0L, 0L);
4359 /**************************************************************************
4360 * waveOutGetPosition [WINMM.170]
4362 UINT WINAPI
waveOutGetPosition(HWAVEOUT hWaveOut
, LPMMTIME lpTime
,
4368 mmt16
.wType
= lpTime
->wType
;
4369 ret
= waveOutGetPosition16(hWaveOut
, &mmt16
, sizeof(mmt16
));
4370 MMSYSTEM_MMTIME16to32(lpTime
, &mmt16
);
4374 /**************************************************************************
4375 * waveOutGetPosition [MMSYSTEM.412]
4377 UINT16 WINAPI
waveOutGetPosition16(HWAVEOUT16 hWaveOut
, LPMMTIME16 lpTime
,
4380 LPWAVEOPENDESC lpDesc
;
4381 TRACE("(%04X, %p, %u);\n", hWaveOut
, lpTime
, uSize
);
4382 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4383 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4384 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */
4385 return wodMessage(lpDesc
->uDeviceID
, WODM_GETPOS
, lpDesc
->dwInstance
,
4386 (DWORD
)lpTime
, (DWORD
)uSize
);
4389 #define WAVEOUT_SHORTCUT_1(xx, XX, atype) \
4390 UINT WINAPI waveOut##xx(HWAVEOUT hWaveOut, atype x) \
4391 {return waveOut##xx##16(hWaveOut, x);} \
4392 UINT16 WINAPI waveOut##xx##16(HWAVEOUT16 hWaveOut, atype x) \
4394 LPWAVEOPENDESC lpDesc; \
4395 TRACE("(%04X, %08lx);\n", hWaveOut, (DWORD)x); \
4396 lpDesc = (LPWAVEOPENDESC)USER_HEAP_LIN_ADDR(hWaveOut); \
4397 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */ \
4398 return (lpDesc == NULL) ? MMSYSERR_INVALHANDLE : \
4399 wodMessage(lpDesc->uDeviceID, WODM_##XX, \
4400 lpDesc->dwInstance, (DWORD)x, 0L); \
4403 WAVEOUT_SHORTCUT_1(GetPitch
, GETPITCH
, LPDWORD
)
4404 WAVEOUT_SHORTCUT_1(SetPitch
, SETPITCH
, DWORD
)
4405 WAVEOUT_SHORTCUT_1(GetPlaybackRate
, GETPLAYBACKRATE
, LPDWORD
)
4406 WAVEOUT_SHORTCUT_1(SetPlaybackRate
, SETPLAYBACKRATE
, DWORD
)
4407 #undef WAVEOUT_SHORTCUT_1
4409 #define WAVEOUT_SHORTCUT_2(xx, XX, atype) \
4410 UINT WINAPI waveOut##xx(UINT devid, atype x) \
4411 {return waveOut##xx##16(devid, x);} \
4412 UINT16 WINAPI waveOut##xx##16(UINT16 devid, atype x) \
4414 TRACE("(%04X, %08lx);\n", devid, (DWORD)x); \
4415 /* FIXME: dwUser parameter is wrong (cf waveOutOpen) */ \
4416 return wodMessage(devid, WODM_##XX, 0, (DWORD)x, 0L); \
4419 WAVEOUT_SHORTCUT_2(GetVolume
, GETVOLUME
, LPDWORD
)
4420 WAVEOUT_SHORTCUT_2(SetVolume
, SETVOLUME
, DWORD
)
4421 #undef WAVEOUT_SHORTCUT_1
4423 /**************************************************************************
4424 * waveOutBreakLoop [MMSYSTEM.419]
4426 UINT WINAPI
waveOutBreakLoop(HWAVEOUT hWaveOut
)
4428 return waveOutBreakLoop16(hWaveOut
);
4431 /**************************************************************************
4432 * waveOutBreakLoop [MMSYSTEM.419]
4434 UINT16 WINAPI
waveOutBreakLoop16(HWAVEOUT16 hWaveOut
)
4436 FIXME("(%04X)\n", hWaveOut
);
4437 return MMSYSERR_INVALHANDLE
;
4440 /**************************************************************************
4441 * waveOutGetID [MMSYSTEM.420]
4443 UINT WINAPI
waveOutGetID(HWAVEOUT hWaveOut
, UINT
* lpuDeviceID
)
4445 LPWAVEOPENDESC lpDesc
;
4447 TRACE("(%04X, %p);\n", hWaveOut
, lpuDeviceID
);
4449 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4450 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4451 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
4452 *lpuDeviceID
= lpDesc
->uDeviceID
;
4456 /**************************************************************************
4457 * waveOutGetID [MMSYSTEM.420]
4459 UINT16 WINAPI
waveOutGetID16(HWAVEOUT16 hWaveOut
, UINT16
* lpuDeviceID
)
4461 LPWAVEOPENDESC lpDesc
;
4463 TRACE("(%04X, %p);\n", hWaveOut
, lpuDeviceID
);
4465 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4466 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4467 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
4468 *lpuDeviceID
= lpDesc
->uDeviceID
;
4472 /**************************************************************************
4473 * waveOutMessage [MMSYSTEM.421]
4475 DWORD WINAPI
waveOutMessage(HWAVEOUT hWaveOut
, UINT uMessage
,
4476 DWORD dwParam1
, DWORD dwParam2
)
4478 LPWAVEOPENDESC lpDesc
;
4480 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4481 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4483 case WODM_GETNUMDEVS
:
4485 case WODM_GETVOLUME
:
4487 case WODM_GETPLAYBACKRATE
:
4488 case WODM_SETVOLUME
:
4490 case WODM_SETPLAYBACKRATE
:
4494 case WODM_UNPREPARE
:
4497 /* no argument conversion needed */
4500 return waveOutWrite(hWaveOut
, (LPWAVEHDR
)dwParam1
, dwParam2
);
4501 case WODM_GETDEVCAPS
:
4502 /* FIXME: UNICODE/ANSI? */
4503 return waveOutGetDevCapsA(hWaveOut
, (LPWAVEOUTCAPSA
)dwParam1
, dwParam2
);
4505 FIXME("can't handle WODM_OPEN, please report.\n");
4508 ERR("(0x%04x, 0x%04x, %08lx, %08lx): unhandled message\n",
4509 hWaveOut
, uMessage
, dwParam1
, dwParam2
);
4512 return wodMessage(lpDesc
->uDeviceID
, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
4515 /**************************************************************************
4516 * waveOutMessage [MMSYSTEM.421]
4518 DWORD WINAPI
waveOutMessage16(HWAVEOUT16 hWaveOut
, UINT16 uMessage
,
4519 DWORD dwParam1
, DWORD dwParam2
)
4521 LPWAVEOPENDESC lpDesc
;
4523 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveOut
);
4524 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4526 case WODM_GETNUMDEVS
:
4527 case WODM_SETVOLUME
:
4529 case WODM_SETPLAYBACKRATE
:
4534 /* no argument conversion needed */
4537 return waveOutGetPosition16(hWaveOut
, (LPMMTIME16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
4538 case WODM_GETVOLUME
:
4539 return waveOutGetVolume16(hWaveOut
, (LPDWORD
)PTR_SEG_TO_LIN(dwParam1
));
4541 return waveOutGetPitch16(hWaveOut
, (LPDWORD
)PTR_SEG_TO_LIN(dwParam1
));
4542 case WODM_GETPLAYBACKRATE
:
4543 return waveOutGetPlaybackRate16(hWaveOut
, (LPDWORD
)PTR_SEG_TO_LIN(dwParam1
));
4544 case WODM_GETDEVCAPS
:
4545 return waveOutGetDevCaps16(hWaveOut
, (LPWAVEOUTCAPS16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
4547 return waveOutPrepareHeader16(hWaveOut
, (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
4548 case WODM_UNPREPARE
:
4549 return waveOutUnprepareHeader16(hWaveOut
, (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
4551 return waveOutWrite16(hWaveOut
, (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
4553 FIXME("can't handle WODM_OPEN, please report.\n");
4556 ERR("(0x%04x, 0x%04x, %08lx, %08lx): unhandled message\n",
4557 hWaveOut
, uMessage
, dwParam1
, dwParam2
);
4559 return wodMessage(lpDesc
->uDeviceID
, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
4562 /**************************************************************************
4563 * waveInGetNumDevs [WINMM.151]
4565 UINT WINAPI
waveInGetNumDevs(void)
4567 return waveInGetNumDevs16();
4570 /**************************************************************************
4571 * waveInGetNumDevs [MMSYSTEM.501]
4573 UINT16 WINAPI
waveInGetNumDevs16(void)
4577 TRACE("waveInGetNumDevs\n");
4578 count
+= widMessage(0, WIDM_GETNUMDEVS
, 0L, 0L, 0L);
4579 TRACE("waveInGetNumDevs return %u \n", count
);
4583 /**************************************************************************
4584 * waveInGetDevCapsA [WINMM.147]
4586 UINT WINAPI
waveInGetDevCapsW(UINT uDeviceID
, LPWAVEINCAPSW lpCaps
, UINT uSize
)
4589 UINT ret
= waveInGetDevCaps16(uDeviceID
, &wic16
, uSize
);
4591 lpCaps
->wMid
= wic16
.wMid
;
4592 lpCaps
->wPid
= wic16
.wPid
;
4593 lpCaps
->vDriverVersion
= wic16
.vDriverVersion
;
4594 lstrcpyAtoW(lpCaps
->szPname
, wic16
.szPname
);
4595 lpCaps
->dwFormats
= wic16
.dwFormats
;
4596 lpCaps
->wChannels
= wic16
.wChannels
;
4601 /**************************************************************************
4602 * waveInGetDevCapsA [WINMM.146]
4604 UINT WINAPI
waveInGetDevCapsA(UINT uDeviceID
, LPWAVEINCAPSA lpCaps
, UINT uSize
)
4607 UINT ret
= waveInGetDevCaps16(uDeviceID
, &wic16
, uSize
);
4609 lpCaps
->wMid
= wic16
.wMid
;
4610 lpCaps
->wPid
= wic16
.wPid
;
4611 lpCaps
->vDriverVersion
= wic16
.vDriverVersion
;
4612 strcpy(lpCaps
->szPname
, wic16
.szPname
);
4613 lpCaps
->dwFormats
= wic16
.dwFormats
;
4614 lpCaps
->wChannels
= wic16
.wChannels
;
4618 /**************************************************************************
4619 * waveInGetDevCaps [MMSYSTEM.502]
4621 UINT16 WINAPI
waveInGetDevCaps16(UINT16 uDeviceID
, LPWAVEINCAPS16 lpCaps
, UINT16 uSize
)
4623 TRACE("waveInGetDevCaps\n");
4625 return widMessage(uDeviceID
, WIDM_GETDEVCAPS
, 0L, (DWORD
)lpCaps
, uSize
);
4628 /**************************************************************************
4629 * waveInGetErrorTextA [WINMM.148]
4631 UINT WINAPI
waveInGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
4633 TRACE("waveInGetErrorText\n");
4634 return waveGetErrorText(uError
, lpText
, uSize
);
4637 /**************************************************************************
4638 * waveInGetErrorTextW [WINMM.149]
4640 UINT WINAPI
waveInGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
4642 LPSTR txt
= HeapAlloc(GetProcessHeap(), 0, uSize
);
4643 UINT ret
= waveGetErrorText(uError
, txt
, uSize
);
4645 lstrcpyAtoW(lpText
, txt
);
4646 HeapFree(GetProcessHeap(), 0, txt
);
4650 /**************************************************************************
4651 * waveInGetErrorText [MMSYSTEM.503]
4653 UINT16 WINAPI
waveInGetErrorText16(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
4655 TRACE("waveInGetErrorText\n");
4656 return waveGetErrorText(uError
, lpText
, uSize
);
4659 /**************************************************************************
4660 * waveInOpen [WINMM.154]
4662 UINT WINAPI
waveInOpen(HWAVEIN
* lphWaveIn
, UINT uDeviceID
,
4663 const LPWAVEFORMAT lpFormat
, DWORD dwCallback
,
4664 DWORD dwInstance
, DWORD dwFlags
)
4667 UINT ret
= waveInOpen16(&hwin16
, uDeviceID
, lpFormat
, dwCallback
, dwInstance
,
4668 CALLBACK32CONV(dwFlags
));
4669 if (lphWaveIn
) *lphWaveIn
= hwin16
;
4673 /**************************************************************************
4674 * waveInOpen [MMSYSTEM.504]
4676 UINT16 WINAPI
waveInOpen16(HWAVEIN16
* lphWaveIn
, UINT16 uDeviceID
,
4677 const LPWAVEFORMAT lpFormat
, DWORD dwCallback
,
4678 DWORD dwInstance
, DWORD dwFlags
)
4681 LPWAVEOPENDESC lpDesc
;
4683 BOOL bMapperFlg
= FALSE
;
4685 TRACE("(%p, %d, %p, %08lX, %08lX, %08lX);\n",
4686 lphWaveIn
, uDeviceID
, lpFormat
, dwCallback
, dwInstance
, dwFlags
);
4687 if (dwFlags
& WAVE_FORMAT_QUERY
)
4688 TRACE("WAVE_FORMAT_QUERY requested !\n");
4689 if (uDeviceID
== (UINT16
)WAVE_MAPPER
) {
4690 TRACE("WAVE_MAPPER mode requested !\n");
4694 if (lpFormat
== NULL
) return WAVERR_BADFORMAT
;
4695 hWaveIn
= USER_HEAP_ALLOC(sizeof(WAVEOPENDESC
));
4696 if (lphWaveIn
!= NULL
) *lphWaveIn
= hWaveIn
;
4697 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4698 if (lpDesc
== NULL
) return MMSYSERR_NOMEM
;
4699 lpDesc
->hWave
= hWaveIn
;
4700 lpDesc
->lpFormat
= lpFormat
;
4701 lpDesc
->dwCallBack
= dwCallback
;
4702 lpDesc
->dwInstance
= dwInstance
;
4703 while (uDeviceID
< MAXWAVEDRIVERS
) {
4704 dwRet
= widMessage(uDeviceID
, WIDM_OPEN
,
4705 lpDesc
->dwInstance
, (DWORD
)lpDesc
, 0L);
4706 if (dwRet
== MMSYSERR_NOERROR
) break;
4707 if (!bMapperFlg
) break;
4709 TRACE("WAVE_MAPPER mode ! try next driver...\n");
4711 lpDesc
->uDeviceID
= uDeviceID
;
4712 if (dwFlags
& WAVE_FORMAT_QUERY
) {
4713 TRACE("End of WAVE_FORMAT_QUERY !\n");
4714 dwRet
= waveInClose16(hWaveIn
);
4715 } else if (dwRet
!= MMSYSERR_NOERROR
) {
4716 USER_HEAP_FREE(hWaveIn
);
4717 if (lphWaveIn
) *lphWaveIn
= 0;
4723 /**************************************************************************
4724 * waveInClose [WINMM.145]
4726 UINT WINAPI
waveInClose(HWAVEIN hWaveIn
)
4728 return waveInClose16(hWaveIn
);
4731 /**************************************************************************
4732 * waveInClose [MMSYSTEM.505]
4734 UINT16 WINAPI
waveInClose16(HWAVEIN16 hWaveIn
)
4736 LPWAVEOPENDESC lpDesc
;
4739 TRACE("(%04X)\n", hWaveIn
);
4740 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4741 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4742 dwRet
= widMessage(lpDesc
->uDeviceID
, WIDM_CLOSE
, lpDesc
->dwInstance
, 0L, 0L);
4743 USER_HEAP_FREE(hWaveIn
);
4747 /**************************************************************************
4748 * waveInPrepareHeader [WINMM.155]
4750 UINT WINAPI
waveInPrepareHeader(HWAVEIN hWaveIn
,
4751 WAVEHDR
* lpWaveInHdr
, UINT uSize
)
4753 LPWAVEOPENDESC lpDesc
;
4755 TRACE("(%04X, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
4756 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4757 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4758 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALHANDLE
;
4759 lpWaveInHdr
->lpNext
= NULL
;
4760 lpWaveInHdr
->dwBytesRecorded
= 0;
4761 lpWaveInHdr
->reserved
= (DWORD
)lpWaveInHdr
;
4763 return widMessage(lpDesc
->uDeviceID
, WIDM_PREPARE
, lpDesc
->dwInstance
,
4764 (DWORD
)lpWaveInHdr
, uSize
);
4767 /**************************************************************************
4768 * waveInPrepareHeader [MMSYSTEM.506]
4770 UINT16 WINAPI
waveInPrepareHeader16(HWAVEIN16 hWaveIn
,
4771 WAVEHDR
* /* SEGPTR */ _lpWaveInHdr
, UINT16 uSize
)
4773 LPWAVEOPENDESC lpDesc
;
4774 LPWAVEHDR lpWaveInHdr
= (LPWAVEHDR
)PTR_SEG_TO_LIN(_lpWaveInHdr
);
4777 TRACE("(%04X, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
4779 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4780 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4781 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALHANDLE
;
4783 lpWaveInHdr
->lpNext
= NULL
;
4784 lpWaveInHdr
->dwBytesRecorded
= 0;
4786 lpWaveInHdr
->reserved
= (DWORD
)_lpWaveInHdr
;
4788 ret
= widMessage(lpDesc
->uDeviceID
, WIDM_PREPARE
, lpDesc
->dwInstance
,
4789 (DWORD
)lpWaveInHdr
, uSize
);
4793 /**************************************************************************
4794 * waveInUnprepareHeader [WINMM.159]
4796 UINT WINAPI
waveInUnprepareHeader(HWAVEIN hWaveIn
,
4797 WAVEHDR
* lpWaveInHdr
, UINT uSize
)
4799 LPWAVEOPENDESC lpDesc
;
4801 TRACE("(%04X, %p, %u);\n",
4802 hWaveIn
, lpWaveInHdr
, uSize
);
4803 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4804 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4805 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALHANDLE
;
4807 lpWaveInHdr
->lpNext
= NULL
;
4808 return widMessage(lpDesc
->uDeviceID
, WIDM_UNPREPARE
, lpDesc
->dwInstance
,
4809 (DWORD
)lpWaveInHdr
, uSize
);
4812 /**************************************************************************
4813 * waveInUnprepareHeader [MMSYSTEM.507]
4815 UINT16 WINAPI
waveInUnprepareHeader16(HWAVEIN16 hWaveIn
,
4816 WAVEHDR
* lpWaveInHdr
, UINT16 uSize
)
4818 LPWAVEOPENDESC lpDesc
;
4820 TRACE("(%04X, %p, %u);\n",
4821 hWaveIn
, lpWaveInHdr
, uSize
);
4822 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4823 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4824 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALHANDLE
;
4826 return widMessage(lpDesc
->uDeviceID
, WIDM_UNPREPARE
, lpDesc
->dwInstance
,
4827 (DWORD
)lpWaveInHdr
, uSize
);
4830 /**************************************************************************
4831 * waveInAddBuffer [WINMM.144]
4833 UINT WINAPI
waveInAddBuffer(HWAVEIN hWaveIn
,
4834 WAVEHDR
* lpWaveInHdr
, UINT uSize
)
4836 LPWAVEOPENDESC lpDesc
;
4838 TRACE("(%04X, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
4840 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4841 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4842 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALHANDLE
;
4844 lpWaveInHdr
->lpNext
= NULL
;
4845 lpWaveInHdr
->dwBytesRecorded
= 0;
4847 return widMessage(lpDesc
->uDeviceID
, WIDM_ADDBUFFER
, lpDesc
->dwInstance
,
4848 (DWORD
)lpWaveInHdr
, uSize
);
4852 /**************************************************************************
4853 * waveInAddBuffer [MMSYSTEM.508]
4855 UINT16 WINAPI
waveInAddBuffer16(HWAVEIN16 hWaveIn
,
4856 WAVEHDR
* lpWaveInHdr
, UINT16 uSize
)
4858 LPWAVEOPENDESC lpDesc
;
4861 TRACE("(%04X, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
4863 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4864 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4865 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALHANDLE
;
4866 lpWaveInHdr
->lpNext
= NULL
;
4867 lpWaveInHdr
->dwBytesRecorded
= 0;
4869 ret
= widMessage(lpDesc
->uDeviceID
, WIDM_ADDBUFFER
, lpDesc
->dwInstance
,
4870 (DWORD
)lpWaveInHdr
, uSize
);
4874 /**************************************************************************
4875 * waveInStart [WINMM.157]
4877 UINT WINAPI
waveInStart(HWAVEIN hWaveIn
)
4879 return waveInStart16(hWaveIn
);
4882 /**************************************************************************
4883 * waveInStart [MMSYSTEM.509]
4885 UINT16 WINAPI
waveInStart16(HWAVEIN16 hWaveIn
)
4887 LPWAVEOPENDESC lpDesc
;
4889 TRACE("(%04X)\n", hWaveIn
);
4890 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4891 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4892 return widMessage(lpDesc
->uDeviceID
, WIDM_START
, lpDesc
->dwInstance
, 0, 0);
4895 /**************************************************************************
4896 * waveInStop [WINMM.158]
4898 UINT WINAPI
waveInStop(HWAVEIN hWaveIn
)
4900 return waveInStop16(hWaveIn
);
4903 /**************************************************************************
4904 * waveInStop [MMSYSTEM.510]
4906 UINT16 WINAPI
waveInStop16(HWAVEIN16 hWaveIn
)
4908 LPWAVEOPENDESC lpDesc
;
4910 TRACE("(%04X)\n", hWaveIn
);
4911 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4912 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4913 return widMessage(lpDesc
->uDeviceID
, WIDM_STOP
, lpDesc
->dwInstance
, 0L, 0L);
4916 /**************************************************************************
4917 * waveInReset [WINMM.156]
4919 UINT WINAPI
waveInReset(HWAVEIN hWaveIn
)
4921 return waveInReset16(hWaveIn
);
4924 /**************************************************************************
4925 * waveInReset [MMSYSTEM.511]
4927 UINT16 WINAPI
waveInReset16(HWAVEIN16 hWaveIn
)
4929 LPWAVEOPENDESC lpDesc
;
4931 TRACE("(%04X)\n", hWaveIn
);
4932 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4933 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4934 return widMessage(lpDesc
->uDeviceID
, WIDM_RESET
, lpDesc
->dwInstance
, 0, 0);
4937 /**************************************************************************
4938 * waveInGetPosition [WINMM.152]
4940 UINT WINAPI
waveInGetPosition(HWAVEIN hWaveIn
, LPMMTIME lpTime
,
4946 mmt16
.wType
= lpTime
->wType
;
4947 ret
= waveInGetPosition16(hWaveIn
, &mmt16
, uSize
);
4949 MMSYSTEM_MMTIME16to32(lpTime
, &mmt16
);
4953 /**************************************************************************
4954 * waveInGetPosition [MMSYSTEM.512]
4956 UINT16 WINAPI
waveInGetPosition16(HWAVEIN16 hWaveIn
, LPMMTIME16 lpTime
,
4959 LPWAVEOPENDESC lpDesc
;
4961 TRACE("(%04X, %p, %u);\n", hWaveIn
, lpTime
, uSize
);
4962 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4963 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4964 return widMessage(lpDesc
->uDeviceID
, WIDM_GETPOS
, lpDesc
->dwInstance
,
4965 (DWORD
)lpTime
, (DWORD
)uSize
);
4968 /**************************************************************************
4969 * waveInGetID [WINMM.150]
4971 UINT WINAPI
waveInGetID(HWAVEIN hWaveIn
, UINT
* lpuDeviceID
)
4973 LPWAVEOPENDESC lpDesc
;
4975 TRACE("waveInGetID\n");
4976 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
4977 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4978 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4979 *lpuDeviceID
= lpDesc
->uDeviceID
;
4983 /**************************************************************************
4984 * waveInGetID [MMSYSTEM.513]
4986 UINT16 WINAPI
waveInGetID16(HWAVEIN16 hWaveIn
, UINT16
* lpuDeviceID
)
4988 LPWAVEOPENDESC lpDesc
;
4990 TRACE("waveInGetID\n");
4991 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
4992 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
4993 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
4994 *lpuDeviceID
= lpDesc
->uDeviceID
;
4998 /**************************************************************************
4999 * waveInMessage [WINMM.153]
5001 DWORD WINAPI
waveInMessage(HWAVEIN hWaveIn
, UINT uMessage
,
5002 DWORD dwParam1
, DWORD dwParam2
)
5004 LPWAVEOPENDESC lpDesc
;
5006 FIXME("(%04X, %04X, %08lX, %08lX)\n",
5007 hWaveIn
, uMessage
, dwParam1
, dwParam2
);
5008 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
5009 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
5012 FIXME("cannot handle WIDM_OPEN, please report.\n");
5014 case WIDM_GETNUMDEVS
:
5021 case WIDM_UNPREPARE
:
5022 case WIDM_ADDBUFFER
:
5024 /* no argument conversion needed */
5026 case WIDM_GETDEVCAPS
:
5027 /*FIXME: ANSI/UNICODE */
5028 return waveInGetDevCapsA(hWaveIn
, (LPWAVEINCAPSA
)dwParam1
, dwParam2
);
5030 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
5031 hWaveIn
, uMessage
, dwParam1
, dwParam2
);
5034 return widMessage(lpDesc
->uDeviceID
, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
5037 /**************************************************************************
5038 * waveInMessage [MMSYSTEM.514]
5040 DWORD WINAPI
waveInMessage16(HWAVEIN16 hWaveIn
, UINT16 uMessage
,
5041 DWORD dwParam1
, DWORD dwParam2
)
5043 LPWAVEOPENDESC lpDesc
;
5045 FIXME("(%04X, %04X, %08lX, %08lX)\n",
5046 hWaveIn
, uMessage
, dwParam1
, dwParam2
);
5047 lpDesc
= (LPWAVEOPENDESC
) USER_HEAP_LIN_ADDR(hWaveIn
);
5048 if (lpDesc
== NULL
) return MMSYSERR_INVALHANDLE
;
5051 FIXME("cannot handle WIDM_OPEN, please report.\n");
5053 case WIDM_GETNUMDEVS
:
5059 /* no argument conversion needed */
5061 case WIDM_GETDEVCAPS
:
5062 return waveInGetDevCaps16(hWaveIn
, (LPWAVEINCAPS16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
5064 return waveInGetPosition16(hWaveIn
, (LPMMTIME16
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
5066 return waveInPrepareHeader16(hWaveIn
, (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
5067 case WIDM_UNPREPARE
:
5068 return waveInUnprepareHeader16(hWaveIn
, (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
5069 case WIDM_ADDBUFFER
:
5070 return waveInAddBuffer16(hWaveIn
, (LPWAVEHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
5072 ERR("(%04x, %04x, %08lx, %08lx): unhandled message\n",
5073 hWaveIn
, uMessage
, dwParam1
, dwParam2
);
5076 return widMessage(lpDesc
->uDeviceID
, uMessage
, lpDesc
->dwInstance
, dwParam1
, dwParam2
);
5079 /**************************************************************************
5080 * DrvOpen [MMSYSTEM.1100]
5082 HDRVR16 WINAPI
DrvOpen(LPSTR lpDriverName
, LPSTR lpSectionName
, LPARAM lParam
)
5084 TRACE("('%s','%s', %08lX);\n", lpDriverName
, lpSectionName
, lParam
);
5086 return OpenDriver16(lpDriverName
, lpSectionName
, lParam
);
5089 /**************************************************************************
5090 * DrvClose [MMSYSTEM.1101]
5092 LRESULT WINAPI
DrvClose(HDRVR16 hDrv
, LPARAM lParam1
, LPARAM lParam2
)
5094 TRACE("(%04X, %08lX, %08lX);\n", hDrv
, lParam1
, lParam2
);
5096 return CloseDriver16(hDrv
, lParam1
, lParam2
);
5099 /**************************************************************************
5100 * DrvSendMessage [MMSYSTEM.1102]
5102 LRESULT WINAPI
DrvSendMessage(HDRVR16 hDrv
, WORD msg
, LPARAM lParam1
,
5105 return SendDriverMessage(hDrv
, msg
, lParam1
, lParam2
);
5108 /**************************************************************************
5109 * DrvGetModuleHandle [MMSYSTEM.1103]
5111 HANDLE16 WINAPI
DrvGetModuleHandle16(HDRVR16 hDrv
)
5113 return GetDriverModuleHandle16(hDrv
);
5116 /**************************************************************************
5117 * DrvDefDriverProc [MMSYSTEM.1104]
5119 LRESULT WINAPI
DrvDefDriverProc(DWORD dwDriverID
, HDRVR16 hDrv
, WORD wMsg
,
5120 DWORD dwParam1
, DWORD dwParam2
)
5122 /* FIXME : any mapping from 32 to 16 bit structure ? */
5123 return DefDriverProc16(dwDriverID
, hDrv
, wMsg
, dwParam1
, dwParam2
);
5126 /**************************************************************************
5127 * DefDriverProc [WINMM.5]
5129 LRESULT WINAPI
DefDriverProc(DWORD dwDriverIdentifier
, HDRVR hDrv
,
5130 UINT Msg
, LPARAM lParam1
, LPARAM lParam2
)
5146 /*#define USE_MM_TSK_WINE*/
5148 /**************************************************************************
5149 * mmTaskCreate [MMSYSTEM.900]
5151 * Creates a 16 bit MM task. It's entry point is lpFunc, and it should be
5152 * called upon creation with dwPmt as parameter.
5154 HINSTANCE16 WINAPI
mmTaskCreate16(SEGPTR spProc
, HINSTANCE16
*lphMmTask
, DWORD dwPmt
)
5156 DWORD showCmd
= 0x40002;
5163 TRACE("(%08lx, %p, %08lx);\n", spProc
, lphMmTask
, dwPmt
);
5164 /* This to work requires NE modules to be started with a binary command line
5165 * which is not currently the case. A patch exists but has never been committed.
5166 * A workaround would be to integrate code for mmtask.tsk into Wine, but
5167 * this requires tremendous work (starting with patching tools/build to
5168 * create NE executables (and not only DLLs) for builtins modules.
5171 FIXME("This is currently broken. It will fail\n");
5173 cmdline
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, 0x0d);
5175 *(LPDWORD
)(cmdline
+ 1) = (DWORD
)spProc
;
5176 *(LPDWORD
)(cmdline
+ 5) = dwPmt
;
5177 *(LPDWORD
)(cmdline
+ 9) = 0;
5179 sel1
= SELECTOR_AllocBlock(cmdline
, 0x0d, SEGMENT_DATA
, FALSE
, FALSE
);
5180 sel2
= SELECTOR_AllocBlock(&showCmd
, sizeof(showCmd
),
5181 SEGMENT_DATA
, FALSE
, FALSE
);
5183 lp
= (LOADPARAMS16
*)HeapAlloc(GetProcessHeap(), 0, sizeof(LOADPARAMS16
));
5184 lp
->hEnvironment
= 0;
5185 lp
->cmdLine
= PTR_SEG_OFF_TO_SEGPTR(sel1
, 0);
5186 lp
->showCmd
= PTR_SEG_OFF_TO_SEGPTR(sel2
, 0);
5189 #ifndef USE_MM_TSK_WINE
5190 handle
= LoadModule16("c:\\windows\\system\\mmtask.tsk", lp
);
5192 handle
= LoadModule16("mmtask.tsk", lp
);
5195 ret
= (handle
) ? 1 : 2;
5201 *lphMmTask
= handle
;
5203 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(sel2
, 0));
5204 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(sel1
, 0));
5206 HeapFree(GetProcessHeap(), 0, lp
);
5207 HeapFree(GetProcessHeap(), 0, cmdline
);
5209 TRACE("=> 0x%04x/%d\n", handle
, ret
);
5213 #ifdef USE_MM_TSK_WINE
5214 /* C equivalent to mmtask.tsk binary content */
5215 void mmTaskEntryPoint16(LPSTR cmdLine
, WORD di
, WORD si
)
5217 int len
= cmdLine
[0x80];
5220 void (*fpProc
)(DWORD
) = (void (*)(DWORD
))PTR_SEG_TO_LIN(*((DWORD
*)(cmdLine
+ 1)));
5221 DWORD dwPmt
= *((DWORD
*)(cmdLine
+ 5));
5224 InitTask16(); /* fixme: pmts / from context ? */
5227 if (SetMessageQueue16(0x40)) {
5229 if (HIWORD(fpProc
)) {
5231 /* EPP StackEnter16(); */
5243 /**************************************************************************
5244 * mmTaskBlock [MMSYSTEM.902]
5246 void WINAPI
mmTaskBlock16(HINSTANCE16 WINE_UNUSED hInst
)
5251 GetMessageA(&msg
, 0, 0, 0);
5253 TranslateMessage(&msg
);
5254 DispatchMessageA(&msg
);
5256 } while (msg
.message
< 0x3A0);
5259 /**************************************************************************
5260 * mmTaskSignal [MMSYSTEM.903]
5262 LRESULT WINAPI
mmTaskSignal16(HTASK16 ht
)
5264 TRACE("(%04x);\n", ht
);
5265 return Callout
.PostAppMessage16(ht
, WM_USER
, 0, 0);
5268 /**************************************************************************
5269 * mmTaskYield16 [MMSYSTEM.905]
5271 void WINAPI
mmTaskYield16(void)
5275 if (PeekMessageA(&msg
, 0, 0, 0, 0)) {
5280 DWORD WINAPI
GetProcessFlags(DWORD
);
5282 /**************************************************************************
5283 * mmThreadCreate [MMSYSTEM.1120]
5286 * Creates a MM thread, calling fpThreadAddr(dwPmt).
5288 * bit.0 set means create a 16 bit task instead of thread calling a 16 bit proc
5289 * bit.1 set means to open a VxD for this thread (unsupported)
5291 LRESULT WINAPI
mmThreadCreate16(FARPROC16 fpThreadAddr
, LPHANDLE lpHndl
, DWORD dwPmt
, DWORD dwFlags
)
5296 TRACE("(%p, %p, %08lx, %08lx)!\n", fpThreadAddr
, lpHndl
, dwPmt
, dwFlags
);
5298 hndl
= GlobalAlloc16(sizeof(WINE_MMTHREAD
), GMEM_SHARE
|GMEM_ZEROINIT
);
5303 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(hndl
, 0);
5306 /* force mmtask routines even if mmthread is required */
5307 /* this will work only if the patch about binary cmd line and NE tasks
5313 lpMMThd
->dwSignature
= WINE_MMTHREAD_CREATED
;
5314 lpMMThd
->dwCounter
= 0;
5315 lpMMThd
->hThread
= 0;
5316 lpMMThd
->dwThreadID
= 0;
5317 lpMMThd
->fpThread
= fpThreadAddr
;
5318 lpMMThd
->dwThreadPmt
= dwPmt
;
5319 lpMMThd
->dwSignalCount
= 0;
5320 lpMMThd
->hEvent
= 0;
5322 lpMMThd
->dwStatus
= 0;
5323 lpMMThd
->dwFlags
= dwFlags
;
5326 if ((dwFlags
& 1) == 0 && (GetProcessFlags(GetCurrentThreadId()) & 8) == 0) {
5327 lpMMThd
->hEvent
= CreateEventA(0, 0, 1, 0);
5329 TRACE("Let's go crazy... trying new MM thread. lpMMThd=%p\n", lpMMThd
);
5330 if (lpMMThd
->dwFlags
& 2) {
5331 /* as long as we don't support MM VxD in wine, we don't need
5332 * to care about this flag
5334 /* FIXME("Don't know how to properly open VxD handles\n"); */
5335 /* lpMMThd->hVxD = OpenVxDHandle(lpMMThd->hEvent); */
5338 lpMMThd
->hThread
= CreateThread(0, 0, (LPTHREAD_START_ROUTINE
)WINE_mmThreadEntryPoint
,
5339 (LPVOID
)(DWORD
)hndl
, CREATE_SUSPENDED
, &lpMMThd
->dwThreadID
);
5340 if (lpMMThd
->hThread
== 0) {
5341 WARN("Couldn't create thread\n");
5342 /* clean-up(VxDhandle...); devicedirectio... */
5343 if (lpMMThd
->hEvent
!= 0)
5344 CloseHandle(lpMMThd
->hEvent
);
5347 TRACE("Got a nice thread hndl=0x%04x id=0x%08lx\n", lpMMThd
->hThread
, lpMMThd
->dwThreadID
);
5351 /* get WINE_mmThreadEntryPoint()
5352 * 2047 is its ordinal in mmsystem.spec
5354 FARPROC16 fp
= GetProcAddress16(GetModuleHandle16("MMSYSTEM"), (SEGPTR
)2047);
5356 TRACE("farproc seg=0x%08lx lin=%p\n", (DWORD
)fp
, PTR_SEG_TO_LIN(fp
));
5358 ret
= (fp
== 0) ? 2 : mmTaskCreate16((DWORD
)fp
, 0, hndl
);
5362 if (lpMMThd
->hThread
&& !ResumeThread(lpMMThd
->hThread
))
5363 WARN("Couldn't resume thread\n");
5365 while (lpMMThd
->dwStatus
!= 0x10) { /* test also HIWORD of dwStatus */
5379 TRACE("ok => %ld\n", ret
);
5383 /**************************************************************************
5384 * mmThreadSignal [MMSYSTEM.1121]
5386 void WINAPI
mmThreadSignal16(HANDLE16 hndl
)
5388 TRACE("(%04x)!\n", hndl
);
5391 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(hndl
, 0);
5393 lpMMThd
->dwCounter
++;
5394 if (lpMMThd
->hThread
!= 0) {
5395 InterlockedIncrement(&lpMMThd
->dwSignalCount
);
5396 SetEvent(lpMMThd
->hEvent
);
5398 mmTaskSignal16(lpMMThd
->hTask
);
5400 lpMMThd
->dwCounter
--;
5404 /**************************************************************************
5405 * MMSYSTEM_ThreadBlock [internal]
5407 static void MMSYSTEM_ThreadBlock(WINE_MMTHREAD
* lpMMThd
)
5412 if (lpMMThd
->dwThreadID
!= GetCurrentThreadId())
5413 ERR("Not called by thread itself\n");
5416 ResetEvent(lpMMThd
->hEvent
);
5417 if (InterlockedDecrement(&lpMMThd
->dwSignalCount
) >= 0)
5419 InterlockedIncrement(&lpMMThd
->dwSignalCount
);
5423 ret
= MsgWaitForMultipleObjects(1, &lpMMThd
->hEvent
, FALSE
, INFINITE
, QS_ALLINPUT
);
5425 case WAIT_OBJECT_0
: /* Event */
5428 case WAIT_OBJECT_0
+ 1: /* Msg */
5430 if (Callout
.PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) {
5431 Callout
.TranslateMessage(&msg
);
5432 Callout
.DispatchMessageA(&msg
);
5436 WARN("S2.x unsupported ret val 0x%08lx\n", ret
);
5442 /**************************************************************************
5443 * mmThreadBlock [MMSYSTEM.1122]
5445 void WINAPI
mmThreadBlock16(HANDLE16 hndl
)
5447 TRACE("(%04x)!\n", hndl
);
5450 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(hndl
, 0);
5452 if (lpMMThd
->hThread
!= 0) {
5453 SYSLEVEL_ReleaseWin16Lock();
5454 MMSYSTEM_ThreadBlock(lpMMThd
);
5455 SYSLEVEL_RestoreWin16Lock();
5457 mmTaskBlock16(lpMMThd
->hTask
);
5463 /**************************************************************************
5464 * mmThreadIsCurrent [MMSYSTEM.1123]
5466 BOOL16 WINAPI
mmThreadIsCurrent16(HANDLE16 hndl
)
5470 TRACE("(%04x)!\n", hndl
);
5472 if (hndl
&& mmThreadIsValid16(hndl
)) {
5473 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(hndl
, 0);
5474 ret
= (GetCurrentThreadId() == lpMMThd
->dwThreadID
);
5476 /* FIXME: just a test */
5477 SYSLEVEL_ReleaseWin16Lock();
5478 SYSLEVEL_RestoreWin16Lock();
5481 TRACE("=> %d\n", ret
);
5485 /**************************************************************************
5486 * mmThreadIsValid [MMSYSTEM.1124]
5488 BOOL16 WINAPI
mmThreadIsValid16(HANDLE16 hndl
)
5492 TRACE("(%04x)!\n", hndl
);
5495 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(hndl
, 0);
5497 if (!IsBadWritePtr(lpMMThd
, sizeof(WINE_MMTHREAD
)) &&
5498 lpMMThd
->dwSignature
== WINE_MMTHREAD_CREATED
&&
5499 IsTask16(lpMMThd
->hTask
)) {
5500 lpMMThd
->dwCounter
++;
5501 if (lpMMThd
->hThread
!= 0) {
5503 if (GetExitCodeThread(lpMMThd
->hThread
, &dwThreadRet
) &&
5504 dwThreadRet
== STATUS_PENDING
) {
5510 lpMMThd
->dwCounter
--;
5513 TRACE("=> %d\n", ret
);
5517 /**************************************************************************
5518 * mmThreadGetTask [MMSYSTEM.1125]
5520 HANDLE16 WINAPI
mmThreadGetTask16(HANDLE16 hndl
)
5524 TRACE("(%04x)\n", hndl
);
5526 if (mmThreadIsValid16(hndl
)) {
5527 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(hndl
, 0);
5528 ret
= lpMMThd
->hTask
;
5533 /**************************************************************************
5534 * mmThreadGetTask [internal]
5536 void CALLBACK
WINE_mmThreadEntryPoint(DWORD _pmt
)
5538 HANDLE16 hndl
= (HANDLE16
)_pmt
;
5539 WINE_MMTHREAD
* lpMMThd
= (WINE_MMTHREAD
*)PTR_SEG_OFF_TO_LIN(hndl
, 0);
5541 TRACE("(%04x %p)\n", hndl
, lpMMThd
);
5543 lpMMThd
->hTask
= LOWORD(GetCurrentTask());
5544 TRACE("[10-%08x] setting hTask to 0x%08x\n", lpMMThd
->hThread
, lpMMThd
->hTask
);
5545 lpMMThd
->dwStatus
= 0x10;
5546 MMSYSTEM_ThreadBlock(lpMMThd
);
5547 TRACE("[20-%08x]\n", lpMMThd
->hThread
);
5548 lpMMThd
->dwStatus
= 0x20;
5549 if (lpMMThd
->fpThread
) {
5550 Callbacks
->CallWOWCallbackProc(lpMMThd
->fpThread
, lpMMThd
->dwThreadPmt
);
5552 lpMMThd
->dwStatus
= 0x30;
5553 TRACE("[30-%08x]\n", lpMMThd
->hThread
);
5554 while (lpMMThd
->dwCounter
) {
5558 TRACE("[XX-%08x]\n", lpMMThd
->hThread
);
5560 lpMMThd
->dwSignature
= WINE_MMTHREAD_DELETED
;
5561 /* close lpMMThread->hVxD directio */
5562 if (lpMMThd
->hEvent
)
5563 CloseHandle(lpMMThd
->hEvent
);
5568 typedef BOOL16 (WINAPI
*MMCPLCALLBACK
)(HWND
, LPCSTR
, LPCSTR
, LPCSTR
);
5570 /**************************************************************************
5571 * mmShowMMCPLPropertySheet [MMSYSTEM.1150]
5573 BOOL16 WINAPI
mmShowMMCPLPropertySheet16(HWND hWnd
, LPCSTR lpStrDevice
,
5574 LPCSTR lpStrTab
, LPCSTR lpStrTitle
)
5579 TRACE("(%04x \"%s\" \"%s\" \"%s\")\n", hWnd
, lpStrDevice
, lpStrTab
, lpStrTitle
);
5581 hndl
= LoadLibraryA("MMSYS.CPL");
5583 MMCPLCALLBACK fp
= (MMCPLCALLBACK
)GetProcAddress(hndl
, "ShowMMCPLPropertySheet");
5585 SYSLEVEL_ReleaseWin16Lock();
5586 ret
= (fp
)(hWnd
, lpStrDevice
, lpStrTab
, lpStrTitle
);
5587 SYSLEVEL_RestoreWin16Lock();
5595 /**************************************************************************
5596 * StackEnter & StackLeave [MMSYSTEM.32][MMSYSTEM.33]
5598 void WINAPI
StackEnterLeave16(void)
5601 /* mmsystem.dll from Win 95 does only this: so does Wine */