Unify the constant used for error codes reporting mapping functions
[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 "mmddk.h"
26 #include "wownt32.h"
27
28 typedef DWORD (WINAPI *MessageProc16)(UINT16 wDevID, UINT16 wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
29 typedef DWORD (WINAPI *MessageProc32)(UINT wDevID, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
30
31 typedef enum {
32     WINMM_MAP_NOMEM,    /* ko, memory problem */
33     WINMM_MAP_MSGERROR, /* ko, unknown message */
34     WINMM_MAP_OK,       /* ok, no memory allocated. to be sent to the proc. */
35     WINMM_MAP_OKMEM,    /* ok, some memory allocated, need to call UnMapMsg. to be sent to the proc. */
36 } WINMM_MapType;
37
38 /* Who said goofy boy ? */
39 #define WINE_DI_MAGIC   0x900F1B01
40
41 typedef struct tagWINE_DRIVER
42 {
43     DWORD                       dwMagic;
44     /* as usual LPWINE_DRIVER == hDriver32 */
45     DWORD                       dwFlags;
46     union {
47         struct {
48             HMODULE                     hModule;
49             DRIVERPROC                  lpDrvProc;
50             DWORD                       dwDriverID;
51         } d32;
52         struct {
53             HDRVR16                     hDriver16;
54         } d16;
55     } d;
56     struct tagWINE_DRIVER*      lpPrevItem;
57     struct tagWINE_DRIVER*      lpNextItem;
58 } WINE_DRIVER, *LPWINE_DRIVER;
59
60 typedef struct tagWINE_MLD {
61 /* EPP struct tagWINE_MLD*      lpNext; */              /* not used so far */
62        UINT                     uDeviceID;
63        UINT                     type;
64        UINT                     mmdIndex;               /* index to low-level driver in MMDrvs table */
65        DWORD                    dwDriverInstance;       /* this value is driver related, as opposed to
66                                                          * opendesc.dwInstance which is client (callback) related */
67        WORD                     bFrom32;
68        WORD                     dwFlags;
69        DWORD                    dwCallback;
70        DWORD                    dwClientInstance;
71 } WINE_MLD, *LPWINE_MLD;
72
73 typedef struct  {
74        WINE_MLD                 mld;
75 } WINE_WAVE, *LPWINE_WAVE;
76
77 typedef struct {
78        WINE_MLD                 mld;
79        MIDIOPENDESC             mod;                    /* FIXME: should be removed */
80 } WINE_MIDI, *LPWINE_MIDI;
81
82 typedef struct {
83        WINE_MLD                 mld;
84 } WINE_MIXER, *LPWINE_MIXER;
85
86 extern  BOOL            MMDRV_Init(void);
87 extern  UINT            MMDRV_GetNum(UINT);
88 extern  LPWINE_MLD      MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
89                                     DWORD* dwCallback, DWORD* dwInstance, BOOL bFrom32);
90 extern  void            MMDRV_Free(HANDLE hndl, LPWINE_MLD mld);
91 extern  DWORD           MMDRV_Open(LPWINE_MLD mld, UINT wMsg, DWORD dwParam1, DWORD dwParam2);
92 extern  DWORD           MMDRV_Close(LPWINE_MLD mld, UINT wMsg);
93 extern  LPWINE_MLD      MMDRV_Get(HANDLE hndl, UINT type, BOOL bCanBeID);
94 extern  LPWINE_MLD      MMDRV_GetRelated(HANDLE hndl, UINT srcType, BOOL bSrcCanBeID, UINT dstTyped);
95 extern  DWORD           MMDRV_Message(LPWINE_MLD mld, WORD wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
96 extern  UINT            MMDRV_PhysicalFeatures(LPWINE_MLD mld, UINT uMsg, DWORD dwParam1, DWORD dwParam2);
97
98 #define MMDRV_AUX               0
99 #define MMDRV_MIXER             1
100 #define MMDRV_MIDIIN            2
101 #define MMDRV_MIDIOUT           3
102 #define MMDRV_WAVEIN            4
103 #define MMDRV_WAVEOUT           5
104 #define MMDRV_MAX               6
105
106 #define WINE_MMTHREAD_CREATED   0x4153494C      /* "BSIL" */
107 #define WINE_MMTHREAD_DELETED   0xDEADDEAD
108
109 typedef struct {
110        DWORD                    dwSignature;            /* 00 "BSIL" when ok, 0xDEADDEAD when being deleted */
111        DWORD                    dwCounter;              /* 04 > 1 when in mmThread functions */
112        HANDLE                   hThread;                /* 08 hThread */
113        DWORD                    dwThreadID;             /* 0C */
114        FARPROC16                fpThread;               /* 10 address of thread proc (segptr or lin depending on dwFlags) */
115        DWORD                    dwThreadPmt;            /* 14 parameter to be passed upon thread creation to fpThread */
116        DWORD                    dwSignalCount;          /* 18 counter used for signaling */
117        HANDLE                   hEvent;                 /* 1C event */
118        HANDLE                   hVxD;                   /* 20 return from OpenVxDHandle */
119        DWORD                    dwStatus;               /* 24 0x00, 0x10, 0x20, 0x30 */
120        DWORD                    dwFlags;                /* 28 dwFlags upon creation */
121        HANDLE16                 hTask;                  /* 2C handle to created task */
122 } WINE_MMTHREAD;
123
124 typedef struct tagWINE_MCIDRIVER {
125         UINT                    wDeviceID;
126         UINT                    wType;
127         LPSTR                   lpstrElementName;
128         LPSTR                   lpstrDeviceType;
129         LPSTR                   lpstrAlias;
130         HDRVR                   hDriver;
131         DRIVERPROC16            driverProc;
132         DWORD                   dwPrivate;
133         YIELDPROC               lpfnYieldProc;
134         DWORD                   dwYieldData;
135         BOOL                    bIs32;
136         HTASK16                 hCreatorTask;
137         DWORD                   CreatorThread;
138         UINT                    uTypeCmdTable;
139         UINT                    uSpecificCmdTable;
140         struct tagWINE_MCIDRIVER*lpNext;
141 } WINE_MCIDRIVER, *LPWINE_MCIDRIVER;
142
143 #define WINE_TIMER_IS32 0x80
144
145 typedef struct tagWINE_TIMERENTRY {
146     UINT                        wDelay;
147     UINT                        wResol;
148     FARPROC16                   lpFunc;
149     DWORD                       dwUser;
150     UINT16                      wFlags;
151     UINT16                      wTimerID;
152     UINT                        uCurTime;
153     struct tagWINE_TIMERENTRY*  lpNext;
154 } WINE_TIMERENTRY, *LPWINE_TIMERENTRY;
155
156 enum mmioProcType {MMIO_PROC_16,MMIO_PROC_32A,MMIO_PROC_32W};
157
158 struct IOProcList
159 {
160     struct IOProcList*pNext;       /* Next item in linked list */
161     FOURCC            fourCC;      /* four-character code identifying IOProc */
162     LPMMIOPROC        pIOProc;     /* pointer to IProc */
163     enum mmioProcType type;        /* 16, 32A or 32W */
164     int               count;       /* number of objects linked to it */
165 };
166
167 typedef struct tagWINE_MMIO {
168     MMIOINFO                    info;
169     struct tagWINE_MMIO*        lpNext;
170     struct IOProcList*          ioProc;
171     BOOL                        bTmpIOProc : 1,
172                                 bBufferLoaded : 1;
173     SEGPTR                      segBuffer16;
174     DWORD                       dwFileSize;
175 } WINE_MMIO, *LPWINE_MMIO;
176
177 typedef struct tagWINE_PLAYSOUND {
178     BOOL                        bLoop : 1,
179                                 bAlloc : 1;
180     LPCWSTR                     pszSound;
181     HMODULE                     hMod;
182     DWORD                       fdwSound;
183     struct tagWINE_PLAYSOUND*   lpNext;
184 } WINE_PLAYSOUND, *LPWINE_PLAYSOUND;
185
186 typedef struct tagWINE_MM_IDATA {
187     /* winmm part */
188     HANDLE                      hWinMM32Instance;
189     HANDLE                      hWinMM16Instance;
190     HANDLE                      h16Module32;
191     CRITICAL_SECTION            cs;
192     /* mm timer part */
193     HANDLE                      hMMTimer;
194     DWORD                       mmSysTimeMS;
195     LPWINE_TIMERENTRY           lpTimerList;
196     int                         nSizeLpTimers;
197     LPWINE_TIMERENTRY           lpTimers;
198     /* mci part */
199     LPWINE_MCIDRIVER            lpMciDrvs;
200     /* low level drivers (unused yet) */
201     /* LPWINE_WAVE              lpWave; */
202     /* LPWINE_MIDI              lpMidi; */
203     /* LPWINE_MIXER             lpMixer; */
204     /* mmio part */
205     LPWINE_MMIO                 lpMMIO;
206     LRESULT (CALLBACK*          pFnMmioCallback16)(SEGPTR,LPMMIOINFO,UINT,LPARAM,LPARAM);
207     /* playsound and sndPlaySound */
208     WINE_PLAYSOUND*             lpPlaySound;
209     HANDLE                      psLastEvent;
210     HANDLE                      psStopEvent;
211 } WINE_MM_IDATA, *LPWINE_MM_IDATA;
212
213 /* function prototypes */
214
215 typedef LONG                    (*MCIPROC16)(DWORD, HDRVR16, WORD, DWORD, DWORD);
216 typedef LONG                    (*MCIPROC)(DWORD, HDRVR, DWORD, DWORD, DWORD);
217
218 extern LPWINE_DRIVER            DRIVER_FindFromHDrvr(HDRVR hDrvr);
219 extern BOOL                     DRIVER_GetLibName(LPCSTR keyName, LPCSTR sectName, LPSTR buf, int sz);
220 extern LPWINE_DRIVER            DRIVER_TryOpenDriver32(LPCSTR fn, LPARAM lParam2);
221
222 extern LPWINE_MCIDRIVER         MCI_GetDriver(UINT16 uDevID);
223 extern UINT                     MCI_GetDriverFromString(LPCSTR str);
224 extern DWORD                    MCI_WriteString(LPSTR lpDstStr, DWORD dstSize, LPCSTR lpSrcStr);
225 extern const char*              MCI_MessageToString(UINT16 wMsg);
226
227 extern UINT             WINAPI  MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
228
229 extern LRESULT                  MCI_CleanUp(LRESULT dwRet, UINT wMsg, DWORD dwParam2, BOOL bIs32);
230
231 extern DWORD                    MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2, BOOL bFrom32);
232 extern DWORD                    MCI_SendCommandFrom32(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
233 extern DWORD                    MCI_SendCommandFrom16(UINT wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2);
234
235 void            CALLBACK        WINE_mmThreadEntryPoint(DWORD _pmt);
236
237 void                            MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16);
238 void                            MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16, const MMTIME* mmt32);
239
240 UINT                            MMSYSTEM_mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD dwCallback,
241                                                    DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32);
242 UINT                            MMSYSTEM_midiOutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID, DWORD dwCallback,
243                                                      DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
244 UINT                            MMSYSTEM_midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD dwCallback,
245                                                     DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
246 MMRESULT                        MMSYSTEM_MidiStream_Open(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
247                                                          DWORD cMidi, DWORD dwCallback,
248                                                          DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32);
249 UINT                            MMSYSTEM_waveOpen(HANDLE* lphndl, UINT uDeviceID, UINT uType,
250                                                   const LPWAVEFORMATEX lpFormat, DWORD dwCallback, 
251                                                   DWORD dwInstance, DWORD dwFlags, BOOL bFrom32);
252 WORD                            timeSetEventInternal(UINT wDelay, UINT wResol,
253                                                      FARPROC16 lpFunc, DWORD dwUser, UINT wFlags);
254 HMMIO                           MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo,
255                                           DWORD dwOpenFlags, enum mmioProcType type);
256 LPMMIOPROC                      MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
257                                                    DWORD dwFlags, enum mmioProcType type);
258 LRESULT                         MMIO_SendMessage(HMMIO hmmio, UINT uMessage, LPARAM lParam1, 
259                                                  LPARAM lParam2, enum mmioProcType type);
260 LPWINE_MMIO                     MMIO_Get(LPWINE_MM_IDATA iData, HMMIO h);
261
262 BOOL                            MULTIMEDIA_MciInit(void);
263 LPWINE_MM_IDATA                 MULTIMEDIA_GetIData(void);
264 BOOL                            MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode);
265
266 LPWINE_MM_IDATA                 TIME_MMTimeStart(void);
267 void                            TIME_MMTimeStop(void);
268
269 /* HANDLE16 -> HANDLE conversions */
270 #define HDRVR_32(h16)           ((HDRVR)(ULONG_PTR)(h16))
271 #define HMIDI_32(h16)           ((HMIDI)(ULONG_PTR)(h16))
272 #define HMIDIIN_32(h16)         ((HMIDIIN)(ULONG_PTR)(h16))
273 #define HMIDIOUT_32(h16)        ((HMIDIOUT)(ULONG_PTR)(h16))
274 #define HMIDISTRM_32(h16)       ((HMIDISTRM)(ULONG_PTR)(h16))
275 #define HMIXER_32(h16)          ((HMIXER)(ULONG_PTR)(h16))
276 #define HMIXEROBJ_32(h16)       ((HMIXEROBJ)(ULONG_PTR)(h16))
277 #define HMMIO_32(h16)           ((HMMIO)(ULONG_PTR)(h16))
278 #define HWAVE_32(h16)           ((HWAVE)(ULONG_PTR)(h16))
279 #define HWAVEIN_32(h16)         ((HWAVEIN)(ULONG_PTR)(h16))
280 #define HWAVEOUT_32(h16)        ((HWAVEOUT)(ULONG_PTR)(h16))
281
282 /* HANDLE -> HANDLE16 conversions */
283 #define HDRVR_16(h32)           (LOWORD(h32))
284 #define HMIDI_16(h32)           (LOWORD(h32))
285 #define HMIDIIN_16(h32)         (LOWORD(h32))
286 #define HMIDIOUT_16(h32)        (LOWORD(h32))
287 #define HMIDISTRM_16(h32)       (LOWORD(h32))
288 #define HMIXER_16(h32)          (LOWORD(h32))
289 #define HMIXEROBJ_16(h32)       (LOWORD(h32))
290 #define HMMIO_16(h32)           (LOWORD(h32))
291 #define HWAVE_16(h32)           (LOWORD(h32))
292 #define HWAVEIN_16(h32)         (LOWORD(h32))
293 #define HWAVEOUT_16(h32)        (LOWORD(h32))