Create the system heap event before the shared mapping to avoid a race
[wine] / dlls / 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 <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "mmddk.h"
30
31 typedef DWORD (WINAPI *MessageProc16)(UINT16 wDevID, UINT16 wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
32 typedef DWORD (WINAPI *MessageProc32)(UINT wDevID, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
33
34 typedef enum {
35     WINMM_MAP_NOMEM,    /* ko, memory problem */
36     WINMM_MAP_MSGERROR, /* ko, unknown message */
37     WINMM_MAP_OK,       /* ok, no memory allocated. to be sent to the proc. */
38     WINMM_MAP_OKMEM,    /* ok, some memory allocated, need to call UnMapMsg. to be sent to the proc. */
39 } WINMM_MapType;
40
41 /* Who said goofy boy ? */
42 #define WINE_DI_MAGIC   0x900F1B01
43
44 typedef struct tagWINE_DRIVER
45 {
46     DWORD                       dwMagic;
47     /* as usual LPWINE_DRIVER == hDriver32 */
48     DWORD                       dwFlags;
49     union {
50         struct {
51             HMODULE                     hModule;
52             DRIVERPROC                  lpDrvProc;
53             DWORD                       dwDriverID;
54         } d32;
55         struct {
56             UINT16                      hDriver16;
57         } d16;
58     } d;
59     struct tagWINE_DRIVER*      lpPrevItem;
60     struct tagWINE_DRIVER*      lpNextItem;
61 } WINE_DRIVER, *LPWINE_DRIVER;
62
63 typedef DWORD   (CALLBACK *WINEMM_msgFunc16)(UINT16, WORD, DWORD, DWORD, DWORD);
64 typedef DWORD   (CALLBACK *WINEMM_msgFunc32)(UINT  , UINT, DWORD, DWORD, DWORD);
65
66 /* for each loaded driver and each known type of driver, this structure contains
67  * the information needed to access it
68  */
69 typedef struct tagWINE_MM_DRIVER_PART {
70     int                         nIDMin;         /* lower bound of global indexes for this type */
71     int                         nIDMax;         /* hhigher bound of global indexes for this type */
72     union {
73         WINEMM_msgFunc32        fnMessage32;    /* pointer to function */
74         WINEMM_msgFunc16        fnMessage16;
75     } u;
76 } WINE_MM_DRIVER_PART;
77
78 #define MMDRV_AUX               0
79 #define MMDRV_MIXER             1
80 #define MMDRV_MIDIIN            2
81 #define MMDRV_MIDIOUT           3
82 #define MMDRV_WAVEIN            4
83 #define MMDRV_WAVEOUT           5
84 #define MMDRV_MAX               6
85
86 /* each low-level .drv will be associated with an instance of this structure */
87 typedef struct tagWINE_MM_DRIVER {
88     HDRVR                       hDriver;
89     LPSTR                       drvname;        /* name of the driver */
90     BOOL                        bIs32 : 1,      /* TRUE if 32 bit driver, FALSE for 16 */
91                                 bIsMapper : 1;  /* TRUE if mapper */
92     WINE_MM_DRIVER_PART         parts[MMDRV_MAX];/* Information for all known types */
93 } WINE_MM_DRIVER, *LPWINE_MM_DRIVER;
94
95 typedef struct tagWINE_MLD {
96 /* EPP struct tagWINE_MLD*      lpNext; */              /* not used so far */
97        UINT                     uDeviceID;
98        UINT                     type;
99        UINT                     mmdIndex;               /* index to low-level driver in MMDrvs table */
100        DWORD                    dwDriverInstance;       /* this value is driver related, as opposed to
101                                                          * opendesc.dwInstance which is client (callback) related */
102        WORD                     bFrom32;
103        WORD                     dwFlags;
104        DWORD                    dwCallback;
105        DWORD                    dwClientInstance;
106 } WINE_MLD, *LPWINE_MLD;
107
108 typedef struct  {
109        WINE_MLD                 mld;
110 } WINE_WAVE, *LPWINE_WAVE;
111
112 typedef struct {
113        WINE_MLD                 mld;
114        MIDIOPENDESC             mod;                    /* FIXME: should be removed */
115 } WINE_MIDI, *LPWINE_MIDI;
116
117 typedef struct {
118        WINE_MLD                 mld;
119 } WINE_MIXER, *LPWINE_MIXER;
120
121 #define WINE_MMTHREAD_CREATED   0x4153494C      /* "BSIL" */
122 #define WINE_MMTHREAD_DELETED   0xDEADDEAD
123
124 typedef struct {
125        DWORD                    dwSignature;            /* 00 "BSIL" when ok, 0xDEADDEAD when being deleted */
126        DWORD                    dwCounter;              /* 04 > 1 when in mmThread functions */
127        HANDLE                   hThread;                /* 08 hThread */
128        DWORD                    dwThreadID;             /* 0C */
129        DWORD                    fpThread;               /* 10 address of thread proc (segptr or lin depending on dwFlags) */
130        DWORD                    dwThreadPmt;            /* 14 parameter to be passed upon thread creation to fpThread */
131        DWORD                    dwSignalCount;          /* 18 counter used for signaling */
132        HANDLE                   hEvent;                 /* 1C event */
133        HANDLE                   hVxD;                   /* 20 return from OpenVxDHandle */
134        DWORD                    dwStatus;               /* 24 0x00, 0x10, 0x20, 0x30 */
135        DWORD                    dwFlags;                /* 28 dwFlags upon creation */
136        UINT16                   hTask;                  /* 2C handle to created task */
137 } WINE_MMTHREAD;
138
139 typedef struct tagWINE_MCIDRIVER {
140         UINT                    wDeviceID;
141         UINT                    wType;
142         LPSTR                   lpstrElementName;
143         LPSTR                   lpstrDeviceType;
144         LPSTR                   lpstrAlias;
145         HDRVR                   hDriver;
146         DWORD                   dwPrivate;
147         YIELDPROC               lpfnYieldProc;
148         DWORD                   dwYieldData;
149         BOOL                    bIs32;
150         DWORD                   CreatorThread;
151         UINT                    uTypeCmdTable;
152         UINT                    uSpecificCmdTable;
153         struct tagWINE_MCIDRIVER*lpNext;
154 } WINE_MCIDRIVER, *LPWINE_MCIDRIVER;
155
156 #define WINE_TIMER_IS32 0x80
157
158 typedef struct tagWINE_TIMERENTRY {
159     UINT                        wDelay;
160     UINT                        wResol;
161     LPTIMECALLBACK              lpFunc; /* can be lots of things */
162     DWORD                       dwUser;
163     UINT16                      wFlags;
164     UINT16                      wTimerID;
165     UINT                        uCurTime;
166     struct tagWINE_TIMERENTRY*  lpNext;
167 } WINE_TIMERENTRY, *LPWINE_TIMERENTRY;
168
169 enum mmioProcType {MMIO_PROC_16,MMIO_PROC_32A,MMIO_PROC_32W};
170
171 struct IOProcList
172 {
173     struct IOProcList*pNext;       /* Next item in linked list */
174     FOURCC            fourCC;      /* four-character code identifying IOProc */
175     LPMMIOPROC        pIOProc;     /* pointer to IProc */
176     enum mmioProcType type;        /* 16, 32A or 32W */
177     int               count;       /* number of objects linked to it */
178 };
179
180 typedef struct tagWINE_MMIO {
181     MMIOINFO                    info;
182     struct tagWINE_MMIO*        lpNext;
183     struct IOProcList*          ioProc;
184     BOOL                        bTmpIOProc : 1,
185                                 bBufferLoaded : 1;
186     DWORD                       segBuffer16;
187     DWORD                       dwFileSize;
188 } WINE_MMIO, *LPWINE_MMIO;
189
190 typedef struct tagWINE_PLAYSOUND {
191     BOOL                        bLoop : 1,
192                                 bAlloc : 1;
193     LPCWSTR                     pszSound;
194     HMODULE                     hMod;
195     DWORD                       fdwSound;
196     HANDLE                      hThread;
197     struct tagWINE_PLAYSOUND*   lpNext;
198 } WINE_PLAYSOUND, *LPWINE_PLAYSOUND;
199
200 typedef struct tagWINE_MM_IDATA {
201     /* winmm part */
202     HANDLE                      hWinMM32Instance;
203     HANDLE                      hWinMM16Instance;
204     CRITICAL_SECTION            cs;
205     /* mci part */
206     LPWINE_MCIDRIVER            lpMciDrvs;
207     /* low level drivers (unused yet) */
208     /* LPWINE_WAVE              lpWave; */
209     /* LPWINE_MIDI              lpMidi; */
210     /* LPWINE_MIXER             lpMixer; */
211     /* mmio part */
212     LPWINE_MMIO                 lpMMIO;
213     /* playsound and sndPlaySound */
214     WINE_PLAYSOUND*             lpPlaySound;
215     HANDLE                      psLastEvent;
216     HANDLE                      psStopEvent;
217 } WINE_MM_IDATA, *LPWINE_MM_IDATA;
218
219 /* function prototypes */
220
221 typedef LONG                    (*MCIPROC)(DWORD, HDRVR, DWORD, DWORD, DWORD);
222 typedef WINMM_MapType           (*MMDRV_MAPFUNC)(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2);
223 typedef WINMM_MapType           (*MMDRV_UNMAPFUNC)(UINT wMsg, LPDWORD lpdwUser, LPDWORD lpParam1, LPDWORD lpParam2, MMRESULT ret);
224
225 LPWINE_DRIVER   DRIVER_FindFromHDrvr(HDRVR hDrvr);
226 BOOL            DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz);
227 LPWINE_DRIVER   DRIVER_TryOpenDriver32(LPCSTR fn, LPARAM lParam2);
228 void            DRIVER_UnloadAll(void);
229
230 BOOL            MMDRV_Init(void);
231 void            MMDRV_Exit(void);
232 UINT            MMDRV_GetNum(UINT);
233 LPWINE_MLD      MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
234                             DWORD* dwCallback, DWORD* dwInstance, BOOL bFrom32);
235 void            MMDRV_Free(HANDLE hndl, LPWINE_MLD mld);
236 DWORD           MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwParam2);
237 DWORD           MMDRV_Close(LPWINE_MLD mld, UINT wMsg);
238 LPWINE_MLD      MMDRV_Get(HANDLE hndl, UINT type, BOOL bCanBeID);
239 LPWINE_MLD      MMDRV_GetRelated(HANDLE hndl, UINT srcType, BOOL bSrcCanBeID, UINT dstTyped);
240 DWORD           MMDRV_Message(LPWINE_MLD mld, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2, BOOL bFrom32);
241 UINT            MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1, DWORD dwParam2);
242 BOOL            MMDRV_Is32(unsigned int);
243 void            MMDRV_InstallMap(unsigned int, MMDRV_MAPFUNC, MMDRV_UNMAPFUNC,
244                                  MMDRV_MAPFUNC, MMDRV_UNMAPFUNC, LPDRVCALLBACK);
245
246 BOOL            MCI_Init(void);
247 WINE_MCIDRIVER* MCI_GetDriver(UINT16 uDevID);
248 UINT            MCI_GetDriverFromString(LPCSTR str);
249 DWORD           MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr);
250 const char*     MCI_MessageToString(UINT16 wMsg);
251 UINT    WINAPI  MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
252 LRESULT         MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2);
253 DWORD           MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
254 DWORD           MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
255 DWORD           MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
256 UINT            MCI_SetCommandTable(void *table, UINT uDevType);
257
258 BOOL            WINMM_CheckForMMSystem(void);
259
260 UINT            MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD dwCallback,
261                            DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32);
262 UINT            MIDI_OutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID, DWORD dwCallback,
263                              DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
264 UINT            MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD dwCallback,
265                             DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
266 MMRESULT        MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
267                                 DWORD cMidi, DWORD dwCallback,
268                                 DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32);
269 UINT            WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
270                           const LPWAVEFORMATEX lpFormat, DWORD dwCallback, 
271                           DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
272
273 HMMIO           MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo,
274                           DWORD dwOpenFlags, enum mmioProcType type);
275 LPMMIOPROC      MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
276                                    DWORD dwFlags, enum mmioProcType type);
277 LRESULT         MMIO_SendMessage(HMMIO hmmio, UINT uMessage, LPARAM lParam1, 
278                                  LPARAM lParam2, enum mmioProcType type);
279 LPWINE_MMIO     MMIO_Get(HMMIO h);
280
281 WORD            TIME_SetEventInternal(UINT wDelay, UINT wResol, LPTIMECALLBACK lpFunc,
282                                       DWORD dwUser, UINT wFlags);
283 void            TIME_MMTimeStart(void);
284 void            TIME_MMTimeStop(void);
285
286 /* Global variables */
287 extern LPWINE_MM_IDATA  WINMM_IData;
288 extern DWORD            WINMM_SysTimeMS;
289
290 /* pointers to 16 bit functions (if sibling MMSYSTEM.DLL is loaded
291  * NULL otherwise
292  */
293 extern  WINE_MMTHREAD*  (*pFnGetMMThread16)(UINT16);
294 extern  LPWINE_DRIVER   (*pFnOpenDriver16)(LPCSTR,LPCSTR,LPARAM);
295 extern  LRESULT         (*pFnCloseDriver16)(UINT16,LPARAM,LPARAM);
296 extern  LRESULT         (*pFnSendMessage16)(UINT16,UINT,LPARAM,LPARAM);
297 extern  WINMM_MapType   (*pFnMciMapMsg16To32A)(WORD,WORD,DWORD*);
298 extern  WINMM_MapType   (*pFnMciUnMapMsg16To32A)(WORD,WORD,DWORD);
299 extern  WINMM_MapType   (*pFnMciMapMsg32ATo16)(WORD,WORD,DWORD,DWORD*);
300 extern  WINMM_MapType   (*pFnMciUnMapMsg32ATo16)(WORD,WORD,DWORD,DWORD);
301 extern  LRESULT         (*pFnCallMMDrvFunc16)(DWORD /* in fact FARPROC16 */,WORD,WORD,LONG,LONG,LONG);
302 extern  unsigned        (*pFnLoadMMDrvFunc16)(LPCSTR,LPWINE_DRIVER, LPWINE_MM_DRIVER);
303 extern  LRESULT         (*pFnMmioCallback16)(DWORD,LPMMIOINFO,UINT,LPARAM,LPARAM);
304 extern  void            (WINAPI *pFnReleaseThunkLock)(DWORD*);
305 extern  void            (WINAPI *pFnRestoreThunkLock)(DWORD);
306 /* GetDriverFlags() returned bits is not documented (nor the call itself)
307  * Here are Wine only definitions of the bits
308  */
309 #define WINE_GDF_EXIST  0x80000000
310 #define WINE_GDF_16BIT  0x10000000