tags:

views:

38

answers:

3

I call getDC(hwnd) and then later on close call ReleaseDC(hwnd,dc). This is for an OpenGL engine and after i call WGLMakeCurrent(Null,Null) and WGLDeleteContext.

ReleaseDC returns error code 1425 which is 1425L ERROR_DC_NOT_FOUND Invalid HDC passed to ReleaseDC.

I don't understand how an HDC could be invalid after previously getting it from the same HWND.

I checked its pointer when i got it and it remains the same (not that it helps to check such a thing), but I am running out of ideas.

A: 

Are you passing the correct hwnd as the first parameter to ReleaseDC? Also, your window class may need the CS_OWNDC class style to be set.

Michael Goldshteyn
A: 

Are you certain you're calling ReleaseDC correctly? According to MSDN it should be ReleaseDC( hwnd, dc );

Joel Lucsy
i am sure i am calling it correctly, just not sure what kinds of things lock or prevent a dc from being released. I edited my post to be persistent with how im calling release.
Joe
Well, `ReleaseDC(hwnd)` woudn't even compile, so it is surely a typo in OP's question.
Andreas Rejbrand
+1  A: 

Lots of OpenGl samples do rather (to my mind) weired things with device contexts. If you are using a window with a style like CS_OWNDC or are caching the HDC for the life of the application it might be that you have over released the HDC, or are trying to release it after the window has been destroyed.

I havn't seen any papers claiming that caching HDCs (or using styles like CS_OWNDC) is important or contributes at all to the performace of an OpenGL application. Also, painting to any DC outside of BeginPaint/EndPaint makes life complicated for the NT 6.1 desktop window manager so, outside of initial setup, I far prefer to simply use the WM_PAINT message to render the OpenGL scene, switching in the relevent context via WGLMakeCurrent(). It makes keeping track of HDCs much more manageable (i.e. you dont really have to) and your app suddenly can deal with multiple OpenGL windows at once.

Chris Becke
I agree... i see this in some examples (ie handling rendering via WM_PAINT). I wish i knew more on this.
Joe