Expression: _CrtIsValidHeapPointer(pUserData)
程序遇到如題的運行時報錯,參考下面這段文字,采取將自定義類的對象定義改為new方式生成后問題解決。
!!Expression: _CrtIsValidHeapPointer(pUserData)
void CImageRecView::OnFileColhistogram()?
{
?// TODO: Add your command handler code here
?CImageRecDoc *pDoc = GetDocument();
?LPSTR lpDIB;
?ColHistogram MyColHist;
?lpDIB = (LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
?
?pMyColHist->RGBtoHSV(lpDIB);
?::GlobalUnlock((HGLOBAL)pDoc->GetHDIB());
}
問題就出在紅色的地方,自定義了一個類
將上面的語句改為
?ColHistogram * pMyColHist;
?pMyColHist = new ColHistogram;
就可以了,不過現在也不知道為什么
(MSDN)中的這段話
The ? _CrtIsValidHeapPointer ? function ? is ? used ? to ? ensure ? that ? a ? specific ? memory ? address ? is ? within ? the ? local ? heap. ? The ? “local” ? heap ? refers ? to ? the ? heap ? created ? and ? managed ? by ? a ? particular ? instance ? of ? the ? C ? run-time ? library. ? If ? a ? dynamically ? linked ? library ? (DLL) ? contains ? a ? static ? link ? to ? the ? run-time ? library, ? then ? it ? has ? its ? own ? instance ? of ? the ? run-time ? heap, ? and ? therefore ? its ? own ? heap, ? independent ? of ? the ? application’s ? local ? heap. ? When ? _DEBUG ? is ? not ? defined, ? calls ? to ? _CrtIsValidHeapPointer ? are ? removed ? during ? preprocessing.
看了這段話稍微覺得有點意思了,我在程序中自己申請了本地堆,也有要生成動態連接庫的DIB類,要連接c運行庫,那么我的ColHistogram的實例必須動態生成,因為它在c運行庫中沒有對應的堆。比如我添加Cstring str;程序就不會有問題,但是我只知道CString是系統定義的,和c運行庫有什么關系我就不清楚了。如果靜態鏈接C運行庫,那么,dll就要擁有一個獨立于應用程序(調用它的exe)的本地堆(但是我的程序沒有),如果沒有定義_DEBUG,那么_CrtIsValidHeapPointer將被預處理器移除。大概就是這個樣子,上面所說的很多東西我都不確定,只是現在的一種解釋。
還有dbgheap.c文件似乎是在dll里,還沒有辦法看
轉自:http://blog.csdn.net/haokongdashi/archive/2010/02/23/5318461.aspx
轉載于:https://www.cnblogs.com/sifenkesi/archive/2011/03/25/1995066.html
總結
以上是生活随笔為你收集整理的Expression: _CrtIsValidHeapPointer(pUserData)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LINUX服务器开启防火墙并屏蔽恶意IP
- 下一篇: mysql UNIX时间戳与日期的相互转