Sign in to follow this  
Wh0p

ReleaseDC failing with error code 0

Recommended Posts

I think the topic title describes the problem sufficiently.

 

Here is the code how I create and release he contexts, however I do nothing else with them at the moment (I reduced everything to just the plain window...)

The error code of GetLastError() is 0 which confuses me in thinking no error occured but the result of ReleaseDC is 0 too....

// Get a Device Context
if (!(_HDC = GetDC(_hWnd)))							
{
	Shutdown();
	Log::Get ().Write (L"Can't create a GL Device Context.");
	return;
}

// Find a matching Pixel Format
GLuint		PixelFormat;
if (!(PixelFormat = ChoosePixelFormat (_HDC, &pfd)))	
{
	Shutdown();	
	Log::Get ().Write (L"Can't find a suitable PixelFormat.");
	return;	
}

// Set the Pixel Format
if(!SetPixelFormat (_HDC,PixelFormat, &pfd))		
{
	Shutdown();
	Log::Get ().Write (L"Can't set the PixelFormat.");
	return;	
}

// Get a Rendering Context
if (!(_HRC = wglCreateContext (_HDC)))				
{
	Shutdown();	
	Log::Get ().Write (L"Can't create a GL Rendering Context.");
	return;	
}

// Activate the Rendering Context
if(!wglMakeCurrent (_HDC, _HRC))					
{
	Shutdown();
	Log::Get ().Write (L"Can't activate the GL Rendering Context.");
return;	
}

ShowWindow (_hWnd, SW_SHOW);
SetForegroundWindow (_hWnd);
SetFocus (_hWnd);
}
if (_HRC)	
{
	if (!wglMakeCurrent (NULL, NULL))
	{	Log::Get ().Write (L"Release Of DC And RC Failed."); }
		if (!wglDeleteContext (_HRC))
	{	Log::Get ().Write (L"Release Rendering Context Failed.");	}
		_HRC = NULL;
}
if (_HDC && !ReleaseDC (_hWnd, _HDC))
{
        DWORD err = GetLastError (); // <<<<<< err == 0 ????
	Log::Get ().Write (L"Release Device Context Failed.");
	_HDC = NULL;
}
}

Share this post


Link to post
Share on other sites

Never mind. I have been doing bad stuff during the WM_CLOSE message.

Hope humanity forgives my impulsive "things are not going well" post...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this