Losing surfaces

Does anyone have a sample of some working code that waits until Direct X (on
a windows machine of course) returns hardware surfaces after an SDL app has
been alt+tabbed, and then reloads the surfaces? I know of the example code
in the docs, but I simply can’t make it work. My surfaces are never
returned, and my waiting loop … well … loops forever.

I use code like this:

while ( SDL_BlitSurface(image_dat, NULL, display, dspRect) == -2 )
{
while ( SDL_LockSurface(image_dat) < 0 )
SDL_Delay(10);

// Yay, got passed the locking, which I can never manage :(

}