gdiplus: Check pointer in GdipGetLineRectI.
[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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw, 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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw2, 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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw3, 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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw4, 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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw, 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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw2, 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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw3, 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     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw4, 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 = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, *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 = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, *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 = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, *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 = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, *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 static HRESULT WINAPI
381 IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc,
382                               LPDIRECTDRAWSURFACE *ppSurface,
383                               IUnknown *pUnkOuter)
384 {
385     LPDIRECTDRAWSURFACE7 pSurface7;
386     IDirectDrawSurfaceImpl *impl;
387     HRESULT hr;
388
389     /* Remove front buffer flag, this causes failure in v7, and its added to normal
390      * primaries anyway
391      */
392     pSDesc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
393     /* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
394      * since the data layout is the same */
395     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
396                                                        IDirectDraw,
397                                                        IDirectDraw7,
398                                                        This),
399                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
400
401     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
402      * IDirectDrawSurface vtable layout at the beginning  */
403     *ppSurface = (LPDIRECTDRAWSURFACE) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
404                                     IDirectDrawSurface7, IDirectDrawSurface3,
405                                     pSurface7);
406
407     impl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, pSurface7);
408     if(SUCCEEDED(hr) && impl)
409     {
410         impl->version = 1;
411         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
412                              IDirectDraw,
413                              IDirectDraw7,
414                              This));
415         impl->ifaceToRelease = NULL;
416     }
417
418     return hr;
419 }
420
421 static HRESULT WINAPI
422 IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc,
423                                LPDIRECTDRAWSURFACE *ppSurface,
424                                IUnknown *pUnkOuter)
425 {
426     LPDIRECTDRAWSURFACE7 pSurface7;
427     IDirectDrawSurfaceImpl *impl;
428     HRESULT hr;
429
430     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
431                                                        IDirectDraw2,
432                                                        IDirectDraw7,
433                                                        This),
434                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
435
436     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
437      * IDirectDrawSurface vtable layout at the beginning  */
438     *ppSurface = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
439                                     IDirectDrawSurface7, IDirectDrawSurface3,
440                                     pSurface7);
441
442     impl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, pSurface7);
443     if(SUCCEEDED(hr) && impl)
444     {
445         impl->version = 2;
446         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
447                              IDirectDraw2,
448                              IDirectDraw7,
449                              This));
450         impl->ifaceToRelease = NULL;
451     }
452
453     return hr;
454 }
455
456 static HRESULT WINAPI
457 IDirectDraw3Impl_CreateSurface(LPDIRECTDRAW3 This, LPDDSURFACEDESC pSDesc,
458                                LPDIRECTDRAWSURFACE *ppSurface,
459                                IUnknown *pUnkOuter)
460 {
461     LPDIRECTDRAWSURFACE7 pSurface7;
462     IDirectDrawSurfaceImpl *impl;
463     HRESULT hr;
464
465     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
466                                                        IDirectDraw3,
467                                                        IDirectDraw7,
468                                                        This),
469                                     (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
470
471     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
472      * IDirectDrawSurface vtable layout at the beginning  */
473     *ppSurface = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
474                                     IDirectDrawSurface7, IDirectDrawSurface3,
475                                     pSurface7);
476
477     impl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, pSurface7);
478     if(SUCCEEDED(hr) && impl)
479     {
480         impl->version = 3;
481         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
482                              IDirectDraw3,
483                              IDirectDraw7,
484                              This));
485         IDirectDraw3_AddRef(This);
486         impl->ifaceToRelease = (IUnknown *) This;
487     }
488
489     return hr;
490 }
491
492 static HRESULT WINAPI
493 IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
494                                LPDIRECTDRAWSURFACE4 *ppSurface,
495                                IUnknown *pUnkOuter)
496 {
497     HRESULT hr;
498     IDirectDrawSurfaceImpl *impl;
499
500     hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
501                                                        IDirectDraw4,
502                                                        IDirectDraw7,
503                                                         This),
504                                     pSDesc,
505                                     (LPDIRECTDRAWSURFACE7 *)ppSurface,
506                                     pUnkOuter);
507     impl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurface);
508     if(SUCCEEDED(hr) && impl)
509     {
510         impl->version = 4;
511         IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl,
512                              IDirectDraw4,
513                              IDirectDraw7,
514                              This));
515         IDirectDraw4_AddRef(This);
516         impl->ifaceToRelease = (IUnknown *) This;
517     }
518     return hr;
519 }
520
521 static HRESULT WINAPI
522 IDirectDrawImpl_DuplicateSurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE pSrc,
523                                  LPDIRECTDRAWSURFACE *ppDst)
524 {
525     LPDIRECTDRAWSURFACE7 pDst7;
526     HRESULT hr;
527
528     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
529                                                           IDirectDraw,
530                                                           IDirectDraw7, This),
531                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
532                                                           IDirectDrawSurface3,
533                                                           IDirectDrawSurface7,
534                                                           pSrc),
535                                        &pDst7);
536
537     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
538      * IDirectDrawSurface vtable layout at the beginning  */
539     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
540                                 IDirectDrawSurface3, pDst7);
541
542     return hr;
543 }
544
545 static HRESULT WINAPI
546 IDirectDraw2Impl_DuplicateSurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE pSrc,
547                                   LPDIRECTDRAWSURFACE *ppDst)
548 {
549     LPDIRECTDRAWSURFACE7 pDst7;
550     HRESULT hr;
551
552     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
553                                                           IDirectDraw2,
554                                                           IDirectDraw7, This),
555                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
556                                                           IDirectDrawSurface3,
557                                                           IDirectDrawSurface7,
558                                                           pSrc),
559                                        &pDst7);
560
561     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
562      * IDirectDrawSurface vtable layout at the beginning  */
563     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
564                                 IDirectDrawSurface3, pDst7);
565
566     return hr;
567 }
568
569 static HRESULT WINAPI
570 IDirectDraw3Impl_DuplicateSurface(LPDIRECTDRAW3 This, LPDIRECTDRAWSURFACE pSrc,
571                                   LPDIRECTDRAWSURFACE *ppDst)
572 {
573     LPDIRECTDRAWSURFACE7 pDst7;
574     HRESULT hr;
575
576     hr = IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
577                                                           IDirectDraw3,
578                                                           IDirectDraw7, This),
579                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
580                                                           IDirectDrawSurface3,
581                                                           IDirectDrawSurface7,
582                                                           pSrc),
583                                        &pDst7);
584
585     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
586      * IDirectDrawSurface vtable layout at the beginning  */
587     *ppDst = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
588                                 IDirectDrawSurface3, pDst7);
589
590     return hr;
591 }
592
593 static HRESULT WINAPI
594 IDirectDraw4Impl_DuplicateSurface(LPDIRECTDRAW4 This,
595                                   LPDIRECTDRAWSURFACE4 pSrc,
596                                   LPDIRECTDRAWSURFACE4 *ppDst)
597 {
598     return IDirectDraw7_DuplicateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
599                                                             IDirectDraw4,
600                                                             IDirectDraw7,
601                                                             This),
602                                          (LPDIRECTDRAWSURFACE7)pSrc,
603                                          (LPDIRECTDRAWSURFACE7 *)ppDst);
604 }
605
606 struct displaymodescallback_context
607 {
608     LPDDENUMMODESCALLBACK func;
609     LPVOID context;
610 };
611
612 static HRESULT CALLBACK
613 EnumDisplayModesCallbackThunk(LPDDSURFACEDESC2 pDDSD2, LPVOID context)
614 {
615     DDSURFACEDESC DDSD;
616     struct displaymodescallback_context *cbcontext = context;
617
618     memcpy(&DDSD,pDDSD2,sizeof(DDSD));
619     DDSD.dwSize = sizeof(DDSD);
620
621     return cbcontext->func(&DDSD, cbcontext->context);
622 }
623
624 static HRESULT WINAPI
625 IDirectDrawImpl_EnumDisplayModes(LPDIRECTDRAW This, DWORD dwFlags,
626                                  LPDDSURFACEDESC pDDSD, LPVOID context,
627                                  LPDDENUMMODESCALLBACK cb)
628 {
629     struct displaymodescallback_context cbcontext;
630
631     cbcontext.func    = cb;
632     cbcontext.context = context;
633
634     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
635                                                             IDirectDraw,
636                                                             IDirectDraw7,
637                                                             This),
638                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
639                                          EnumDisplayModesCallbackThunk);
640 }
641
642 static HRESULT WINAPI
643 IDirectDraw2Impl_EnumDisplayModes(LPDIRECTDRAW2 This, DWORD dwFlags,
644                                   LPDDSURFACEDESC pDDSD, LPVOID context,
645                                   LPDDENUMMODESCALLBACK cb)
646 {
647     struct displaymodescallback_context cbcontext;
648
649     cbcontext.func    = cb;
650     cbcontext.context = context;
651
652     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
653                                                             IDirectDraw2,
654                                                             IDirectDraw7,
655                                                             This),
656                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
657                                          EnumDisplayModesCallbackThunk);
658 }
659
660 static HRESULT WINAPI
661 IDirectDraw3Impl_EnumDisplayModes(LPDIRECTDRAW3 This, DWORD dwFlags,
662                                   LPDDSURFACEDESC pDDSD, LPVOID context,
663                                   LPDDENUMMODESCALLBACK cb)
664 {
665     struct displaymodescallback_context cbcontext;
666
667     cbcontext.func    = cb;
668     cbcontext.context = context;
669
670     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
671                                                             IDirectDraw3,
672                                                             IDirectDraw7,
673                                                             This),
674                                          dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
675                                          EnumDisplayModesCallbackThunk);
676 }
677
678 static HRESULT WINAPI
679 IDirectDraw4Impl_EnumDisplayModes(LPDIRECTDRAW4 This, DWORD dwFlags,
680                                   LPDDSURFACEDESC2 pDDSD, LPVOID context,
681                                   LPDDENUMMODESCALLBACK2 cb)
682 {
683     return IDirectDraw7_EnumDisplayModes(COM_INTERFACE_CAST(IDirectDrawImpl,
684                                                             IDirectDraw4,
685                                                             IDirectDraw7,
686                                                             This),
687                                          dwFlags, pDDSD, context, cb);
688 }
689
690 struct surfacescallback_context
691 {
692     LPDDENUMSURFACESCALLBACK func;
693     LPVOID context;
694 };
695
696 static HRESULT CALLBACK
697 EnumSurfacesCallbackThunk(LPDIRECTDRAWSURFACE7 pSurf, LPDDSURFACEDESC2 pDDSD,
698                           LPVOID context)
699 {
700     struct surfacescallback_context *cbcontext = context;
701
702     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
703      * IDirectDrawSurface vtable layout at the beginning  */
704     return cbcontext->func((LPDIRECTDRAWSURFACE)
705                            COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,
706                                               IDirectDrawSurface7,
707                                               IDirectDrawSurface3, pSurf),
708                            (LPDDSURFACEDESC)pDDSD, cbcontext->context);
709 }
710
711 static HRESULT WINAPI
712 IDirectDrawImpl_EnumSurfaces(LPDIRECTDRAW This, DWORD dwFlags,
713                              LPDDSURFACEDESC pDDSD, LPVOID context,
714                              LPDDENUMSURFACESCALLBACK cb)
715 {
716     struct surfacescallback_context cbcontext;
717
718     cbcontext.func    = cb;
719     cbcontext.context = context;
720
721     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
722                                                         IDirectDraw,
723                                                         IDirectDraw7, This),
724                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
725                                      &cbcontext, EnumSurfacesCallbackThunk);
726 }
727
728 static HRESULT WINAPI
729 IDirectDraw2Impl_EnumSurfaces(LPDIRECTDRAW2 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                                                         IDirectDraw2,
740                                                         IDirectDraw7, This),
741                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
742                                      &cbcontext, EnumSurfacesCallbackThunk);
743 }
744
745 static HRESULT WINAPI
746 IDirectDraw3Impl_EnumSurfaces(LPDIRECTDRAW3 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                                                         IDirectDraw3,
757                                                         IDirectDraw7, This),
758                                      dwFlags, (LPDDSURFACEDESC2)pDDSD,
759                                      &cbcontext, EnumSurfacesCallbackThunk);
760 }
761
762 static HRESULT WINAPI
763 IDirectDraw4Impl_EnumSurfaces(LPDIRECTDRAW4 This, DWORD dwFlags,
764                               LPDDSURFACEDESC2 pDDSD, LPVOID context,
765                               LPDDENUMSURFACESCALLBACK2 cb)
766 {
767     return IDirectDraw7_EnumSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
768                                                         IDirectDraw4,
769                                                         IDirectDraw7, This),
770                                      dwFlags, pDDSD, context,
771                                      (LPDDENUMSURFACESCALLBACK7)cb);
772 }
773
774 static HRESULT WINAPI
775 IDirectDrawImpl_FlipToGDISurface(LPDIRECTDRAW This)
776 {
777     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
778                                                             IDirectDraw,
779                                                             IDirectDraw7,
780                                                             This));
781 }
782
783 static HRESULT WINAPI
784 IDirectDraw2Impl_FlipToGDISurface(LPDIRECTDRAW2 This)
785 {
786     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
787                                                             IDirectDraw2,
788                                                             IDirectDraw7,
789                                                             This));
790 }
791
792 static HRESULT WINAPI
793 IDirectDraw3Impl_FlipToGDISurface(LPDIRECTDRAW3 This)
794 {
795     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
796                                                             IDirectDraw3,
797                                                             IDirectDraw7,
798                                                             This));
799 }
800
801 static HRESULT WINAPI
802 IDirectDraw4Impl_FlipToGDISurface(LPDIRECTDRAW4 This)
803 {
804     return IDirectDraw7_FlipToGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
805                                                             IDirectDraw4,
806                                                             IDirectDraw7,
807                                                             This));
808 }
809
810 static HRESULT WINAPI
811 IDirectDrawImpl_GetCaps(LPDIRECTDRAW This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
812 {
813     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
814                                                    IDirectDraw, IDirectDraw7,
815                                                    This), pDDC1, pDDC2);
816 }
817
818 static HRESULT WINAPI
819 IDirectDraw2Impl_GetCaps(LPDIRECTDRAW2 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
820 {
821     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
822                                                    IDirectDraw2, IDirectDraw7,
823                                                    This), pDDC1, pDDC2);
824 }
825
826 static HRESULT WINAPI
827 IDirectDraw3Impl_GetCaps(LPDIRECTDRAW3 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
828 {
829     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
830                                                    IDirectDraw3, IDirectDraw7,
831                                                    This), pDDC1, pDDC2);
832 }
833
834 static HRESULT WINAPI
835 IDirectDraw4Impl_GetCaps(LPDIRECTDRAW4 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
836 {
837     return IDirectDraw7_GetCaps(COM_INTERFACE_CAST(IDirectDrawImpl,
838                                                    IDirectDraw4, IDirectDraw7,
839                                                    This), pDDC1, pDDC2);
840 }
841
842 static HRESULT WINAPI
843 IDirectDrawImpl_GetDisplayMode(LPDIRECTDRAW This, LPDDSURFACEDESC pDDSD)
844 {
845     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
846                                                           IDirectDraw,
847                                                           IDirectDraw7, This),
848                                        (LPDDSURFACEDESC2)pDDSD);
849 }
850
851 static HRESULT WINAPI
852 IDirectDraw2Impl_GetDisplayMode(LPDIRECTDRAW2 This, LPDDSURFACEDESC pDDSD)
853 {
854     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
855                                                           IDirectDraw2,
856                                                           IDirectDraw7, This),
857                                        (LPDDSURFACEDESC2)pDDSD);
858 }
859
860 static HRESULT WINAPI
861 IDirectDraw3Impl_GetDisplayMode(LPDIRECTDRAW3 This, LPDDSURFACEDESC pDDSD)
862 {
863     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
864                                                           IDirectDraw3,
865                                                           IDirectDraw7, This),
866                                        (LPDDSURFACEDESC2)pDDSD);
867 }
868
869 static HRESULT WINAPI
870 IDirectDraw4Impl_GetDisplayMode(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pDDSD)
871 {
872     return IDirectDraw7_GetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
873                                                           IDirectDraw4,
874                                                           IDirectDraw7, This),
875                                        pDDSD);
876 }
877
878 static HRESULT WINAPI
879 IDirectDrawImpl_GetFourCCCodes(LPDIRECTDRAW This, LPDWORD lpNumCodes,
880                                LPDWORD lpCodes)
881 {
882     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
883                                                           IDirectDraw,
884                                                           IDirectDraw7,
885                                                           This),
886                                        lpNumCodes, lpCodes);
887 }
888
889 static HRESULT WINAPI
890 IDirectDraw2Impl_GetFourCCCodes(LPDIRECTDRAW2 This, LPDWORD lpNumCodes,
891                                 LPDWORD lpCodes)
892 {
893     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
894                                                           IDirectDraw2,
895                                                           IDirectDraw7,
896                                                           This),
897                                        lpNumCodes, lpCodes);
898 }
899
900 static HRESULT WINAPI
901 IDirectDraw3Impl_GetFourCCCodes(LPDIRECTDRAW3 This, LPDWORD lpNumCodes,
902                                 LPDWORD lpCodes)
903 {
904     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
905                                                           IDirectDraw3,
906                                                           IDirectDraw7,
907                                                           This),
908                                        lpNumCodes, lpCodes);
909 }
910
911 static HRESULT WINAPI
912 IDirectDraw4Impl_GetFourCCCodes(LPDIRECTDRAW4 This, LPDWORD lpNumCodes,
913                                 LPDWORD lpCodes)
914 {
915     return IDirectDraw7_GetFourCCCodes(COM_INTERFACE_CAST(IDirectDrawImpl,
916                                                           IDirectDraw4,
917                                                           IDirectDraw7,
918                                                           This),
919                                        lpNumCodes, lpCodes);
920 }
921
922 static HRESULT WINAPI
923 IDirectDrawImpl_GetGDISurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE *ppSurf)
924 {
925     LPDIRECTDRAWSURFACE7 pSurf7;
926     HRESULT hr;
927
928     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
929                                                        IDirectDraw,
930                                                        IDirectDraw7,
931                                                        This), &pSurf7);
932
933     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
934      * IDirectDrawSurface vtable layout at the beginning  */
935     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
936                                  IDirectDrawSurface3, pSurf7);
937
938     return hr;
939 }
940
941 static HRESULT WINAPI
942 IDirectDraw2Impl_GetGDISurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE *ppSurf)
943 {
944     LPDIRECTDRAWSURFACE7 pSurf7;
945     HRESULT hr;
946
947     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
948                                                        IDirectDraw2,
949                                                        IDirectDraw7,
950                                                        This), &pSurf7);
951
952     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
953      * IDirectDrawSurface vtable layout at the beginning  */
954     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
955                                  IDirectDrawSurface3, pSurf7);
956
957     return hr;
958 }
959
960 static HRESULT WINAPI
961 IDirectDraw3Impl_GetGDISurface(LPDIRECTDRAW3 This, LPDIRECTDRAWSURFACE *ppSurf)
962 {
963     LPDIRECTDRAWSURFACE7 pSurf7;
964     HRESULT hr;
965
966     hr = IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
967                                                        IDirectDraw3,
968                                                        IDirectDraw7,
969                                                        This), &pSurf7);
970
971     /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
972      * IDirectDrawSurface vtable layout at the beginning  */
973     *ppSurf = (LPDIRECTDRAWSURFACE)COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
974                                  IDirectDrawSurface3, pSurf7);
975
976     return hr;
977 }
978
979 static HRESULT WINAPI
980 IDirectDraw4Impl_GetGDISurface(LPDIRECTDRAW4 This,
981                                LPDIRECTDRAWSURFACE4 *ppSurf)
982 {
983     return IDirectDraw7_GetGDISurface(COM_INTERFACE_CAST(IDirectDrawImpl,
984                                                          IDirectDraw4,
985                                                          IDirectDraw7,
986                                                          This),
987                                       (LPDIRECTDRAWSURFACE7 *)ppSurf);
988 }
989
990 static HRESULT WINAPI
991 IDirectDrawImpl_GetMonitorFrequency(LPDIRECTDRAW This, LPDWORD pdwFreq)
992 {
993     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
994                                                                IDirectDraw,
995                                                                IDirectDraw7,
996                                                                This),
997                                             pdwFreq);
998 }
999
1000 static HRESULT WINAPI
1001 IDirectDraw2Impl_GetMonitorFrequency(LPDIRECTDRAW2 This, LPDWORD pdwFreq)
1002 {
1003     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
1004                                                                IDirectDraw2,
1005                                                                IDirectDraw7,
1006                                                                This),
1007                                             pdwFreq);
1008 }
1009
1010 static HRESULT WINAPI
1011 IDirectDraw3Impl_GetMonitorFrequency(LPDIRECTDRAW3 This, LPDWORD pdwFreq)
1012 {
1013     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
1014                                                                IDirectDraw3,
1015                                                                IDirectDraw7,
1016                                                                This),
1017                                             pdwFreq);
1018 }
1019
1020 static HRESULT WINAPI
1021 IDirectDraw4Impl_GetMonitorFrequency(LPDIRECTDRAW4 This, LPDWORD pdwFreq)
1022 {
1023     return IDirectDraw7_GetMonitorFrequency(COM_INTERFACE_CAST(IDirectDrawImpl,
1024                                                                IDirectDraw4,
1025                                                                IDirectDraw7,
1026                                                                This),
1027                                             pdwFreq);
1028 }
1029
1030 static HRESULT WINAPI
1031 IDirectDrawImpl_GetScanLine(LPDIRECTDRAW This, LPDWORD pdwLine)
1032 {
1033     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1034                                                        IDirectDraw,
1035                                                        IDirectDraw7,
1036                                                        This), pdwLine);
1037 }
1038
1039 static HRESULT WINAPI
1040 IDirectDraw2Impl_GetScanLine(LPDIRECTDRAW2 This, LPDWORD pdwLine)
1041 {
1042     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1043                                                        IDirectDraw2,
1044                                                        IDirectDraw7,
1045                                                        This), pdwLine);
1046 }
1047
1048 static HRESULT WINAPI
1049 IDirectDraw3Impl_GetScanLine(LPDIRECTDRAW3 This, LPDWORD pdwLine)
1050 {
1051     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1052                                                        IDirectDraw3,
1053                                                        IDirectDraw7,
1054                                                        This), pdwLine);
1055 }
1056
1057 static HRESULT WINAPI
1058 IDirectDraw4Impl_GetScanLine(LPDIRECTDRAW4 This, LPDWORD pdwLine)
1059 {
1060     return IDirectDraw7_GetScanLine(COM_INTERFACE_CAST(IDirectDrawImpl,
1061                                                        IDirectDraw4,
1062                                                        IDirectDraw7,
1063                                                        This), pdwLine);
1064 }
1065
1066 static HRESULT WINAPI
1067 IDirectDrawImpl_GetVerticalBlankStatus(LPDIRECTDRAW This, LPBOOL lpbIsInVB)
1068 {
1069     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1070                                                                   IDirectDraw,
1071                                                                   IDirectDraw7,
1072                                                                   This),
1073                                                lpbIsInVB);
1074 }
1075
1076 static HRESULT WINAPI
1077 IDirectDraw2Impl_GetVerticalBlankStatus(LPDIRECTDRAW2 This, LPBOOL lpbIsInVB)
1078 {
1079     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1080                                                                   IDirectDraw2,
1081                                                                   IDirectDraw7,
1082                                                                   This),
1083                                                lpbIsInVB);
1084 }
1085
1086 static HRESULT WINAPI
1087 IDirectDraw3Impl_GetVerticalBlankStatus(LPDIRECTDRAW3 This, LPBOOL lpbIsInVB)
1088 {
1089     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1090                                                                   IDirectDraw3,
1091                                                                   IDirectDraw7,
1092                                                                   This),
1093                                                lpbIsInVB);
1094 }
1095
1096 static HRESULT WINAPI
1097 IDirectDraw4Impl_GetVerticalBlankStatus(LPDIRECTDRAW4 This, LPBOOL lpbIsInVB)
1098 {
1099     return IDirectDraw7_GetVerticalBlankStatus(COM_INTERFACE_CAST(IDirectDrawImpl,
1100                                                                   IDirectDraw4,
1101                                                                   IDirectDraw7,
1102                                                                   This),
1103                                                lpbIsInVB);
1104 }
1105
1106 static HRESULT WINAPI
1107 IDirectDrawImpl_Initialize(LPDIRECTDRAW iface, LPGUID pGUID)
1108 {
1109     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw, iface);
1110     HRESULT ret_value;
1111
1112     ret_value = IDirectDraw7_Initialize(ICOM_INTERFACE(This, IDirectDraw7), pGUID);
1113
1114     return ret_value;
1115 }
1116
1117 static HRESULT WINAPI
1118 IDirectDraw2Impl_Initialize(LPDIRECTDRAW2 iface, LPGUID pGUID)
1119 {
1120     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw2, iface);
1121     HRESULT ret_value;
1122
1123     ret_value = IDirectDraw7_Initialize(ICOM_INTERFACE(This, IDirectDraw7), pGUID);
1124
1125     return ret_value;
1126 }
1127
1128 static HRESULT WINAPI
1129 IDirectDraw3Impl_Initialize(LPDIRECTDRAW3 iface, LPGUID pGUID)
1130 {
1131     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw3, iface);
1132     HRESULT ret_value;
1133
1134     ret_value = IDirectDraw7_Initialize(ICOM_INTERFACE(This, IDirectDraw7), pGUID);
1135
1136     return ret_value;
1137 }
1138
1139 static HRESULT WINAPI
1140 IDirectDraw4Impl_Initialize(LPDIRECTDRAW4 iface, LPGUID pGUID)
1141 {
1142     ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw4, iface);
1143     HRESULT ret_value;
1144
1145     ret_value = IDirectDraw7_Initialize(ICOM_INTERFACE(This, IDirectDraw7), pGUID);
1146
1147     return ret_value;
1148 }
1149
1150
1151 static HRESULT WINAPI
1152 IDirectDrawImpl_RestoreDisplayMode(LPDIRECTDRAW This)
1153 {
1154     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1155                                                               IDirectDraw,
1156                                                               IDirectDraw7,
1157                                                               This));
1158 }
1159
1160 static HRESULT WINAPI
1161 IDirectDraw2Impl_RestoreDisplayMode(LPDIRECTDRAW2 This)
1162 {
1163     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1164                                                               IDirectDraw2,
1165                                                               IDirectDraw7,
1166                                                               This));
1167 }
1168
1169 static HRESULT WINAPI
1170 IDirectDraw3Impl_RestoreDisplayMode(LPDIRECTDRAW3 This)
1171 {
1172     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1173                                                               IDirectDraw3,
1174                                                               IDirectDraw7,
1175                                                               This));
1176 }
1177
1178 static HRESULT WINAPI
1179 IDirectDraw4Impl_RestoreDisplayMode(LPDIRECTDRAW4 This)
1180 {
1181     return IDirectDraw7_RestoreDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1182                                                               IDirectDraw4,
1183                                                               IDirectDraw7,
1184                                                               This));
1185 }
1186
1187 static HRESULT WINAPI
1188 IDirectDrawImpl_SetCooperativeLevel(LPDIRECTDRAW This, HWND hWnd,
1189                                     DWORD dwFlags)
1190 {
1191     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1192                                                                IDirectDraw,
1193                                                                IDirectDraw7,
1194                                                                This),
1195                                             hWnd, dwFlags);
1196 }
1197
1198 static HRESULT WINAPI
1199 IDirectDraw2Impl_SetCooperativeLevel(LPDIRECTDRAW2 This, HWND hWnd,
1200                                      DWORD dwFlags)
1201 {
1202     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1203                                                                IDirectDraw2,
1204                                                                IDirectDraw7,
1205                                                                This),
1206                                             hWnd, dwFlags);
1207 }
1208
1209 static HRESULT WINAPI
1210 IDirectDraw3Impl_SetCooperativeLevel(LPDIRECTDRAW3 This, HWND hWnd,
1211                                      DWORD dwFlags)
1212 {
1213     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1214                                                                IDirectDraw3,
1215                                                                IDirectDraw7,
1216                                                                This),
1217                                             hWnd, dwFlags);
1218 }
1219
1220 static HRESULT WINAPI
1221 IDirectDraw4Impl_SetCooperativeLevel(LPDIRECTDRAW4 This, HWND hWnd,
1222                                      DWORD dwFlags)
1223 {
1224     return IDirectDraw7_SetCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1225                                                                IDirectDraw4,
1226                                                                IDirectDraw7,
1227                                                                This),
1228                                             hWnd, dwFlags);
1229 }
1230
1231 static HRESULT WINAPI
1232 IDirectDrawImpl_SetDisplayMode(LPDIRECTDRAW This, DWORD a, DWORD b, DWORD c)
1233 {
1234     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1235                                                           IDirectDraw,
1236                                                           IDirectDraw7,
1237                                                           This),
1238                                        a, b, c, 0, 0);
1239 }
1240
1241 static HRESULT WINAPI
1242 IDirectDraw2Impl_SetDisplayMode(LPDIRECTDRAW2 This, DWORD a, DWORD b, DWORD c,
1243                                 DWORD d, DWORD e)
1244 {
1245     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1246                                                           IDirectDraw2,
1247                                                           IDirectDraw7,
1248                                                           This),
1249                                        a, b, c, d, e);
1250 }
1251
1252 static HRESULT WINAPI
1253 IDirectDraw3Impl_SetDisplayMode(LPDIRECTDRAW3 This, DWORD a, DWORD b, DWORD c,
1254                                 DWORD d, DWORD e)
1255 {
1256     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1257                                                           IDirectDraw3,
1258                                                           IDirectDraw7,
1259                                                           This),
1260                                        a, b, c, d, e);
1261 }
1262
1263 static HRESULT WINAPI
1264 IDirectDraw4Impl_SetDisplayMode(LPDIRECTDRAW4 This, DWORD a, DWORD b, DWORD c,
1265                                 DWORD d, DWORD e)
1266 {
1267     return IDirectDraw7_SetDisplayMode(COM_INTERFACE_CAST(IDirectDrawImpl,
1268                                                           IDirectDraw4,
1269                                                           IDirectDraw7,
1270                                                           This),
1271                                        a, b, c, d, e);
1272 }
1273
1274 static HRESULT WINAPI
1275 IDirectDrawImpl_WaitForVerticalBlank(LPDIRECTDRAW This, DWORD dwFlags,
1276                                      HANDLE hEvent)
1277 {
1278     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1279                                                                 IDirectDraw,
1280                                                                 IDirectDraw7,
1281                                                                 This),
1282                                              dwFlags, hEvent);
1283 }
1284
1285 static HRESULT WINAPI
1286 IDirectDraw2Impl_WaitForVerticalBlank(LPDIRECTDRAW2 This, DWORD dwFlags,
1287                                       HANDLE hEvent)
1288 {
1289     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1290                                                                 IDirectDraw2,
1291                                                                 IDirectDraw7,
1292                                                                 This),
1293                                              dwFlags, hEvent);
1294 }
1295
1296 static HRESULT WINAPI
1297 IDirectDraw3Impl_WaitForVerticalBlank(LPDIRECTDRAW3 This, DWORD dwFlags,
1298                                       HANDLE hEvent)
1299 {
1300     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1301                                                                 IDirectDraw3,
1302                                                                 IDirectDraw7,
1303                                                                 This),
1304                                              dwFlags, hEvent);
1305 }
1306
1307 static HRESULT WINAPI
1308 IDirectDraw4Impl_WaitForVerticalBlank(LPDIRECTDRAW4 This, DWORD dwFlags,
1309                                       HANDLE hEvent)
1310 {
1311     return IDirectDraw7_WaitForVerticalBlank(COM_INTERFACE_CAST(IDirectDrawImpl,
1312                                                                 IDirectDraw4,
1313                                                                 IDirectDraw7,
1314                                                                 This),
1315                                              dwFlags, hEvent);
1316 }
1317
1318 static HRESULT WINAPI
1319 IDirectDraw2Impl_GetAvailableVidMem(LPDIRECTDRAW2 This, LPDDSCAPS pCaps,
1320                                     LPDWORD pdwTotal, LPDWORD pdwFree)
1321 {
1322     DDSCAPS2 Caps2;
1323     DDRAW_Convert_DDSCAPS_1_To_2(pCaps, &Caps2);
1324
1325     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
1326                                                               IDirectDraw2,
1327                                                               IDirectDraw7,
1328                                                               This),
1329                                            &Caps2, pdwTotal, pdwFree);
1330 }
1331
1332 static HRESULT WINAPI
1333 IDirectDraw3Impl_GetAvailableVidMem(LPDIRECTDRAW3 This, LPDDSCAPS pCaps,
1334                                     LPDWORD pdwTotal, LPDWORD pdwFree)
1335 {
1336     DDSCAPS2 Caps2;
1337     DDRAW_Convert_DDSCAPS_1_To_2(pCaps, &Caps2);
1338
1339     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
1340                                                               IDirectDraw3,
1341                                                               IDirectDraw7,
1342                                                               This),
1343                                            &Caps2, pdwTotal, pdwFree);
1344 }
1345
1346 static HRESULT WINAPI
1347 IDirectDraw4Impl_GetAvailableVidMem(LPDIRECTDRAW4 This, LPDDSCAPS2 pCaps,
1348                                     LPDWORD pdwTotal, LPDWORD pdwFree)
1349 {
1350     return IDirectDraw7_GetAvailableVidMem(COM_INTERFACE_CAST(IDirectDrawImpl,
1351                                                               IDirectDraw4,
1352                                                               IDirectDraw7,
1353                                                               This),
1354                                            pCaps, pdwTotal, pdwFree);
1355 }
1356
1357 static HRESULT WINAPI
1358 IDirectDraw3Impl_GetSurfaceFromDC(LPDIRECTDRAW3 This, HDC hDC,
1359                                   LPDIRECTDRAWSURFACE *pSurf)
1360 {
1361     return IDirectDraw7_GetSurfaceFromDC(COM_INTERFACE_CAST(IDirectDrawImpl,
1362                                                             IDirectDraw3,
1363                                                             IDirectDraw7,
1364                                                             This),
1365                                          hDC, (LPDIRECTDRAWSURFACE7 *)pSurf);
1366 }
1367
1368 static HRESULT WINAPI
1369 IDirectDraw4Impl_GetSurfaceFromDC(LPDIRECTDRAW4 This, HDC hDC,
1370                                   LPDIRECTDRAWSURFACE4 *pSurf)
1371 {
1372     return IDirectDraw7_GetSurfaceFromDC(COM_INTERFACE_CAST(IDirectDrawImpl,
1373                                                             IDirectDraw4,
1374                                                             IDirectDraw7,
1375                                                             This),
1376                                          hDC, (LPDIRECTDRAWSURFACE7 *)pSurf);
1377 }
1378
1379 static HRESULT WINAPI
1380 IDirectDraw4Impl_RestoreAllSurfaces(LPDIRECTDRAW4 This)
1381 {
1382     return IDirectDraw7_RestoreAllSurfaces(COM_INTERFACE_CAST(IDirectDrawImpl,
1383                                                               IDirectDraw4,
1384                                                               IDirectDraw7,
1385                                                               This));
1386 }
1387
1388 static HRESULT WINAPI
1389 IDirectDraw4Impl_TestCooperativeLevel(LPDIRECTDRAW4 This)
1390 {
1391     return IDirectDraw7_TestCooperativeLevel(COM_INTERFACE_CAST(IDirectDrawImpl,
1392                                                                 IDirectDraw4,
1393                                                                 IDirectDraw7,
1394                                                                 This));
1395 }
1396
1397 static HRESULT WINAPI
1398 IDirectDraw4Impl_GetDeviceIdentifier(LPDIRECTDRAW4 This,
1399                                      LPDDDEVICEIDENTIFIER pDDDI, DWORD dwFlags)
1400 {
1401     DDDEVICEIDENTIFIER2 DDDI2;
1402     HRESULT hr;
1403
1404     hr = IDirectDraw7_GetDeviceIdentifier(COM_INTERFACE_CAST(IDirectDrawImpl,
1405                                                              IDirectDraw4,
1406                                                              IDirectDraw7,
1407                                                              This),
1408                                           &DDDI2, dwFlags);
1409
1410     DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&DDDI2, pDDDI);
1411
1412     return hr;
1413 }
1414
1415 const IDirectDrawVtbl IDirectDraw1_Vtbl =
1416 {
1417     IDirectDrawImpl_QueryInterface,
1418     IDirectDrawImpl_AddRef,
1419     IDirectDrawImpl_Release,
1420     IDirectDrawImpl_Compact,
1421     IDirectDrawImpl_CreateClipper,
1422     IDirectDrawImpl_CreatePalette,
1423     IDirectDrawImpl_CreateSurface,
1424     IDirectDrawImpl_DuplicateSurface,
1425     IDirectDrawImpl_EnumDisplayModes,
1426     IDirectDrawImpl_EnumSurfaces,
1427     IDirectDrawImpl_FlipToGDISurface,
1428     IDirectDrawImpl_GetCaps,
1429     IDirectDrawImpl_GetDisplayMode,
1430     IDirectDrawImpl_GetFourCCCodes,
1431     IDirectDrawImpl_GetGDISurface,
1432     IDirectDrawImpl_GetMonitorFrequency,
1433     IDirectDrawImpl_GetScanLine,
1434     IDirectDrawImpl_GetVerticalBlankStatus,
1435     IDirectDrawImpl_Initialize,
1436     IDirectDrawImpl_RestoreDisplayMode,
1437     IDirectDrawImpl_SetCooperativeLevel,
1438     IDirectDrawImpl_SetDisplayMode,
1439     IDirectDrawImpl_WaitForVerticalBlank,
1440 };
1441
1442 const IDirectDraw2Vtbl IDirectDraw2_Vtbl =
1443 {
1444     IDirectDraw2Impl_QueryInterface,
1445     IDirectDraw2Impl_AddRef,
1446     IDirectDraw2Impl_Release,
1447     IDirectDraw2Impl_Compact,
1448     IDirectDraw2Impl_CreateClipper,
1449     IDirectDraw2Impl_CreatePalette,
1450     IDirectDraw2Impl_CreateSurface,
1451     IDirectDraw2Impl_DuplicateSurface,
1452     IDirectDraw2Impl_EnumDisplayModes,
1453     IDirectDraw2Impl_EnumSurfaces,
1454     IDirectDraw2Impl_FlipToGDISurface,
1455     IDirectDraw2Impl_GetCaps,
1456     IDirectDraw2Impl_GetDisplayMode,
1457     IDirectDraw2Impl_GetFourCCCodes,
1458     IDirectDraw2Impl_GetGDISurface,
1459     IDirectDraw2Impl_GetMonitorFrequency,
1460     IDirectDraw2Impl_GetScanLine,
1461     IDirectDraw2Impl_GetVerticalBlankStatus,
1462     IDirectDraw2Impl_Initialize,
1463     IDirectDraw2Impl_RestoreDisplayMode,
1464     IDirectDraw2Impl_SetCooperativeLevel,
1465     IDirectDraw2Impl_SetDisplayMode,
1466     IDirectDraw2Impl_WaitForVerticalBlank,
1467     IDirectDraw2Impl_GetAvailableVidMem
1468 };
1469
1470 const IDirectDraw3Vtbl IDirectDraw3_Vtbl =
1471 {
1472     IDirectDraw3Impl_QueryInterface,
1473     IDirectDraw3Impl_AddRef,
1474     IDirectDraw3Impl_Release,
1475     IDirectDraw3Impl_Compact,
1476     IDirectDraw3Impl_CreateClipper,
1477     IDirectDraw3Impl_CreatePalette,
1478     IDirectDraw3Impl_CreateSurface,
1479     IDirectDraw3Impl_DuplicateSurface,
1480     IDirectDraw3Impl_EnumDisplayModes,
1481     IDirectDraw3Impl_EnumSurfaces,
1482     IDirectDraw3Impl_FlipToGDISurface,
1483     IDirectDraw3Impl_GetCaps,
1484     IDirectDraw3Impl_GetDisplayMode,
1485     IDirectDraw3Impl_GetFourCCCodes,
1486     IDirectDraw3Impl_GetGDISurface,
1487     IDirectDraw3Impl_GetMonitorFrequency,
1488     IDirectDraw3Impl_GetScanLine,
1489     IDirectDraw3Impl_GetVerticalBlankStatus,
1490     IDirectDraw3Impl_Initialize,
1491     IDirectDraw3Impl_RestoreDisplayMode,
1492     IDirectDraw3Impl_SetCooperativeLevel,
1493     IDirectDraw3Impl_SetDisplayMode,
1494     IDirectDraw3Impl_WaitForVerticalBlank,
1495     IDirectDraw3Impl_GetAvailableVidMem,
1496     IDirectDraw3Impl_GetSurfaceFromDC,
1497 };
1498
1499 const IDirectDraw4Vtbl IDirectDraw4_Vtbl =
1500 {
1501     IDirectDraw4Impl_QueryInterface,
1502     IDirectDraw4Impl_AddRef,
1503     IDirectDraw4Impl_Release,
1504     IDirectDraw4Impl_Compact,
1505     IDirectDraw4Impl_CreateClipper,
1506     IDirectDraw4Impl_CreatePalette,
1507     IDirectDraw4Impl_CreateSurface,
1508     IDirectDraw4Impl_DuplicateSurface,
1509     IDirectDraw4Impl_EnumDisplayModes,
1510     IDirectDraw4Impl_EnumSurfaces,
1511     IDirectDraw4Impl_FlipToGDISurface,
1512     IDirectDraw4Impl_GetCaps,
1513     IDirectDraw4Impl_GetDisplayMode,
1514     IDirectDraw4Impl_GetFourCCCodes,
1515     IDirectDraw4Impl_GetGDISurface,
1516     IDirectDraw4Impl_GetMonitorFrequency,
1517     IDirectDraw4Impl_GetScanLine,
1518     IDirectDraw4Impl_GetVerticalBlankStatus,
1519     IDirectDraw4Impl_Initialize,
1520     IDirectDraw4Impl_RestoreDisplayMode,
1521     IDirectDraw4Impl_SetCooperativeLevel,
1522     IDirectDraw4Impl_SetDisplayMode,
1523     IDirectDraw4Impl_WaitForVerticalBlank,
1524     IDirectDraw4Impl_GetAvailableVidMem,
1525     IDirectDraw4Impl_GetSurfaceFromDC,
1526     IDirectDraw4Impl_RestoreAllSurfaces,
1527     IDirectDraw4Impl_TestCooperativeLevel,
1528     IDirectDraw4Impl_GetDeviceIdentifier
1529 };