|
-
May 22nd, 2012, 01:47 AM
#1
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.
-
May 22nd, 2012, 11:57 AM
#2
Re: CreateDIBSection and Access violation
What is 'dcMem'? How is it being created?
Viggy
-
May 23rd, 2012, 01:25 AM
#3
Re: CreateDIBSection and Access violation
 Originally Posted by MrViggy
What is 'dcMem'? How is it being created?
Viggy
CDC dcMem;
dcMem.CreateCompatibleDC(NULL);
-
May 29th, 2012, 07:53 PM
#4
Re: CreateDIBSection and Access violation
 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);
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
|