Creating the Surfaces

After the DDSURFACEDESC structure is filled, you can use it and lpDD, the pointer to the DirectDraw object that was created by the DirectDrawCreate function, to call the IDirectDraw::CreateSurface method, as shown in the following example:

ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); 
if(ddrval == DD_OK) 
{ 
    // lpDDSPrimary points to the new surface. 
} 
else 
{ 
    // The surface was not created. 
    return FALSE; 
} 
 

The lpDDSPrimary parameter will point to the primary surface returned by CreateSurface if the call succeeds.

After the pointer to the primary surface is available, you can use the IDirectDrawSurface3::GetAttachedSurface method to retrieve a pointer to the back buffer, as shown in the following example:

ddscaps.dwCaps = DDSCAPS_BACKBUFFER; 
ddrval = lpDDSPrimary->GetAttachedSurface(&ddcaps, &lpDDSBack); 
if(ddrval == DD_OK) 
{ 
    // lpDDSBack points to the back buffer. 
} 
else 
{ 
    return FALSE; 
} 
 

By supplying the address of the surface's primary surface and by setting the capabilities value with the DDSCAPS_BACKBUFFER flag, the lpDDSBack parameter will point to the back buffer if the IDirectDrawSurface3::GetAttachedSurface call succeeds.