Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Resource leak?

Resource leak?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gavin Jerman
    wrote on last edited by
    #1

    BoundsChecker v7 is reporting the error 'Argument 2 in ReleaseDC (HDC__ hdc = 0xE00105F5) still contains non default/stock objects.' in the d'tor for CClientDC in the code:

    void CHListBox::updateWidth(LPCTSTR s)
    {
    CClientDC dc(this);
    CFont * f = CListBox::GetFont();
    CFont* pOldFont = dc.SelectObject(f);

    CSize sz = dc.GetTextExtent(s, \_tcslen(s));
    
    dc.SelectObject(pOldFont);
    
    sz.cx += 3 \* ::GetSystemMetrics(SM\_CXBORDER);
    if (sz.cx > width)
    { /\* extend \*/
    	width = sz.cx;
    	CListBox::SetHorizontalExtent(width);
    } /\* extend \*/
    

    }

    I'm fairly confident that there is no leak. Do you agree? Gavin

    A A 2 Replies Last reply
    0
    • G Gavin Jerman

      BoundsChecker v7 is reporting the error 'Argument 2 in ReleaseDC (HDC__ hdc = 0xE00105F5) still contains non default/stock objects.' in the d'tor for CClientDC in the code:

      void CHListBox::updateWidth(LPCTSTR s)
      {
      CClientDC dc(this);
      CFont * f = CListBox::GetFont();
      CFont* pOldFont = dc.SelectObject(f);

      CSize sz = dc.GetTextExtent(s, \_tcslen(s));
      
      dc.SelectObject(pOldFont);
      
      sz.cx += 3 \* ::GetSystemMetrics(SM\_CXBORDER);
      if (sz.cx > width)
      { /\* extend \*/
      	width = sz.cx;
      	CListBox::SetHorizontalExtent(width);
      } /\* extend \*/
      

      }

      I'm fairly confident that there is no leak. Do you agree? Gavin

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      CFont* GetFont( ) const; Return Value A pointer to a CFont that contains the current font. The pointer may be temporary and should not be stored for later use. so maybe CFont * f = new CFont( CListBox::GetFont() ); ??????

      1 Reply Last reply
      0
      • G Gavin Jerman

        BoundsChecker v7 is reporting the error 'Argument 2 in ReleaseDC (HDC__ hdc = 0xE00105F5) still contains non default/stock objects.' in the d'tor for CClientDC in the code:

        void CHListBox::updateWidth(LPCTSTR s)
        {
        CClientDC dc(this);
        CFont * f = CListBox::GetFont();
        CFont* pOldFont = dc.SelectObject(f);

        CSize sz = dc.GetTextExtent(s, \_tcslen(s));
        
        dc.SelectObject(pOldFont);
        
        sz.cx += 3 \* ::GetSystemMetrics(SM\_CXBORDER);
        if (sz.cx > width)
        { /\* extend \*/
        	width = sz.cx;
        	CListBox::SetHorizontalExtent(width);
        } /\* extend \*/
        

        }

        I'm fairly confident that there is no leak. Do you agree? Gavin

        A Offline
        A Offline
        Anders Molin
        wrote on last edited by
        #3

        Gavin Jerman wrote: I'm fairly confident that there is no leak. Do you agree? Yes. - Anders Money talks, but all mine ever says is "Goodbye!"

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups