Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Access Violation 0xC0000005

Access Violation 0xC0000005

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsdebugginghelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    whiteclouds
    wrote on last edited by
    #1

    Hi all! I'm developing an console application with MFC support. Now I meet an exception when I execute the following code:

    CBitmap 	\*bitmap;
    CDC 		memDC;
    CRect		rect;
    CWnd \*pWnd=m\_pWndHide;//->GetWindow(GW\_HWNDFIRST);
    

    // CWindowDC dc(pWnd);

    memDC.CreateCompatibleDC(&m\_hDC);//(&dc);
    
    // Calculate required height from specified width
    int height = CAH\_glo\_y \* width / CAH\_glo\_x;
    
    bitmap = new CBitmap();
    //The next line will occur "Access Violation 0xC0000005"
    bitmap->CreateCompatibleBitmap(&m\_hDC, width, height );//(&dc, width, height );
    CBitmap\* pOldBitmap = memDC.SelectObject(bitmap);
    // using the current background colour (assume white for the moment)
    memDC.PatBlt(0, 0, width,height, WHITENESS);
    ...
    

    I trace this error into a source file named SBHEAP.c in MFC then. The function stopped in is __sbh_alloc_block. The related code is following:

            ...
            pEntry->pEntryNext = pHead->pEntryNext;
            pEntry->pEntryPrev = pHead;
            pHead->pEntryNext = pEntry;
            pEntry->pEntryNext->pEntryPrev = pEntry;//Stop here
            ...
    

    I watch the value of pHead->pEntryNext . It is NULL. So I can't access it. But I don't know why and how to resolve it.:confused: This code will be executed many times before. But it is wrong when the 3 times. If someone can tell me or give me some good advice, I will be very glad. Thanks! Regards whiteclouds

    N 1 Reply Last reply
    0
    • W whiteclouds

      Hi all! I'm developing an console application with MFC support. Now I meet an exception when I execute the following code:

      CBitmap 	\*bitmap;
      CDC 		memDC;
      CRect		rect;
      CWnd \*pWnd=m\_pWndHide;//->GetWindow(GW\_HWNDFIRST);
      

      // CWindowDC dc(pWnd);

      memDC.CreateCompatibleDC(&m\_hDC);//(&dc);
      
      // Calculate required height from specified width
      int height = CAH\_glo\_y \* width / CAH\_glo\_x;
      
      bitmap = new CBitmap();
      //The next line will occur "Access Violation 0xC0000005"
      bitmap->CreateCompatibleBitmap(&m\_hDC, width, height );//(&dc, width, height );
      CBitmap\* pOldBitmap = memDC.SelectObject(bitmap);
      // using the current background colour (assume white for the moment)
      memDC.PatBlt(0, 0, width,height, WHITENESS);
      ...
      

      I trace this error into a source file named SBHEAP.c in MFC then. The function stopped in is __sbh_alloc_block. The related code is following:

              ...
              pEntry->pEntryNext = pHead->pEntryNext;
              pEntry->pEntryPrev = pHead;
              pHead->pEntryNext = pEntry;
              pEntry->pEntryNext->pEntryPrev = pEntry;//Stop here
              ...
      

      I watch the value of pHead->pEntryNext . It is NULL. So I can't access it. But I don't know why and how to resolve it.:confused: This code will be executed many times before. But it is wrong when the 3 times. If someone can tell me or give me some good advice, I will be very glad. Thanks! Regards whiteclouds

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      whiteclouds wrote:

      bitmap->CreateCompatibleBitmap(&m_hDC, width, height );//(&dc, width, height );

      Note that if width and height is too big then CreateCompatibleBitmap does fail. Also how did you get m_hDC. Is this a valid DC?

      Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

      W 1 Reply Last reply
      0
      • N Nibu babu thomas

        whiteclouds wrote:

        bitmap->CreateCompatibleBitmap(&m_hDC, width, height );//(&dc, width, height );

        Note that if width and height is too big then CreateCompatibleBitmap does fail. Also how did you get m_hDC. Is this a valid DC?

        Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

        W Offline
        W Offline
        whiteclouds
        wrote on last edited by
        #3

        Hi, thomas! Thanks for your reply. I think I had found the reason. After I delete some variables that aren't be used any more, the exception is missing. But another exception is occur same as this when I use the code following:

        	time\_t	ltime;		// local time
        	struct	tm	\*gmt;	// Greenwich Mean Time
        	png\_time	ttime;	// png format
        
        	time (&ltime);	// get the local time---EXCEPTION 0xC0000005 OCCUR HERE!
        	gmt = gmtime (&ltime);	// convert to gmt
        	png\_convert\_from\_struct\_tm (&ttime, gmt);  // convert to png format
        	png\_set\_tIME (png\_ptr, info\_ptr, &ttime);
        

        I trace this exception into MFC and I found when a function named _mlock was invoked in the __tzset function, the exception occur. The related code like this:

                \_mlock( \_TIME\_LOCK );
        

        I don't know the reason and hope you or others can give me some suggestion. Thank you! Regards! whiteclouds

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups