Advertisement

07.22.2008 at 06:23AM PDT, ID: 23584987
[x]
Attachment Details

Occasional BitBlt failure, GetLastError=0

Asked by alexatsearidge in C++ Programming Language, Windows MFC Programming, Video Editing

Tags: MFC, C++, Microsoft, BitBlt, CDC, StretchBlt, error

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.CreateCompatibleDC(clientDC) )
                  throw -1;

            if(! m_imageMemBitmap.CreateCompatibleBitmap(clientDC, CAM_W*m_numCamW, CAM_H*m_numCamH))
                  throw -1;

            if( (m_pImageMemOldBitmap = m_imageMemDC.SelectObject(&m_imageMemBitmap)) == 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->SetStretchBltMode(COLORONCOLOR);

      EnterCriticalSection(&m_imageMemDCSection);
      clientDC->StretchBlt(0, 0, clientWidth, clientHeight, &m_imageMemDC, 0, 0, CAM_W*m_numCamW, CAM_H*m_numCamH, SRCCOPY)
      LeaveCriticalSection(&m_imageMemDCSection);

      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_imageMemDCSection);
            if(! ::BitBlt(m_imageMemDC.GetSafeHdc(), posX, posY + GetInfoBarHeight(), width-2, height - GetInfoBarHeight() *2,imgPtr->GetDC(), 0, 0, SRCCOPY))
                {
                  CString info;
                  info.FormatMessage(IDS_E_BITBLT, _camID,  GetLastError());
                  theLog.Log(info, EVENTLOG_ERROR_TYPE, 0, 0, CRITICAL);
                  TRACE (info);
            }
            LeaveCriticalSection(&m_imageMemDCSection);

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
Related Solutions: BitBlt failure
[+][-]07.22.2008 at 07:00AM PDT, ID: 22059394

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C++ Programming Language, Windows MFC Programming, Video Editing
Tags: MFC, C++, Microsoft, BitBlt, CDC, StretchBlt, error
Sign Up Now!
Solution Provided By: Kdo
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.22.2008 at 07:33AM PDT, ID: 22059824

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:59AM PDT, ID: 22060128

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:25AM PDT, ID: 22072286

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:30AM PDT, ID: 22072346

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_Related_20080208