Hello, I've wrote a program in win32 that does some drawing. After running it for a while it stops drawing the colors for the shapes I draw using GDI functions and it throws multiple time this error: err:local:LOCAL_GetBlock not enough space in GDI heap 10bf for 36 bytes The WM_PAINT message looks like this: GetClientRect (m_pMainWnd->m_hWnd, &rc); hdc = BeginPaint (m_pMainWnd->m_hWnd, &ps); // Create an off-screen DC for double-buffering hdcMem = CreateCompatibleDC (hdc); hbmMem = CreateCompatibleBitmap (hdc, rc.right, rc.bottom); hOld = SelectObject (hdcMem, hbmMem); // Draw into hdcMem FillRect (hdcMem,&rc,CreateSolidBrush (RGB(255,255,255)) ); m_pMainWnd->OnPaint (hdcMem); // Transfer the off-screen DC to the screen BitBlt (hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY); // Free-up the off-screen DC SelectObject (hdcMem, hOld); DeleteObject (hbmMem); DeleteDC (hdcMem); EndPaint (m_hWnd, &ps); OnPaint method for m_pMainWnd looks like this: HPEN hPen = CreatePen( PS_SOLID, 3, m_cCurPen); // m_cCurPen: COLORREF HBRUSH hBrush = CreateSolidBrush( m_cCurBrush ); // m_cCurBrush: COLORREF HPEN hOldPen = (HPEN) SelectObject( dc,hPen ); HBRUSH hOldBrush = (HBRUSH) SelectObject( dc,hBrush ); Ellipse (dc,m_ptOrg.x, m_ptOrg.y, m_ptOrg.x+m_ptDim.x, m_ptOrg.y+m_ptDim.y); SelectObject( dc,hOldPen ); SelectObject( dc,hOldBrush ); DeleteObject( hPen ); DeleteObject( hBrush ); What did I do wrong?