CreateDIBSection takes a const pointer to BITMAPINFO.
[wine] / dlls / ddraw / ddraw / thunks.c
1 /* Direct Draw Thunks and old vtables
2  * Copyright 2000 TransGaming Technologies Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 #include <stdarg.h>
19
20 #include "windef.h"
21 #include "winbase.h"
22 #include "wingdi.h"
23 #include "ddraw.h"
24 #include "ddraw_private.h"
25 #include "ddcomimpl.h"
26
27 static HRESULT WINAPI
28 IDirectDrawImpl_QueryInterface(LPDIRECTDRAW This, REFIID iid, LPVOID *ppObj)
29 {
30     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl,
31                                                           IDirectDraw,
32                                                           IDirectDraw7, This),
33                                        iid, ppObj);
34 }
35
36 static HRESULT WINAPI
37 IDirectDraw2Impl_QueryInterface(LPDIRECTDRAW2 This, REFIID iid, LPVOID *ppObj)
38 {
39     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl,
40                                                           IDirectDraw2,
41                                                           IDirectDraw7, This),
42                                        iid, ppObj);
43 }
44
45
46 static HRESULT WINAPI
47 IDirectDraw4Impl_QueryInterface(LPDIRECTDRAW4 This, REFIID iid, LPVOID *ppObj)
48 {
49     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl,
50                                                           IDirectDraw4,
51                                                           IDirectDraw7, This),
52                                        iid, ppObj);
53 }
54
55 static ULONG WINAPI
56 IDirectDrawImpl_AddRef(LPDIRECTDRAW This)
57 {
58     return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl,
59                                                   IDirectDraw, IDirectDraw7,
60                                                   This));
61 }
62
63 static ULONG WINAPI
64 IDirectDraw2Impl_AddRef(LPDIRECTDRAW2 This)
65 {
66     return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl,
67                                                   IDirectDraw2, IDirectDraw7,
68                                                   This));
69 }
70
71 static ULONG WINAPI
72 IDirectDraw4Impl_AddRef(LPDIRECTDRAW4 This)
73 {
74     return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl,
75                                                   IDirectDraw4, IDirectDraw7,
76                                                   This));
77 }
78
79 static ULONG WINAPI
80 IDirectDrawImpl_Release(LPDIRECTDRAW This)
81 {
82     return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
83                                                    IDirectDraw, IDirectDraw7,
84                                                    This));
85 }
86
87 static ULONG WINAPI
88 IDirectDraw2Impl_Release(LPDIRECTDRAW2 This)
89 {
90     return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
91                                                    IDirectDraw2, IDirectDraw7,
92                                                    This));
93 }
94
95 static ULONG WINAPI
96 IDirectDraw4Impl_Release(LPDIRECTDRAW4 This)
97 {
98     return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
99                                                    IDirectDraw4, IDirectDraw7,
100                                                    This));
101 }
102
103 static HRESULT WINAPI
104 IDirectDrawImpl_Compact(LPDIRECTDRAW This)
105 {
106     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
107                                                    IDirectDraw, IDirectDraw7,
108                                                    This));
109 }
110
111 static HRESULT WINAPI
112 IDirectDraw2Impl_Compact(LPDIRECTDRAW2 This)
113 {
114     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
115                                                    IDirectDraw2, IDirectDraw7,
116                                                    This));
117 }
118
119 static HRESULT WINAPI
120 IDirectDraw4Impl_Compact(LPDIRECTDRAW4 This)
121 {
122     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
123                                                    IDirectDraw4, IDirectDraw7,
124                                                    This));
125 }
126
127 static HRESULT WINAPI
128 IDirectDrawImpl_CreateClipper(LPDIRECTDRAW This, DWORD dwFlags,
129                               LPDIRECTDRAWCLIPPER *ppClipper,
130                               IUnknown *pUnkOuter)
131 {
132     return IDirectDraw7_CreateClipper(COM_INTERFACE_CAST(IDirectDrawImpl,
133                                                          IDirectDraw,
134                                                          IDirectDraw7,
135                                                          This),
136                                       dwFlags, ppClipper, pUnkOuter);
137 }
138
139 static HRESULT WINAPI
140 IDirectDraw2Impl_CreateClipper(LPDIRECTDRAW2 This, DWORD dwFlags,
141                                LPDIRECTDRAWCLIPPER *ppClipper,
142                                IUnknown *pUnkOuter)
143 {
144     return IDirectDraw7_CreateClipper(COM_INTERFACE_CAST(IDirectDrawImpl,
145                                                          IDirectDraw2,
146                                                          IDirectDraw7,
147                                                          This),
148                                       dwFlags, ppClipper, pUnkOuter);
149 }
150
151 static HRESULT WINAPI
152 IDirectDraw4Impl_CreateClipper(LPDIRECTDRAW4 This, DWORD dwFlags,
153                                LPDIRECTDRAWCLIPPER *ppClipper,
154                                IUnknown *pUnkOuter)
155 {
156     return IDirectDraw7_CreateClipper(COM_INTERFACE_CAST(IDirectDrawImpl,
157                                                          IDirectDraw4,
158                                                          IDirectDraw7,
159                                                          This),
160                                       dwFlags, ppClipper, pUnkOuter);
161 }
162
163 static HRESULT WINAPI
164 IDirectDrawImpl_CreatePalette(LPDIRECTDRAW This, DWORD dwFlags,
165                               LPPALETTEENTRY pEntries,
166                               LPDIRECTDRAWPALETTE *ppPalette,
167                               IUnknown *pUnkOuter)
168 {
169     return IDirectDraw7_CreatePalette(COM_INTERFACE_CAST(IDirectDrawImpl,
170                                                          IDirectDraw,
171                                                          IDirectDraw7,
172                                                          This),
173                                       dwFlags, pEntries, ppPalette, pUnkOuter);
174 }
175
176 static HRESULT WINAPI
177 IDirectDraw2Impl_CreatePalette(LPDIRECTDRAW2 This, DWORD dwFlags,
178                                LPPALETTEENTRY pEntries,
179                                LPDIRECTDRAWPALETTE *ppPalette,
180                                IUnknown *pUnkOuter)
181 {
182     return IDirectDraw7_CreatePalette(COM_INTERFACE_CAST(IDirectDrawImpl,
183                                                          IDirectDraw2,
184                                                          IDirectDraw7,
185                                                          This),
186                                       dwFlags, pEntries, ppPalette, pUnkOuter);
187 }
188
189 static HRESULT WINAPI
190 IDirectDraw4Impl_CreatePalette(LPDIRECTDRAW4 This, DWORD dwFlags,
191                                LPPALETTEENTRY pEntries,
192                                LPDIRECTDRAWPALETTE *ppPalette,
193                                IUnknown *pUnkOuter)
194 {
195     return IDirectDraw7_CreatePalette(COM_INTERFACE_CAST(IDirectDrawImpl,
196                                                          IDirectDraw4,
197                                                          IDirectDraw7,
198                                                          This),
199                                       dwFlags, pEntries, ppPalette, pUnkOuter);
200 }
201
202 static HRESULT WINAPI
203 IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc,
204                               LPDIRECTDRAWSURFACE *ppSurface,
205                               IUnknown *pUnkOuter)
206 {
207     LPDIRECTDRAWSURFACE7 pSurface7;
208     HRESULT hr;
209
210     /* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
211      * since the data layout is the same */
212     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
213                                                        IDirectDraw,
214                                                        IDirectDraw7,
215                                                        This),
216                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
217
218     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
219      * IDirectDrawSurface vtable layout at the beginning  */
220     *ppSurface = (LPDIRECTDRAWSURFACE) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
221                                     IDirectDrawSurface7, IDirectDrawSurface3,
222                                     pSurface7);
223
224     return hr;
225 }
226
227 static HRESULT WINAPI
228 IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc,
229                                LPDIRECTDRAWSURFACE *ppSurface,
230                                IUnknown *pUnkOuter)
231 {
232     LPDIRECTDRAWSURFACE7 pSurface7;
233     HRESULT hr;
234
235     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
236                                                        IDirectDraw2,
237                                                        IDirectDraw7,
238                                                        This),
239                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
240
241     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
242      * IDirectDrawSurface vtable layout at the beginning  */
243     *ppSurface = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
244                                     IDirectDrawSurface7, IDirectDrawSurface3,
245                                     pSurface7);
246
247     return hr;
248 }
249
250 static HRESULT WINAPI
251 IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
252                                LPDIRECTDRAWSURFACE4 *ppSurface,
253                                IUnknown *pUnkOuter)
254 {
255     return IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
256                                                          IDirectDraw4,
257                                                          IDirectDraw7,
258                                                          This),
259                                       pSDesc,
260                                       (LPDIRECTDRAWSURFACE7 *)ppSurface,
261                                       pUnkOuter);
262 }
263
264 static HRESULT WINAPI
265 IDirectDrawImpl_DuplicateSurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE pSrc,
266                                  LPDIRECTDRAWSURFACE *ppDst)
267 {
268     LPDIRECTDRAWSURFACE7 pDst7;
269     HRESULT hr;
270
271     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
272                                                           IDirectDraw,
273                                                           IDirectDraw7, This),
274                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
275                                                           IDirectDrawSurface3,
276                                                           IDirectDrawSurface7,
277                                                           pSrc),
278                                        &pDst7);
279
280     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
281      * IDirectDrawSurface vtable layout at the beginning  */
282     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
283                                 IDirectDrawSurface3, pDst7);
284
285     return hr;
286 }
287
288 static HRESULT WINAPI
289 IDirectDraw2Impl_DuplicateSurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE pSrc,
290                                   LPDIRECTDRAWSURFACE *ppDst)
291 {
292     LPDIRECTDRAWSURFACE7 pDst7;
293     HRESULT hr;
294
295     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
296                                                           IDirectDraw2,
297                                                           IDirectDraw7, This),
298                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
299                                                           IDirectDrawSurface3,
300                                                           IDirectDrawSurface7,
301                                                           pSrc),
302                                        &pDst7);
303
304     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
305      * IDirectDrawSurface vtable layout at the beginning  */
306     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
307                                 IDirectDrawSurface3, pDst7);
308
309     return hr;
310 }
311
312 static HRESULT WINAPI
313 IDirectDraw4Impl_DuplicateSurface(LPDIRECTDRAW4 This,
314                                   LPDIRECTDRAWSURFACE4 pSrc,
315                                   LPDIRECTDRAWSURFACE4 *ppDst)
316 {
317     return IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
318                                                             IDirectDraw4,
319                                                             IDirectDraw7,
320                                                             This),
321                                          (LPDIRECTDRAWSURFACE7)pSrc,
322                                          (LPDIRECTDRAWSURFACE7 *)ppDst);
323 }
324
325 struct displaymodescallback_context
326 {
327     LPDDENUMMODESCALLBACK func;
328     LPVOID context;
329 };
330
331 static HRESULT CALLBACK
332 EnumDisplayModesCallbackThunk(LPDDSURFACEDESC2 pDDSD2, LPVOID context)
333 {
334     DDSURFACEDESC DDSD;
335     struct displaymodescallback_context *cbcontext = context;
336
337     memcpy(&DDSD,pDDSD2,sizeof(DDSD));
338     DDSD.dwSize = sizeof(DDSD);
339
340     return cbcontext->func(&DDSD, cbcontext->context);
341 }
342
343 static HRESULT WINAPI
344 IDirectDrawImpl_EnumDisplayModes(LPDIRECTDRAW This, DWORD dwFlags,
345                                  LPDDSURFACEDESC pDDSD, LPVOID context,
346                                  LPDDENUMMODESCALLBACK cb)
347 {
348     struct displaymodescallback_context cbcontext;
349
350     cbcontext.func    = cb;
351     cbcontext.context = context;
352
353     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
354                                                             IDirectDraw,
355                                                             IDirectDraw7,
356                                                             This),
357                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
358                                          EnumDisplayModesCallbackThunk);
359 }
360
361 static HRESULT WINAPI
362 IDirectDraw2Impl_EnumDisplayModes(LPDIRECTDRAW2 This, DWORD dwFlags,
363                                   LPDDSURFACEDESC pDDSD, LPVOID context,
364                                   LPDDENUMMODESCALLBACK cb)
365 {
366     struct displaymodescallback_context cbcontext;
367
368     cbcontext.func    = cb;
369     cbcontext.context = context;
370
371     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
372                                                             IDirectDraw2,
373                                                             IDirectDraw7,
374                                                             This),
375                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
376                                          EnumDisplayModesCallbackThunk);
377 }
378
379 static HRESULT WINAPI
380 IDirectDraw4Impl_EnumDisplayModes(LPDIRECTDRAW4 This, DWORD dwFlags,
381                                   LPDDSURFACEDESC2 pDDSD, LPVOID context,
382                                   LPDDENUMMODESCALLBACK2 cb)
383 {
384     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
385                                                             IDirectDraw4,
386                                                             IDirectDraw7,
387                                                             This),
388                                          dwFlags, pDDSD, context, cb);
389 }
390
391 struct surfacescallback_context
392 {
393     LPDDENUMSURFACESCALLBACK func;
394     LPVOID context;
395 };
396
397 static HRESULT CALLBACK
398 EnumSurfacesCallbackThunk(LPDIRECTDRAWSURFACE7 pSurf, LPDDSURFACEDESC2 pDDSD,
399                           LPVOID context)
400 {
401     struct surfacescallback_context *cbcontext = context;
402
403     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
404      * IDirectDrawSurface vtable layout at the beginning  */
405     return cbcontext->func((LPDIRECTDRAWSURFACE)
406                            COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
407                                               IDirectDrawSurface7,
408                                               IDirectDrawSurface3, pSurf),
409                            (LPDDSURFACEDESC)pDDSD, cbcontext->context);
410 }
411
412 static HRESULT WINAPI
413 IDirectDrawImpl_EnumSurfaces(LPDIRECTDRAW This, DWORD dwFlags,
414                              LPDDSURFACEDESC pDDSD, LPVOID context,
415                              LPDDENUMSURFACESCALLBACK cb)
416 {
417     struct surfacescallback_context cbcontext;
418
419     cbcontext.func    = cb;
420     cbcontext.context = context;
421
422     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
423                                                         IDirectDraw,
424                                                         IDirectDraw7, This),
425                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
426                                      &cbcontext, EnumSurfacesCallbackThunk);
427 }
428
429 static HRESULT WINAPI
430 IDirectDraw2Impl_EnumSurfaces(LPDIRECTDRAW2 This, DWORD dwFlags,
431                               LPDDSURFACEDESC pDDSD, LPVOID context,
432                               LPDDENUMSURFACESCALLBACK cb)
433 {
434     struct surfacescallback_context cbcontext;
435
436     cbcontext.func    = cb;
437     cbcontext.context = context;
438
439     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
440                                                         IDirectDraw2,
441                                                         IDirectDraw7, This),
442                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
443                                      &cbcontext, EnumSurfacesCallbackThunk);
444 }
445
446 static HRESULT WINAPI
447 IDirectDraw4Impl_EnumSurfaces(LPDIRECTDRAW4 This, DWORD dwFlags,
448                               LPDDSURFACEDESC2 pDDSD, LPVOID context,
449                               LPDDENUMSURFACESCALLBACK2 cb)
450 {
451     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
452                                                         IDirectDraw4,
453                                                         IDirectDraw7, This),
454                                      dwFlags, pDDSD, context,
455                                      (LPDDENUMSURFACESCALLBACK7)cb);
456 }
457
458 static HRESULT WINAPI
459 IDirectDrawImpl_FlipToGDISurface(LPDIRECTDRAW This)
460 {
461     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
462                                                             IDirectDraw,
463                                                             IDirectDraw7,
464                                                             This));
465 }
466
467 static HRESULT WINAPI
468 IDirectDraw2Impl_FlipToGDISurface(LPDIRECTDRAW2 This)
469 {
470     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
471                                                             IDirectDraw2,
472                                                             IDirectDraw7,
473                                                             This));
474 }
475
476 static HRESULT WINAPI
477 IDirectDraw4Impl_FlipToGDISurface(LPDIRECTDRAW4 This)
478 {
479     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
480                                                             IDirectDraw4,
481                                                             IDirectDraw7,
482                                                             This));
483 }
484
485 static HRESULT WINAPI
486 IDirectDrawImpl_GetCaps(LPDIRECTDRAW This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
487 {
488     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
489                                                    IDirectDraw, IDirectDraw7,
490                                                    This), pDDC1, pDDC2);
491 }
492
493 static HRESULT WINAPI
494 IDirectDraw2Impl_GetCaps(LPDIRECTDRAW2 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
495 {
496     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
497                                                    IDirectDraw2, IDirectDraw7,
498                                                    This), pDDC1, pDDC2);
499 }
500
501 static HRESULT WINAPI
502 IDirectDraw4Impl_GetCaps(LPDIRECTDRAW4 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
503 {
504     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
505                                                    IDirectDraw4, IDirectDraw7,
506                                                    This), pDDC1, pDDC2);
507 }
508
509 static HRESULT WINAPI
510 IDirectDrawImpl_GetDisplayMode(LPDIRECTDRAW This, LPDDSURFACEDESC pDDSD)
511 {
512     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
513                                                           IDirectDraw,
514                                                           IDirectDraw7, This),
515                                        (LPDDSURFACEDESC2)pDDSD);
516 }
517
518 static HRESULT WINAPI
519 IDirectDraw2Impl_GetDisplayMode(LPDIRECTDRAW2 This, LPDDSURFACEDESC pDDSD)
520 {
521     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
522                                                           IDirectDraw2,
523                                                           IDirectDraw7, This),
524                                        (LPDDSURFACEDESC2)pDDSD);
525 }
526
527 static HRESULT WINAPI
528 IDirectDraw4Impl_GetDisplayMode(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pDDSD)
529 {
530     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
531                                                           IDirectDraw4,
532                                                           IDirectDraw7, This),
533                                        pDDSD);
534 }
535
536 static HRESULT WINAPI
537 IDirectDrawImpl_GetFourCCCodes(LPDIRECTDRAW This, LPDWORD lpNumCodes,
538                                LPDWORD lpCodes)
539 {
540     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
541                                                           IDirectDraw,
542                                                           IDirectDraw7,
543                                                           This),
544                                        lpNumCodes, lpCodes);
545 }
546
547 static HRESULT WINAPI
548 IDirectDraw2Impl_GetFourCCCodes(LPDIRECTDRAW2 This, LPDWORD lpNumCodes,
549                                 LPDWORD lpCodes)
550 {
551     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
552                                                           IDirectDraw2,
553                                                           IDirectDraw7,
554                                                           This),
555                                        lpNumCodes, lpCodes);
556 }
557
558 static HRESULT WINAPI
559 IDirectDraw4Impl_GetFourCCCodes(LPDIRECTDRAW4 This, LPDWORD lpNumCodes,
560                                 LPDWORD lpCodes)
561 {
562     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
563                                                           IDirectDraw4,
564                                                           IDirectDraw7,
565                                                           This),
566                                        lpNumCodes, lpCodes);
567 }
568
569 static HRESULT WINAPI
570 IDirectDrawImpl_GetGDISurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE *ppSurf)
571 {
572     LPDIRECTDRAWSURFACE7 pSurf7;
573     HRESULT hr;
574
575     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
576                                                        IDirectDraw,
577                                                        IDirectDraw7,
578                                                        This), &pSurf7);
579
580     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
581      * IDirectDrawSurface vtable layout at the beginning  */
582     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
583                                  IDirectDrawSurface3, pSurf7);
584
585     return hr;
586 }
587
588 static HRESULT WINAPI
589 IDirectDraw2Impl_GetGDISurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE *ppSurf)
590 {
591     LPDIRECTDRAWSURFACE7 pSurf7;
592     HRESULT hr;
593
594     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
595                                                        IDirectDraw2,
596                                                        IDirectDraw7,
597                                                        This), &pSurf7);
598
599     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
600      * IDirectDrawSurface vtable layout at the beginning  */
601     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
602                                  IDirectDrawSurface3, pSurf7);
603
604     return hr;
605 }
606
607 static HRESULT WINAPI
608 IDirectDraw4Impl_GetGDISurface(LPDIRECTDRAW4 This,
609                                LPDIRECTDRAWSURFACE4 *ppSurf)
610 {
611     return IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
612                                                          IDirectDraw4,
613                                                          IDirectDraw7,
614                                                          This),
615                                       (LPDIRECTDRAWSURFACE7 *)ppSurf);
616 }
617
618 static HRESULT WINAPI
619 IDirectDrawImpl_GetMonitorFrequency(LPDIRECTDRAW This, LPDWORD pdwFreq)
620 {
621     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
622                                                                IDirectDraw,
623                                                                IDirectDraw7,
624                                                                This),
625                                             pdwFreq);
626 }
627
628 static HRESULT WINAPI
629 IDirectDraw2Impl_GetMonitorFrequency(LPDIRECTDRAW2 This, LPDWORD pdwFreq)
630 {
631     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
632                                                                IDirectDraw2,
633                                                                IDirectDraw7,
634                                                                This),
635                                             pdwFreq);
636 }
637
638 static HRESULT WINAPI
639 IDirectDraw4Impl_GetMonitorFrequency(LPDIRECTDRAW4 This, LPDWORD pdwFreq)
640 {
641     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
642                                                                IDirectDraw4,
643                                                                IDirectDraw7,
644                                                                This),
645                                             pdwFreq);
646 }
647
648 static HRESULT WINAPI
649 IDirectDrawImpl_GetScanLine(LPDIRECTDRAW This, LPDWORD pdwLine)
650 {
651     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
652                                                        IDirectDraw,
653                                                        IDirectDraw7,
654                                                        This), pdwLine);
655 }
656
657 static HRESULT WINAPI
658 IDirectDraw2Impl_GetScanLine(LPDIRECTDRAW2 This, LPDWORD pdwLine)
659 {
660     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
661                                                        IDirectDraw2,
662                                                        IDirectDraw7,
663                                                        This), pdwLine);
664 }
665
666 static HRESULT WINAPI
667 IDirectDraw4Impl_GetScanLine(LPDIRECTDRAW4 This, LPDWORD pdwLine)
668 {
669     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
670                                                        IDirectDraw4,
671                                                        IDirectDraw7,
672                                                        This), pdwLine);
673 }
674
675 static HRESULT WINAPI
676 IDirectDrawImpl_GetVerticalBlankStatus(LPDIRECTDRAW This, LPBOOL lpbIsInVB)
677 {
678     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
679                                                                   IDirectDraw,
680                                                                   IDirectDraw7,
681                                                                   This),
682                                                lpbIsInVB);
683 }
684
685 static HRESULT WINAPI
686 IDirectDraw2Impl_GetVerticalBlankStatus(LPDIRECTDRAW2 This, LPBOOL lpbIsInVB)
687 {
688     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
689                                                                   IDirectDraw2,
690                                                                   IDirectDraw7,
691                                                                   This),
692                                                lpbIsInVB);
693 }
694
695 static HRESULT WINAPI
696 IDirectDraw4Impl_GetVerticalBlankStatus(LPDIRECTDRAW4 This, LPBOOL lpbIsInVB)
697 {
698     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
699                                                                   IDirectDraw4,
700                                                                   IDirectDraw7,
701                                                                   This),
702                                                lpbIsInVB);
703 }
704
705 static HRESULT WINAPI
706 IDirectDrawImpl_Initialize(LPDIRECTDRAW iface, LPGUID pGUID)
707 {
708     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw, iface);
709     HRESULT ret_value;
710
711     ret_value = IDirectDraw7_Initialize(ICOM_INTERFACE(This, IDirectDraw7), pGUID);
712     
713     /* Overwrite the falsely set 'DIRECTDRAW7' flag */
714     This->local.dwLocalFlags &= ~DDRAWILCL_DIRECTDRAW7;
715     
716     return ret_value;
717 }
718
719 static HRESULT WINAPI
720 IDirectDraw2Impl_Initialize(LPDIRECTDRAW2 iface, LPGUID pGUID)
721 {
722     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw2, iface);
723     HRESULT ret_value;
724     
725     ret_value = IDirectDraw7_Initialize(ICOM_INTERFACE(This, IDirectDraw7), pGUID);
726
727     /* Overwrite the falsely set 'DIRECTDRAW7' flag */
728     This->local.dwLocalFlags &= ~DDRAWILCL_DIRECTDRAW7;
729     
730     return ret_value;
731 }
732
733 static HRESULT WINAPI
734 IDirectDraw4Impl_Initialize(LPDIRECTDRAW4 iface, LPGUID pGUID)
735 {
736     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw4, iface);
737     HRESULT ret_value;
738     
739     ret_value = IDirectDraw7_Initialize(ICOM_INTERFACE(This, IDirectDraw7), pGUID);
740     
741     /* Overwrite the falsely set 'DIRECTDRAW7' flag */
742     This->local.dwLocalFlags &= ~DDRAWILCL_DIRECTDRAW7;
743     
744     return ret_value;
745 }
746
747
748 static HRESULT WINAPI
749 IDirectDrawImpl_RestoreDisplayMode(LPDIRECTDRAW This)
750 {
751     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
752                                                               IDirectDraw,
753                                                               IDirectDraw7,
754                                                               This));
755 }
756
757 static HRESULT WINAPI
758 IDirectDraw2Impl_RestoreDisplayMode(LPDIRECTDRAW2 This)
759 {
760     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
761                                                               IDirectDraw2,
762                                                               IDirectDraw7,
763                                                               This));
764 }
765
766 static HRESULT WINAPI
767 IDirectDraw4Impl_RestoreDisplayMode(LPDIRECTDRAW4 This)
768 {
769     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
770                                                               IDirectDraw4,
771                                                               IDirectDraw7,
772                                                               This));
773 }
774
775 static HRESULT WINAPI
776 IDirectDrawImpl_SetCooperativeLevel(LPDIRECTDRAW This, HWND hWnd,
777                                     DWORD dwFlags)
778 {
779     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
780                                                                IDirectDraw,
781                                                                IDirectDraw7,
782                                                                This),
783                                             hWnd, dwFlags);
784 }
785
786 static HRESULT WINAPI
787 IDirectDraw2Impl_SetCooperativeLevel(LPDIRECTDRAW2 This, HWND hWnd,
788                                      DWORD dwFlags)
789 {
790     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
791                                                                IDirectDraw2,
792                                                                IDirectDraw7,
793                                                                This),
794                                             hWnd, dwFlags);
795 }
796
797 static HRESULT WINAPI
798 IDirectDraw4Impl_SetCooperativeLevel(LPDIRECTDRAW4 This, HWND hWnd,
799                                      DWORD dwFlags)
800 {
801     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
802                                                                IDirectDraw4,
803                                                                IDirectDraw7,
804                                                                This),
805                                             hWnd, dwFlags);
806 }
807
808 static HRESULT WINAPI
809 IDirectDrawImpl_SetDisplayMode(LPDIRECTDRAW This, DWORD a, DWORD b, DWORD c)
810 {
811     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
812                                                           IDirectDraw,
813                                                           IDirectDraw7,
814                                                           This),
815                                        a, b, c, 0, 0);
816 }
817
818 static HRESULT WINAPI
819 IDirectDraw2Impl_SetDisplayMode(LPDIRECTDRAW2 This, DWORD a, DWORD b, DWORD c,
820                                 DWORD d, DWORD e)
821 {
822     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
823                                                           IDirectDraw2,
824                                                           IDirectDraw7,
825                                                           This),
826                                        a, b, c, d, e);
827 }
828
829 static HRESULT WINAPI
830 IDirectDraw4Impl_SetDisplayMode(LPDIRECTDRAW4 This, DWORD a, DWORD b, DWORD c,
831                                 DWORD d, DWORD e)
832 {
833     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
834                                                           IDirectDraw4,
835                                                           IDirectDraw7,
836                                                           This),
837                                        a, b, c, d, e);
838 }
839
840 static HRESULT WINAPI
841 IDirectDrawImpl_WaitForVerticalBlank(LPDIRECTDRAW This, DWORD dwFlags,
842                                      HANDLE hEvent)
843 {
844     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
845                                                                 IDirectDraw,
846                                                                 IDirectDraw7,
847                                                                 This),
848                                              dwFlags, hEvent);
849 }
850
851 static HRESULT WINAPI
852 IDirectDraw2Impl_WaitForVerticalBlank(LPDIRECTDRAW2 This, DWORD dwFlags,
853                                       HANDLE hEvent)
854 {
855     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
856                                                                 IDirectDraw2,
857                                                                 IDirectDraw7,
858                                                                 This),
859                                              dwFlags, hEvent);
860 }
861
862 static HRESULT WINAPI
863 IDirectDraw4Impl_WaitForVerticalBlank(LPDIRECTDRAW4 This, DWORD dwFlags,
864                                       HANDLE hEvent)
865 {
866     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
867                                                                 IDirectDraw4,
868                                                                 IDirectDraw7,
869                                                                 This),
870                                              dwFlags, hEvent);
871 }
872
873 static HRESULT WINAPI
874 IDirectDraw2Impl_GetAvailableVidMem(LPDIRECTDRAW2 This, LPDDSCAPS pCaps,
875                                     LPDWORD pdwTotal, LPDWORD pdwFree)
876 {
877     DDSCAPS2 Caps2;
878     DDRAW_Convert_DDSCAPS_1_To_2(pCaps, &Caps2);
879
880     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
881                                                               IDirectDraw2,
882                                                               IDirectDraw7,
883                                                               This),
884                                            &Caps2, pdwTotal, pdwFree);
885 }
886
887 static HRESULT WINAPI
888 IDirectDraw4Impl_GetAvailableVidMem(LPDIRECTDRAW4 This, LPDDSCAPS2 pCaps,
889                                     LPDWORD pdwTotal, LPDWORD pdwFree)
890 {
891     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
892                                                               IDirectDraw4,
893                                                               IDirectDraw7,
894                                                               This),
895                                            pCaps, pdwTotal, pdwFree);
896 }
897
898 static HRESULT WINAPI
899 IDirectDraw4Impl_GetSurfaceFromDC(LPDIRECTDRAW4 This, HDC hDC,
900                                   LPDIRECTDRAWSURFACE4 *pSurf)
901 {
902     return IDirectDraw7_GetSurfaceFromDC(COM_INTERFACE_CAST(IDirectDrawImpl,
903                                                             IDirectDraw4,
904                                                             IDirectDraw7,
905                                                             This),
906                                          hDC, (LPDIRECTDRAWSURFACE7 *)pSurf);
907 }
908
909 static HRESULT WINAPI
910 IDirectDraw4Impl_RestoreAllSurfaces(LPDIRECTDRAW4 This)
911 {
912     return IDirectDraw7_RestoreAllSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
913                                                               IDirectDraw4,
914                                                               IDirectDraw7,
915                                                               This));
916 }
917
918 static HRESULT WINAPI
919 IDirectDraw4Impl_TestCooperativeLevel(LPDIRECTDRAW4 This)
920 {
921     return IDirectDraw7_TestCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
922                                                                 IDirectDraw4,
923                                                                 IDirectDraw7,
924                                                                 This));
925 }
926
927 static HRESULT WINAPI
928 IDirectDraw4Impl_GetDeviceIdentifier(LPDIRECTDRAW4 This,
929                                      LPDDDEVICEIDENTIFIER pDDDI, DWORD dwFlags)
930 {
931     DDDEVICEIDENTIFIER2 DDDI2;
932     HRESULT hr;
933
934     hr = IDirectDraw7_GetDeviceIdentifier(COM_INTERFACE_CAST(IDirectDrawImpl,
935                                                              IDirectDraw4,
936                                                              IDirectDraw7,
937                                                              This),
938                                           &DDDI2, dwFlags);
939
940     DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&DDDI2, pDDDI);
941
942     return hr;
943 }
944
945 ICOM_VTABLE(IDirectDraw) DDRAW_IDirectDraw_VTable =
946 {
947     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
948     IDirectDrawImpl_QueryInterface,
949     IDirectDrawImpl_AddRef,
950     IDirectDrawImpl_Release,
951     IDirectDrawImpl_Compact,
952     IDirectDrawImpl_CreateClipper,
953     IDirectDrawImpl_CreatePalette,
954     IDirectDrawImpl_CreateSurface,
955     IDirectDrawImpl_DuplicateSurface,
956     IDirectDrawImpl_EnumDisplayModes,
957     IDirectDrawImpl_EnumSurfaces,
958     IDirectDrawImpl_FlipToGDISurface,
959     IDirectDrawImpl_GetCaps,
960     IDirectDrawImpl_GetDisplayMode,
961     IDirectDrawImpl_GetFourCCCodes,
962     IDirectDrawImpl_GetGDISurface,
963     IDirectDrawImpl_GetMonitorFrequency,
964     IDirectDrawImpl_GetScanLine,
965     IDirectDrawImpl_GetVerticalBlankStatus,
966     IDirectDrawImpl_Initialize,
967     IDirectDrawImpl_RestoreDisplayMode,
968     IDirectDrawImpl_SetCooperativeLevel,
969     IDirectDrawImpl_SetDisplayMode,
970     IDirectDrawImpl_WaitForVerticalBlank,
971 };
972
973 ICOM_VTABLE(IDirectDraw2) DDRAW_IDirectDraw2_VTable =
974 {
975     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
976     IDirectDraw2Impl_QueryInterface,
977     IDirectDraw2Impl_AddRef,
978     IDirectDraw2Impl_Release,
979     IDirectDraw2Impl_Compact,
980     IDirectDraw2Impl_CreateClipper,
981     IDirectDraw2Impl_CreatePalette,
982     IDirectDraw2Impl_CreateSurface,
983     IDirectDraw2Impl_DuplicateSurface,
984     IDirectDraw2Impl_EnumDisplayModes,
985     IDirectDraw2Impl_EnumSurfaces,
986     IDirectDraw2Impl_FlipToGDISurface,
987     IDirectDraw2Impl_GetCaps,
988     IDirectDraw2Impl_GetDisplayMode,
989     IDirectDraw2Impl_GetFourCCCodes,
990     IDirectDraw2Impl_GetGDISurface,
991     IDirectDraw2Impl_GetMonitorFrequency,
992     IDirectDraw2Impl_GetScanLine,
993     IDirectDraw2Impl_GetVerticalBlankStatus,
994     IDirectDraw2Impl_Initialize,
995     IDirectDraw2Impl_RestoreDisplayMode,
996     IDirectDraw2Impl_SetCooperativeLevel,
997     IDirectDraw2Impl_SetDisplayMode,
998     IDirectDraw2Impl_WaitForVerticalBlank,
999     IDirectDraw2Impl_GetAvailableVidMem
1000 };
1001
1002 ICOM_VTABLE(IDirectDraw4) DDRAW_IDirectDraw4_VTable =
1003 {
1004     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1005     IDirectDraw4Impl_QueryInterface,
1006     IDirectDraw4Impl_AddRef,
1007     IDirectDraw4Impl_Release,
1008     IDirectDraw4Impl_Compact,
1009     IDirectDraw4Impl_CreateClipper,
1010     IDirectDraw4Impl_CreatePalette,
1011     IDirectDraw4Impl_CreateSurface,
1012     IDirectDraw4Impl_DuplicateSurface,
1013     IDirectDraw4Impl_EnumDisplayModes,
1014     IDirectDraw4Impl_EnumSurfaces,
1015     IDirectDraw4Impl_FlipToGDISurface,
1016     IDirectDraw4Impl_GetCaps,
1017     IDirectDraw4Impl_GetDisplayMode,
1018     IDirectDraw4Impl_GetFourCCCodes,
1019     IDirectDraw4Impl_GetGDISurface,
1020     IDirectDraw4Impl_GetMonitorFrequency,
1021     IDirectDraw4Impl_GetScanLine,
1022     IDirectDraw4Impl_GetVerticalBlankStatus,
1023     IDirectDraw4Impl_Initialize,
1024     IDirectDraw4Impl_RestoreDisplayMode,
1025     IDirectDraw4Impl_SetCooperativeLevel,
1026     IDirectDraw4Impl_SetDisplayMode,
1027     IDirectDraw4Impl_WaitForVerticalBlank,
1028     IDirectDraw4Impl_GetAvailableVidMem,
1029     IDirectDraw4Impl_GetSurfaceFromDC,
1030     IDirectDraw4Impl_RestoreAllSurfaces,
1031     IDirectDraw4Impl_TestCooperativeLevel,
1032     IDirectDraw4Impl_GetDeviceIdentifier
1033 };