Problem with CImage- at second call.
-
I need to use class CImage, to get Pixels from hBitmap.. I want to use this class in ATL ActiveX dll, whick can be in more that one number created. But following simple code crushes after second call of it, due to some static members of CImage, (not first) It is need be correctly freed, how to do it? Thanks. Code which makes ASSERT, at second call - in other DLL:
l_pImage = new CImage(); l_pImage->Attach(hBitmap); //hrgn = CreateRegionTrCr( l_pImage, cTransparentColor); pImage->GetPixel(0, 0); ///HERE !!!! //pImage->Detach(); //pImage->ReleaseGDIPlus(); delete l_pImage; __________ ATL code containing error: inline COLORREF CImage::GetPixel( int x, int y ) const throw() { ATLASSERT( m_hBitmap != NULL ); ATLASSERT( (x >= 0) && (x < m_nWidth) ); ATLASSERT( (y >= 0) && (y < m_nHeight) ); GetDC(); COLORREF clr = ::GetPixel( m_hDC, x, y ); ReleaseDC(); return( clr ); _________ inline void CImage::ReleaseDC() const throw() { HBITMAP hBitmap; ATLASSERT( m_hDC != NULL ); m_nDCRefCount--; if( m_nDCRefCount == 0 ) { hBitmap = HBITMAP( ::SelectObject( m_hDC, m_hOldBitmap ) ); ATLASSERT( hBitmap == m_hBitmap ); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE !!<<<<<< s_cache.ReleaseDC( m_hDC ); m_hDC = NULL; } }