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