|
-
Jun 4th, 2002, 07:20 AM
#1
DIB sections
Why does this code produce an access violation at the CopyMemory line?
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;
}
pData is a pointer to memory which contains a complete BMP file. CreateDIBSection should allocate memory and set pBits to point to this memory.
I tried using HeapSize to get the block size of pBits but since it is allocated by the system it fails.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 4th, 2002, 09:28 AM
#2
You cannot call ::CreateDIBSection(NULL....);
Rather than NULL it has to have a valid DC handle--usually from CreateCompatibleDC.
If you can do it that way, it's news to me, anyway. 
CreateDIBSection is failing. No memory allocated.
-
Jun 4th, 2002, 10:34 AM
#3
As described in Petzold's Programming Windows I need the dc handle only if I use DIB_PAL_COLORS.
Also, the function returns a bitmap handle (not NULL) and pBits isn't NUL either. (Both would be NULL if the function failed).
There are some news for you 
I know that there is memory, I just think it's not enough.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|