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