1

Topic: WTL and Dr. Memory

All greetings.

drmemory (
http://code.google.com/p/drmemory/downloads/list)

Shows an error of operation with GDI in:: ImageList_DrawIndirect (&ildp);

Prompt in what a crime?


Error #181: GDI USAGE ERROR: DC 0xa8015c49 that contains selected object being deleted

# 0 system call NtGdiDeleteObjectApp

# 1 GDI32.dll! DeleteDC +0xb6 (0x74e5596a <GDI32.dll+0x1596a>)

# 2 GDI32.dll! DeleteDC +0x11 (0x74e558c5 <GDI32.dll+0x158c5>)

# 3 COMCTL32.dll! DSA_SetItem +0x96e (0x71ec2198 <COMCTL32.dll+0x32198>)

# 4 COMCTL32.dll! ImageList_DrawIndirect +0x3a (0x71ea3612 <COMCTL32.dll+0x13612>)

# 5 WTL::CCommandBarCtrlImpl<WTL::CMDICommandBarCtrl,WTL::CCommandBarCtrlBase,ATL::CWinTraits<1442840576,0>>:: _CreateVistaBitmapHelper [c:\vc10\r5xx\wtl\atlctrlw.h:3237]

# 6 WTL::CCommandBarCtrlImpl<WTL::CMDICommandBarCtrl,WTL::CCommandBarCtrlBase,ATL::CWinTraits<1442840576,0>>:: _AddVistaBitmapsFromImageList [c:\vc10\r5xx\wtl\atlctrlw.h:3156]

# 7 MainFrame:: createMainMenu [c:\vc10\r5xx\windows\mainfrm.cpp:393]

# 8 MainFrame:: OnCreate [c:\vc10\r5xx\windows\mainfrm.cpp:535]

# 9 MainFrame:: ProcessWindowMessage [c:\vc10\r5xx\windows\mainfrm.h:133]

#10 WTL::CMDIFrameWindowImpl<MainFrame,WTL::CMDIWindow,ATL::CWinTraits<114229248,262400>>:: MDIFrameWindowProc [c:\vc10\r5xx\wtl\atlframe.h:1501]

#11 USER32.dll! gapfnScSendMessage +0x331 (0x766b62fa <USER32.dll+0x162fa>)

Note: @0:00:44.275 in thread 11732




The code in WTL




//Implementation - support for Vista menus 
#if _WTL_CMDBAR_VISTA_MENUS 
    void _AddVistaBitmapsFromImageList (int nStartIndex, int nCount) 
    { 
        //Create display compatible memory DC 
        CClientDC dc (NULL); 
        CDC dcMem; 
        dcMem. CreateCompatibleDC (dc); 
        HBITMAP hBitmapSave = dcMem. GetCurrentBitmap (); 

        T* pT = static_cast <T *> (this); 
        //Create bitmaps for all menu items 
        for (int i = 0; i <nCount; i ++) 
        { 
            HBITMAP hBitmap = pT-> _ CreateVistaBitmapHelper (nStartIndex + i, dc, dcMem); 
            dcMem. SelectBitmap (hBitmapSave); 
            m_arrVistaBitmap. Add (hBitmap); 
        }
    }


    HBITMAP _CreateVistaBitmapHelper (int nIndex, HDC hDCSource, HDC hDCTarget) 
    { 
        //Create 32-bit bitmap 
        BITMAPINFO bi = {0}; 
        bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); 
        bi.bmiHeader.biWidth = m_szBitmap.cx; 
        bi.bmiHeader.biHeight = m_szBitmap.cy; 
        bi.bmiHeader.biPlanes = 1; 
        bi.bmiHeader.biBitCount = 32; 
        bi.bmiHeader.biCompression = BI_RGB; 
        bi.bmiHeader.biSizeImage = 0; 
        bi.bmiHeader.biXPelsPerMeter = 0; 
        bi.bmiHeader.biYPelsPerMeter = 0; 
        bi.bmiHeader.biClrUsed = 0; 
        bi.bmiHeader.biClrImportant = 0; 
        HBITMAP hBitmap =:: CreateDIBSection (hDCSource, &bi, DIB_RGB_COLORS, NULL, NULL, 0); 
        ATLASSERT (hBitmap! = NULL); 

        //Select bitmap into target DC and draw from image list to it 
        if (hBitmap! = NULL) 
        { 
            :: SelectObject (hDCTarget, hBitmap); 

            IMAGELISTDRAWPARAMS ildp = {0}; 
            ildp.cbSize = sizeof (IMAGELISTDRAWPARAMS); 
            ildp.himl = m_hImageList; 
            ildp.i = nIndex; 
            ildp.hdcDst = hDCTarget; 
            ildp.x = 0; 
            ildp.y = 0; 
            ildp.cx = 0; 
            ildp.cy = 0; 
            ildp.xBitmap = 0; 
            ildp.yBitmap = 0; 
            ildp.fStyle = ILD_TRANSPARENT; 
            ildp.fState = ILS_ALPHA; 
            ildp. Frame = 255; 
[b]            :: ImageList_DrawIndirect (&ildp);    
        }

        return hBitmap; 
    }[/b]