Win32 directx hardware surfaces

I’m trying to restore my hardware surfaces when someone alt-tabs (or
whatever) away from my game and then back again.
This is the code I’m trying to use, which is more or less exactly from the
example in the docs.

The problem is it gets trapped in the lock surface loop, and never manages
to lock the surface.

Any help would be greatly appreciated.

while ( SDL_BlitSurface(image_dat, NULL, display, dspRect) == -2 )
{

	while ( SDL_LockSurface(image_dat) < 0 )
		SDL_Delay(10);
	SDL_UnlockSurface(image_dat);
	load(); // Loads the surface's data again
}_________________________________________________________________

Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp