| Platform SDK: DirectX |
The information in this section pertains only to applications written in C and C++. See DirectDraw Visual Basic Tutorials.
After the DDSURFACEDESC2 structure is filled, you can use it and g_pDD, the pointer to the DirectDraw object that was created by the DirectDrawCreateEx function, to call the IDirectDraw7::CreateSurface method, as shown in the following example.
hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);
if (hRet != DD_OK)
{
// g_pDDSPrimary points to the new surface.
}
else
{
// The surface was not created.
return FALSE;
}
The g_pDDSPrimary 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 IDirectDrawSurface7::GetAttachedSurface method to retrieve a pointer to the back buffer, as shown in the following example.
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
hRet = g_pDDSPrimary->GetAttachedSurface(&ddscaps, &g_pDDSBack);
if (hRet != DD_OK)
{
// g_pDDSBack 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 g_pDDSBack parameter will point to the back buffer if the IDirectDrawSurface7::GetAttachedSurface call succeeds.