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/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msvideo
);
37 /* Drivers32 settings */
38 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
40 /* handle16 --> handle conversions */
41 #define HDRAWDIB_32(h16) ((HDRAWDIB)(ULONG_PTR)(h16))
42 #define HIC_32(h16) ((HIC)(ULONG_PTR)(h16))
44 /* handle --> handle16 conversions */
45 #define HDRVR_16(h32) (LOWORD(h32))
46 #define HDRAWDIB_16(h32) (LOWORD(h32))
47 #define HIC_16(h32) (LOWORD(h32))
49 /***********************************************************************
50 * DrawDibOpen [MSVIDEO.102]
52 HDRAWDIB16 VFWAPI
DrawDibOpen16(void)
54 return HDRAWDIB_16(DrawDibOpen());
57 /***********************************************************************
58 * DrawDibClose [MSVIDEO.103]
60 BOOL16 VFWAPI
DrawDibClose16(HDRAWDIB16 hdd
)
62 return DrawDibClose(HDRAWDIB_32(hdd
));
65 /************************************************************************
66 * DrawDibBegin [MSVIDEO.104]
68 BOOL16 VFWAPI
DrawDibBegin16(HDRAWDIB16 hdd
, HDC16 hdc
, INT16 dxDst
,
69 INT16 dyDst
, LPBITMAPINFOHEADER lpbi
, INT16 dxSrc
,
70 INT16 dySrc
, UINT16 wFlags
)
72 return DrawDibBegin(HDRAWDIB_32(hdd
), HDC_32(hdc
), dxDst
, dyDst
, lpbi
,
73 dxSrc
, dySrc
, wFlags
);
76 /***********************************************************************
77 * DrawDibEnd [MSVIDEO.105]
79 BOOL16 VFWAPI
DrawDibEnd16(HDRAWDIB16 hdd
)
81 return DrawDibEnd(HDRAWDIB_32(hdd
));
84 /**********************************************************************
85 * DrawDibDraw [MSVIDEO.106]
87 BOOL16 VFWAPI
DrawDibDraw16(HDRAWDIB16 hdd
, HDC16 hdc
, INT16 xDst
, INT16 yDst
,
88 INT16 dxDst
, INT16 dyDst
, LPBITMAPINFOHEADER lpbi
,
89 LPVOID lpBits
, INT16 xSrc
, INT16 ySrc
, INT16 dxSrc
,
90 INT16 dySrc
, UINT16 wFlags
)
92 return DrawDibDraw(HDRAWDIB_32(hdd
), HDC_32(hdc
), xDst
, yDst
, dxDst
,
93 dyDst
, lpbi
, lpBits
, xSrc
, ySrc
, dxSrc
, dySrc
, wFlags
);
96 /***********************************************************************
97 * DrawDibGetPalette [MSVIDEO.108]
99 HPALETTE16 VFWAPI
DrawDibGetPalette16(HDRAWDIB16 hdd
)
101 return HPALETTE_16(DrawDibGetPalette(HDRAWDIB_32(hdd
)));
104 /***********************************************************************
105 * DrawDibSetPalette [MSVIDEO.110]
107 BOOL16 VFWAPI
DrawDibSetPalette16(HDRAWDIB16 hdd
, HPALETTE16 hpal
)
109 return DrawDibSetPalette(HDRAWDIB_32(hdd
), HPALETTE_32(hpal
));
112 /***********************************************************************
113 * DrawDibRealize [MSVIDEO.112]
115 UINT16 VFWAPI
DrawDibRealize16(HDRAWDIB16 hdd
, HDC16 hdc
,
118 return (UINT16
)DrawDibRealize(HDRAWDIB_32(hdd
), HDC_32(hdc
), fBackground
);
121 /*************************************************************************
122 * DrawDibStart [MSVIDEO.118]
124 BOOL16 VFWAPI
DrawDibStart16(HDRAWDIB16 hdd
, DWORD rate
)
126 return DrawDibStart(HDRAWDIB_32(hdd
), rate
);
129 /*************************************************************************
130 * DrawDibStop [MSVIDEO.119]
132 BOOL16 VFWAPI
DrawDibStop16(HDRAWDIB16 hdd
)
134 return DrawDibStop(HDRAWDIB_32(hdd
));
137 /***********************************************************************
138 * ICOpen [MSVIDEO.203]
140 HIC16 VFWAPI
ICOpen16(DWORD fccType
, DWORD fccHandler
, UINT16 wMode
)
142 return HIC_16(ICOpen(fccType
, fccHandler
, wMode
));
145 /***********************************************************************
146 * _ICMessage [MSVIDEO.207]
148 LRESULT VFWAPIV
ICMessage16( HIC16 hic
, UINT16 msg
, UINT16 cb
, VA_LIST16 valist
)
155 lpData
= HeapAlloc(GetProcessHeap(), 0, cb
);
157 TRACE("0x%08x, %u, %u, ...)\n", (DWORD
) hic
, msg
, cb
);
159 for (i
= 0; i
< cb
/ sizeof(WORD
); i
++)
161 lpData
[i
] = VA_ARG16(valist
, WORD
);
164 segData
= MapLS(lpData
);
165 ret
= ICSendMessage16(hic
, msg
, segData
, (DWORD
) cb
);
167 HeapFree(GetProcessHeap(), 0, lpData
);
171 /***********************************************************************
172 * ICGetInfo [MSVIDEO.212]
174 LRESULT VFWAPI
ICGetInfo16(HIC16 hic
, ICINFO16
* picinfo
, DWORD cb
)
178 TRACE("(0x%08x,%p,%d)\n", (DWORD
) hic
, picinfo
, cb
);
179 ret
= ICSendMessage16(hic
, ICM_GETINFO
, (DWORD
) picinfo
, cb
);
180 TRACE(" -> 0x%08lx\n", ret
);
184 /***********************************************************************
185 * ICLocate [MSVIDEO.213]
187 HIC16 VFWAPI
ICLocate16(DWORD fccType
, DWORD fccHandler
,
188 LPBITMAPINFOHEADER lpbiIn
, LPBITMAPINFOHEADER lpbiOut
,
191 return HIC_16(ICLocate(fccType
, fccHandler
, lpbiIn
, lpbiOut
, wFlags
));
194 /***********************************************************************
195 * _ICCompress [MSVIDEO.224]
197 DWORD VFWAPIV
ICCompress16(HIC16 hic
, DWORD dwFlags
,
198 LPBITMAPINFOHEADER lpbiOutput
, LPVOID lpData
,
199 LPBITMAPINFOHEADER lpbiInput
, LPVOID lpBits
,
200 LPDWORD lpckid
, LPDWORD lpdwFlags
,
201 LONG lFrameNum
, DWORD dwFrameSize
,
202 DWORD dwQuality
, LPBITMAPINFOHEADER lpbiPrev
,
209 TRACE("(0x%08x,%d,%p,%p,%p,%p,...)\n", (DWORD
) hic
, dwFlags
,
210 lpbiOutput
, lpData
, lpbiInput
, lpBits
);
212 iccmp
.dwFlags
= dwFlags
;
214 iccmp
.lpbiOutput
= lpbiOutput
;
215 iccmp
.lpOutput
= lpData
;
216 iccmp
.lpbiInput
= lpbiInput
;
217 iccmp
.lpInput
= lpBits
;
219 iccmp
.lpckid
= lpckid
;
220 iccmp
.lpdwFlags
= lpdwFlags
;
221 iccmp
.lFrameNum
= lFrameNum
;
222 iccmp
.dwFrameSize
= dwFrameSize
;
223 iccmp
.dwQuality
= dwQuality
;
224 iccmp
.lpbiPrev
= lpbiPrev
;
225 iccmp
.lpPrev
= lpPrev
;
226 seg_iccmp
= MapLS(&iccmp
);
227 ret
= ICSendMessage16(hic
, ICM_COMPRESS
, seg_iccmp
, sizeof(ICCOMPRESS
));
232 /***********************************************************************
233 * _ICDecompress [MSVIDEO.230]
235 DWORD VFWAPIV
ICDecompress16(HIC16 hic
, DWORD dwFlags
,
236 LPBITMAPINFOHEADER lpbiFormat
, LPVOID lpData
,
237 LPBITMAPINFOHEADER lpbi
, LPVOID lpBits
)
243 TRACE("(0x%08x,%d,%p,%p,%p,%p)\n", (DWORD
) hic
, dwFlags
, lpbiFormat
,
244 lpData
, lpbi
, lpBits
);
246 icd
.dwFlags
= dwFlags
;
247 icd
.lpbiInput
= lpbiFormat
;
248 icd
.lpInput
= lpData
;
249 icd
.lpbiOutput
= lpbi
;
250 icd
.lpOutput
= lpBits
;
252 segptr
= MapLS(&icd
);
253 ret
= ICSendMessage16(hic
, ICM_DECOMPRESS
, segptr
, sizeof(ICDECOMPRESS
));
258 /***********************************************************************
259 * _ICDrawBegin [MSVIDEO.232]
261 DWORD VFWAPIV
ICDrawBegin16(HIC16 hic
, /* [in] */
262 DWORD dwFlags
, /* [in] flags */
263 HPALETTE16 hpal
, /* [in] palette to draw with */
264 HWND16 hwnd
, /* [in] window to draw to */
265 HDC16 hdc
, /* [in] HDC to draw to */
266 INT16 xDst
, /* [in] destination rectangle */
267 INT16 yDst
, /* [in] */
268 INT16 dxDst
, /* [in] */
269 INT16 dyDst
, /* [in] */
270 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw NOTE: SEGPTR */
271 INT16 xSrc
, /* [in] source rectangle */
272 INT16 ySrc
, /* [in] */
273 INT16 dxSrc
, /* [in] */
274 INT16 dySrc
, /* [in] */
275 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
276 DWORD dwScale
) /* [in] */
282 TRACE ("(0x%08x,%d,0x%08x,0x%08x,0x%08x,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
283 (DWORD
) hic
, dwFlags
, (DWORD
) hpal
, (DWORD
) hwnd
, (DWORD
) hdc
,
284 xDst
, yDst
, dxDst
, dyDst
, lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
,
287 icdb
.dwFlags
= dwFlags
;
295 icdb
.lpbi
= lpbi
; /* Keep this as SEGPTR for the mapping code to deal with */
300 icdb
.dwRate
= dwRate
;
301 icdb
.dwScale
= dwScale
;
302 seg_icdb
= MapLS(&icdb
);
303 ret
= (DWORD
) ICSendMessage16(hic
, ICM_DRAW_BEGIN
, seg_icdb
,
304 sizeof(ICDRAWBEGIN16
));
309 /***********************************************************************
310 * _ICDraw [MSVIDEO.234]
312 DWORD VFWAPIV
ICDraw16(HIC16 hic
, DWORD dwFlags
,
313 LPVOID lpFormat
, /* [???] NOTE: SEGPTR */
314 LPVOID lpData
, /* [???] NOTE: SEGPTR */
315 DWORD cbData
, LONG lTime
)
321 TRACE("(0x%08x,0x%08x,%p,%p,%d,%d)\n", (DWORD
) hic
, dwFlags
,
322 lpFormat
, lpData
, cbData
, lTime
);
323 icd
.dwFlags
= dwFlags
;
324 icd
.lpFormat
= lpFormat
;
328 seg_icd
= MapLS(&icd
);
329 ret
= ICSendMessage16(hic
, ICM_DRAW
, seg_icd
, sizeof(ICDRAW
));
334 /***********************************************************************
335 * ICGetDisplayFormat [MSVIDEO.239]
337 HIC16 VFWAPI
ICGetDisplayFormat16(HIC16 hic
, LPBITMAPINFOHEADER lpbiIn
,
338 LPBITMAPINFOHEADER lpbiOut
, INT16 depth
,
341 return HIC_16(ICGetDisplayFormat(HIC_32(hic
), lpbiIn
, lpbiOut
, depth
,
345 #define COPY(x,y) (x->y = x##16->y);
346 #define COPYPTR(x,y) (x->y = MapSL((SEGPTR)x##16->y));
348 /******************************************************************
349 * MSVIDEO_MapICDEX16To32
353 static LPVOID
MSVIDEO_MapICDEX16To32(LPDWORD lParam
)
357 ICDECOMPRESSEX
*icdx
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDECOMPRESSEX
));
358 ICDECOMPRESSEX16
*icdx16
= MapSL(*lParam
);
362 COPYPTR(icdx
, lpbiSrc
);
363 COPYPTR(icdx
, lpSrc
);
364 COPYPTR(icdx
, lpbiDst
);
365 COPYPTR(icdx
, lpDst
);
375 *lParam
= (DWORD
)(icdx
);
379 /******************************************************************
380 * MSVIDEO_MapMsg16To32
384 static LPVOID
MSVIDEO_MapMsg16To32(UINT msg
, LPDWORD lParam1
, LPDWORD lParam2
)
388 TRACE("Mapping %d\n", msg
);
399 case ICM_COMPRESS_END
:
400 case ICM_DECOMPRESS_END
:
401 case ICM_DECOMPRESSEX_END
:
403 case ICM_DRAW_START_PLAY
:
404 case ICM_DRAW_STOP_PLAY
:
405 case ICM_DRAW_REALIZE
:
406 case ICM_DRAW_RENDERBUFFER
:
410 case ICM_GETDEFAULTQUALITY
:
413 case ICM_DRAW_WINDOW
:
414 case ICM_GETBUFFERSWANTED
:
415 *lParam1
= (DWORD
)MapSL(*lParam1
);
419 ICINFO
*ici
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICINFO
));
422 ici16
= MapSL(*lParam1
);
425 ici
->dwSize
= sizeof(ICINFO
);
427 COPY(ici
, fccHandler
);
429 COPY(ici
, dwVersion
);
430 COPY(ici
, dwVersionICM
);
431 MultiByteToWideChar( CP_ACP
, 0, ici16
->szName
, -1, ici
->szName
, 16 );
432 MultiByteToWideChar( CP_ACP
, 0, ici16
->szDescription
, -1, ici
->szDescription
, 128 );
433 MultiByteToWideChar( CP_ACP
, 0, ici16
->szDriver
, -1, ici
->szDriver
, 128 );
434 *lParam1
= (DWORD
)(ici
);
435 *lParam2
= sizeof(ICINFO
);
440 ICCOMPRESS
*icc
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS
));
443 icc16
= MapSL(*lParam1
);
447 COPYPTR(icc
, lpbiOutput
);
448 COPYPTR(icc
, lpOutput
);
449 COPYPTR(icc
, lpbiInput
);
450 COPYPTR(icc
, lpInput
);
451 COPYPTR(icc
, lpckid
);
452 COPYPTR(icc
, lpdwFlags
);
453 COPY(icc
, lFrameNum
);
454 COPY(icc
, dwFrameSize
);
455 COPY(icc
, dwQuality
);
456 COPYPTR(icc
, lpbiPrev
);
457 COPYPTR(icc
, lpPrev
);
459 *lParam1
= (DWORD
)(icc
);
460 *lParam2
= sizeof(ICCOMPRESS
);
465 ICDECOMPRESS
*icd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDECOMPRESS
));
466 ICDECOMPRESS
*icd16
; /* Same structure except for the pointers */
468 icd16
= MapSL(*lParam1
);
472 COPYPTR(icd
, lpbiInput
);
473 COPYPTR(icd
, lpInput
);
474 COPYPTR(icd
, lpbiOutput
);
475 COPYPTR(icd
, lpOutput
);
478 *lParam1
= (DWORD
)(icd
);
479 *lParam2
= sizeof(ICDECOMPRESS
);
482 case ICM_COMPRESS_BEGIN
:
483 case ICM_COMPRESS_GET_FORMAT
:
484 case ICM_COMPRESS_GET_SIZE
:
485 case ICM_COMPRESS_QUERY
:
486 case ICM_DECOMPRESS_GET_FORMAT
:
487 case ICM_DECOMPRESS_QUERY
:
488 case ICM_DECOMPRESS_BEGIN
:
489 case ICM_DECOMPRESS_SET_PALETTE
:
490 case ICM_DECOMPRESS_GET_PALETTE
:
491 *lParam1
= (DWORD
)MapSL(*lParam1
);
492 *lParam2
= (DWORD
)MapSL(*lParam2
);
494 case ICM_DECOMPRESSEX_QUERY
:
495 if ((*lParam2
!= sizeof(ICDECOMPRESSEX16
)) && (*lParam2
!= 0))
496 WARN("*lParam2 has unknown value %p\n", (ICDECOMPRESSEX16
*)*lParam2
);
497 /* FIXME: *lParm2 is meant to be 0 or an ICDECOMPRESSEX16*, but is sizeof(ICDECOMRPESSEX16)
498 * This is because of ICMessage(). Special case it?
500 LPVOID* addr = HeapAlloc(GetProcessHeap(), 0, 2*sizeof(LPVOID));
501 addr[0] = MSVIDEO_MapICDEX16To32(lParam1);
503 addr[1] = MSVIDEO_MapICDEX16To32(lParam2);
510 case ICM_DECOMPRESSEX_BEGIN
:
511 case ICM_DECOMPRESSEX
:
512 ret
= MSVIDEO_MapICDEX16To32(lParam1
);
513 *lParam2
= sizeof(ICDECOMPRESSEX
);
517 ICDRAWBEGIN
*icdb
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDRAWBEGIN
));
518 ICDRAWBEGIN16
*icdb16
= MapSL(*lParam1
);
522 icdb
->hpal
= HPALETTE_32(icdb16
->hpal
);
523 icdb
->hwnd
= HWND_32(icdb16
->hwnd
);
524 icdb
->hdc
= HDC_32(icdb16
->hdc
);
537 *lParam1
= (DWORD
)(icdb
);
538 *lParam2
= sizeof(ICDRAWBEGIN
);
541 case ICM_DRAW_SUGGESTFORMAT
:
543 ICDRAWSUGGEST
*icds
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDRAWSUGGEST
));
544 ICDRAWSUGGEST16
*icds16
= MapSL(*lParam1
);
549 COPYPTR(icds
, lpbiIn
);
550 COPYPTR(icds
, lpbiSuggest
);
555 icds
->hicDecompressor
= HIC_32(icds16
->hicDecompressor
);
557 *lParam1
= (DWORD
)(icds
);
558 *lParam2
= sizeof(ICDRAWSUGGEST
);
563 ICDRAW
*icd
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICDRAW
));
564 ICDRAW
*icd16
= MapSL(*lParam1
);
568 COPYPTR(icd
, lpFormat
);
569 COPYPTR(icd
, lpData
);
573 *lParam1
= (DWORD
)(icd
);
574 *lParam2
= sizeof(ICDRAW
);
581 FIXME("%d is not yet handled. Expect a crash.\n", msg
);
589 /******************************************************************
590 * MSVIDEO_UnmapMsg16To32
594 static void MSVIDEO_UnmapMsg16To32(UINT msg
, LPVOID data16
, LPDWORD lParam1
, LPDWORD lParam2
)
596 TRACE("Unmapping %d\n", msg
);
598 #define UNCOPY(x, y) (x##16->y = x->y);
604 ICINFO
*ici
= (ICINFO
*)(*lParam1
);
605 ICINFO16
*ici16
= data16
;
607 UNCOPY(ici
, fccType
);
608 UNCOPY(ici
, fccHandler
);
609 UNCOPY(ici
, dwFlags
);
610 UNCOPY(ici
, dwVersion
);
611 UNCOPY(ici
, dwVersionICM
);
612 WideCharToMultiByte( CP_ACP
, 0, ici
->szName
, -1, ici16
->szName
,
613 sizeof(ici16
->szName
), NULL
, NULL
);
614 ici16
->szName
[sizeof(ici16
->szName
)-1] = 0;
615 WideCharToMultiByte( CP_ACP
, 0, ici
->szDescription
, -1, ici16
->szDescription
,
616 sizeof(ici16
->szDescription
), NULL
, NULL
);
617 ici16
->szDescription
[sizeof(ici16
->szDescription
)-1] = 0;
618 /* This just gives garbage for some reason - BB
619 lstrcpynWtoA(ici16->szDriver, ici->szDriver, 128);*/
621 HeapFree(GetProcessHeap(), 0, ici
);
624 case ICM_DECOMPRESS_QUERY
:
627 HeapFree(GetProcessHeap(), 0, x[0]);
629 HeapFree(GetProcessHeap(), 0, x[1]);
634 case ICM_DECOMPRESSEX_QUERY
:
635 case ICM_DECOMPRESSEX_BEGIN
:
636 case ICM_DECOMPRESSEX
:
638 case ICM_DRAW_SUGGESTFORMAT
:
640 HeapFree(GetProcessHeap(), 0, data16
);
643 ERR("Unmapping unmapped msg %d\n", msg
);
648 /***********************************************************************
649 * ICInfo [MSVIDEO.200]
651 BOOL16 VFWAPI
ICInfo16(DWORD fccType
, DWORD fccHandler
, ICINFO16
*lpicinfo
)
655 DWORD lParam
= (DWORD
)lpicinfo
;
656 DWORD size
= ((ICINFO
*)(MapSL((SEGPTR
)lpicinfo
)))->dwSize
;
658 /* Use the mapping functions to map the ICINFO structure */
659 lpv
= MSVIDEO_MapMsg16To32(ICM_GETINFO
, &lParam
, &size
);
661 ret
= ICInfo(fccType
, fccHandler
, (ICINFO
*)lParam
);
663 MSVIDEO_UnmapMsg16To32(ICM_GETINFO
, lpv
, &lParam
, &size
);
668 /******************************************************************
673 static LRESULT CALLBACK
IC_Callback3216(DWORD pfn16
, HIC hic
, HDRVR hdrv
, UINT msg
, DWORD lp1
, DWORD lp2
)
681 lp2
= (DWORD
)MapLS((void*)lp2
);
684 args
[7] = HIWORD(hic
);
685 args
[6] = LOWORD(hic
);
686 args
[5] = HDRVR_16(hdrv
);
688 args
[3] = HIWORD(lp1
);
689 args
[2] = LOWORD(lp1
);
690 args
[1] = HIWORD(lp2
);
691 args
[0] = LOWORD(lp2
);
692 WOWCallback16Ex( pfn16
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
703 #define MAX_THUNKS 32
705 static struct msvideo_thunk
707 BYTE popl_eax
; /* popl %eax (return address) */
708 BYTE pushl_func
; /* pushl $pfn16 (16bit callback function) */
710 BYTE pushl_eax
; /* pushl %eax */
711 BYTE jmp
; /* ljmp WDML_InvokeCallback16 */
713 HIC16 hIC16
; /* driver's handle */
716 static CRITICAL_SECTION msvideo_cs
;
717 static CRITICAL_SECTION_DEBUG critsect_debug
=
720 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
721 0, 0, { (DWORD_PTR
)(__FILE__
": msvideo_cs") }
723 static CRITICAL_SECTION msvideo_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
725 static struct msvideo_thunk
* MSVIDEO_AddThunk(DWORD pfn16
)
727 struct msvideo_thunk
* thunk
;
731 MSVIDEO_Thunks
= VirtualAlloc(NULL
, MAX_THUNKS
* sizeof(*MSVIDEO_Thunks
), MEM_COMMIT
,
732 PAGE_EXECUTE_READWRITE
);
733 if (!MSVIDEO_Thunks
) return NULL
;
734 for (thunk
= MSVIDEO_Thunks
; thunk
< &MSVIDEO_Thunks
[MAX_THUNKS
]; thunk
++)
736 thunk
->popl_eax
= 0x58; /* popl %eax */
737 thunk
->pushl_func
= 0x68; /* pushl $pfn16 */
739 thunk
->pushl_eax
= 0x50; /* pushl %eax */
740 thunk
->jmp
= 0xe9; /* jmp IC_Callback3216 */
741 thunk
->callback
= (char *)IC_Callback3216
- (char *)(&thunk
->callback
+ 1);
745 for (thunk
= MSVIDEO_Thunks
; thunk
< &MSVIDEO_Thunks
[MAX_THUNKS
]; thunk
++)
747 if (thunk
->pfn16
== 0)
749 thunk
->pfn16
= pfn16
;
753 FIXME("Out of msvideo-thunks. Bump MAX_THUNKS\n");
757 static struct msvideo_thunk
* MSVIDEO_HasThunk(HIC16 hic
)
759 struct msvideo_thunk
* thunk
;
761 for (thunk
= MSVIDEO_Thunks
; thunk
< &MSVIDEO_Thunks
[MAX_THUNKS
]; thunk
++)
763 if (thunk
->hIC16
== hic
) return thunk
;
768 /***********************************************************************
769 * ICOpenFunction [MSVIDEO.206]
771 HIC16 VFWAPI
ICOpenFunction16(DWORD fccType
, DWORD fccHandler
, UINT16 wMode
, FARPROC16 lpfnHandler
)
774 struct msvideo_thunk
* thunk
;
776 EnterCriticalSection(&msvideo_cs
);
777 if (!(thunk
= MSVIDEO_AddThunk((DWORD
)lpfnHandler
)))
779 LeaveCriticalSection(&msvideo_cs
);
782 if ((hic32
= ICOpenFunction(fccType
, fccHandler
, wMode
, IC_Callback3216
)))
783 thunk
->hIC16
= HIC_16(hic32
);
786 LeaveCriticalSection(&msvideo_cs
);
787 return HIC_16(hic32
);
790 /***********************************************************************
791 * ICSendMessage [MSVIDEO.205]
793 LRESULT VFWAPI
ICSendMessage16(HIC16 hic
, UINT16 msg
, DWORD lParam1
, DWORD lParam2
)
795 LRESULT ret
= ICERR_BADHANDLE
;
796 struct msvideo_thunk
* thunk
;
798 if ((thunk
= MSVIDEO_HasThunk(hic
)))
803 /* FIXME: original code was passing hdrv first and hic second */
804 /* but this doesn't match what IC_Callback3216 does */
805 args
[7] = HIWORD(hic
);
806 args
[6] = LOWORD(hic
);
807 args
[5] = 0; /* the 32bit also sets it to NULL */
809 args
[3] = HIWORD(lParam1
);
810 args
[2] = LOWORD(lParam1
);
811 args
[1] = HIWORD(lParam2
);
812 args
[0] = LOWORD(lParam2
);
813 WOWCallback16Ex( thunk
->pfn16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
818 /* map the message for a 32 bit infrastructure, and pass it along */
819 void* data16
= MSVIDEO_MapMsg16To32(msg
, &lParam1
, &lParam2
);
821 ret
= ICSendMessage(HIC_32(hic
), msg
, lParam1
, lParam2
);
823 MSVIDEO_UnmapMsg16To32(msg
, data16
, &lParam1
, &lParam2
);
828 /***********************************************************************
829 * ICClose [MSVIDEO.204]
831 LRESULT WINAPI
ICClose16(HIC16 hic
)
833 BOOL ret
= ICClose(HIC_32(hic
));
835 EnterCriticalSection(&msvideo_cs
);
838 struct msvideo_thunk
* thunk
;
839 if ((thunk
= MSVIDEO_HasThunk(hic
)))
846 LeaveCriticalSection(&msvideo_cs
);
850 /***********************************************************************
851 * VideoCapDriverDescAndVer [MSVIDEO.22]
853 DWORD WINAPI
VideoCapDriverDescAndVer16(WORD nr
, LPSTR buf1
, WORD buf1len
,
854 LPSTR buf2
, WORD buf2len
)
856 static const char version_info_spec
[] = "\\StringFileInfo\\040904E4\\FileDescription";
860 char *s
, buf
[2048], fn
[260];
863 DWORD i
, cnt
= 0, lRet
;
869 TRACE("(%d,%p,%d,%p,%d)\n", nr
, buf1
, buf1len
, buf2
, buf2len
);
870 lRet
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_QUERY_VALUE
, &hKey
);
871 if (lRet
== ERROR_SUCCESS
)
873 RegQueryInfoKeyA( hKey
, 0, 0, 0, &cnt
, 0, 0, 0, 0, 0, 0, 0);
874 for (i
= 0; i
< cnt
; i
++)
876 bufLen
= sizeof(buf
) / sizeof(buf
[0]);
877 lRet
= RegEnumKeyExA(hKey
, i
, buf
, &bufLen
, 0, 0, 0, &lastWrite
);
878 if (lRet
!= ERROR_SUCCESS
) continue;
879 if (strncasecmp(buf
, "vid", 3)) continue;
882 lRet
= RegQueryValueExA(hKey
, buf
, 0, 0, (LPBYTE
)fn
, &fnLen
);
883 if (lRet
== ERROR_SUCCESS
) found
= TRUE
;
889 /* search system.ini if not found in the registry */
890 if (!found
&& GetPrivateProfileStringA("drivers32", NULL
, NULL
, buf
, sizeof(buf
), "system.ini"))
892 for (s
= buf
; *s
; s
+= strlen(s
) + 1)
894 if (strncasecmp(s
, "vid", 3)) continue;
896 if (GetPrivateProfileStringA("drivers32", s
, NULL
, fn
, sizeof(fn
), "system.ini"))
904 TRACE("No more VID* entries found nr=%d\n", nr
);
907 infosize
= GetFileVersionInfoSizeA(fn
, &verhandle
);
910 TRACE("%s has no fileversioninfo.\n", fn
);
913 infobuf
= HeapAlloc(GetProcessHeap(), 0, infosize
);
914 if (GetFileVersionInfoA(fn
, verhandle
, infosize
, infobuf
))
916 /* Yes, two space behind : */
917 /* FIXME: test for buflen */
918 snprintf(buf2
, buf2len
, "Version: %d.%d.%d.%d\n",
919 ((WORD
*)infobuf
)[0x0f],
920 ((WORD
*)infobuf
)[0x0e],
921 ((WORD
*)infobuf
)[0x11],
922 ((WORD
*)infobuf
)[0x10]
924 TRACE("version of %s is %s\n", fn
, buf2
);
928 TRACE("GetFileVersionInfoA failed for %s.\n", fn
);
929 lstrcpynA(buf2
, fn
, buf2len
); /* msvideo.dll appears to copy fn*/
931 /* FIXME: language problem? */
932 if (VerQueryValueA( infobuf
,
938 UINT copylen
= min(subblocklen
,buf1len
-1);
939 memcpy(buf1
, subblock
, copylen
);
940 buf1
[copylen
] = '\0';
941 TRACE("VQA returned %s\n", (LPCSTR
)subblock
);
945 TRACE("VQA did not return on query \\StringFileInfo\\040904E4\\FileDescription?\n");
946 lstrcpynA(buf1
, fn
, buf1len
); /* msvideo.dll appears to copy fn*/
948 HeapFree(GetProcessHeap(), 0, infobuf
);
952 /**************************************************************************
953 * DllEntryPoint (MSVIDEO.3)
955 * MSVIDEO DLL entry point
958 BOOL WINAPI
VIDEO_LibMain(DWORD fdwReason
, HINSTANCE hinstDLL
, WORD ds
,
959 WORD wHeapSize
, DWORD dwReserved1
, WORD wReserved2
)
963 case DLL_PROCESS_ATTACH
:
965 case DLL_PROCESS_DETACH
:
967 case DLL_THREAD_ATTACH
:
968 case DLL_THREAD_DETACH
: