No matter how hard I looked and whatever I tried, I couldn't find why this code is leaking. Actually, I'm not sure about the leak but the number of GDI objects increases everytime I use this piece of code.
HBITMAP hBmp;
hBmp = CreateDIBitmap(dc, &stBmpIH, CBM_INIT, m_pBitmapData, m_pBitmapInfo, DIB_RGB_COLORS) ;
Bitmap *pBMP = NULL;
HPALETTE hPal = NULL;
Color col = 0;
pBMP = Bitmap::FromHBITMAP(hBmp, hPal);
if (m_bFlip)
{
pBMP->RotateFlip( Rotate90FlipXY );
pBMP->GetHBITMAP(col,&hBmp);
m_bFlip = FALSE;
}
else
{
pBMP->RotateFlip( RotateNoneFlipX );
pBMP->GetHBITMAP(col,&hBmp);
}
delete pBMP;
I've checked the GDI objects with a tool, and what I found is the HBITMAP hBmp is the one that is leaking. How should I remove it?
DeleteObject is NOT working.
Thanks
Let's assume that it is actually in your code even though the snippet doesn't show it. Then the next explanation is this statement:
Which overwrites the value for hBmp, preventing you from releasing it properly. Fix:
You'll probably need to do some more work on the error handling code.