changing video modes - fatal error in kernel

Hi!

My problem is connected to changing resolutions and destroying-recreating windows.
Here’s a simplifided version of the code I use to start my engine after some menu screens
(I killed the error handling for now).

My problem is:
Using this procedure sometimes (let’s say very frequently) I got a fatal error in kernerl32. (All the return values are ok - Window is created, i got a rendering context, pixelformat is ok… etc)
Could this be the wrong one?

hRC = wglGetCurrentContext();
hDC = wglGetCurrentDC() ; 
wglMakeCurrent(NULL, NULL) ; 
wglDeleteContext(hRC); 
ReleaseDC (hwndApp, hDC) ; 
killmainwindow();

if ( createmainwindow(width, height) == FALSE)
{
Fatal_Error(“Could not create the OpenGL window”);
ChangeDisplaySettings(NULL, 0);
return False;
}

ChangeResolution(width, height, mybpp)

hDC=GetDC(hwndApp);
SetupPixelFormat(hDC,mybpp );
hRC = wglCreateContext(hDC);	
wglMakeCurrent(hDC, hRC);		
initGL(); 				//setup inital parameters
ResizeViewport(sman->screenWidth,sman->screenHeight,1.0,1.0); //setup projection

thanks.
mandroka