update for HEAD-2003091401
[reactos.git] / lib / winmm / winemm.h
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*****************************************************************************
4  * Copyright 1998, Luiz Otavio L. Zorzella
5  *           1999, Eric Pouech
6  *
7  * Purpose:   multimedia declarations (internal to WINMM & MMSYSTEM DLLs)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *****************************************************************************
23  */
24
25 #include <mmddk.h>
26
27 #ifdef __WINE_FOR_REACTOS__
28
29 #include <wine/windef16.h>
30 // AG: This is most likely BAD:
31 #define MMTIME16 MMTIME
32 #define LPMMTIME16 LPMMTIME
33
34 #else
35
36 #include "wine/mmsystem16.h"
37 #include "wownt32.h"
38
39 #endif
40
41
42 typedef DWORD (WINAPI *MessageProc16)(UINT16 wDevID, UINT16 wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
43 typedef DWORD (WINAPI *MessageProc32)(UINT wDevID, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
44
45 typedef enum {
46     WINMM_MAP_NOMEM,    /* ko, memory problem */
47     WINMM_MAP_MSGERROR, /* ko, unknown message */
48     WINMM_MAP_OK,       /* ok, no memory allocated. to be sent to the proc. */
49     WINMM_MAP_OKMEM,    /* ok, some memory allocated, need to call UnMapMsg. to be sent to the proc. */
50 } WINMM_MapType;
51
52 /* Who said goofy boy ? */
53 #define WINE_DI_MAGIC   0x900F1B01
54
55 typedef struct tagWINE_DRIVER
56 {
57     DWORD                       dwMagic;
58     /* as usual LPWINE_DRIVER == hDriver32 */
59     DWORD                       dwFlags;
60     union {
61         struct {
62             HMODULE                     hModule;
63             DRIVERPROC                  lpDrvProc;
64             DWORD                       dwDriverID;
65         } d32;
66         struct {
67             HDRVR16                     hDriver16;
68         } d16;
69     } d;
70     struct tagWINE_DRIVER*      lpPrevItem;
71     struct tagWINE_DRIVER*      lpNextItem;
72 } WINE_DRIVER, *LPWINE_DRIVER;
73
74 typedef DWORD   (CALLBACK *WINEMM_msgFunc16)(UINT16, WORD, DWORD, DWORD, DWORD);
75 typedef DWORD   (CALLBACK *WINEMM_msgFunc32)(UINT  , UINT, DWORD, DWORD, DWORD);
76
77 /* for each loaded driver and each known type of driver, this structure contains
78  * the information needed to access it
79  */
80 typedef struct tagWINE_MM_DRIVER_PART {
81     int                         nIDMin;         /* lower bound of global indexes for this type */
82     int                         nIDMax;         /* hhigher bound of global indexes for this type */
83     union {
84         WINEMM_msgFunc32        fnMessage32;    /* pointer to fonction */
85         WINEMM_msgFunc16        fnMessage16;
86     } u;
87 } WINE_MM_DRIVER_PART;
88
89 #define MMDRV_AUX               0
90 #define MMDRV_MIXER             1
91 #define MMDRV_MIDIIN            2
92 #define MMDRV_MIDIOUT           3
93 #define MMDRV_WAVEIN            4
94 #define MMDRV_WAVEOUT           5
95 #define MMDRV_MAX               6
96
97 /* each low-level .drv will be associated with an instance of this structure */
98 typedef struct tagWINE_MM_DRIVER {
99     HDRVR                       hDriver;
100     LPSTR                       drvname;        /* name of the driver */
101     BOOL                        bIs32 : 1,      /* TRUE if 32 bit driver, FALSE for 16 */
102                                 bIsMapper : 1;  /* TRUE if mapper */
103     WINE_MM_DRIVER_PART         parts[MMDRV_MAX];/* Information for all known types */
104 } WINE_MM_DRIVER, *LPWINE_MM_DRIVER;
105
106 typedef struct tagWINE_MLD {
107 /* EPP struct tagWINE_MLD*      lpNext; */              /* not used so far */
108        UINT                     uDeviceID;
109        UINT                     type;
110        UINT                     mmdIndex;               /* index to low-level driver in MMDrvs table */
111        DWORD                    dwDriverInstance;       /* this value is driver related, as opposed to
112                                                          * opendesc.dwInstance which is client (callback) related */
113        WORD                     bFrom32;
114        WORD                     dwFlags;
115        DWORD                    dwCallback;
116        DWORD                    dwClientInstance;
117 } WINE_MLD, *LPWINE_MLD;
118
119 typedef struct  {
120        WINE_MLD                 mld;
121 } WINE_WAVE, *LPWINE_WAVE;
122
123 typedef struct {
124        WINE_MLD                 mld;
125        MIDIOPENDESC             mod;                    /* FIXME: should be removed */
126 } WINE_MIDI, *LPWINE_MIDI;
127
128 typedef struct {
129        WINE_MLD                 mld;
130 } WINE_MIXER, *LPWINE_MIXER;
131
132 #define WINE_MMTHREAD_CREATED   0x4153494C      /* "BSIL" */
133 #define WINE_MMTHREAD_DELETED   0xDEADDEAD
134
135 typedef struct {
136        DWORD                    dwSignature;            /* 00 "BSIL" when ok, 0xDEADDEAD when being deleted */
137        DWORD                    dwCounter;              /* 04 > 1 when in mmThread functions */
138        HANDLE                   hThread;                /* 08 hThread */
139        DWORD                    dwThreadID;             /* 0C */
140        FARPROC16                fpThread;               /* 10 address of thread proc (segptr or lin depending on dwFlags) */
141        DWORD                    dwThreadPmt;            /* 14 parameter to be passed upon thread creation to fpThread */
142        DWORD                    dwSignalCount;          /* 18 counter used for signaling */
143        HANDLE                   hEvent;                 /* 1C event */
144        HANDLE                   hVxD;                   /* 20 return from OpenVxDHandle */
145        DWORD                    dwStatus;               /* 24 0x00, 0x10, 0x20, 0x30 */
146        DWORD                    dwFlags;                /* 28 dwFlags upon creation */
147        HANDLE16                 hTask;                  /* 2C handle to created task */
148 } WINE_MMTHREAD;
149
150 typedef struct tagWINE_MCIDRIVER {
151         UINT                    wDeviceID;
152         UINT                    wType;
153         LPSTR                   lpstrElementName;
154         LPSTR                   lpstrDeviceType;
155         LPSTR                   lpstrAlias;
156         HDRVR                   hDriver;
157         DRIVERPROC16            driverProc;
158         DWORD                   dwPrivate;
159         YIELDPROC               lpfnYieldProc;
160         DWORD                   dwYieldData;
161         BOOL                    bIs32;
162         DWORD                   CreatorThread;
163         UINT                    uTypeCmdTable;
164         UINT                    uSpecificCmdTable;
165         struct tagWINE_MCIDRIVER*lpNext;
166 } WINE_MCIDRIVER, *LPWINE_MCIDRIVER;
167
168 #define WINE_TIMER_IS32 0x80
169
170 typedef struct tagWINE_TIMERENTRY {
171     UINT                        wDelay;
172     UINT                        wResol;
173     FARPROC16                   lpFunc;
174     DWORD                       dwUser;
175     UINT16                      wFlags;
176     UINT16                      wTimerID;
177     UINT                        uCurTime;
178     struct tagWINE_TIMERENTRY*  lpNext;
179 } WINE_TIMERENTRY, *LPWINE_TIMERENTRY;
180
181 enum mmioProcType {MMIO_PROC_16,MMIO_PROC_32A,MMIO_PROC_32W};
182
183 struct IOProcList
184 {
185     struct IOProcList*pNext;       /* Next item in linked list */
186     FOURCC            fourCC;      /* four-character code identifying IOProc */
187     LPMMIOPROC        pIOProc;     /* pointer to IProc */
188     enum mmioProcType type;        /* 16, 32A or 32W */
189     int               count;       /* number of objects linked to it */
190 };
191
192 typedef struct tagWINE_MMIO {
193     MMIOINFO                    info;
194     struct tagWINE_MMIO*        lpNext;
195     struct IOProcList*          ioProc;
196     BOOL                        bTmpIOProc : 1,
197                                 bBufferLoaded : 1;
198     SEGPTR                      segBuffer16;
199     DWORD                       dwFileSize;
200 } WINE_MMIO, *LPWINE_MMIO;
201
202 typedef struct tagWINE_PLAYSOUND {
203     BOOL                        bLoop : 1,
204                                 bAlloc : 1;
205     LPCWSTR                     pszSound;
206     HMODULE                     hMod;
207     DWORD                       fdwSound;
208     struct tagWINE_PLAYSOUND*   lpNext;
209 } WINE_PLAYSOUND, *LPWINE_PLAYSOUND;
210
211 typedef struct tagWINE_MM_IDATA {
212     /* winmm part */
213     HANDLE                      hWinMM32Instance;
214     HANDLE                      hWinMM16Instance;
215     CRITICAL_SECTION            cs;
216     /* mm timer part */
217     HANDLE                      hMMTimer;
218     DWORD                       mmSysTimeMS;
219     LPWINE_TIMERENTRY           lpTimerList;
220     int                         nSizeLpTimers;
221     LPWINE_TIMERENTRY           lpTimers;
222     /* mci part */
223     LPWINE_MCIDRIVER            lpMciDrvs;
224     /* low level drivers (unused yet) */
225     /* LPWINE_WAVE              lpWave; */
226     /* LPWINE_MIDI              lpMidi; */
227     /* LPWINE_MIXER             lpMixer; */
228     /* mmio part */
229     LPWINE_MMIO                 lpMMIO;
230     /* playsound and sndPlaySound */
231     WINE_PLAYSOUND*             lpPlaySound;
232     HANDLE                      psLastEvent;
233     HANDLE                      psStopEvent;
234 } WINE_MM_IDATA, *LPWINE_MM_IDATA;
235
236 /* function prototypes */
237
238 typedef LONG                    (*MCIPROC16)(DWORD, HDRVR16, WORD, DWORD, DWORD);
239 typedef LONG                    (*MCIPROC)(DWORD, HDRVR, DWORD, DWORD, DWORD);
240 typedef WINMM_MapType           (*MMDRV_MAPFUNC)(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2);
241 typedef WINMM_MapType           (*MMDRV_UNMAPFUNC)(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT ret);
242
243 LPWINE_DRIVER   DRIVER_FindFromHDrvr(HDRVR hDrvr);
244 BOOL            DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz);
245 LPWINE_DRIVER   DRIVER_TryOpenDriver32(LPCSTR fn, LPARAM lParam2);
246 void            DRIVER_UnloadAll(void);
247
248 BOOL            MMDRV_Init(void);
249 void            MMDRV_Exit(void);
250 UINT            MMDRV_GetNum(UINT);
251 LPWINE_MLD      MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
252                             DWORD* dwCallback, DWORD* dwInstance, BOOL bFrom32);
253 void            MMDRV_Free(HANDLE hndl, LPWINE_MLD mld);
254 DWORD           MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwParam2);
255 DWORD           MMDRV_Close(LPWINE_MLD mld, UINT wMsg);
256 LPWINE_MLD      MMDRV_Get(HANDLE hndl, UINT type, BOOL bCanBeID);
257 LPWINE_MLD      MMDRV_GetRelated(HANDLE hndl, UINT srcType, BOOL bSrcCanBeID, UINT dstTyped);
258 DWORD           MMDRV_Message(LPWINE_MLD mld, WORD wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
259 UINT            MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1, DWORD dwParam2);
260 BOOL            MMDRV_Is32(unsigned int);
261 void            MMDRV_InstallMap(unsigned int, MMDRV_MAPFUNC, MMDRV_UNMAPFUNC,
262                                  MMDRV_MAPFUNC, MMDRV_UNMAPFUNC, LPDRVCALLBACK);
263
264 BOOL            MCI_Init(void);
265 WINE_MCIDRIVER* MCI_GetDriver(UINT16 uDevID);
266 UINT            MCI_GetDriverFromString(LPCSTR str);
267 DWORD           MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr);
268 const char*     MCI_MessageToString(UINT16 wMsg);
269 UINT    WINAPI  MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
270 LRESULT         MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2);
271 DWORD           MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
272 DWORD           MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
273 DWORD           MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
274 UINT            MCI_SetCommandTable(void *table, UINT uDevType);
275
276 BOOL            WINMM_CheckForMMSystem(void);
277
278 UINT            MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD dwCallback,
279                            DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32);
280 UINT            MIDI_OutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID, DWORD dwCallback,
281                              DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
282 UINT            MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD dwCallback,
283                             DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
284 MMRESULT        MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
285                                 DWORD cMidi, DWORD dwCallback,
286                                 DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32);
287 UINT            WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
288                           LPCWAVEFORMATEX lpFormat, DWORD dwCallback, 
289                           DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
290
291 HMMIO           MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo,
292                           DWORD dwOpenFlags, enum mmioProcType type);
293 LPMMIOPROC      MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
294                                    DWORD dwFlags, enum mmioProcType type);
295 LRESULT         MMIO_SendMessage(HMMIO hmmio, UINT uMessage, LPARAM lParam1, 
296                                  LPARAM lParam2, enum mmioProcType type);
297 LPWINE_MMIO     MMIO_Get(HMMIO h);
298
299 WORD            TIME_SetEventInternal(UINT wDelay, UINT wResol,
300                                       FARPROC16 lpFunc, DWORD dwUser, UINT wFlags);
301 void            TIME_MMTimeStart(void);
302 void            TIME_MMTimeStop(void);
303
304 /* Global variables */
305 extern LPWINE_MM_IDATA  WINMM_IData;
306
307 /* pointers to 16 bit functions (if sibling MMSYSTEM.DLL is loaded
308  * NULL otherwise
309  */
310 extern  WINE_MMTHREAD*  (*pFnGetMMThread16)(HANDLE16);
311 extern  LPWINE_DRIVER   (*pFnOpenDriver16)(LPCSTR,LPCSTR,LPARAM);
312 extern  LRESULT         (*pFnCloseDriver16)(HDRVR16,LPARAM,LPARAM);
313 extern  LRESULT         (*pFnSendMessage16)(HDRVR16,UINT,LPARAM,LPARAM);
314 extern  WINMM_MapType   (*pFnMciMapMsg16To32A)(WORD,WORD,DWORD*);
315 extern  WINMM_MapType   (*pFnMciUnMapMsg16To32A)(WORD,WORD,DWORD);
316 extern  WINMM_MapType   (*pFnMciMapMsg32ATo16)(WORD,WORD,DWORD,DWORD*);
317 extern  WINMM_MapType   (*pFnMciUnMapMsg32ATo16)(WORD,WORD,DWORD,DWORD);
318 extern  LRESULT         (*pFnCallMMDrvFunc16)(FARPROC16,WORD,WORD,LONG,LONG,LONG);
319 extern  unsigned        (*pFnLoadMMDrvFunc16)(LPCSTR,LPWINE_DRIVER, LPWINE_MM_DRIVER);
320 extern  LRESULT         (*pFnMmioCallback16)(SEGPTR,LPMMIOINFO,UINT,LPARAM,LPARAM);
321
322 /* mmsystem (16 bit files) only functions */
323 void            MMDRV_Init16(void);
324 void            MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16);
325 void            MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16, const MMTIME* mmt32);
326
327 /* HANDLE16 -> HANDLE conversions */
328 #define HDRVR_32(h16)           ((HDRVR)(ULONG_PTR)(h16))
329 #define HMIDI_32(h16)           ((HMIDI)(ULONG_PTR)(h16))
330 #define HMIDIIN_32(h16)         ((HMIDIIN)(ULONG_PTR)(h16))
331 #define HMIDIOUT_32(h16)        ((HMIDIOUT)(ULONG_PTR)(h16))
332 #define HMIDISTRM_32(h16)       ((HMIDISTRM)(ULONG_PTR)(h16))
333 #define HMIXER_32(h16)          ((HMIXER)(ULONG_PTR)(h16))
334 #define HMIXEROBJ_32(h16)       ((HMIXEROBJ)(ULONG_PTR)(h16))
335 #define HMMIO_32(h16)           ((HMMIO)(ULONG_PTR)(h16))
336 #define HWAVE_32(h16)           ((HWAVE)(ULONG_PTR)(h16))
337 #define HWAVEIN_32(h16)         ((HWAVEIN)(ULONG_PTR)(h16))
338 #define HWAVEOUT_32(h16)        ((HWAVEOUT)(ULONG_PTR)(h16))
339
340 /* HANDLE -> HANDLE16 conversions */
341 #define HDRVR_16(h32)           (LOWORD(h32))
342 #define HMIDI_16(h32)           (LOWORD(h32))
343 #define HMIDIIN_16(h32)         (LOWORD(h32))
344 #define HMIDIOUT_16(h32)        (LOWORD(h32))
345 #define HMIDISTRM_16(h32)       (LOWORD(h32))
346 #define HMIXER_16(h32)          (LOWORD(h32))
347 #define HMIXEROBJ_16(h32)       (LOWORD(h32))
348 #define HMMIO_16(h32)           (LOWORD(h32))
349 #define HWAVE_16(h32)           (LOWORD(h32))
350 #define HWAVEIN_16(h32)         (LOWORD(h32))
351 #define HWAVEOUT_16(h32)        (LOWORD(h32))