|
-
September 8th, 2017, 03:04 PM
#2
Re: GetDC(null) sanity check...Will this DC ever get released?
 Originally Posted by mega Kluge
I'm running some legacy code that eventually fails on GetDC(null). It will return NULL with GetLastError() returning 0. The documention I've read says that the culprit is a GDI resource leak somewhere.
Fair enough.
A lot of the code has calls to GetDC() like so:
Code:
m_hOldBmp = (HBITMAP) ::SelectObject(GetDC(), m_hBmp);
// and
m_hBmp = ::CreateDIBSection(GetDC(), (BITMAPINFO*) &bmih, DIB_RGB_COLORS, NULL,NULL, 0 );
I can't find in the documentation if the DC returned from these GetDC() calls will ever be released. They aren't being released in the code. I've run handle leak profilers and nothing is amiss. However, sure enough, after enough hours, the software will fail and all calls to GetDC() will return NULL.
Is calling GetDC() as the parameter to a method like this good practice? Should something different be done here?
I have no idea where you searched for docs about GetDC() and whether "the DC ... will ever be released", however MSDN claims it clear enough:
After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do not have to be released. ReleaseDC must be called from the same thread that called GetDC. The number of DCs is limited only by available memory.
Victor Nijegorodov
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|