Why does this code produce an access violation at the CopyMemory line?
pData is a pointer to memory which contains a complete BMP file. CreateDIBSection should allocate memory and set pBits to point to this memory.Code:bool CDbBitmap::BmpToDibSec(BYTE *pData) { PBITMAPFILEHEADER pBMFH = (PBITMAPFILEHEADER)pData; ASSERT(pBMFH->bfType == 0x4D42); // check again if really BMP DWORD dwBitOffset = pBMFH->bfOffBits; BITMAPINFO *pbi = (BITMAPINFO*)(pData + sizeof(BITMAPFILEHEADER)); // Create the DIB section BYTE *pBits; HBITMAP hB = ::CreateDIBSection(NULL, pbi, DIB_RGB_COLORS, (PVOID*)&pBits, NULL, 0); ::CopyMemory(pBits, pData + dwBitOffset, pBMFH->bfSize - dwBitOffset); Attach((HGDIOBJ)hB); return true; }
I tried using HeapSize to get the block size of pBits but since it is allocated by the system it fails.




CornedBee
Reply With Quote