Dave Colter
Dave Colter

Reputation: 21

Why does CBitmap::CreateCompatibleBitmap fail with error code 0?

In creating a bitmap in memory in preparation for printing, the CreateCompatibleBitmap call fails. GetLastError returns 0. I have no idea why it should.

Here is the function call that fails:

if (!m_pImageMemBitmap->CreateCompatibleBitmap(pDC, m_nMemDCWidth, m_nMemDCHeight))
{
    DWORD dwError = ::GetLastError();
    CString errorMessage;
    errorMessage.Format(_T("CreateCompatibleBitmap failed with error code %lu\n"), dwError);
    TRACE(errorMessage);
}

My understanding is that, although it is undocumented, a CBitmap cannot be larger than 4Gb. That limitation is considered here: m_nMemDCWidth is 76,500, m_nMemDCHeight is 6600, and the color depth is 8 bits for a total of 4,039,200,000 bits -- well under 4Gb.

Further, the failure is intermittent and inconsistent. Monitoring with Process Explorer does not turn up any obvious resource shortages or leaks.

Upvotes: 2

Views: 53

Answers (0)

Related Questions