CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Posts
    306

    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.

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: CreateDIBSection and Access violation

    What is 'dcMem'? How is it being created?

    Viggy

  3. #3
    Join Date
    Jul 2001
    Posts
    306

    Re: CreateDIBSection and Access violation

    Quote Originally Posted by MrViggy View Post
    What is 'dcMem'? How is it being created?

    Viggy
    CDC dcMem;
    dcMem.CreateCompatibleDC(NULL);

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CreateDIBSection and Access violation

    Quote Originally Posted by Ralf Schneider View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured