Access Violation 0xC0000005
-
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
-
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
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
-
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
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 (<ime); // get the local time---EXCEPTION 0xC0000005 OCCUR HERE! gmt = gmtime (<ime); // 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