I'm seeing a very similar problem with my BitBlt's. It will return FALSE only occasionally (once every few hours, being called a few times a second) and an immediate call to GetLastError returns 0.
MFC in VS .NET 2003. I don't know what Hyperthreading is or whether I have it enabled, though.
We have a dialog app that connects over TCP/IP to a server and receives video data. On the data receive callback, we BitBlt the image into a CDC that was created in initialization using the following:
CDC* clientDC = this->GetWindowDC();
if(clientDC == NULL)
throw -1;
if(! m_imageMemDC.CreateCompati
bleDC(clie
ntDC) )
throw -1;
if(! m_imageMemBitmap.CreateCom
patibleBit
map(client
DC, CAM_W*m_numCamW, CAM_H*m_numCamH))
throw -1;
if( (m_pImageMemOldBitmap = m_imageMemDC.SelectObject(
&m_imageMe
mBitmap)) == NULL )
throw -1;
this->ReleaseDC(clientDC);
A Timer control is used to send a WM_PAINT every second. OnPaint, we StretchBlt the m_imageMemDC to the screen, as follows:
CDC* clientDC = this->GetWindowDC();
if(clientDC == NULL)
return;
clientDC->SetStretchBltMod
e(COLORONC
OLOR);
EnterCriticalSection(&m_im
ageMemDCSe
ction);
clientDC->StretchBlt(0, 0, clientWidth, clientHeight, &m_imageMemDC, 0, 0, CAM_W*m_numCamW, CAM_H*m_numCamH, SRCCOPY)
LeaveCriticalSection(&m_im
ageMemDCSe
ction);
this->ReleaseDC(clientDC);
As you can see, we use a CCriticalSection, and lock it every time we access m_imageMemDC. Here's the BitBlt code:
EnterCriticalSection(&m_im
ageMemDCSe
ction);
if(! ::BitBlt(m_imageMemDC.GetS
afeHdc(), posX, posY + GetInfoBarHeight(), width-2, height - GetInfoBarHeight() *2,imgPtr->GetDC(), 0, 0, SRCCOPY))
{
CString info;
info.FormatMessage(IDS_E_B
ITBLT, _camID, GetLastError());
theLog.Log(info, EVENTLOG_ERROR_TYPE, 0, 0, CRITICAL);
TRACE (info);
}
LeaveCriticalSection(&m_im
ageMemDCSe
ction);
As previously mentioned, we get the eventlog error, which includes the GetLastError() return code as '0', on average once an hour, but not at a regular interval.
Why does BitBlt fail?
Thanks.
Start Free Trial