下面是以下代码。0xC0000005打印功能中出现错误
void SignalView::OnFilePrintPreview()
{
if(RcursorPosX-LcursorPosX<=0){
AfxMessageBox(_T("Please set cursor positions.\nYou can only print out the area between left and right cursors"));
return;
}
CScrollView::OnFilePrintPreview();
}
BOOL SignalView::OnPreparePrinting(CPrintInfo* pInfo)
{
if(RcursorPosX-LcursorPosX>100*4*2)
RcursorPosX = LcursorPosX+100*4*2; //800 = 100 cursor x 4(gridX) x 2(zoomX)
pInfo->SetMinPage(1);
pInfo->SetMaxPage(1);
return DoPreparePrinting(pInfo); //<===========
}
void SignalView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
PRINTDLG* pPrintDlg = new PRINTDLG;
AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg);
DEVMODE* lpDevMode = (DEVMODE*)::GlobalLock(pPrintDlg->hDevMode);
lpDevMode->dmOrientation = DMORIENT_LANDSCAPE;
while(!pDC->ResetDC(lpDevMode));
::GlobalUnlock(pPrintDlg->hDevMode);
delete pPrintDlg;
}
我正在尝试使用打印功能。但我重拍了它,因为我删除了它,并重新创建了一个新的类,它来自CScrollView
,所以我不使用从一开始就制作的原始视图。
现在,我达到了我想要的,但问题是当我尝试打电话并关闭打印事件OnFilePrintPreview()
约30-40次时发生错误,然后它将关闭并显示错误消息0xC0000005
。
它发生在功能DoPreparePrinting(pInfo)
,然后它COMMDLG_AFXCTXFUNC(BOOL ,PrintDlgW,(LPPRINTDLGW unnamed1),(unnamed1))
在afxcomctl32.inl
文件,然后它引发一个错误消息。
为什么会发生这个问题?代码似乎朝着正确的方向发展?
P.S. 在反汇编模式下发生错误。
COMMDLG_AFXCTXFUNC(BOOL ,PrintDlgW,(LPPRINTDLGW unnamed1),(unnamed1))
7824CD80 mov edi,edi
7824CD82 push ebp
7824CD83 mov ebp,esp
7824CD85 mov eax,dword ptr [unnamed1]
7824CD88 push eax
7824CD89 call AfxGetModuleState (780F3320h)
7824CD8E mov ecx,dword ptr [eax+94h]
7824CD94 mov ecx,dword ptr [ecx+4]
7824CD97 call CCommDlgWrapper::_PrintDlgW (7824CDB0h)
7824CD9C pop ebp //<======= it's stopped at this point.
7824CD9D ret 4
使用调试器通过查看调用堆栈来找出崩溃发生的位置。 –
谢谢你的评论。我评论了上面的代码。请检查一下。 – Sean