2 * msvideo 16-bit functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2000 Bradley Baetz
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
33 #include "wine/winbase16.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msvideo
);
40 /* Drivers32 settings */
41 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
43 /* handle16 --> handle conversions */
44 #define HDRAWDIB_32(h16) ((HDRAWDIB)(ULONG_PTR)(h16))
45 #define HIC_32(h16) ((HIC)(ULONG_PTR)(h16))
47 /* handle --> handle16 conversions */
48 #define HDRVR_16(h32) (LOWORD(h32))
49 #define HDRAWDIB_16(h32) (LOWORD(h32))
50 #define HIC_16(h32) (LOWORD(h32))
52 /***********************************************************************
53 * DrawDibOpen [MSVIDEO.102]
55 HDRAWDIB16 VFWAPI
DrawDibOpen16(void)
57 return HDRAWDIB_16(DrawDibOpen());
60 /***********************************************************************
61 * DrawDibClose [MSVIDEO.103]
63 BOOL16 VFWAPI
DrawDibClose16(HDRAWDIB16 hdd
)
65 return DrawDibClose(HDRAWDIB_32(hdd
));
68 /************************************************************************
69 * DrawDibBegin [MSVIDEO.104]
71 BOOL16 VFWAPI
DrawDibBegin16(HDRAWDIB16 hdd
, HDC16 hdc
, INT16 dxDst
,
72 INT16 dyDst
, LPBITMAPINFOHEADER lpbi
, INT16 dxSrc
,
73 INT16 dySrc
, UINT16 wFlags
)
75 return DrawDibBegin(HDRAWDIB_32(hdd
), HDC_32(hdc
), dxDst
, dyDst
, lpbi
,
76 dxSrc
, dySrc
, wFlags
);
79 /***********************************************************************
80 * DrawDibEnd [MSVIDEO.105]
82 BOOL16 VFWAPI
DrawDibEnd16(HDRAWDIB16 hdd
)
84 return DrawDibEnd(HDRAWDIB_32(hdd
));
87 /**********************************************************************
88 * DrawDibDraw [MSVIDEO.106]
90 BOOL16 VFWAPI
DrawDibDraw16(HDRAWDIB16 hdd
, HDC16 hdc
, INT16 xDst
, INT16 yDst
,
91 INT16 dxDst
, INT16 dyDst
, LPBITMAPINFOHEADER lpbi
,
92 LPVOID lpBits
, INT16 xSrc
, INT16 ySrc
, INT16 dxSrc
,
93 INT16 dySrc
, UINT16 wFlags
)
95 return DrawDibDraw(HDRAWDIB_32(hdd
), HDC_32(hdc
), xDst
, yDst
, dxDst
,
96 dyDst
, lpbi
, lpBits
, xSrc
, ySrc
, dxSrc
, dySrc
, wFlags
);
99 /***********************************************************************
100 * DrawDibGetPalette [MSVIDEO.108]
102 HPALETTE16 VFWAPI
DrawDibGetPalette16(HDRAWDIB16 hdd
)
104 return HPALETTE_16(DrawDibGetPalette(HDRAWDIB_32(hdd
)));
107 /***********************************************************************
108 * DrawDibSetPalette [MSVIDEO.110]
110 BOOL16 VFWAPI
DrawDibSetPalette16(HDRAWDIB16 hdd
, HPALETTE16 hpal
)
112 return DrawDibSetPalette(HDRAWDIB_32(hdd
), HPALETTE_32(hpal
));
115 /***********************************************************************
116 * DrawDibRealize [MSVIDEO.112]
118 UINT16 VFWAPI
DrawDibRealize16(HDRAWDIB16 hdd
, HDC16 hdc
,
121 return (UINT16
)DrawDibRealize(HDRAWDIB_32(hdd
), HDC_32(hdc
), fBackground
);
124 /*************************************************************************
125 * DrawDibProfileDisplay [MSVIDEO.114]
127 BOOL16 VFWAPI
DrawDibProfileDisplay16(LPBITMAPINFOHEADER lpbi
)
129 TRACE("(%p)\n", lpbi
);
130 return DrawDibProfileDisplay(lpbi
);
133 /*************************************************************************
134 * DrawDibStart [MSVIDEO.118]
136 BOOL16 VFWAPI
DrawDibStart16(HDRAWDIB16 hdd
, DWORD rate
)
138 return DrawDibStart(HDRAWDIB_32(hdd
), rate
);
141 /*************************************************************************
142 * DrawDibStop [MSVIDEO.119]
144 BOOL16 VFWAPI
DrawDibStop16(HDRAWDIB16 hdd
)
146 return DrawDibStop(HDRAWDIB_32(hdd
));
149 /***********************************************************************
150 * ICOpen [MSVIDEO.203]
152 HIC16 VFWAPI
ICOpen16(DWORD fccType
, DWORD fccHandler
, UINT16 wMode
)
154 return HIC_16(ICOpen(fccType
, fccHandler
, wMode
));
157 /***********************************************************************
158 * _ICMessage [MSVIDEO.207]
160 LRESULT VFWAPIV
ICMessage16( HIC16 hic
, UINT16 msg
, UINT16 cb
, VA_LIST16 valist
)
167 lpData
= HeapAlloc(GetProcessHeap(), 0, cb
);
169 TRACE("0x%08x, %u, %u, ...)\n", (DWORD
) hic
, msg
, cb
);
171 for (i
= 0; i
< cb
/ sizeof(WORD
); i
++)
173 lpData
[i
] = VA_ARG16(valist
, WORD
);
176 segData
= MapLS(lpData
);
177 ret
= ICSendMessage16(hic
, msg
, segData
, (DWORD
) cb
);
179 HeapFree(GetProcessHeap(), 0, lpData
);
183 /***********************************************************************
184 * ICGetInfo [MSVIDEO.212]
186 LRESULT VFWAPI
ICGetInfo16(HIC16 hic
, ICINFO16
* picinfo
, DWORD cb
)
190 TRACE("(0x%08x,%p,%d)\n", (DWORD
) hic
, picinfo
, cb
);
191 ret
= ICSendMessage16(hic
, ICM_GETINFO
, (DWORD
) picinfo
, cb
);
192 TRACE(" -> 0x%08lx\n", ret
);
196 /***********************************************************************
197 * ICLocate [MSVIDEO.213]
199 HIC16 VFWAPI
ICLocate16(DWORD fccType
, DWORD fccHandler
,
200 LPBITMAPINFOHEADER lpbiIn
, LPBITMAPINFOHEADER lpbiOut
,
203 return HIC_16(ICLocate(fccType
, fccHandler
, lpbiIn
, lpbiOut
, wFlags
));
206 /***********************************************************************
207 * _ICCompress [MSVIDEO.224]
209 DWORD VFWAPIV
ICCompress16(HIC16 hic
, DWORD dwFlags
,
210 LPBITMAPINFOHEADER lpbiOutput
, LPVOID lpData
,
211 LPBITMAPINFOHEADER lpbiInput
, LPVOID lpBits
,
212 LPDWORD lpckid
, LPDWORD lpdwFlags
,
213 LONG lFrameNum
, DWORD dwFrameSize
,
214 DWORD dwQuality
, LPBITMAPINFOHEADER lpbiPrev
,
221 TRACE("(0x%08x,%d,%p,%p,%p,%p,...)\n", (DWORD
) hic
, dwFlags
,
222 lpbiOutput
, lpData
, lpbiInput
, lpBits
);
224 iccmp
.dwFlags
= dwFlags
;
226 iccmp
.lpbiOutput
= lpbiOutput
;
227 iccmp
.lpOutput
= lpData
;
228 iccmp
.lpbiInput
= lpbiInput
;
229 iccmp
.lpInput
= lpBits
;
231 iccmp
.lpckid
= lpckid
;
232 iccmp
.lpdwFlags
= lpdwFlags
;
233 iccmp
.lFrameNum
= lFrameNum
;
234 iccmp
.dwFrameSize
= dwFrameSize
;
235 iccmp
.dwQuality
= dwQuality
;
236 iccmp
.lpbiPrev
= lpbiPrev
;
237 iccmp
.lpPrev
= lpPrev
;
238 seg_iccmp
= MapLS(&iccmp
);
239 ret
= ICSendMessage16(hic
, ICM_COMPRESS
, seg_iccmp
, sizeof(ICCOMPRESS
));
244 /***********************************************************************
245 * _ICDecompress [MSVIDEO.230]
247 DWORD VFWAPIV
ICDecompress16(HIC16 hic
, DWORD dwFlags
,
248 LPBITMAPINFOHEADER lpbiFormat
, LPVOID lpData
,
249 LPBITMAPINFOHEADER lpbi
, LPVOID lpBits
)
255 TRACE("(0x%08x,%d,%p,%p,%p,%p)\n", (DWORD
) hic
, dwFlags
, lpbiFormat
,
256 lpData
, lpbi
, lpBits
);
258 icd
.dwFlags
= dwFlags
;
259 icd
.lpbiInput
= lpbiFormat
;
260 icd
.lpInput
= lpData
;
261 icd
.lpbiOutput
= lpbi
;
262 icd
.lpOutput
= lpBits
;
264 segptr
= MapLS(&icd
);
265 ret
= ICSendMessage16(hic
, ICM_DECOMPRESS
, segptr
, sizeof(ICDECOMPRESS
));
270 /***********************************************************************
271 * _ICDrawBegin [MSVIDEO.232]
273 DWORD VFWAPIV
ICDrawBegin16(HIC16 hic
, /* [in] */
274 DWORD dwFlags
, /* [in] flags */
275 HPALETTE16 hpal
, /* [in] palette to draw with */
276 HWND16 hwnd
, /* [in] window to draw to */
277 HDC16 hdc
, /* [in] HDC to draw to */
278 INT16 xDst
, /* [in] destination rectangle */
279 INT16 yDst
, /* [in] */
280 INT16 dxDst
, /* [in] */
281 INT16 dyDst
, /* [in] */
282 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw NOTE: SEGPTR */
283 INT16 xSrc
, /* [in] source rectangle */
284 INT16 ySrc
, /* [in] */
285 INT16 dxSrc
, /* [in] */
286 INT16 dySrc
, /* [in] */
287 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
288 DWORD dwScale
) /* [in] */
294 TRACE ("(0x%08x,%d,0x%08x,0x%08x,0x%08x,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
295 (DWORD
) hic
, dwFlags
, (DWORD
) hpal
, (DWORD
) hwnd
, (DWORD
) hdc
,
296 xDst
, yDst
, dxDst
, dyDst
, lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
,
299 icdb
.dwFlags
= dwFlags
;
307 icdb
.lpbi
= lpbi
; /* Keep this as SEGPTR for the mapping code to deal with */
312 icdb
.dwRate
= dwRate
;
313 icdb
.dwScale
= dwScale
;
314 seg_icdb
= MapLS(&icdb
);
315 ret
= (DWORD
) ICSendMessage16(hic
, ICM_DRAW_BEGIN
, seg_icdb
,
316 sizeof(ICDRAWBEGIN16
));
321 /***********************************************************************
322 * _ICDraw [MSVIDEO.234]
324 DWORD VFWAPIV
ICDraw16(HIC16 hic
, DWORD dwFlags
,
325 LPVOID lpFormat
, /* [???] NOTE: SEGPTR */
326 LPVOID lpData
, /* [???] NOTE: SEGPTR */
327 DWORD cbData
, LONG lTime
)
333 TRACE("(0x%08x,0x%08x,%p,%p,%d,%d)\n", (DWORD
) hic
, dwFlags
,
334 lpFormat
, lpData
, cbData
, lTime
);
335 icd
.dwFlags
= dwFlags
;
336 icd
.lpFormat
= lpFormat
;
340 seg_icd
= MapLS(&icd
);
341 ret
= ICSendMessage16(hic
, ICM_DRAW
, seg_icd
, sizeof(ICDRAW
));
346 /***********************************************************************
347 * ICGetDisplayFormat [MSVIDEO.239]
349 HIC16 VFWAPI
ICGetDisplayFormat16(HIC16 hic
, LPBITMAPINFOHEADER lpbiIn
,
350 LPBITMAPINFOHEADER lpbiOut
, INT16 depth
,
353 return HIC_16(ICGetDisplayFormat(HIC_32(hic
), lpbiIn
, lpbiOut
, depth
,
357 #define COPY(x,y) (x->y = x##16->y);
358 #define COPYPTR(x,y) (x->y = MapSL((SEGPTR)x##16->y));
360 /******************************************************************
361 * MSVIDEO_MapICDEX16To32
365 static LPVOID
MSVIDEO_MapICDEX16To32(LPDWORD lParam
)
369 ICDECOMPRESSEX
*icdx
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDECOMPRESSEX
));
370 ICDECOMPRESSEX16
*icdx16
= MapSL(*lParam
);
374 COPYPTR(icdx
, lpbiSrc
);
375 COPYPTR(icdx
, lpSrc
);
376 COPYPTR(icdx
, lpbiDst
);
377 COPYPTR(icdx
, lpDst
);
387 *lParam
= (DWORD
)(icdx
);
391 /******************************************************************
392 * MSVIDEO_MapMsg16To32
396 static LPVOID
MSVIDEO_MapMsg16To32(UINT msg
, LPDWORD lParam1
, LPDWORD lParam2
)
400 TRACE("Mapping %d\n", msg
);
411 case ICM_COMPRESS_END
:
412 case ICM_DECOMPRESS_END
:
413 case ICM_DECOMPRESSEX_END
:
415 case ICM_DRAW_START_PLAY
:
416 case ICM_DRAW_STOP_PLAY
:
417 case ICM_DRAW_REALIZE
:
418 case ICM_DRAW_RENDERBUFFER
:
422 case ICM_GETDEFAULTQUALITY
:
425 case ICM_DRAW_WINDOW
:
426 case ICM_GETBUFFERSWANTED
:
427 *lParam1
= (DWORD
)MapSL(*lParam1
);
431 ICINFO
*ici
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICINFO
));
434 ici16
= MapSL(*lParam1
);
437 ici
->dwSize
= sizeof(ICINFO
);
439 COPY(ici
, fccHandler
);
441 COPY(ici
, dwVersion
);
442 COPY(ici
, dwVersionICM
);
443 MultiByteToWideChar( CP_ACP
, 0, ici16
->szName
, -1, ici
->szName
, 16 );
444 MultiByteToWideChar( CP_ACP
, 0, ici16
->szDescription
, -1, ici
->szDescription
, 128 );
445 MultiByteToWideChar( CP_ACP
, 0, ici16
->szDriver
, -1, ici
->szDriver
, 128 );
446 *lParam1
= (DWORD
)(ici
);
447 *lParam2
= sizeof(ICINFO
);
452 ICCOMPRESS
*icc
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS
));
455 icc16
= MapSL(*lParam1
);
459 COPYPTR(icc
, lpbiOutput
);
460 COPYPTR(icc
, lpOutput
);
461 COPYPTR(icc
, lpbiInput
);
462 COPYPTR(icc
, lpInput
);
463 COPYPTR(icc
, lpckid
);
464 COPYPTR(icc
, lpdwFlags
);
465 COPY(icc
, lFrameNum
);
466 COPY(icc
, dwFrameSize
);
467 COPY(icc
, dwQuality
);
468 COPYPTR(icc
, lpbiPrev
);
469 COPYPTR(icc
, lpPrev
);
471 *lParam1
= (DWORD
)(icc
);
472 *lParam2
= sizeof(ICCOMPRESS
);
477 ICDECOMPRESS
*icd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDECOMPRESS
));
478 ICDECOMPRESS
*icd16
; /* Same structure except for the pointers */
480 icd16
= MapSL(*lParam1
);
484 COPYPTR(icd
, lpbiInput
);
485 COPYPTR(icd
, lpInput
);
486 COPYPTR(icd
, lpbiOutput
);
487 COPYPTR(icd
, lpOutput
);
490 *lParam1
= (DWORD
)(icd
);
491 *lParam2
= sizeof(ICDECOMPRESS
);
494 case ICM_COMPRESS_BEGIN
:
495 case ICM_COMPRESS_GET_FORMAT
:
496 case ICM_COMPRESS_GET_SIZE
:
497 case ICM_COMPRESS_QUERY
:
498 case ICM_DECOMPRESS_GET_FORMAT
:
499 case ICM_DECOMPRESS_QUERY
:
500 case ICM_DECOMPRESS_BEGIN
:
501 case ICM_DECOMPRESS_SET_PALETTE
:
502 case ICM_DECOMPRESS_GET_PALETTE
:
503 *lParam1
= (DWORD
)MapSL(*lParam1
);
504 *lParam2
= (DWORD
)MapSL(*lParam2
);
506 case ICM_DECOMPRESSEX_QUERY
:
507 if ((*lParam2
!= sizeof(ICDECOMPRESSEX16
)) && (*lParam2
!= 0))
508 WARN("*lParam2 has unknown value %p\n", (ICDECOMPRESSEX16
*)*lParam2
);
509 /* FIXME: *lParm2 is meant to be 0 or an ICDECOMPRESSEX16*, but is sizeof(ICDECOMRPESSEX16)
510 * This is because of ICMessage(). Special case it?
512 LPVOID* addr = HeapAlloc(GetProcessHeap(), 0, 2*sizeof(LPVOID));
513 addr[0] = MSVIDEO_MapICDEX16To32(lParam1);
515 addr[1] = MSVIDEO_MapICDEX16To32(lParam2);
522 case ICM_DECOMPRESSEX_BEGIN
:
523 case ICM_DECOMPRESSEX
:
524 ret
= MSVIDEO_MapICDEX16To32(lParam1
);
525 *lParam2
= sizeof(ICDECOMPRESSEX
);
529 ICDRAWBEGIN
*icdb
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDRAWBEGIN
));
530 ICDRAWBEGIN16
*icdb16
= MapSL(*lParam1
);
534 icdb
->hpal
= HPALETTE_32(icdb16
->hpal
);
535 icdb
->hwnd
= HWND_32(icdb16
->hwnd
);
536 icdb
->hdc
= HDC_32(icdb16
->hdc
);
549 *lParam1
= (DWORD
)(icdb
);
550 *lParam2
= sizeof(ICDRAWBEGIN
);
553 case ICM_DRAW_SUGGESTFORMAT
:
555 ICDRAWSUGGEST
*icds
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDRAWSUGGEST
));
556 ICDRAWSUGGEST16
*icds16
= MapSL(*lParam1
);
561 COPYPTR(icds
, lpbiIn
);
562 COPYPTR(icds
, lpbiSuggest
);
567 icds
->hicDecompressor
= HIC_32(icds16
->hicDecompressor
);
569 *lParam1
= (DWORD
)(icds
);
570 *lParam2
= sizeof(ICDRAWSUGGEST
);
575 ICDRAW
*icd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDRAW
));
576 ICDRAW
*icd16
= MapSL(*lParam1
);
580 COPYPTR(icd
, lpFormat
);
581 COPYPTR(icd
, lpData
);
585 *lParam1
= (DWORD
)(icd
);
586 *lParam2
= sizeof(ICDRAW
);
593 FIXME("%d is not yet handled. Expect a crash.\n", msg
);
601 /******************************************************************
602 * MSVIDEO_UnmapMsg16To32
606 static void MSVIDEO_UnmapMsg16To32(UINT msg
, LPVOID data16
, LPDWORD lParam1
, LPDWORD lParam2
)
608 TRACE("Unmapping %d\n", msg
);
610 #define UNCOPY(x, y) (x##16->y = x->y);
616 ICINFO
*ici
= (ICINFO
*)(*lParam1
);
617 ICINFO16
*ici16
= data16
;
619 UNCOPY(ici
, fccType
);
620 UNCOPY(ici
, fccHandler
);
621 UNCOPY(ici
, dwFlags
);
622 UNCOPY(ici
, dwVersion
);
623 UNCOPY(ici
, dwVersionICM
);
624 WideCharToMultiByte( CP_ACP
, 0, ici
->szName
, -1, ici16
->szName
,
625 sizeof(ici16
->szName
), NULL
, NULL
);
626 ici16
->szName
[sizeof(ici16
->szName
)-1] = 0;
627 WideCharToMultiByte( CP_ACP
, 0, ici
->szDescription
, -1, ici16
->szDescription
,
628 sizeof(ici16
->szDescription
), NULL
, NULL
);
629 ici16
->szDescription
[sizeof(ici16
->szDescription
)-1] = 0;
630 /* This just gives garbage for some reason - BB
631 lstrcpynWtoA(ici16->szDriver, ici->szDriver, 128);*/
633 HeapFree(GetProcessHeap(), 0, ici
);
636 case ICM_DECOMPRESS_QUERY
:
639 HeapFree(GetProcessHeap(), 0, x[0]);
641 HeapFree(GetProcessHeap(), 0, x[1]);
646 case ICM_DECOMPRESSEX_QUERY
:
647 case ICM_DECOMPRESSEX_BEGIN
:
648 case ICM_DECOMPRESSEX
:
650 case ICM_DRAW_SUGGESTFORMAT
:
652 HeapFree(GetProcessHeap(), 0, data16
);
655 ERR("Unmapping unmapped msg %d\n", msg
);
660 /***********************************************************************
661 * ICInfo [MSVIDEO.200]
663 BOOL16 VFWAPI
ICInfo16(DWORD fccType
, DWORD fccHandler
, ICINFO16
*lpicinfo
)
667 DWORD lParam
= (DWORD
)lpicinfo
;
668 DWORD size
= ((ICINFO
*)(MapSL((SEGPTR
)lpicinfo
)))->dwSize
;
670 /* Use the mapping functions to map the ICINFO structure */
671 lpv
= MSVIDEO_MapMsg16To32(ICM_GETINFO
, &lParam
, &size
);
673 ret
= ICInfo(fccType
, fccHandler
, (ICINFO
*)lParam
);
675 MSVIDEO_UnmapMsg16To32(ICM_GETINFO
, lpv
, &lParam
, &size
);
680 /******************************************************************
685 static LRESULT CALLBACK
IC_Callback3216(DWORD pfn16
, HIC hic
, HDRVR hdrv
, UINT msg
, LPARAM lp1
, LPARAM lp2
)
693 lp2
= (DWORD
)MapLS((void*)lp2
);
696 args
[7] = HIWORD(hic
);
697 args
[6] = LOWORD(hic
);
698 args
[5] = HDRVR_16(hdrv
);
700 args
[3] = HIWORD(lp1
);
701 args
[2] = LOWORD(lp1
);
702 args
[1] = HIWORD(lp2
);
703 args
[0] = LOWORD(lp2
);
704 WOWCallback16Ex( pfn16
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
715 #define MAX_THUNKS 32
717 #include "pshpack1.h"
718 static struct msvideo_thunk
720 BYTE popl_eax
; /* popl %eax (return address) */
721 BYTE pushl_func
; /* pushl $pfn16 (16bit callback function) */
723 BYTE pushl_eax
; /* pushl %eax */
724 BYTE jmp
; /* ljmp WDML_InvokeCallback16 */
726 HIC16 hIC16
; /* driver's handle */
730 static CRITICAL_SECTION msvideo_cs
;
731 static CRITICAL_SECTION_DEBUG critsect_debug
=
734 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
735 0, 0, { (DWORD_PTR
)(__FILE__
": msvideo_cs") }
737 static CRITICAL_SECTION msvideo_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
739 static struct msvideo_thunk
* MSVIDEO_AddThunk(DWORD pfn16
)
741 struct msvideo_thunk
* thunk
;
745 MSVIDEO_Thunks
= VirtualAlloc(NULL
, MAX_THUNKS
* sizeof(*MSVIDEO_Thunks
), MEM_COMMIT
,
746 PAGE_EXECUTE_READWRITE
);
747 if (!MSVIDEO_Thunks
) return NULL
;
748 for (thunk
= MSVIDEO_Thunks
; thunk
< &MSVIDEO_Thunks
[MAX_THUNKS
]; thunk
++)
750 thunk
->popl_eax
= 0x58; /* popl %eax */
751 thunk
->pushl_func
= 0x68; /* pushl $pfn16 */
753 thunk
->pushl_eax
= 0x50; /* pushl %eax */
754 thunk
->jmp
= 0xe9; /* jmp IC_Callback3216 */
755 thunk
->callback
= (char *)IC_Callback3216
- (char *)(&thunk
->callback
+ 1);
759 for (thunk
= MSVIDEO_Thunks
; thunk
< &MSVIDEO_Thunks
[MAX_THUNKS
]; thunk
++)
761 if (thunk
->pfn16
== 0)
763 thunk
->pfn16
= pfn16
;
767 FIXME("Out of msvideo-thunks. Bump MAX_THUNKS\n");
771 static struct msvideo_thunk
* MSVIDEO_HasThunk(HIC16 hic
)
773 struct msvideo_thunk
* thunk
;
778 for (thunk
= MSVIDEO_Thunks
; thunk
< &MSVIDEO_Thunks
[MAX_THUNKS
]; thunk
++)
780 if (thunk
->hIC16
== hic
) return thunk
;
785 /***********************************************************************
786 * ICOpenFunction [MSVIDEO.206]
788 HIC16 VFWAPI
ICOpenFunction16(DWORD fccType
, DWORD fccHandler
, UINT16 wMode
, FARPROC16 lpfnHandler
)
791 struct msvideo_thunk
* thunk
;
793 EnterCriticalSection(&msvideo_cs
);
794 if (!(thunk
= MSVIDEO_AddThunk((DWORD
)lpfnHandler
)))
796 LeaveCriticalSection(&msvideo_cs
);
799 if ((hic32
= ICOpenFunction(fccType
, fccHandler
, wMode
, (DRIVERPROC
)thunk
)))
800 thunk
->hIC16
= HIC_16(hic32
);
803 LeaveCriticalSection(&msvideo_cs
);
804 return HIC_16(hic32
);
807 /***********************************************************************
808 * ICSendMessage [MSVIDEO.205]
810 LRESULT VFWAPI
ICSendMessage16(HIC16 hic
, UINT16 msg
, DWORD lParam1
, DWORD lParam2
)
812 LRESULT ret
= ICERR_BADHANDLE
;
813 struct msvideo_thunk
* thunk
;
815 if ((thunk
= MSVIDEO_HasThunk(hic
)))
820 /* FIXME: original code was passing hdrv first and hic second */
821 /* but this doesn't match what IC_Callback3216 does */
822 args
[7] = HIWORD(hic
);
823 args
[6] = LOWORD(hic
);
824 args
[5] = 0; /* the 32bit also sets it to NULL */
826 args
[3] = HIWORD(lParam1
);
827 args
[2] = LOWORD(lParam1
);
828 args
[1] = HIWORD(lParam2
);
829 args
[0] = LOWORD(lParam2
);
830 WOWCallback16Ex( thunk
->pfn16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
835 /* map the message for a 32 bit infrastructure, and pass it along */
836 void* data16
= MSVIDEO_MapMsg16To32(msg
, &lParam1
, &lParam2
);
838 ret
= ICSendMessage(HIC_32(hic
), msg
, lParam1
, lParam2
);
840 MSVIDEO_UnmapMsg16To32(msg
, data16
, &lParam1
, &lParam2
);
845 /***********************************************************************
846 * ICClose [MSVIDEO.204]
848 LRESULT WINAPI
ICClose16(HIC16 hic
)
850 BOOL ret
= ICClose(HIC_32(hic
));
852 EnterCriticalSection(&msvideo_cs
);
855 struct msvideo_thunk
* thunk
;
856 if ((thunk
= MSVIDEO_HasThunk(hic
)))
863 LeaveCriticalSection(&msvideo_cs
);
867 /***********************************************************************
868 * VideoCapDriverDescAndVer [MSVIDEO.22]
870 DWORD WINAPI
VideoCapDriverDescAndVer16(WORD nr
, LPSTR buf1
, WORD buf1len
,
871 LPSTR buf2
, WORD buf2len
)
873 static const char version_info_spec
[] = "\\StringFileInfo\\040904E4\\FileDescription";
877 char *s
, buf
[2048], fn
[260];
880 DWORD i
, cnt
= 0, lRet
;
886 TRACE("(%d,%p,%d,%p,%d)\n", nr
, buf1
, buf1len
, buf2
, buf2len
);
887 lRet
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_QUERY_VALUE
, &hKey
);
888 if (lRet
== ERROR_SUCCESS
)
890 RegQueryInfoKeyA( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
891 for (i
= 0; i
< cnt
; i
++)
893 bufLen
= ARRAY_SIZE(buf
);
894 lRet
= RegEnumKeyExA(hKey
, i
, buf
, &bufLen
, 0, 0, 0, &lastWrite
);
895 if (lRet
!= ERROR_SUCCESS
) continue;
896 if (_strnicmp(buf
, "vid", 3)) continue;
899 lRet
= RegQueryValueExA(hKey
, buf
, 0, 0, (LPBYTE
)fn
, &fnLen
);
900 if (lRet
== ERROR_SUCCESS
) found
= TRUE
;
906 /* search system.ini if not found in the registry */
907 if (!found
&& GetPrivateProfileStringA("drivers32", NULL
, NULL
, buf
, sizeof(buf
), "system.ini"))
909 for (s
= buf
; *s
; s
+= strlen(s
) + 1)
911 if (_strnicmp(s
, "vid", 3)) continue;
913 if (GetPrivateProfileStringA("drivers32", s
, NULL
, fn
, sizeof(fn
), "system.ini"))
921 TRACE("No more VID* entries found nr=%d\n", nr
);
924 infosize
= GetFileVersionInfoSizeA(fn
, &verhandle
);
927 TRACE("%s has no fileversioninfo.\n", fn
);
930 infobuf
= HeapAlloc(GetProcessHeap(), 0, infosize
);
931 if (GetFileVersionInfoA(fn
, verhandle
, infosize
, infobuf
))
933 /* Yes, two space behind : */
934 /* FIXME: test for buflen */
935 snprintf(buf2
, buf2len
, "Version: %d.%d.%d.%d\n",
936 ((WORD
*)infobuf
)[0x0f],
937 ((WORD
*)infobuf
)[0x0e],
938 ((WORD
*)infobuf
)[0x11],
939 ((WORD
*)infobuf
)[0x10]
941 TRACE("version of %s is %s\n", fn
, buf2
);
945 TRACE("GetFileVersionInfoA failed for %s.\n", fn
);
946 lstrcpynA(buf2
, fn
, buf2len
); /* msvideo.dll appears to copy fn*/
948 /* FIXME: language problem? */
949 if (VerQueryValueA( infobuf
,
955 UINT copylen
= min(subblocklen
,buf1len
-1);
956 memcpy(buf1
, subblock
, copylen
);
957 buf1
[copylen
] = '\0';
958 TRACE("VQA returned %s\n", (LPCSTR
)subblock
);
962 TRACE("VQA did not return on query \\StringFileInfo\\040904E4\\FileDescription?\n");
963 lstrcpynA(buf1
, fn
, buf1len
); /* msvideo.dll appears to copy fn*/
965 HeapFree(GetProcessHeap(), 0, infobuf
);
969 /**************************************************************************
970 * DllEntryPoint (MSVIDEO.3)
972 * MSVIDEO DLL entry point
975 BOOL WINAPI
VIDEO_LibMain(DWORD fdwReason
, HINSTANCE hinstDLL
, WORD ds
,
976 WORD wHeapSize
, DWORD dwReserved1
, WORD wReserved2
)
980 case DLL_PROCESS_ATTACH
:
982 case DLL_PROCESS_DETACH
:
983 DeleteCriticalSection(&msvideo_cs
);
989 /***********************************************************************
990 * MCIWndRegisterClass(MSVIDEO.251)
992 BOOL CDECL
MCIWndRegisterClass16(void)
994 return MCIWndRegisterClass();
997 static LRESULT (WINAPI
*pMCIWndProc
)(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
);
999 static LRESULT WINAPI
MCIWndProc16(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1003 case MCIWNDM_SENDSTRINGA
:
1004 case MCIWNDM_SETTIMEFORMATA
:
1005 lparam
= (ULONG_PTR
)MapSL(lparam
);
1012 return CallWindowProcA(pMCIWndProc
, hwnd
, msg
, wparam
, lparam
);
1015 /***********************************************************************
1016 * MCIWndCreate(MSVIDEO.250)
1018 HWND16 CDECL
MCIWndCreate16(HWND16 parent
, HINSTANCE16 hinst16
,
1019 DWORD style
, LPSTR file
)
1021 HWND hwnd
= MCIWndCreateA(HWND_32(parent
), 0, style
, file
);
1023 pMCIWndProc
= (void *)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)MCIWndProc16
);
1024 return HWND_16(hwnd
);