Surface Interfaces

DirectDrawSurface objects expose their functionality through the IDirectDrawSurface, IDirectDrawSurface2, and IDirectDrawSurface3 interfaces. Each new interface version provides the same utility as its predecessors, with additional options available through new methods.

The IDirectDrawSurface interface is the oldest version of the interface and is provided by default when you create a surface by using the IDirectDraw2::CreateSurface method. To utilize the new functionality provided by another version of the interface, you must query for the new version by calling its QueryInterface method. The following example shows how you can do this:

LPDIRECTDRAWSURFACE lpSurf;

LPDIRECTDRAWSURFACE2 lpSurf2;

// Create surfaces.

memset(&ddsd, 0, sizeof(ddsd));

ddsd.dwSize = sizeof(ddsd);

ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;

ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |

DDSCAPS_SYSTEMMEMORY;

ddsd.dwWidth = 10;

ddsd.dwHeight = 10;

ddrval = lpDD2->CreateSurface(&ddsd, &lpSurf,

NULL);

if(ddrval != DD_OK)

return;

ddrval = lpSurf->QueryInterface(

IID_IDirectDrawSurface2, (LPVOID *)&lpSurf2);

if(ddrval != DD_OK)

return;

ddrval = lpSurf2->PageLock(0);

if(ddrval != DD_OK)

return;

ddrval = lpSurf2->PageUnlock(0);

if(ddrval != DD_OK)

return;

The preceding example retrieves a DirectDrawSurface object's IDirectDrawSurface2 interface by specifying the IID_IDirectDraw2 reference identifier when it calls the QueryInterface method. To retrieve an IDirectDrawSurface3 interface, use the IID_IDirectDrawSurface3 reference identifier instead.