CreateDIBSection and Access violation
Hello,
I hope, some of the experts can help me.
I want to draw to a DIB created with CreateDIBSection, but I get an access violation.
Code:
BITMAPINFO bmi;
memset(&bmi,0,sizeof(BITMAPINFO));
tBYTE* lpBits;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
glTexSize=4096;
bmi.bmiHeader.biWidth = glTexSize;
bmi.bmiHeader.biHeight = glTexSize;
bmi.bmiHeader.biPlanes = 1; /* must be 1 */
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
// Create DIB for rendering context
tHANDLE dib =CreateDIBSection(dcMem.m_hDC,&bmi,DIB_RGB_COLORS,(void**)&lpBits, NULL, 0);
tHANDLE old=::SelectObject(dcMem.m_hDC,dib);
// Draw to dcMem with GDI
.......
Draw to dcMem leads to an access violation.
What is wrong?
Do I need to allocate memory?
thx.
Re: CreateDIBSection and Access violation
What is 'dcMem'? How is it being created?
Viggy
Re: CreateDIBSection and Access violation
Quote:
Originally Posted by
MrViggy
What is 'dcMem'? How is it being created?
Viggy
CDC dcMem;
dcMem.CreateCompatibleDC(NULL);
Re: CreateDIBSection and Access violation
Quote:
Originally Posted by
Ralf Schneider
Code:
// ... snip ...
tBYTE* lpBits;
// ... snip ...
tHANDLE dib =CreateDIBSection(dcMem.m_hDC,&bmi,DIB_RGB_COLORS,(void**)&lpBits, NULL, 0);
What's a "tBYTE"? The fact that you had to forcefully cast it, in order to get the CreateDIBSection call to compile, should have been a hint that you are using the wrong type.
Try this:
Code:
// ... snip ...
void* lpBits;
// ... snip ...
tHANDLE dib =CreateDIBSection(dcMem.m_hDC,&bmi,DIB_RGB_COLORS, /* no cast needed (void**) */ &lpBits, NULL, 0);