home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_04 / QueryDDraw / QueryDDraw.cpp next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  6.3 KB  |  176 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : queryddraw.cpp                                                         //
  10. //  Description: Examine DirectX interfaces and their vtables                        //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define NOCRYPT
  16. #define CINTERFACE
  17.  
  18. #include <windows.h>
  19. #include <ddraw.h>
  20. #include <stdio.h>
  21.  
  22. // IDirectDraw 
  23. // IDirectDraw2
  24. // IDirectDraw4
  25.  
  26. // IDirectDrawSurface
  27. // IDirectDrawSurface2
  28. // IDirectDrawSurface3
  29. // IDirectDrawSurface4
  30. // IDirectDrawSurface7
  31.  
  32. // IDirectDrawPalette
  33. // IDirectDrawClipper
  34. // IDirectDrawColorControl
  35. // IDirectDrawGammaControl
  36.  
  37.  
  38. void DumpInterface(const char * name, const IID & iid, const void * vtbl, int size)
  39. {
  40.     static int first = 1;
  41.  
  42.     if ( first )
  43.     {
  44.         printf("[ddraw]\n");
  45.         first = 0;
  46.     }
  47.  
  48.     const unsigned * vTable = (const unsigned *) vtbl;
  49.  
  50.     printf("%08x %08x %d, %s\n", vTable, vTable[0], size/4, name);
  51.  
  52.     printf("         {%08x-%04x-%04x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x}\n",
  53.         iid.Data1, iid.Data2, iid.Data3, 
  54.         iid.Data4[0], iid.Data4[1], iid.Data4[2], iid.Data4[3],
  55.         iid.Data4[4], iid.Data4[5], iid.Data4[6], iid.Data4[7]);
  56. }
  57.  
  58.  
  59. HRESULT QueryDirectDrawVTables(HWND hWnd)
  60. {
  61.     IDirectDraw * lpdd;
  62.  
  63.     HRESULT hr = DirectDrawCreate(NULL, & lpdd, NULL);
  64.  
  65.     if ( hr!=DD_OK )
  66.         return hr;
  67.  
  68.     IDirectDraw_SetCooperativeLevel(lpdd, hWnd, DDSCL_NORMAL);
  69.     IDirectDraw_SetDisplayMode(lpdd, 1152, 864, 24);
  70.  
  71.     DumpInterface("IID_IDirectDraw", IID_IDirectDraw, lpdd->lpVtbl, sizeof(* lpdd->lpVtbl) );
  72.  
  73.     {
  74.         IDirectDraw2 * lpdd2;
  75.  
  76.         IDirectDraw_QueryInterface(lpdd, IID_IDirectDraw2, (void **) & lpdd2);
  77.  
  78.         DumpInterface("IID_IDirectDraw2", IID_IDirectDraw2, lpdd2->lpVtbl, sizeof(* lpdd2->lpVtbl));
  79.  
  80.         IDirectDraw2_Release(lpdd2);
  81.     }
  82.  
  83.     {
  84.         IDirectDraw4 * lpdd4;
  85.  
  86.         IDirectDraw_QueryInterface(lpdd, IID_IDirectDraw4, (void **) & lpdd4);
  87.  
  88.         DumpInterface("IID_IDirectDraw4", IID_IDirectDraw4, lpdd4->lpVtbl, sizeof(* lpdd4->lpVtbl));
  89.  
  90.         IDirectDraw4_Release(lpdd4);
  91.     }
  92.  
  93.     {
  94.         DDSURFACEDESC ddsd;
  95.         ddsd.dwSize = sizeof(ddsd);
  96.         ddsd.dwFlags = DDSD_CAPS;
  97.         ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  98.  
  99.         IDirectDrawSurface * p;
  100.  
  101.         hr = IDirectDraw_CreateSurface(lpdd, &ddsd, & p, NULL);
  102.  
  103.         if ( hr==DD_OK )
  104.         {
  105.             DumpInterface("IID_IDirectDrawSurface", IID_IDirectDrawSurface, p->lpVtbl, sizeof(* p->lpVtbl));
  106.  
  107.             IDirectDrawSurface_Release(p);
  108.         }
  109.     }
  110.  
  111.     {
  112.         DDSURFACEDESC2 ddsd;
  113.         ddsd.dwSize = sizeof(ddsd);
  114.         ddsd.dwFlags = DDSD_CAPS;
  115.         ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  116.  
  117.         IDirectDrawSurface4 * p;
  118.  
  119.         IDirectDraw4 * lpdd4;
  120.  
  121.         IDirectDraw_QueryInterface(lpdd, IID_IDirectDraw4, (void **) & lpdd4);
  122.  
  123.         hr = IDirectDraw4_CreateSurface(lpdd4, &ddsd, & p, NULL);
  124.  
  125.         if ( hr==DD_OK )
  126.         {
  127.             DumpInterface("IID_IDirectDrawSurface4", IID_IDirectDrawSurface4, p->lpVtbl, sizeof(* p->lpVtbl));
  128.  
  129.             IDirectDrawSurface4_Release(p);
  130.         }
  131.  
  132.         IDirectDraw4_Release(lpdd4);
  133.     }
  134.  
  135.  
  136.     IDirectDraw_Release(lpdd);
  137.  
  138.     return DD_OK;
  139. }
  140.  
  141. #define DEF_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)  const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } };
  142.  
  143. DEF_GUID( IID_IDirectDraw,                0x6C14DB80,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
  144. DEF_GUID( IID_IDirectDraw2,             0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
  145. DEF_GUID( IID_IDirectDraw4,             0x9c59509a,0x39bd,0x11d1,0x8c,0x4a,0x00,0xc0,0x4f,0xd9,0x30,0xc5 );
  146. DEF_GUID( IID_IDirectDrawSurface,        0x6C14DB81,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
  147. DEF_GUID( IID_IDirectDrawSurface2,        0x57805885,0x6eec,0x11cf,0x94,0x41,0xa8,0x23,0x03,0xc1,0x0e,0x27 );
  148. DEF_GUID( IID_IDirectDrawSurface3,      0xDA044E00,0x69B2,0x11D0,0xA1,0xD5,0x00,0xAA,0x00,0xB8,0xDF,0xBB );
  149. DEF_GUID( IID_IDirectDrawSurface4,      0x0B2B8630,0xAD35,0x11D0,0x8E,0xA6,0x00,0x60,0x97,0x97,0xEA,0x5B );
  150. DEF_GUID( IID_IDirectDrawSurface7,      0x06675a80,0x3b9b,0x11d2,0xb9,0x2f,0x00,0x60,0x97,0x97,0xea,0x5b );
  151. DEF_GUID( IID_IDirectDrawPalette,        0x6C14DB84,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
  152. DEF_GUID( IID_IDirectDrawClipper,        0x6C14DB85,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
  153. DEF_GUID( IID_IDirectDrawColorControl,     0x4B9F0EE0,0x0D7E,0x11D0,0x9B,0x06,0x00,0xA0,0xC9,0x03,0xA3,0xB8 );
  154. DEF_GUID( IID_IDirectDrawGammaControl,  0x69C11C3E,0xB46B,0x11D1,0xAD,0x7A,0x00,0xC0,0x4F,0xC2,0x9B,0x4E );
  155.  
  156. int main(int argc, char * argv[], char * envp[])
  157. {
  158.     QueryDirectDrawVTables(GetDesktopWindow());
  159.     
  160.     return 0;
  161. }
  162.  
  163.  
  164.  
  165. /*
  166.  
  167. DEFINE_GUID( IID_IDirectDrawSurface,        0x6C14DB81,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
  168. DEFINE_GUID( IID_IDirectDrawSurface2,        0x57805885,0x6eec,0x11cf,0x94,0x41,0xa8,0x23,0x03,0xc1,0x0e,0x27 );
  169. DEFINE_GUID( IID_IDirectDrawSurface3,           0xDA044E00,0x69B2,0x11D0,0xA1,0xD5,0x00,0xAA,0x00,0xB8,0xDF,0xBB );
  170. DEFINE_GUID( IID_IDirectDrawSurface4,           0x0B2B8630,0xAD35,0x11D0,0x8E,0xA6,0x00,0x60,0x97,0x97,0xEA,0x5B );
  171. DEFINE_GUID( IID_IDirectDrawSurface7,           0x06675a80,0x3b9b,0x11d2,0xb9,0x2f,0x00,0x60,0x97,0x97,0xea,0x5b );
  172. DEFINE_GUID( IID_IDirectDrawPalette,        0x6C14DB84,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
  173. DEFINE_GUID( IID_IDirectDrawClipper,        0x6C14DB85,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
  174. DEFINE_GUID( IID_IDirectDrawColorControl,     0x4B9F0EE0,0x0D7E,0x11D0,0x9B,0x06,0x00,0xA0,0xC9,0x03,0xA3,0xB8 );
  175. DEFINE_GUID( IID_IDirectDrawGammaControl,       0x69C11C3E,0xB46B,0x11D1,0xAD,0x7A,0x00,0xC0,0x4F,0xC2,0x9B,0x4E );
  176. */