wininet: Directly return error from HTTP_HttpSendRequest.
[wine/multimedia.git] / dlls / mmsystem.dll16 / mci16.c
blobf09923acf3a6d96d6b9d36dd41886943e3de610b
1 /*
2 * MMSYSTEM functions
4 * Copyright 1993 Martin Ayotte
5 * 1998-2003,2009 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <string.h>
24 #include <stdio.h>
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "mmsystem.h"
31 #include "winternl.h"
32 #include "wownt32.h"
33 #include "winnls.h"
35 #include "wine/winuser16.h"
36 #include "winemm16.h"
37 #include "digitalv.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(mmsys);
43 /**************************************************************************
44 * MCI_MessageToString [internal]
46 static const char* MCI_MessageToString(UINT wMsg)
48 static char buffer[100];
50 #define CASE(s) case (s): return #s
52 switch (wMsg) {
53 CASE(DRV_LOAD);
54 CASE(DRV_ENABLE);
55 CASE(DRV_OPEN);
56 CASE(DRV_CLOSE);
57 CASE(DRV_DISABLE);
58 CASE(DRV_FREE);
59 CASE(DRV_CONFIGURE);
60 CASE(DRV_QUERYCONFIGURE);
61 CASE(DRV_INSTALL);
62 CASE(DRV_REMOVE);
63 CASE(DRV_EXITSESSION);
64 CASE(DRV_EXITAPPLICATION);
65 CASE(DRV_POWER);
66 CASE(MCI_BREAK);
67 CASE(MCI_CLOSE);
68 CASE(MCI_CLOSE_DRIVER);
69 CASE(MCI_COPY);
70 CASE(MCI_CUE);
71 CASE(MCI_CUT);
72 CASE(MCI_DELETE);
73 CASE(MCI_ESCAPE);
74 CASE(MCI_FREEZE);
75 CASE(MCI_PAUSE);
76 CASE(MCI_PLAY);
77 CASE(MCI_GETDEVCAPS);
78 CASE(MCI_INFO);
79 CASE(MCI_LOAD);
80 CASE(MCI_OPEN);
81 CASE(MCI_OPEN_DRIVER);
82 CASE(MCI_PASTE);
83 CASE(MCI_PUT);
84 CASE(MCI_REALIZE);
85 CASE(MCI_RECORD);
86 CASE(MCI_RESUME);
87 CASE(MCI_SAVE);
88 CASE(MCI_SEEK);
89 CASE(MCI_SET);
90 CASE(MCI_SPIN);
91 CASE(MCI_STATUS);
92 CASE(MCI_STEP);
93 CASE(MCI_STOP);
94 CASE(MCI_SYSINFO);
95 CASE(MCI_UNFREEZE);
96 CASE(MCI_UPDATE);
97 CASE(MCI_WHERE);
98 CASE(MCI_WINDOW);
99 /* constants for digital video */
100 CASE(MCI_CAPTURE);
101 CASE(MCI_MONITOR);
102 CASE(MCI_RESERVE);
103 CASE(MCI_SETAUDIO);
104 CASE(MCI_SIGNAL);
105 CASE(MCI_SETVIDEO);
106 CASE(MCI_QUALITY);
107 CASE(MCI_LIST);
108 CASE(MCI_UNDO);
109 CASE(MCI_CONFIGURE);
110 CASE(MCI_RESTORE);
111 #undef CASE
112 default:
113 sprintf(buffer, "MCI_<<%04X>>", wMsg);
114 return buffer;
118 static LPWSTR MCI_strdupAtoW( LPCSTR str )
120 LPWSTR ret;
121 INT len;
123 if (!str) return NULL;
124 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
125 ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
126 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
127 return ret;
130 /**************************************************************************
131 * MCI_MapMsg16To32W [internal]
133 static MMSYSTEM_MapType MCI_MapMsg16To32W(WORD wMsg, DWORD dwFlags, DWORD_PTR* lParam)
135 if (*lParam == 0)
136 return MMSYSTEM_MAP_OK;
137 /* FIXME: to add also (with seg/linear modifications to do):
138 * MCI_LIST, MCI_LOAD, MCI_QUALITY, MCI_RESERVE, MCI_RESTORE, MCI_SAVE
139 * MCI_SETAUDIO, MCI_SETTUNER, MCI_SETVIDEO
141 switch (wMsg) {
142 /* case MCI_CAPTURE */
143 case MCI_CLOSE:
144 case MCI_CLOSE_DRIVER:
145 case MCI_CONFIGURE:
146 case MCI_COPY:
147 case MCI_CUE:
148 case MCI_CUT:
149 case MCI_DELETE:
150 case MCI_FREEZE:
151 case MCI_GETDEVCAPS:
152 /* case MCI_INDEX: */
153 /* case MCI_MARK: */
154 /* case MCI_MONITOR: */
155 case MCI_PASTE:
156 case MCI_PAUSE:
157 case MCI_PLAY:
158 case MCI_PUT:
159 case MCI_REALIZE:
160 case MCI_RECORD:
161 case MCI_RESUME:
162 case MCI_SEEK:
163 case MCI_SET:
164 /* case MCI_SETTIMECODE:*/
165 /* case MCI_SIGNAL:*/
166 case MCI_SPIN:
167 case MCI_STATUS: /* FIXME: is wrong for digital video */
168 case MCI_STEP:
169 case MCI_STOP:
170 /* case MCI_UNDO: */
171 case MCI_UNFREEZE:
172 case MCI_UPDATE:
173 case MCI_WHERE:
174 *lParam = (DWORD)MapSL(*lParam);
175 return MMSYSTEM_MAP_OK;
176 case MCI_WINDOW:
177 /* in fact, I would also need the dwFlags... to see
178 * which members of lParam are effectively used
180 *lParam = (DWORD)MapSL(*lParam);
181 FIXME("Current mapping may be wrong\n");
182 break;
183 case MCI_BREAK:
185 LPMCI_BREAK_PARMS mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_BREAK_PARMS));
186 LPMCI_BREAK_PARMS16 mbp16 = MapSL(*lParam);
188 if (mbp32) {
189 mbp32->dwCallback = mbp16->dwCallback;
190 mbp32->nVirtKey = mbp16->nVirtKey;
191 mbp32->hwndBreak = HWND_32(mbp16->hwndBreak);
192 } else {
193 return MMSYSTEM_MAP_NOMEM;
195 *lParam = (DWORD)mbp32;
197 return MMSYSTEM_MAP_OKMEM;
198 case MCI_ESCAPE:
200 LPMCI_VD_ESCAPE_PARMSW mvep32w = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_VD_ESCAPE_PARMSW));
201 LPMCI_VD_ESCAPE_PARMS16 mvep16 = MapSL(*lParam);
203 if (mvep32w) {
204 mvep32w->dwCallback = mvep16->dwCallback;
205 mvep32w->lpstrCommand = MCI_strdupAtoW(MapSL(mvep16->lpstrCommand));
206 } else {
207 return MMSYSTEM_MAP_NOMEM;
209 *lParam = (DWORD)mvep32w;
211 return MMSYSTEM_MAP_OKMEM;
212 case MCI_INFO:
214 LPMCI_INFO_PARMSW mip32w = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_INFO_PARMSW));
215 LPMCI_INFO_PARMS16 mip16 = MapSL(*lParam);
217 /* FIXME this is wrong if device is of type
218 * MCI_DEVTYPE_DIGITAL_VIDEO, some members are not mapped
220 if (mip32w) {
221 *(LPMCI_INFO_PARMS16*)(mip32w) = mip16;
222 mip32w = (LPMCI_INFO_PARMSW)((char*)mip32w + sizeof(LPMCI_INFO_PARMS16));
223 mip32w->dwCallback = mip16->dwCallback;
224 mip32w->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mip16->dwRetSize * sizeof(WCHAR));
225 mip32w->dwRetSize = mip16->dwRetSize * sizeof(WCHAR);
226 } else {
227 return MMSYSTEM_MAP_NOMEM;
229 *lParam = (DWORD)mip32w;
231 return MMSYSTEM_MAP_OKMEM;
232 case MCI_OPEN:
233 case MCI_OPEN_DRIVER:
235 LPMCI_OPEN_PARMSW mop32w = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_OPEN_PARMSW) + 2 * sizeof(DWORD));
236 LPMCI_OPEN_PARMS16 mop16 = MapSL(*lParam);
238 if (mop32w) {
239 *(LPMCI_OPEN_PARMS16*)(mop32w) = mop16;
240 mop32w = (LPMCI_OPEN_PARMSW)((char*)mop32w + sizeof(LPMCI_OPEN_PARMS16));
241 mop32w->dwCallback = mop16->dwCallback;
242 mop32w->wDeviceID = mop16->wDeviceID;
243 if( ( dwFlags & ( MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID)) == MCI_OPEN_TYPE)
244 mop32w->lpstrDeviceType = MCI_strdupAtoW(MapSL(mop16->lpstrDeviceType));
245 else
246 mop32w->lpstrDeviceType = (LPWSTR) mop16->lpstrDeviceType;
247 if( ( dwFlags & ( MCI_OPEN_ELEMENT | MCI_OPEN_ELEMENT_ID)) == MCI_OPEN_ELEMENT)
248 mop32w->lpstrElementName = MCI_strdupAtoW(MapSL(mop16->lpstrElementName));
249 else
250 mop32w->lpstrElementName = (LPWSTR) mop16->lpstrElementName;
251 if( ( dwFlags & MCI_OPEN_ALIAS))
252 mop32w->lpstrAlias = MCI_strdupAtoW(MapSL(mop16->lpstrAlias));
253 else
254 mop32w->lpstrAlias = (LPWSTR) mop16->lpstrAlias;
255 /* copy extended information if any...
256 * FIXME: this may seg fault if initial structure does not contain them and
257 * the reads after msip16 fail under LDT limits...
258 * NOTE: this should be split in two. First pass, while calling MCI_OPEN, and
259 * should not take care of extended parameters, and should be used by MCI_Open
260 * to fetch uDevType. When, this is known, the mapping for sending the
261 * MCI_OPEN_DRIVER shall be done depending on uDevType.
263 memcpy(mop32w + 1, mop16 + 1, 2 * sizeof(DWORD));
264 } else {
265 return MMSYSTEM_MAP_NOMEM;
267 *lParam = (DWORD)mop32w;
269 return MMSYSTEM_MAP_OKMEM;
270 case MCI_SYSINFO:
272 LPMCI_SYSINFO_PARMSW msip32w = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_SYSINFO_PARMSW));
273 LPMCI_SYSINFO_PARMS16 msip16 = MapSL(*lParam);
275 if (msip32w) {
276 *(LPMCI_SYSINFO_PARMS16*)(msip32w) = msip16;
277 msip32w = (LPMCI_SYSINFO_PARMSW)((char*)msip32w + sizeof(LPMCI_OPEN_PARMS16));
278 msip32w->dwCallback = msip16->dwCallback;
279 msip32w->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, msip16->dwRetSize * sizeof(WCHAR));
280 msip32w->dwRetSize = msip16->dwRetSize;
281 msip32w->dwNumber = msip16->dwNumber;
282 msip32w->wDeviceType = msip16->wDeviceType;
283 } else {
284 return MMSYSTEM_MAP_NOMEM;
286 *lParam = (DWORD)msip32w;
288 return MMSYSTEM_MAP_OKMEM;
289 case MCI_SOUND:
291 LPMCI_SOUND_PARMSW mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_SOUND_PARMSW));
292 LPMCI_SOUND_PARMS16 mbp16 = MapSL(*lParam);
294 if (mbp32) {
295 mbp32->dwCallback = mbp16->dwCallback;
296 mbp32->lpstrSoundName = MCI_strdupAtoW(MapSL(mbp16->lpstrSoundName));
297 } else {
298 return MMSYSTEM_MAP_NOMEM;
300 *lParam = (DWORD)mbp32;
302 return MMSYSTEM_MAP_OKMEM;
303 case DRV_LOAD:
304 case DRV_ENABLE:
305 case DRV_OPEN:
306 case DRV_CLOSE:
307 case DRV_DISABLE:
308 case DRV_FREE:
309 case DRV_CONFIGURE:
310 case DRV_QUERYCONFIGURE:
311 case DRV_INSTALL:
312 case DRV_REMOVE:
313 case DRV_EXITSESSION:
314 case DRV_EXITAPPLICATION:
315 case DRV_POWER:
316 FIXME("This is a hack\n");
317 return MMSYSTEM_MAP_OK;
318 default:
319 FIXME("Don't know how to map msg=%s\n", MCI_MessageToString(wMsg));
321 return MMSYSTEM_MAP_MSGERROR;
324 /**************************************************************************
325 * MCI_UnMapMsg16To32W [internal]
327 static MMSYSTEM_MapType MCI_UnMapMsg16To32W(WORD wMsg, DWORD dwFlags, DWORD_PTR lParam)
329 switch (wMsg) {
330 /* case MCI_CAPTURE */
331 case MCI_CLOSE:
332 case MCI_CLOSE_DRIVER:
333 case MCI_CONFIGURE:
334 case MCI_COPY:
335 case MCI_CUE:
336 case MCI_CUT:
337 case MCI_DELETE:
338 case MCI_FREEZE:
339 case MCI_GETDEVCAPS:
340 /* case MCI_INDEX: */
341 /* case MCI_MARK: */
342 /* case MCI_MONITOR: */
343 case MCI_PASTE:
344 case MCI_PAUSE:
345 case MCI_PLAY:
346 case MCI_PUT:
347 case MCI_REALIZE:
348 case MCI_RECORD:
349 case MCI_RESUME:
350 case MCI_SEEK:
351 case MCI_SET:
352 /* case MCI_SETTIMECODE:*/
353 /* case MCI_SIGNAL:*/
354 case MCI_SPIN:
355 case MCI_STATUS:
356 case MCI_STEP:
357 case MCI_STOP:
358 /* case MCI_UNDO: */
359 case MCI_UNFREEZE:
360 case MCI_UPDATE:
361 case MCI_WHERE:
362 return MMSYSTEM_MAP_OK;
364 case MCI_WINDOW:
365 /* FIXME ?? see Map function */
366 return MMSYSTEM_MAP_OK;
368 case MCI_BREAK:
369 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
370 return MMSYSTEM_MAP_OK;
371 case MCI_ESCAPE:
372 if (lParam) {
373 LPMCI_VD_ESCAPE_PARMSW mvep32W = (LPMCI_VD_ESCAPE_PARMSW)lParam;
374 HeapFree(GetProcessHeap(), 0, (LPVOID)mvep32W->lpstrCommand);
375 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
377 return MMSYSTEM_MAP_OK;
378 case MCI_INFO:
379 if (lParam) {
380 LPMCI_INFO_PARMSW mip32w = (LPMCI_INFO_PARMSW)lParam;
381 LPMCI_INFO_PARMS16 mip16 = *(LPMCI_INFO_PARMS16*)((char*)mip32w - sizeof(LPMCI_INFO_PARMS16));
383 WideCharToMultiByte(CP_ACP, 0,
384 mip32w->lpstrReturn, mip32w->dwRetSize / sizeof(WCHAR),
385 MapSL(mip16->lpstrReturn), mip16->dwRetSize,
386 NULL, NULL);
387 HeapFree(GetProcessHeap(), 0, mip32w->lpstrReturn);
388 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
390 return MMSYSTEM_MAP_OK;
391 case MCI_SYSINFO:
392 if (lParam) {
393 LPMCI_SYSINFO_PARMSW msip32w = (LPMCI_SYSINFO_PARMSW)lParam;
394 LPMCI_SYSINFO_PARMS16 msip16 = *(LPMCI_SYSINFO_PARMS16*)((char*)msip32w - sizeof(LPMCI_SYSINFO_PARMS16));
396 WideCharToMultiByte(CP_ACP, 0,
397 msip32w->lpstrReturn, msip32w->dwRetSize,
398 MapSL(msip16->lpstrReturn), msip16->dwRetSize,
399 NULL, NULL);
400 HeapFree(GetProcessHeap(), 0, msip32w->lpstrReturn);
401 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
403 return MMSYSTEM_MAP_OK;
404 case MCI_SOUND:
405 if (lParam) {
406 LPMCI_SOUND_PARMSW msp32W = (LPMCI_SOUND_PARMSW)lParam;
407 HeapFree(GetProcessHeap(), 0, (LPVOID)msp32W->lpstrSoundName);
408 HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
410 return MMSYSTEM_MAP_OK;
411 case MCI_OPEN:
412 case MCI_OPEN_DRIVER:
413 if (lParam) {
414 LPMCI_OPEN_PARMSW mop32w = (LPMCI_OPEN_PARMSW)lParam;
415 LPMCI_OPEN_PARMS16 mop16 = *(LPMCI_OPEN_PARMS16*)((char*)mop32w - sizeof(LPMCI_OPEN_PARMS16));
417 mop16->wDeviceID = mop32w->wDeviceID;
418 if( ( dwFlags & ( MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID)) == MCI_OPEN_TYPE)
419 HeapFree(GetProcessHeap(), 0, (LPWSTR)mop32w->lpstrDeviceType);
420 if( ( dwFlags & ( MCI_OPEN_ELEMENT | MCI_OPEN_ELEMENT_ID)) == MCI_OPEN_ELEMENT)
421 HeapFree(GetProcessHeap(), 0, (LPWSTR)mop32w->lpstrElementName);
422 if( ( dwFlags & MCI_OPEN_ALIAS))
423 HeapFree(GetProcessHeap(), 0, (LPWSTR)mop32w->lpstrAlias);
424 if (!HeapFree(GetProcessHeap(), 0, (LPVOID)(lParam - sizeof(LPMCI_OPEN_PARMS16))))
425 FIXME("bad free line=%d\n", __LINE__);
427 return MMSYSTEM_MAP_OK;
428 case DRV_LOAD:
429 case DRV_ENABLE:
430 case DRV_OPEN:
431 case DRV_CLOSE:
432 case DRV_DISABLE:
433 case DRV_FREE:
434 case DRV_CONFIGURE:
435 case DRV_QUERYCONFIGURE:
436 case DRV_INSTALL:
437 case DRV_REMOVE:
438 case DRV_EXITSESSION:
439 case DRV_EXITAPPLICATION:
440 case DRV_POWER:
441 FIXME("This is a hack\n");
442 return MMSYSTEM_MAP_OK;
443 default:
444 FIXME("Map/Unmap internal error on msg=%s\n", MCI_MessageToString(wMsg));
446 return MMSYSTEM_MAP_MSGERROR;
449 /* ###################################################
450 * # MCI #
451 * ###################################################
454 #include <pshpack1.h>
455 #define MCI_MAX_THUNKS 32
457 static struct mci_thunk
459 BYTE popl_eax; /* popl %eax (return address) */
460 BYTE pushl_func; /* pushl $pfn16 (16bit callback function) */
461 YIELDPROC16 yield16;
462 BYTE pushl_eax; /* pushl %eax */
463 BYTE jmp; /* ljmp MCI_Yield1632 */
464 DWORD callback;
465 MCIDEVICEID id;
466 } *MCI_Thunks;
468 #include <poppack.h>
470 static CRITICAL_SECTION mci_cs;
471 static CRITICAL_SECTION_DEBUG mci_critsect_debug =
473 0, 0, &mci_cs,
474 { &mci_critsect_debug.ProcessLocksList, &mci_critsect_debug.ProcessLocksList },
475 0, 0, { (DWORD_PTR)(__FILE__ ": mmsystem_mci_cs") }
477 static CRITICAL_SECTION mci_cs = { &mci_critsect_debug, -1, 0, 0, 0, 0 };
479 static UINT MCI_Yield1632(DWORD pfn16, MCIDEVICEID id, DWORD yield_data)
481 WORD args[8];
483 if (!pfn16)
485 MSG msg;
486 PeekMessageW( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
487 return 0;
490 /* 16 bit func, call it */
491 TRACE("Function (16 bit) !\n");
493 args[2] = (MCIDEVICEID16)id;
494 args[1] = HIWORD(yield_data);
495 args[0] = LOWORD(yield_data);
496 return WOWCallback16Ex(pfn16, WCB16_PASCAL, sizeof(args), args, NULL);
499 /******************************************************************
500 * MCI_AddThunk
503 static struct mci_thunk* MCI_AddThunk(MCIDEVICEID id, YIELDPROC16 pfn16)
505 struct mci_thunk* thunk;
507 if (!MCI_Thunks)
509 MCI_Thunks = VirtualAlloc(NULL, MCI_MAX_THUNKS * sizeof(*MCI_Thunks), MEM_COMMIT,
510 PAGE_EXECUTE_READWRITE);
511 if (!MCI_Thunks) return NULL;
512 for (thunk = MCI_Thunks; thunk < &MCI_Thunks[MCI_MAX_THUNKS]; thunk++)
514 thunk->popl_eax = 0x58; /* popl %eax */
515 thunk->pushl_func = 0x68; /* pushl $pfn16 */
516 thunk->yield16 = 0;
517 thunk->pushl_eax = 0x50; /* pushl %eax */
518 thunk->jmp = 0xe9; /* jmp MCI_Yield1632 */
519 thunk->callback = (char *)MCI_Yield1632 - (char *)(&thunk->callback + 1);
520 thunk->id = 0;
523 for (thunk = MCI_Thunks; thunk < &MCI_Thunks[MCI_MAX_THUNKS]; thunk++)
525 if (thunk->yield16 == 0)
527 thunk->yield16 = pfn16;
528 thunk->id = id;
529 return thunk;
532 FIXME("Out of mci-thunks. Bump MCI_MAX_THUNKS\n");
533 return NULL;
536 /******************************************************************
537 * MCI_HasThunk
540 static struct mci_thunk* MCI_HasThunk(YIELDPROC pfn)
542 struct mci_thunk* thunk;
544 if (!MCI_Thunks) return NULL;
545 for (thunk = MCI_Thunks; thunk < &MCI_Thunks[MCI_MAX_THUNKS]; thunk++)
547 if ((YIELDPROC)thunk == pfn) return thunk;
549 return NULL;
552 /**************************************************************************
553 * mciSetYieldProc [MMSYSTEM.714]
555 BOOL16 WINAPI mciSetYieldProc16(UINT16 uDeviceID, YIELDPROC16 fpYieldProc, DWORD dwYieldData)
557 struct mci_thunk* thunk;
558 BOOL ret;
560 TRACE("(%u, %p, %08x)\n", uDeviceID, fpYieldProc, dwYieldData);
562 if (!(thunk = MCI_AddThunk(uDeviceID, fpYieldProc)))
563 return FALSE;
564 ret = mciSetYieldProc(uDeviceID, (YIELDPROC)thunk, dwYieldData);
565 if (!ret) thunk->yield16 = NULL;
566 return ret;
569 /**************************************************************************
570 * mciGetYieldProc [MMSYSTEM.716]
572 YIELDPROC16 WINAPI mciGetYieldProc16(UINT16 uDeviceID, DWORD* lpdwYieldData)
574 YIELDPROC yield;
575 DWORD data;
576 struct mci_thunk* thunk;
578 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
580 yield = mciGetYieldProc(uDeviceID, &data);
581 if (!yield || !(thunk = MCI_HasThunk(yield))) return NULL;
583 if (lpdwYieldData) *lpdwYieldData = data;
584 return thunk->yield16;
587 /**************************************************************************
588 * mciGetErrorString [MMSYSTEM.706]
590 BOOL16 WINAPI mciGetErrorString16(DWORD wError, LPSTR lpstrBuffer, UINT16 uLength)
592 return mciGetErrorStringA(wError, lpstrBuffer, uLength);
595 /**************************************************************************
596 * mciDriverNotify [MMSYSTEM.711]
598 BOOL16 WINAPI mciDriverNotify16(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
600 TRACE("(%04X, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
602 return PostMessageA(HWND_32(hWndCallBack), MM_MCINOTIFY, wStatus, wDevID);
605 /**************************************************************************
606 * mciGetDriverData [MMSYSTEM.708]
608 DWORD WINAPI mciGetDriverData16(UINT16 uDeviceID)
610 return mciGetDriverData(uDeviceID);
613 /**************************************************************************
614 * mciSetDriverData [MMSYSTEM.707]
616 BOOL16 WINAPI mciSetDriverData16(UINT16 uDeviceID, DWORD data)
618 return mciSetDriverData(uDeviceID, data);
621 /**************************************************************************
622 * mciSendCommand [MMSYSTEM.701]
624 DWORD WINAPI mciSendCommand16(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD p2)
626 DWORD dwRet;
627 BOOL to32;
628 DWORD_PTR dwParam2 = p2;
630 TRACE("(%04X, %u, %08X, %08lX)\n", wDevID, wMsg, dwParam1, dwParam2);
632 switch (wMsg) {
633 case MCI_CLOSE:
634 case MCI_OPEN:
635 case MCI_SYSINFO:
636 case MCI_BREAK:
637 case MCI_SOUND:
638 to32 = TRUE;
639 break;
640 default:
641 /* FIXME: this is suboptimal. If MCI driver is a 16bit one, we'll be
642 * doing 16=>32W, then 32W=>16 conversions.
643 * We could directly call the 16bit driver if we had the information.
645 to32 = TRUE;
647 if (to32) {
648 MMSYSTEM_MapType res;
650 dwRet = MCIERR_INVALID_DEVICE_ID;
652 switch (res = MCI_MapMsg16To32W(wMsg, dwParam1, &dwParam2)) {
653 case MMSYSTEM_MAP_MSGERROR:
654 TRACE("Not handled yet (%u)\n", wMsg);
655 dwRet = MCIERR_DRIVER_INTERNAL;
656 break;
657 case MMSYSTEM_MAP_NOMEM:
658 TRACE("Problem mapping msg=%u from 16 to 32a\n", wMsg);
659 dwRet = MCIERR_OUT_OF_MEMORY;
660 break;
661 case MMSYSTEM_MAP_OK:
662 case MMSYSTEM_MAP_OKMEM:
663 dwRet = mciSendCommandW(wDevID, wMsg, dwParam1, dwParam2);
664 if (res == MMSYSTEM_MAP_OKMEM)
665 MCI_UnMapMsg16To32W(wMsg, dwParam1, dwParam2);
666 break;
669 else
671 #if 0
672 if (wDevID == MCI_ALL_DEVICE_ID) {
673 FIXME("unhandled MCI_ALL_DEVICE_ID\n");
674 dwRet = MCIERR_CANNOT_USE_ALL;
675 } else {
676 dwRet = SendDriverMessage(hdrv, wMsg, dwParam1, dwParam2);
678 #endif
680 if (wMsg == MCI_CLOSE && dwRet == 0 && MCI_Thunks)
682 /* free yield thunks, if any */
683 unsigned i;
684 for (i = 0; i < MCI_MAX_THUNKS; i++)
686 if (MCI_Thunks[i].id == wDevID)
687 MCI_Thunks[i].yield16 = NULL;
690 return dwRet;
693 /**************************************************************************
694 * mciGetDeviceID [MMSYSTEM.703]
696 UINT16 WINAPI mciGetDeviceID16(LPCSTR lpstrName)
698 TRACE("(\"%s\")\n", lpstrName);
700 return mciGetDeviceIDA(lpstrName);
703 /**************************************************************************
704 * mciGetDeviceIDFromElementID [MMSYSTEM.715]
706 UINT16 WINAPI mciGetDeviceIDFromElementID16(DWORD dwElementID, LPCSTR lpstrType)
708 return mciGetDeviceIDFromElementIDA(dwElementID, lpstrType);
711 /**************************************************************************
712 * mciGetCreatorTask [MMSYSTEM.717]
714 HTASK16 WINAPI mciGetCreatorTask16(UINT16 uDeviceID)
716 return HTASK_16(mciGetCreatorTask(uDeviceID));
719 /**************************************************************************
720 * mciDriverYield [MMSYSTEM.710]
722 UINT16 WINAPI mciDriverYield16(UINT16 uDeviceID)
724 return mciDriverYield(uDeviceID);
727 /**************************************************************************
728 * mciSendString [MMSYSTEM.702]
730 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
731 UINT16 uRetLen, HWND16 hwndCallback)
733 return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback));
736 /**************************************************************************
737 * mciLoadCommandResource [MMSYSTEM.705]
739 UINT16 WINAPI mciLoadCommandResource16(HINSTANCE16 hInst, LPCSTR resname, UINT16 type)
741 TRACE("(%04x, %s, %x)!\n", hInst, resname, type);
742 return MCI_NO_COMMAND_TABLE;
745 /**************************************************************************
746 * mciFreeCommandResource [MMSYSTEM.713]
748 BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
750 TRACE("(%04x)!\n", uTable);
752 return FALSE;
755 /**************************************************************************
756 * mciExecute [MMSYSTEM.712]
758 BOOL16 WINAPI mciExecute16(LPCSTR lpstrCommand)
760 return mciExecute(lpstrCommand);