ddraw: Get rid of ICOM_OBJECT.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20 #include "wine/port.h"
21
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 #define COBJMACROS
28 #define NONAMELESSUNION
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winerror.h"
33 #include "wingdi.h"
34 #include "wine/exception.h"
35
36 #include "ddraw.h"
37 #include "d3d.h"
38
39 #include "ddraw_private.h"
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(ddraw_thunk);
43 WINE_DECLARE_DEBUG_CHANNEL(ddraw);
44
45 static HRESULT WINAPI
46 IDirectDrawImpl_QueryInterface(LPDIRECTDRAW This, REFIID iid, LPVOID *ppObj)
47 {
48     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl,
49                                                           IDirectDraw,
50                                                           IDirectDraw7, This),
51                                        iid, ppObj);
52 }
53
54 static HRESULT WINAPI
55 IDirectDraw2Impl_QueryInterface(LPDIRECTDRAW2 This, REFIID iid, LPVOID *ppObj)
56 {
57     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl,
58                                                           IDirectDraw2,
59                                                           IDirectDraw7, This),
60                                        iid, ppObj);
61 }
62
63 static HRESULT WINAPI
64 IDirectDraw3Impl_QueryInterface(LPDIRECTDRAW3 This, REFIID iid, LPVOID *ppObj)
65 {
66     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl,
67                                                           IDirectDraw3,
68                                                           IDirectDraw7, This),
69                                        iid, ppObj);
70 }
71
72 static HRESULT WINAPI
73 IDirectDraw4Impl_QueryInterface(LPDIRECTDRAW4 This, REFIID iid, LPVOID *ppObj)
74 {
75     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl,
76                                                           IDirectDraw4,
77                                                           IDirectDraw7, This),
78                                        iid, ppObj);
79 }
80
81 static ULONG WINAPI
82 IDirectDrawImpl_AddRef(LPDIRECTDRAW iface)
83 {
84     IDirectDrawImpl *This = ddraw_from_ddraw1(iface);
85     ULONG ref = InterlockedIncrement(&This->ref1);
86
87     TRACE("(%p) : incrementing IDirectDraw refcount from %u.\n", This, ref -1);
88
89     if(ref == 1) InterlockedIncrement(&This->numIfaces);
90
91     return ref;
92 }
93
94 static ULONG WINAPI
95 IDirectDraw2Impl_AddRef(LPDIRECTDRAW2 iface)
96 {
97     IDirectDrawImpl *This = ddraw_from_ddraw2(iface);
98     ULONG ref = InterlockedIncrement(&This->ref2);
99
100     TRACE("(%p) : incrementing IDirectDraw2 refcount from %u.\n", This, ref -1);
101
102     if(ref == 1) InterlockedIncrement(&This->numIfaces);
103
104     return ref;
105 }
106
107 static ULONG WINAPI
108 IDirectDraw3Impl_AddRef(LPDIRECTDRAW3 iface)
109 {
110     IDirectDrawImpl *This = ddraw_from_ddraw3(iface);
111     ULONG ref = InterlockedIncrement(&This->ref3);
112
113     TRACE("(%p) : incrementing IDirectDraw3 refcount from %u.\n", This, ref -1);
114
115     if(ref == 1) InterlockedIncrement(&This->numIfaces);
116
117     return ref;
118 }
119
120 static ULONG WINAPI
121 IDirectDraw4Impl_AddRef(LPDIRECTDRAW4 iface)
122 {
123     IDirectDrawImpl *This = ddraw_from_ddraw4(iface);
124     ULONG ref = InterlockedIncrement(&This->ref4);
125
126     TRACE("(%p) : incrementing IDirectDraw4 refcount from %u.\n", This, ref -1);
127
128     if(ref == 1) InterlockedIncrement(&This->numIfaces);
129
130     return ref;
131 }
132
133 static ULONG WINAPI
134 IDirectDrawImpl_Release(LPDIRECTDRAW iface)
135 {
136     IDirectDrawImpl *This = ddraw_from_ddraw1(iface);
137     ULONG ref = InterlockedDecrement(&This->ref1);
138
139     TRACE_(ddraw)("(%p)->() decrementing IDirectDraw refcount from %u.\n", This, ref +1);
140
141     if(ref == 0)
142     {
143         ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
144         if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
145     }
146
147     return ref;
148 }
149
150 static ULONG WINAPI
151 IDirectDraw2Impl_Release(LPDIRECTDRAW2 iface)
152 {
153     IDirectDrawImpl *This = ddraw_from_ddraw2(iface);
154     ULONG ref = InterlockedDecrement(&This->ref2);
155
156     TRACE_(ddraw)("(%p)->() decrementing IDirectDraw2 refcount from %u.\n", This, ref +1);
157
158     if(ref == 0)
159     {
160         ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
161         if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
162     }
163
164     return ref;
165 }
166
167 static ULONG WINAPI
168 IDirectDraw3Impl_Release(LPDIRECTDRAW3 iface)
169 {
170     IDirectDrawImpl *This = ddraw_from_ddraw3(iface);
171     ULONG ref = InterlockedDecrement(&This->ref3);
172
173     TRACE_(ddraw)("(%p)->() decrementing IDirectDraw3 refcount from %u.\n", This, ref +1);
174
175     if(ref == 0)
176     {
177         ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
178         if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
179     }
180
181     return ref;
182 }
183
184 static ULONG WINAPI
185 IDirectDraw4Impl_Release(LPDIRECTDRAW4 iface)
186 {
187     IDirectDrawImpl *This = ddraw_from_ddraw4(iface);
188     ULONG ref = InterlockedDecrement(&This->ref4);
189
190     TRACE_(ddraw)("(%p)->() decrementing IDirectDraw4 refcount from %u.\n", This, ref +1);
191
192     if(ref == 0)
193     {
194         ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
195         if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
196     }
197
198     return ref;
199 }
200
201 static HRESULT WINAPI
202 IDirectDrawImpl_Compact(LPDIRECTDRAW This)
203 {
204     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
205                                                    IDirectDraw, IDirectDraw7,
206                                                    This));
207 }
208
209 static HRESULT WINAPI
210 IDirectDraw2Impl_Compact(LPDIRECTDRAW2 This)
211 {
212     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
213                                                    IDirectDraw2, IDirectDraw7,
214                                                    This));
215 }
216
217     static HRESULT WINAPI
218 IDirectDraw3Impl_Compact(LPDIRECTDRAW3 This)
219 {
220     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
221                                                    IDirectDraw3, IDirectDraw7,
222                                                    This));
223 }
224
225 static HRESULT WINAPI
226 IDirectDraw4Impl_Compact(LPDIRECTDRAW4 This)
227 {
228     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
229                                                    IDirectDraw4, IDirectDraw7,
230                                                    This));
231 }
232
233 static HRESULT WINAPI
234 IDirectDrawImpl_CreateClipper(LPDIRECTDRAW This, DWORD dwFlags,
235                               LPDIRECTDRAWCLIPPER *ppClipper,
236                               IUnknown *pUnkOuter)
237 {
238     return IDirectDraw7_CreateClipper(COM_INTERFACE_CAST(IDirectDrawImpl,
239                                                          IDirectDraw,
240                                                          IDirectDraw7,
241                                                          This),
242                                       dwFlags, ppClipper, pUnkOuter);
243 }
244
245 static HRESULT WINAPI
246 IDirectDraw2Impl_CreateClipper(LPDIRECTDRAW2 This, DWORD dwFlags,
247                                LPDIRECTDRAWCLIPPER *ppClipper,
248                                IUnknown *pUnkOuter)
249 {
250     return IDirectDraw7_CreateClipper(COM_INTERFACE_CAST(IDirectDrawImpl,
251                                                          IDirectDraw2,
252                                                          IDirectDraw7,
253                                                          This),
254                                       dwFlags, ppClipper, pUnkOuter);
255 }
256
257 static HRESULT WINAPI
258 IDirectDraw3Impl_CreateClipper(LPDIRECTDRAW3 This, DWORD dwFlags,
259                                LPDIRECTDRAWCLIPPER *ppClipper,
260                                IUnknown *pUnkOuter)
261 {
262     return IDirectDraw7_CreateClipper(COM_INTERFACE_CAST(IDirectDrawImpl,
263                                                          IDirectDraw3,
264                                                          IDirectDraw7,
265                                                          This),
266                                       dwFlags, ppClipper, pUnkOuter);
267 }
268
269 static HRESULT WINAPI
270 IDirectDraw4Impl_CreateClipper(LPDIRECTDRAW4 This, DWORD dwFlags,
271                                LPDIRECTDRAWCLIPPER *ppClipper,
272                                IUnknown *pUnkOuter)
273 {
274     return IDirectDraw7_CreateClipper(COM_INTERFACE_CAST(IDirectDrawImpl,
275                                                          IDirectDraw4,
276                                                          IDirectDraw7,
277                                                          This),
278                                       dwFlags, ppClipper, pUnkOuter);
279 }
280
281 static HRESULT WINAPI
282 IDirectDrawImpl_CreatePalette(LPDIRECTDRAW This, DWORD dwFlags,
283                               LPPALETTEENTRY pEntries,
284                               LPDIRECTDRAWPALETTE *ppPalette,
285                               IUnknown *pUnkOuter)
286 {
287     HRESULT hr;
288     hr = IDirectDraw7_CreatePalette(COM_INTERFACE_CAST(IDirectDrawImpl,
289                                                          IDirectDraw,
290                                                          IDirectDraw7,
291                                                          This),
292                                       dwFlags, pEntries, ppPalette, pUnkOuter);
293     if(SUCCEEDED(hr) && *ppPalette)
294     {
295         IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette;
296         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
297                              IDirectDraw,
298                              IDirectDraw7,
299                              This));
300         impl->ifaceToRelease = NULL;
301
302     }
303     return hr;
304 }
305
306 static HRESULT WINAPI
307 IDirectDraw2Impl_CreatePalette(LPDIRECTDRAW2 This, DWORD dwFlags,
308                                LPPALETTEENTRY pEntries,
309                                LPDIRECTDRAWPALETTE *ppPalette,
310                                IUnknown *pUnkOuter)
311 {
312     HRESULT hr;
313     hr = IDirectDraw7_CreatePalette(COM_INTERFACE_CAST(IDirectDrawImpl,
314                                                          IDirectDraw2,
315                                                          IDirectDraw7,
316                                                          This),
317                                       dwFlags, pEntries, ppPalette, pUnkOuter);
318     if(SUCCEEDED(hr) && *ppPalette)
319     {
320         IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette;
321         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
322                              IDirectDraw2,
323                              IDirectDraw7,
324                              This));
325         impl->ifaceToRelease = NULL;
326     }
327     return hr;
328 }
329
330 static HRESULT WINAPI
331 IDirectDraw3Impl_CreatePalette(LPDIRECTDRAW3 This, DWORD dwFlags,
332                                LPPALETTEENTRY pEntries,
333                                LPDIRECTDRAWPALETTE *ppPalette,
334                                IUnknown *pUnkOuter)
335 {
336     HRESULT hr;
337     hr = IDirectDraw7_CreatePalette(COM_INTERFACE_CAST(IDirectDrawImpl,
338                                                          IDirectDraw3,
339                                                          IDirectDraw7,
340                                                          This),
341                                       dwFlags, pEntries, ppPalette, pUnkOuter);
342     if(SUCCEEDED(hr) && *ppPalette)
343     {
344         IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette;
345         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
346                              IDirectDraw3,
347                              IDirectDraw7,
348                              This));
349         IDirectDraw4_AddRef(This);
350         impl->ifaceToRelease = (IUnknown *) This;
351     }
352     return hr;
353 }
354
355 static HRESULT WINAPI
356 IDirectDraw4Impl_CreatePalette(LPDIRECTDRAW4 This, DWORD dwFlags,
357                                LPPALETTEENTRY pEntries,
358                                LPDIRECTDRAWPALETTE *ppPalette,
359                                IUnknown *pUnkOuter)
360 {
361     HRESULT hr;
362     hr = IDirectDraw7_CreatePalette(COM_INTERFACE_CAST(IDirectDrawImpl,
363                                                          IDirectDraw4,
364                                                          IDirectDraw7,
365                                                          This),
366                                       dwFlags, pEntries, ppPalette, pUnkOuter);
367     if(SUCCEEDED(hr) && *ppPalette)
368     {
369         IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette;
370         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
371                              IDirectDraw4,
372                              IDirectDraw7,
373                              This));
374         IDirectDraw4_AddRef(This);
375         impl->ifaceToRelease = (IUnknown *) This;
376     }
377     return hr;
378 }
379
380 /* Must set all attached surfaces (e.g. mipmaps) versions as well */
381 static void set_surf_version(IDirectDrawSurfaceImpl *surf, int version)
382 {
383     int i;
384     TRACE("%p->version(%d) = %d\n", surf, surf->version, version);
385     surf->version = version;
386     for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
387     {
388         if(!surf->complex_array[i]) break;
389         set_surf_version(surf->complex_array[i], version);
390     }
391     while( (surf = surf->next_attached) )
392     {
393         set_surf_version(surf, version);
394     }
395 }
396
397 static HRESULT WINAPI
398 IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc,
399                               LPDIRECTDRAWSURFACE *ppSurface,
400                               IUnknown *pUnkOuter)
401 {
402     LPDIRECTDRAWSURFACE7 pSurface7;
403     IDirectDrawSurfaceImpl *impl;
404     HRESULT hr;
405
406     /* Remove front buffer flag, this causes failure in v7, and its added to normal
407      * primaries anyway
408      */
409     pSDesc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
410     /* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
411      * since the data layout is the same */
412     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
413                                                        IDirectDraw,
414                                                        IDirectDraw7,
415                                                        This),
416                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
417
418     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
419      * IDirectDrawSurface vtable layout at the beginning  */
420     *ppSurface = (LPDIRECTDRAWSURFACE) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
421                                     IDirectDrawSurface7, IDirectDrawSurface3,
422                                     pSurface7);
423
424     impl = (IDirectDrawSurfaceImpl *)pSurface7;
425     if(SUCCEEDED(hr) && impl)
426     {
427         set_surf_version(impl, 1);
428         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
429                              IDirectDraw,
430                              IDirectDraw7,
431                              This));
432         impl->ifaceToRelease = NULL;
433     }
434
435     return hr;
436 }
437
438 static HRESULT WINAPI
439 IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc,
440                                LPDIRECTDRAWSURFACE *ppSurface,
441                                IUnknown *pUnkOuter)
442 {
443     LPDIRECTDRAWSURFACE7 pSurface7;
444     IDirectDrawSurfaceImpl *impl;
445     HRESULT hr;
446
447     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
448                                                        IDirectDraw2,
449                                                        IDirectDraw7,
450                                                        This),
451                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
452
453     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
454      * IDirectDrawSurface vtable layout at the beginning  */
455     *ppSurface = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
456                                     IDirectDrawSurface7, IDirectDrawSurface3,
457                                     pSurface7);
458
459     impl = (IDirectDrawSurfaceImpl *)pSurface7;
460     if(SUCCEEDED(hr) && impl)
461     {
462         set_surf_version(impl, 2);
463         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
464                              IDirectDraw2,
465                              IDirectDraw7,
466                              This));
467         impl->ifaceToRelease = NULL;
468     }
469
470     return hr;
471 }
472
473 static HRESULT WINAPI
474 IDirectDraw3Impl_CreateSurface(LPDIRECTDRAW3 This, LPDDSURFACEDESC pSDesc,
475                                LPDIRECTDRAWSURFACE *ppSurface,
476                                IUnknown *pUnkOuter)
477 {
478     LPDIRECTDRAWSURFACE7 pSurface7;
479     IDirectDrawSurfaceImpl *impl;
480     HRESULT hr;
481
482     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
483                                                        IDirectDraw3,
484                                                        IDirectDraw7,
485                                                        This),
486                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
487
488     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
489      * IDirectDrawSurface vtable layout at the beginning  */
490     *ppSurface = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
491                                     IDirectDrawSurface7, IDirectDrawSurface3,
492                                     pSurface7);
493
494     impl = (IDirectDrawSurfaceImpl *)pSurface7;
495     if(SUCCEEDED(hr) && impl)
496     {
497         set_surf_version(impl, 3);
498         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
499                              IDirectDraw3,
500                              IDirectDraw7,
501                              This));
502         IDirectDraw3_AddRef(This);
503         impl->ifaceToRelease = (IUnknown *) This;
504     }
505
506     return hr;
507 }
508
509 static HRESULT WINAPI
510 IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
511                                LPDIRECTDRAWSURFACE4 *ppSurface,
512                                IUnknown *pUnkOuter)
513 {
514     HRESULT hr;
515     IDirectDrawSurfaceImpl *impl;
516
517     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
518                                                        IDirectDraw4,
519                                                        IDirectDraw7,
520                                                         This),
521                                     pSDesc,
522                                     (LPDIRECTDRAWSURFACE7 *)ppSurface,
523                                     pUnkOuter);
524     impl = (IDirectDrawSurfaceImpl *)*ppSurface;
525     if(SUCCEEDED(hr) && impl)
526     {
527         set_surf_version(impl, 4);
528         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
529                              IDirectDraw4,
530                              IDirectDraw7,
531                              This));
532         IDirectDraw4_AddRef(This);
533         impl->ifaceToRelease = (IUnknown *) This;
534     }
535     return hr;
536 }
537
538 static HRESULT WINAPI
539 IDirectDrawImpl_DuplicateSurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE pSrc,
540                                  LPDIRECTDRAWSURFACE *ppDst)
541 {
542     LPDIRECTDRAWSURFACE7 pDst7;
543     HRESULT hr;
544
545     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
546                                                           IDirectDraw,
547                                                           IDirectDraw7, This),
548                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
549                                                           IDirectDrawSurface3,
550                                                           IDirectDrawSurface7,
551                                                           pSrc),
552                                        &pDst7);
553
554     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
555      * IDirectDrawSurface vtable layout at the beginning  */
556     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
557                                 IDirectDrawSurface3, pDst7);
558
559     return hr;
560 }
561
562 static HRESULT WINAPI
563 IDirectDraw2Impl_DuplicateSurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE pSrc,
564                                   LPDIRECTDRAWSURFACE *ppDst)
565 {
566     LPDIRECTDRAWSURFACE7 pDst7;
567     HRESULT hr;
568
569     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
570                                                           IDirectDraw2,
571                                                           IDirectDraw7, This),
572                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
573                                                           IDirectDrawSurface3,
574                                                           IDirectDrawSurface7,
575                                                           pSrc),
576                                        &pDst7);
577
578     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
579      * IDirectDrawSurface vtable layout at the beginning  */
580     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
581                                 IDirectDrawSurface3, pDst7);
582
583     return hr;
584 }
585
586 static HRESULT WINAPI
587 IDirectDraw3Impl_DuplicateSurface(LPDIRECTDRAW3 This, LPDIRECTDRAWSURFACE pSrc,
588                                   LPDIRECTDRAWSURFACE *ppDst)
589 {
590     LPDIRECTDRAWSURFACE7 pDst7;
591     HRESULT hr;
592
593     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
594                                                           IDirectDraw3,
595                                                           IDirectDraw7, This),
596                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
597                                                           IDirectDrawSurface3,
598                                                           IDirectDrawSurface7,
599                                                           pSrc),
600                                        &pDst7);
601
602     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
603      * IDirectDrawSurface vtable layout at the beginning  */
604     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
605                                 IDirectDrawSurface3, pDst7);
606
607     return hr;
608 }
609
610 static HRESULT WINAPI
611 IDirectDraw4Impl_DuplicateSurface(LPDIRECTDRAW4 This,
612                                   LPDIRECTDRAWSURFACE4 pSrc,
613                                   LPDIRECTDRAWSURFACE4 *ppDst)
614 {
615     return IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
616                                                             IDirectDraw4,
617                                                             IDirectDraw7,
618                                                             This),
619                                          (LPDIRECTDRAWSURFACE7)pSrc,
620                                          (LPDIRECTDRAWSURFACE7 *)ppDst);
621 }
622
623 struct displaymodescallback_context
624 {
625     LPDDENUMMODESCALLBACK func;
626     LPVOID context;
627 };
628
629 static HRESULT CALLBACK
630 EnumDisplayModesCallbackThunk(LPDDSURFACEDESC2 pDDSD2, LPVOID context)
631 {
632     DDSURFACEDESC DDSD;
633     struct displaymodescallback_context *cbcontext = context;
634
635     memcpy(&DDSD,pDDSD2,sizeof(DDSD));
636     DDSD.dwSize = sizeof(DDSD);
637
638     return cbcontext->func(&DDSD, cbcontext->context);
639 }
640
641 static HRESULT WINAPI
642 IDirectDrawImpl_EnumDisplayModes(LPDIRECTDRAW This, DWORD dwFlags,
643                                  LPDDSURFACEDESC pDDSD, LPVOID context,
644                                  LPDDENUMMODESCALLBACK cb)
645 {
646     struct displaymodescallback_context cbcontext;
647
648     cbcontext.func    = cb;
649     cbcontext.context = context;
650
651     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
652                                                             IDirectDraw,
653                                                             IDirectDraw7,
654                                                             This),
655                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
656                                          EnumDisplayModesCallbackThunk);
657 }
658
659 static HRESULT WINAPI
660 IDirectDraw2Impl_EnumDisplayModes(LPDIRECTDRAW2 This, DWORD dwFlags,
661                                   LPDDSURFACEDESC pDDSD, LPVOID context,
662                                   LPDDENUMMODESCALLBACK cb)
663 {
664     struct displaymodescallback_context cbcontext;
665
666     cbcontext.func    = cb;
667     cbcontext.context = context;
668
669     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
670                                                             IDirectDraw2,
671                                                             IDirectDraw7,
672                                                             This),
673                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
674                                          EnumDisplayModesCallbackThunk);
675 }
676
677 static HRESULT WINAPI
678 IDirectDraw3Impl_EnumDisplayModes(LPDIRECTDRAW3 This, DWORD dwFlags,
679                                   LPDDSURFACEDESC pDDSD, LPVOID context,
680                                   LPDDENUMMODESCALLBACK cb)
681 {
682     struct displaymodescallback_context cbcontext;
683
684     cbcontext.func    = cb;
685     cbcontext.context = context;
686
687     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
688                                                             IDirectDraw3,
689                                                             IDirectDraw7,
690                                                             This),
691                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
692                                          EnumDisplayModesCallbackThunk);
693 }
694
695 static HRESULT WINAPI
696 IDirectDraw4Impl_EnumDisplayModes(LPDIRECTDRAW4 This, DWORD dwFlags,
697                                   LPDDSURFACEDESC2 pDDSD, LPVOID context,
698                                   LPDDENUMMODESCALLBACK2 cb)
699 {
700     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
701                                                             IDirectDraw4,
702                                                             IDirectDraw7,
703                                                             This),
704                                          dwFlags, pDDSD, context, cb);
705 }
706
707 struct surfacescallback_context
708 {
709     LPDDENUMSURFACESCALLBACK func;
710     LPVOID context;
711 };
712
713 static HRESULT CALLBACK
714 EnumSurfacesCallbackThunk(LPDIRECTDRAWSURFACE7 pSurf, LPDDSURFACEDESC2 pDDSD,
715                           LPVOID context)
716 {
717     struct surfacescallback_context *cbcontext = context;
718
719     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
720      * IDirectDrawSurface vtable layout at the beginning  */
721     return cbcontext->func((LPDIRECTDRAWSURFACE)
722                            COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
723                                               IDirectDrawSurface7,
724                                               IDirectDrawSurface3, pSurf),
725                            (LPDDSURFACEDESC)pDDSD, cbcontext->context);
726 }
727
728 static HRESULT WINAPI
729 IDirectDrawImpl_EnumSurfaces(LPDIRECTDRAW This, DWORD dwFlags,
730                              LPDDSURFACEDESC pDDSD, LPVOID context,
731                              LPDDENUMSURFACESCALLBACK cb)
732 {
733     struct surfacescallback_context cbcontext;
734
735     cbcontext.func    = cb;
736     cbcontext.context = context;
737
738     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
739                                                         IDirectDraw,
740                                                         IDirectDraw7, This),
741                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
742                                      &cbcontext, EnumSurfacesCallbackThunk);
743 }
744
745 static HRESULT WINAPI
746 IDirectDraw2Impl_EnumSurfaces(LPDIRECTDRAW2 This, DWORD dwFlags,
747                               LPDDSURFACEDESC pDDSD, LPVOID context,
748                               LPDDENUMSURFACESCALLBACK cb)
749 {
750     struct surfacescallback_context cbcontext;
751
752     cbcontext.func    = cb;
753     cbcontext.context = context;
754
755     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
756                                                         IDirectDraw2,
757                                                         IDirectDraw7, This),
758                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
759                                      &cbcontext, EnumSurfacesCallbackThunk);
760 }
761
762 static HRESULT WINAPI
763 IDirectDraw3Impl_EnumSurfaces(LPDIRECTDRAW3 This, DWORD dwFlags,
764                               LPDDSURFACEDESC pDDSD, LPVOID context,
765                               LPDDENUMSURFACESCALLBACK cb)
766 {
767     struct surfacescallback_context cbcontext;
768
769     cbcontext.func    = cb;
770     cbcontext.context = context;
771
772     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
773                                                         IDirectDraw3,
774                                                         IDirectDraw7, This),
775                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
776                                      &cbcontext, EnumSurfacesCallbackThunk);
777 }
778
779 static HRESULT WINAPI
780 IDirectDraw4Impl_EnumSurfaces(LPDIRECTDRAW4 This, DWORD dwFlags,
781                               LPDDSURFACEDESC2 pDDSD, LPVOID context,
782                               LPDDENUMSURFACESCALLBACK2 cb)
783 {
784     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
785                                                         IDirectDraw4,
786                                                         IDirectDraw7, This),
787                                      dwFlags, pDDSD, context,
788                                      (LPDDENUMSURFACESCALLBACK7)cb);
789 }
790
791 static HRESULT WINAPI
792 IDirectDrawImpl_FlipToGDISurface(LPDIRECTDRAW This)
793 {
794     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
795                                                             IDirectDraw,
796                                                             IDirectDraw7,
797                                                             This));
798 }
799
800 static HRESULT WINAPI
801 IDirectDraw2Impl_FlipToGDISurface(LPDIRECTDRAW2 This)
802 {
803     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
804                                                             IDirectDraw2,
805                                                             IDirectDraw7,
806                                                             This));
807 }
808
809 static HRESULT WINAPI
810 IDirectDraw3Impl_FlipToGDISurface(LPDIRECTDRAW3 This)
811 {
812     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
813                                                             IDirectDraw3,
814                                                             IDirectDraw7,
815                                                             This));
816 }
817
818 static HRESULT WINAPI
819 IDirectDraw4Impl_FlipToGDISurface(LPDIRECTDRAW4 This)
820 {
821     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
822                                                             IDirectDraw4,
823                                                             IDirectDraw7,
824                                                             This));
825 }
826
827 static HRESULT WINAPI
828 IDirectDrawImpl_GetCaps(LPDIRECTDRAW This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
829 {
830     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
831                                                    IDirectDraw, IDirectDraw7,
832                                                    This), pDDC1, pDDC2);
833 }
834
835 static HRESULT WINAPI
836 IDirectDraw2Impl_GetCaps(LPDIRECTDRAW2 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
837 {
838     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
839                                                    IDirectDraw2, IDirectDraw7,
840                                                    This), pDDC1, pDDC2);
841 }
842
843 static HRESULT WINAPI
844 IDirectDraw3Impl_GetCaps(LPDIRECTDRAW3 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
845 {
846     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
847                                                    IDirectDraw3, IDirectDraw7,
848                                                    This), pDDC1, pDDC2);
849 }
850
851 static HRESULT WINAPI
852 IDirectDraw4Impl_GetCaps(LPDIRECTDRAW4 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
853 {
854     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
855                                                    IDirectDraw4, IDirectDraw7,
856                                                    This), pDDC1, pDDC2);
857 }
858
859 static HRESULT WINAPI
860 IDirectDrawImpl_GetDisplayMode(LPDIRECTDRAW This, LPDDSURFACEDESC pDDSD)
861 {
862     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
863                                                           IDirectDraw,
864                                                           IDirectDraw7, This),
865                                        (LPDDSURFACEDESC2)pDDSD);
866 }
867
868 static HRESULT WINAPI
869 IDirectDraw2Impl_GetDisplayMode(LPDIRECTDRAW2 This, LPDDSURFACEDESC pDDSD)
870 {
871     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
872                                                           IDirectDraw2,
873                                                           IDirectDraw7, This),
874                                        (LPDDSURFACEDESC2)pDDSD);
875 }
876
877 static HRESULT WINAPI
878 IDirectDraw3Impl_GetDisplayMode(LPDIRECTDRAW3 This, LPDDSURFACEDESC pDDSD)
879 {
880     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
881                                                           IDirectDraw3,
882                                                           IDirectDraw7, This),
883                                        (LPDDSURFACEDESC2)pDDSD);
884 }
885
886 static HRESULT WINAPI
887 IDirectDraw4Impl_GetDisplayMode(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pDDSD)
888 {
889     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
890                                                           IDirectDraw4,
891                                                           IDirectDraw7, This),
892                                        pDDSD);
893 }
894
895 static HRESULT WINAPI
896 IDirectDrawImpl_GetFourCCCodes(LPDIRECTDRAW This, LPDWORD lpNumCodes,
897                                LPDWORD lpCodes)
898 {
899     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
900                                                           IDirectDraw,
901                                                           IDirectDraw7,
902                                                           This),
903                                        lpNumCodes, lpCodes);
904 }
905
906 static HRESULT WINAPI
907 IDirectDraw2Impl_GetFourCCCodes(LPDIRECTDRAW2 This, LPDWORD lpNumCodes,
908                                 LPDWORD lpCodes)
909 {
910     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
911                                                           IDirectDraw2,
912                                                           IDirectDraw7,
913                                                           This),
914                                        lpNumCodes, lpCodes);
915 }
916
917 static HRESULT WINAPI
918 IDirectDraw3Impl_GetFourCCCodes(LPDIRECTDRAW3 This, LPDWORD lpNumCodes,
919                                 LPDWORD lpCodes)
920 {
921     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
922                                                           IDirectDraw3,
923                                                           IDirectDraw7,
924                                                           This),
925                                        lpNumCodes, lpCodes);
926 }
927
928 static HRESULT WINAPI
929 IDirectDraw4Impl_GetFourCCCodes(LPDIRECTDRAW4 This, LPDWORD lpNumCodes,
930                                 LPDWORD lpCodes)
931 {
932     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
933                                                           IDirectDraw4,
934                                                           IDirectDraw7,
935                                                           This),
936                                        lpNumCodes, lpCodes);
937 }
938
939 static HRESULT WINAPI
940 IDirectDrawImpl_GetGDISurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE *ppSurf)
941 {
942     LPDIRECTDRAWSURFACE7 pSurf7;
943     HRESULT hr;
944
945     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
946                                                        IDirectDraw,
947                                                        IDirectDraw7,
948                                                        This), &pSurf7);
949
950     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
951      * IDirectDrawSurface vtable layout at the beginning  */
952     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
953                                  IDirectDrawSurface3, pSurf7);
954
955     return hr;
956 }
957
958 static HRESULT WINAPI
959 IDirectDraw2Impl_GetGDISurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE *ppSurf)
960 {
961     LPDIRECTDRAWSURFACE7 pSurf7;
962     HRESULT hr;
963
964     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
965                                                        IDirectDraw2,
966                                                        IDirectDraw7,
967                                                        This), &pSurf7);
968
969     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
970      * IDirectDrawSurface vtable layout at the beginning  */
971     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
972                                  IDirectDrawSurface3, pSurf7);
973
974     return hr;
975 }
976
977 static HRESULT WINAPI
978 IDirectDraw3Impl_GetGDISurface(LPDIRECTDRAW3 This, LPDIRECTDRAWSURFACE *ppSurf)
979 {
980     LPDIRECTDRAWSURFACE7 pSurf7;
981     HRESULT hr;
982
983     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
984                                                        IDirectDraw3,
985                                                        IDirectDraw7,
986                                                        This), &pSurf7);
987
988     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
989      * IDirectDrawSurface vtable layout at the beginning  */
990     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
991                                  IDirectDrawSurface3, pSurf7);
992
993     return hr;
994 }
995
996 static HRESULT WINAPI
997 IDirectDraw4Impl_GetGDISurface(LPDIRECTDRAW4 This,
998                                LPDIRECTDRAWSURFACE4 *ppSurf)
999 {
1000     return IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
1001                                                          IDirectDraw4,
1002                                                          IDirectDraw7,
1003                                                          This),
1004                                       (LPDIRECTDRAWSURFACE7 *)ppSurf);
1005 }
1006
1007 static HRESULT WINAPI
1008 IDirectDrawImpl_GetMonitorFrequency(LPDIRECTDRAW This, LPDWORD pdwFreq)
1009 {
1010     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
1011                                                                IDirectDraw,
1012                                                                IDirectDraw7,
1013                                                                This),
1014                                             pdwFreq);
1015 }
1016
1017 static HRESULT WINAPI
1018 IDirectDraw2Impl_GetMonitorFrequency(LPDIRECTDRAW2 This, LPDWORD pdwFreq)
1019 {
1020     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
1021                                                                IDirectDraw2,
1022                                                                IDirectDraw7,
1023                                                                This),
1024                                             pdwFreq);
1025 }
1026
1027 static HRESULT WINAPI
1028 IDirectDraw3Impl_GetMonitorFrequency(LPDIRECTDRAW3 This, LPDWORD pdwFreq)
1029 {
1030     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
1031                                                                IDirectDraw3,
1032                                                                IDirectDraw7,
1033                                                                This),
1034                                             pdwFreq);
1035 }
1036
1037 static HRESULT WINAPI
1038 IDirectDraw4Impl_GetMonitorFrequency(LPDIRECTDRAW4 This, LPDWORD pdwFreq)
1039 {
1040     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
1041                                                                IDirectDraw4,
1042                                                                IDirectDraw7,
1043                                                                This),
1044                                             pdwFreq);
1045 }
1046
1047 static HRESULT WINAPI
1048 IDirectDrawImpl_GetScanLine(LPDIRECTDRAW This, LPDWORD pdwLine)
1049 {
1050     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1051                                                        IDirectDraw,
1052                                                        IDirectDraw7,
1053                                                        This), pdwLine);
1054 }
1055
1056 static HRESULT WINAPI
1057 IDirectDraw2Impl_GetScanLine(LPDIRECTDRAW2 This, LPDWORD pdwLine)
1058 {
1059     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1060                                                        IDirectDraw2,
1061                                                        IDirectDraw7,
1062                                                        This), pdwLine);
1063 }
1064
1065 static HRESULT WINAPI
1066 IDirectDraw3Impl_GetScanLine(LPDIRECTDRAW3 This, LPDWORD pdwLine)
1067 {
1068     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1069                                                        IDirectDraw3,
1070                                                        IDirectDraw7,
1071                                                        This), pdwLine);
1072 }
1073
1074 static HRESULT WINAPI
1075 IDirectDraw4Impl_GetScanLine(LPDIRECTDRAW4 This, LPDWORD pdwLine)
1076 {
1077     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1078                                                        IDirectDraw4,
1079                                                        IDirectDraw7,
1080                                                        This), pdwLine);
1081 }
1082
1083 static HRESULT WINAPI
1084 IDirectDrawImpl_GetVerticalBlankStatus(LPDIRECTDRAW This, LPBOOL lpbIsInVB)
1085 {
1086     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1087                                                                   IDirectDraw,
1088                                                                   IDirectDraw7,
1089                                                                   This),
1090                                                lpbIsInVB);
1091 }
1092
1093 static HRESULT WINAPI
1094 IDirectDraw2Impl_GetVerticalBlankStatus(LPDIRECTDRAW2 This, LPBOOL lpbIsInVB)
1095 {
1096     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1097                                                                   IDirectDraw2,
1098                                                                   IDirectDraw7,
1099                                                                   This),
1100                                                lpbIsInVB);
1101 }
1102
1103 static HRESULT WINAPI
1104 IDirectDraw3Impl_GetVerticalBlankStatus(LPDIRECTDRAW3 This, LPBOOL lpbIsInVB)
1105 {
1106     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1107                                                                   IDirectDraw3,
1108                                                                   IDirectDraw7,
1109                                                                   This),
1110                                                lpbIsInVB);
1111 }
1112
1113 static HRESULT WINAPI
1114 IDirectDraw4Impl_GetVerticalBlankStatus(LPDIRECTDRAW4 This, LPBOOL lpbIsInVB)
1115 {
1116     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1117                                                                   IDirectDraw4,
1118                                                                   IDirectDraw7,
1119                                                                   This),
1120                                                lpbIsInVB);
1121 }
1122
1123 static HRESULT WINAPI
1124 IDirectDrawImpl_Initialize(LPDIRECTDRAW iface, LPGUID pGUID)
1125 {
1126     IDirectDrawImpl *This = ddraw_from_ddraw1(iface);
1127     HRESULT ret_value;
1128
1129     ret_value = IDirectDraw7_Initialize((IDirectDraw7 *)This, pGUID);
1130
1131     return ret_value;
1132 }
1133
1134 static HRESULT WINAPI
1135 IDirectDraw2Impl_Initialize(LPDIRECTDRAW2 iface, LPGUID pGUID)
1136 {
1137     IDirectDrawImpl *This = ddraw_from_ddraw2(iface);
1138     HRESULT ret_value;
1139
1140     ret_value = IDirectDraw7_Initialize((IDirectDraw7 *)This, pGUID);
1141
1142     return ret_value;
1143 }
1144
1145 static HRESULT WINAPI
1146 IDirectDraw3Impl_Initialize(LPDIRECTDRAW3 iface, LPGUID pGUID)
1147 {
1148     IDirectDrawImpl *This = ddraw_from_ddraw3(iface);
1149     HRESULT ret_value;
1150
1151     ret_value = IDirectDraw7_Initialize((IDirectDraw7 *)This, pGUID);
1152
1153     return ret_value;
1154 }
1155
1156 static HRESULT WINAPI
1157 IDirectDraw4Impl_Initialize(LPDIRECTDRAW4 iface, LPGUID pGUID)
1158 {
1159     IDirectDrawImpl *This = ddraw_from_ddraw4(iface);
1160     HRESULT ret_value;
1161
1162     ret_value = IDirectDraw7_Initialize((IDirectDraw7 *)This, pGUID);
1163
1164     return ret_value;
1165 }
1166
1167
1168 static HRESULT WINAPI
1169 IDirectDrawImpl_RestoreDisplayMode(LPDIRECTDRAW This)
1170 {
1171     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1172                                                               IDirectDraw,
1173                                                               IDirectDraw7,
1174                                                               This));
1175 }
1176
1177 static HRESULT WINAPI
1178 IDirectDraw2Impl_RestoreDisplayMode(LPDIRECTDRAW2 This)
1179 {
1180     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1181                                                               IDirectDraw2,
1182                                                               IDirectDraw7,
1183                                                               This));
1184 }
1185
1186 static HRESULT WINAPI
1187 IDirectDraw3Impl_RestoreDisplayMode(LPDIRECTDRAW3 This)
1188 {
1189     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1190                                                               IDirectDraw3,
1191                                                               IDirectDraw7,
1192                                                               This));
1193 }
1194
1195 static HRESULT WINAPI
1196 IDirectDraw4Impl_RestoreDisplayMode(LPDIRECTDRAW4 This)
1197 {
1198     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1199                                                               IDirectDraw4,
1200                                                               IDirectDraw7,
1201                                                               This));
1202 }
1203
1204 static HRESULT WINAPI
1205 IDirectDrawImpl_SetCooperativeLevel(LPDIRECTDRAW This, HWND hWnd,
1206                                     DWORD dwFlags)
1207 {
1208     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1209                                                                IDirectDraw,
1210                                                                IDirectDraw7,
1211                                                                This),
1212                                             hWnd, dwFlags);
1213 }
1214
1215 static HRESULT WINAPI
1216 IDirectDraw2Impl_SetCooperativeLevel(LPDIRECTDRAW2 This, HWND hWnd,
1217                                      DWORD dwFlags)
1218 {
1219     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1220                                                                IDirectDraw2,
1221                                                                IDirectDraw7,
1222                                                                This),
1223                                             hWnd, dwFlags);
1224 }
1225
1226 static HRESULT WINAPI
1227 IDirectDraw3Impl_SetCooperativeLevel(LPDIRECTDRAW3 This, HWND hWnd,
1228                                      DWORD dwFlags)
1229 {
1230     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1231                                                                IDirectDraw3,
1232                                                                IDirectDraw7,
1233                                                                This),
1234                                             hWnd, dwFlags);
1235 }
1236
1237 static HRESULT WINAPI
1238 IDirectDraw4Impl_SetCooperativeLevel(LPDIRECTDRAW4 This, HWND hWnd,
1239                                      DWORD dwFlags)
1240 {
1241     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1242                                                                IDirectDraw4,
1243                                                                IDirectDraw7,
1244                                                                This),
1245                                             hWnd, dwFlags);
1246 }
1247
1248 static HRESULT WINAPI
1249 IDirectDrawImpl_SetDisplayMode(LPDIRECTDRAW This, DWORD a, DWORD b, DWORD c)
1250 {
1251     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1252                                                           IDirectDraw,
1253                                                           IDirectDraw7,
1254                                                           This),
1255                                        a, b, c, 0, 0);
1256 }
1257
1258 static HRESULT WINAPI
1259 IDirectDraw2Impl_SetDisplayMode(LPDIRECTDRAW2 This, DWORD a, DWORD b, DWORD c,
1260                                 DWORD d, DWORD e)
1261 {
1262     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1263                                                           IDirectDraw2,
1264                                                           IDirectDraw7,
1265                                                           This),
1266                                        a, b, c, d, e);
1267 }
1268
1269 static HRESULT WINAPI
1270 IDirectDraw3Impl_SetDisplayMode(LPDIRECTDRAW3 This, DWORD a, DWORD b, DWORD c,
1271                                 DWORD d, DWORD e)
1272 {
1273     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1274                                                           IDirectDraw3,
1275                                                           IDirectDraw7,
1276                                                           This),
1277                                        a, b, c, d, e);
1278 }
1279
1280 static HRESULT WINAPI
1281 IDirectDraw4Impl_SetDisplayMode(LPDIRECTDRAW4 This, DWORD a, DWORD b, DWORD c,
1282                                 DWORD d, DWORD e)
1283 {
1284     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1285                                                           IDirectDraw4,
1286                                                           IDirectDraw7,
1287                                                           This),
1288                                        a, b, c, d, e);
1289 }
1290
1291 static HRESULT WINAPI
1292 IDirectDrawImpl_WaitForVerticalBlank(LPDIRECTDRAW This, DWORD dwFlags,
1293                                      HANDLE hEvent)
1294 {
1295     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1296                                                                 IDirectDraw,
1297                                                                 IDirectDraw7,
1298                                                                 This),
1299                                              dwFlags, hEvent);
1300 }
1301
1302 static HRESULT WINAPI
1303 IDirectDraw2Impl_WaitForVerticalBlank(LPDIRECTDRAW2 This, DWORD dwFlags,
1304                                       HANDLE hEvent)
1305 {
1306     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1307                                                                 IDirectDraw2,
1308                                                                 IDirectDraw7,
1309                                                                 This),
1310                                              dwFlags, hEvent);
1311 }
1312
1313 static HRESULT WINAPI
1314 IDirectDraw3Impl_WaitForVerticalBlank(LPDIRECTDRAW3 This, DWORD dwFlags,
1315                                       HANDLE hEvent)
1316 {
1317     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1318                                                                 IDirectDraw3,
1319                                                                 IDirectDraw7,
1320                                                                 This),
1321                                              dwFlags, hEvent);
1322 }
1323
1324 static HRESULT WINAPI
1325 IDirectDraw4Impl_WaitForVerticalBlank(LPDIRECTDRAW4 This, DWORD dwFlags,
1326                                       HANDLE hEvent)
1327 {
1328     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1329                                                                 IDirectDraw4,
1330                                                                 IDirectDraw7,
1331                                                                 This),
1332                                              dwFlags, hEvent);
1333 }
1334
1335 static HRESULT WINAPI
1336 IDirectDraw2Impl_GetAvailableVidMem(LPDIRECTDRAW2 This, LPDDSCAPS pCaps,
1337                                     LPDWORD pdwTotal, LPDWORD pdwFree)
1338 {
1339     DDSCAPS2 Caps2;
1340     DDRAW_Convert_DDSCAPS_1_To_2(pCaps, &Caps2);
1341
1342     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
1343                                                               IDirectDraw2,
1344                                                               IDirectDraw7,
1345                                                               This),
1346                                            &Caps2, pdwTotal, pdwFree);
1347 }
1348
1349 static HRESULT WINAPI
1350 IDirectDraw3Impl_GetAvailableVidMem(LPDIRECTDRAW3 This, LPDDSCAPS pCaps,
1351                                     LPDWORD pdwTotal, LPDWORD pdwFree)
1352 {
1353     DDSCAPS2 Caps2;
1354     DDRAW_Convert_DDSCAPS_1_To_2(pCaps, &Caps2);
1355
1356     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
1357                                                               IDirectDraw3,
1358                                                               IDirectDraw7,
1359                                                               This),
1360                                            &Caps2, pdwTotal, pdwFree);
1361 }
1362
1363 static HRESULT WINAPI
1364 IDirectDraw4Impl_GetAvailableVidMem(LPDIRECTDRAW4 This, LPDDSCAPS2 pCaps,
1365                                     LPDWORD pdwTotal, LPDWORD pdwFree)
1366 {
1367     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
1368                                                               IDirectDraw4,
1369                                                               IDirectDraw7,
1370                                                               This),
1371                                            pCaps, pdwTotal, pdwFree);
1372 }
1373
1374 static HRESULT WINAPI
1375 IDirectDraw3Impl_GetSurfaceFromDC(LPDIRECTDRAW3 This, HDC hDC,
1376                                   LPDIRECTDRAWSURFACE *pSurf)
1377 {
1378     return IDirectDraw7_GetSurfaceFromDC(COM_INTERFACE_CAST(IDirectDrawImpl,
1379                                                             IDirectDraw3,
1380                                                             IDirectDraw7,
1381                                                             This),
1382                                          hDC, (LPDIRECTDRAWSURFACE7 *)pSurf);
1383 }
1384
1385 static HRESULT WINAPI
1386 IDirectDraw4Impl_GetSurfaceFromDC(LPDIRECTDRAW4 This, HDC hDC,
1387                                   LPDIRECTDRAWSURFACE4 *pSurf)
1388 {
1389     return IDirectDraw7_GetSurfaceFromDC(COM_INTERFACE_CAST(IDirectDrawImpl,
1390                                                             IDirectDraw4,
1391                                                             IDirectDraw7,
1392                                                             This),
1393                                          hDC, (LPDIRECTDRAWSURFACE7 *)pSurf);
1394 }
1395
1396 static HRESULT WINAPI
1397 IDirectDraw4Impl_RestoreAllSurfaces(LPDIRECTDRAW4 This)
1398 {
1399     return IDirectDraw7_RestoreAllSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
1400                                                               IDirectDraw4,
1401                                                               IDirectDraw7,
1402                                                               This));
1403 }
1404
1405 static HRESULT WINAPI
1406 IDirectDraw4Impl_TestCooperativeLevel(LPDIRECTDRAW4 This)
1407 {
1408     return IDirectDraw7_TestCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1409                                                                 IDirectDraw4,
1410                                                                 IDirectDraw7,
1411                                                                 This));
1412 }
1413
1414 static HRESULT WINAPI
1415 IDirectDraw4Impl_GetDeviceIdentifier(LPDIRECTDRAW4 This,
1416                                      LPDDDEVICEIDENTIFIER pDDDI, DWORD dwFlags)
1417 {
1418     DDDEVICEIDENTIFIER2 DDDI2;
1419     HRESULT hr;
1420
1421     hr = IDirectDraw7_GetDeviceIdentifier(COM_INTERFACE_CAST(IDirectDrawImpl,
1422                                                              IDirectDraw4,
1423                                                              IDirectDraw7,
1424                                                              This),
1425                                           &DDDI2, dwFlags);
1426
1427     DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&DDDI2, pDDDI);
1428
1429     return hr;
1430 }
1431
1432 const IDirectDrawVtbl IDirectDraw1_Vtbl =
1433 {
1434     IDirectDrawImpl_QueryInterface,
1435     IDirectDrawImpl_AddRef,
1436     IDirectDrawImpl_Release,
1437     IDirectDrawImpl_Compact,
1438     IDirectDrawImpl_CreateClipper,
1439     IDirectDrawImpl_CreatePalette,
1440     IDirectDrawImpl_CreateSurface,
1441     IDirectDrawImpl_DuplicateSurface,
1442     IDirectDrawImpl_EnumDisplayModes,
1443     IDirectDrawImpl_EnumSurfaces,
1444     IDirectDrawImpl_FlipToGDISurface,
1445     IDirectDrawImpl_GetCaps,
1446     IDirectDrawImpl_GetDisplayMode,
1447     IDirectDrawImpl_GetFourCCCodes,
1448     IDirectDrawImpl_GetGDISurface,
1449     IDirectDrawImpl_GetMonitorFrequency,
1450     IDirectDrawImpl_GetScanLine,
1451     IDirectDrawImpl_GetVerticalBlankStatus,
1452     IDirectDrawImpl_Initialize,
1453     IDirectDrawImpl_RestoreDisplayMode,
1454     IDirectDrawImpl_SetCooperativeLevel,
1455     IDirectDrawImpl_SetDisplayMode,
1456     IDirectDrawImpl_WaitForVerticalBlank,
1457 };
1458
1459 const IDirectDraw2Vtbl IDirectDraw2_Vtbl =
1460 {
1461     IDirectDraw2Impl_QueryInterface,
1462     IDirectDraw2Impl_AddRef,
1463     IDirectDraw2Impl_Release,
1464     IDirectDraw2Impl_Compact,
1465     IDirectDraw2Impl_CreateClipper,
1466     IDirectDraw2Impl_CreatePalette,
1467     IDirectDraw2Impl_CreateSurface,
1468     IDirectDraw2Impl_DuplicateSurface,
1469     IDirectDraw2Impl_EnumDisplayModes,
1470     IDirectDraw2Impl_EnumSurfaces,
1471     IDirectDraw2Impl_FlipToGDISurface,
1472     IDirectDraw2Impl_GetCaps,
1473     IDirectDraw2Impl_GetDisplayMode,
1474     IDirectDraw2Impl_GetFourCCCodes,
1475     IDirectDraw2Impl_GetGDISurface,
1476     IDirectDraw2Impl_GetMonitorFrequency,
1477     IDirectDraw2Impl_GetScanLine,
1478     IDirectDraw2Impl_GetVerticalBlankStatus,
1479     IDirectDraw2Impl_Initialize,
1480     IDirectDraw2Impl_RestoreDisplayMode,
1481     IDirectDraw2Impl_SetCooperativeLevel,
1482     IDirectDraw2Impl_SetDisplayMode,
1483     IDirectDraw2Impl_WaitForVerticalBlank,
1484     IDirectDraw2Impl_GetAvailableVidMem
1485 };
1486
1487 const IDirectDraw3Vtbl IDirectDraw3_Vtbl =
1488 {
1489     IDirectDraw3Impl_QueryInterface,
1490     IDirectDraw3Impl_AddRef,
1491     IDirectDraw3Impl_Release,
1492     IDirectDraw3Impl_Compact,
1493     IDirectDraw3Impl_CreateClipper,
1494     IDirectDraw3Impl_CreatePalette,
1495     IDirectDraw3Impl_CreateSurface,
1496     IDirectDraw3Impl_DuplicateSurface,
1497     IDirectDraw3Impl_EnumDisplayModes,
1498     IDirectDraw3Impl_EnumSurfaces,
1499     IDirectDraw3Impl_FlipToGDISurface,
1500     IDirectDraw3Impl_GetCaps,
1501     IDirectDraw3Impl_GetDisplayMode,
1502     IDirectDraw3Impl_GetFourCCCodes,
1503     IDirectDraw3Impl_GetGDISurface,
1504     IDirectDraw3Impl_GetMonitorFrequency,
1505     IDirectDraw3Impl_GetScanLine,
1506     IDirectDraw3Impl_GetVerticalBlankStatus,
1507     IDirectDraw3Impl_Initialize,
1508     IDirectDraw3Impl_RestoreDisplayMode,
1509     IDirectDraw3Impl_SetCooperativeLevel,
1510     IDirectDraw3Impl_SetDisplayMode,
1511     IDirectDraw3Impl_WaitForVerticalBlank,
1512     IDirectDraw3Impl_GetAvailableVidMem,
1513     IDirectDraw3Impl_GetSurfaceFromDC,
1514 };
1515
1516 const IDirectDraw4Vtbl IDirectDraw4_Vtbl =
1517 {
1518     IDirectDraw4Impl_QueryInterface,
1519     IDirectDraw4Impl_AddRef,
1520     IDirectDraw4Impl_Release,
1521     IDirectDraw4Impl_Compact,
1522     IDirectDraw4Impl_CreateClipper,
1523     IDirectDraw4Impl_CreatePalette,
1524     IDirectDraw4Impl_CreateSurface,
1525     IDirectDraw4Impl_DuplicateSurface,
1526     IDirectDraw4Impl_EnumDisplayModes,
1527     IDirectDraw4Impl_EnumSurfaces,
1528     IDirectDraw4Impl_FlipToGDISurface,
1529     IDirectDraw4Impl_GetCaps,
1530     IDirectDraw4Impl_GetDisplayMode,
1531     IDirectDraw4Impl_GetFourCCCodes,
1532     IDirectDraw4Impl_GetGDISurface,
1533     IDirectDraw4Impl_GetMonitorFrequency,
1534     IDirectDraw4Impl_GetScanLine,
1535     IDirectDraw4Impl_GetVerticalBlankStatus,
1536     IDirectDraw4Impl_Initialize,
1537     IDirectDraw4Impl_RestoreDisplayMode,
1538     IDirectDraw4Impl_SetCooperativeLevel,
1539     IDirectDraw4Impl_SetDisplayMode,
1540     IDirectDraw4Impl_WaitForVerticalBlank,
1541     IDirectDraw4Impl_GetAvailableVidMem,
1542     IDirectDraw4Impl_GetSurfaceFromDC,
1543     IDirectDraw4Impl_RestoreAllSurfaces,
1544     IDirectDraw4Impl_TestCooperativeLevel,
1545     IDirectDraw4Impl_GetDeviceIdentifier
1546 };