Я использую вспомогательный класс для блокировки / разблокировки, как показано ниже. Тогда вы используете это так:
mBackBuffer->Flip( DDFLIP_WAIT );
{
DDSURFACEDESC2 ddsd;
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );
ReadLock r( mBackBuffer, ddsd, NULL /* for whole surface */ );
if ( r )
{
// ddsd.lpSurface contains the void* pointer to the bytes
// ddsd.lPitch contains the byte count of each horizontal line
}
} // ReadLock разблокируется, когда выходит из области действия
class ReadLock
{
public:
ReadLock(IDirectDrawSurface7* surface, DDSURFACEDESC2& ddsd, LPRECT pRect = 0 ) : surface_(surface), mpRect( pRect ), hr( S_OK )
{
hr = surface_->Lock( mpRect, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WAIT | DDLOCK_READONLY, 0 );
}
HRESULT getResult() const { return hr; }
bool operator!() const { return FAILED( hr ); }
operator bool() const { return SUCCEEDED( hr ); }
~ReadLock()
{
if ( surface_ && SUCCEEDED( hr ) )
surface_->Unlock(mpRect);
}
private:
HRESULT hr;
RECT* mpRect;
IDirectDrawSurface7* surface_;
};