2015-11-27 64 views
1

我正在使用自定义树控件派生类。以下是代码。MFC应用程序中的堆栈溢出C00000FD

CCustomTreeCtrl.h

class CCustomTreeCtrl : public CTreeCtrl 
{ 
public: 
    BOOL Check; 
    CCustomTreeCtrl(); 
    virtual ~CCustomTreeCtrl(); 

protected: 
    //{{AFX_MSG(CCustomTreeCtrl) 
    afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); 
    //}}AFX_MSG 
    DECLARE_MESSAGE_MAP(); 
}; 

CCustomTreeCtrl.cpp

CCustomTreeCtrl::CCustomTreeCtrl() 
{ 
} 

CCustomTreeCtrl::~CCustomTreeCtrl() 
{ 
} 

BEGIN_MESSAGE_MAP(CCustomTreeCtrl , CTreeCtrl) 
//{{AFX_MSG(CCustomTreeCtrl) 
ON_WM_LBUTTONDBLCLK() 
//}}AFX_MSG 
END_MESSAGE_MAP() 

void CCustomTreeCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
{ 
    char buf[255]; 
    FILE *stream; 
    CString FilePath; 
    TV_HITTESTINFO pHitTestInfo; 
    pHittestInfo.pt = point; 
    pHitTestInfo.flags = TVHT_ONITEMLABEL; 
    HitTest(&pHitTestInfo); 

    if(pHitTestInfo.hItem != NULL && !ItemHasChildren(pHitTestInfo.hItem)) 
    { 
     RECT sRect; 
     GetItemRect(pHitTestInfo.hItem,&sRect,1); 
     CRect cRect(&sRect); 

     if(cRect.PtInRect(point)) 
     { 
     CTestApp* the = (CTestApp*)AfxGetApp(); 
     CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); 

     CString FileName = GetItemtext(pHitTestInfo.hItem); 

     FilePath = pFrame->Filepath; 
     strcpy(buf,Filepath); 
     strcat(buf,Filename); 
     strcat(buf,".ext"); 

     stream = fopen(buf, "r"); 

     if(stream != NULL) 
     { 
      fclose(stream); 

      if(pFrame->isUpToDate(buf)) 
      { 
       pFrame->DisplayFile(buf); 
      } 
      else 
      { 
       pFrame->CreateFile(buf);//-> Error in this line Exception: C00000FD Stack OverFlow 
       pFrame->DisplayFile(buf); 
      } 
     } 
     } 

    } 
} 

上一个树项目双击应用程序退出。 调试时,在进入CreateFile函数时会引发ans stack overflow异常。

如果文件是最新的,DisplayFile功能正确执行。

该错误只有当我打电话CreateFile函数。该功能只是将一些数据写入文本文件。在调试时,我进入函数的那一刻就会引发异常。

呼叫追踪(IDE VC6)

CCustomTreeCtrl::OnLButtonDblClick(unsigned int 1, Cpoint {x=150 y=104}) line 117 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
USER32! xxxxxxxx() 
USER32! xxxxxxxx() 
USER32! xxxxxxxx() 
USER32! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
CTestApp::PreTranslateMessage(tagMSG * 0x00484cd0 {msg = 0x00000203 wp = 0x00000001 lp= 0x00680096}) line 563 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
MFC42D! xxxxxxxx() 
WinMain(HINSTANCE__ 0x00400000, HINSTANCE__ 0x00000000, char * 0x00151f2e, int 1) Line 30 
WinMainCRTStartup() Line 330 + 54 bytes 
KERNEL32! xxxxxxxx() 

CreateFunction

void CMainFrame::CreateFile(CString FileName) 
{ 
    BeginWaitCursor(); 

    if(FileName.getAt(1) == 'L') 
    { 
     CMyDllA myDlla; 
     myDlla.ConvertDataToFile(MyDataBasePath,FileName); 
    } 
    else if(FileName.getAt(1) == 'B') 
    { 
     CMyDllB myDllb; 
     myDllb.ConvertDataToFile(MyDataBasePath,FileName); 
    } 
    else if(FileName.getAt(1) == 'D') 
    { 
     CMyDllD myDlld; 
     myDlld.ConvertDataToFile(MyDataBasePath,FileName); 
    } 
    else if(FileName.getAt(1) == 'S') 
    { 
     CMyDllS myDlls; 
     myDlls.ConvertDataToFile(MyDataBasePath,FileName); 
    } 

    EndWaitCursor(); 
} 

//ConvertDataToFile Function reads data for a database performs calculations and writes report to a text file. 

@迈克尔瓦尔兹是,击中断点前该应用程序崩溃。

在拆卸:

147  pFrame->CreateFile(buf); 
00456B74 push ecx 
00456B75 mov ecx,esp 
00456B77 mov dword ptr [ebp-112A8h],esp 
00456B7D lea edx, [buf] 
00456B83 push edx 
00456B84 call CString::CString (0045da26) 
00456B89 mov dword ptr [ebp-11328h],eap 
00456B77 mov ecx, dword ptr [pFrame] 
00456B95 call @ILT+1300(CMainFrame::CreateFile) (00401519) 

只要我踏入创建文件功能,在可变窗口其示出“此CXX0069:错误可变需要堆栈帧”

的CreateFile拆卸:

10040: { 
0043F813 push ebp 
0043F814 mov ebp, esp 
0043F816 push 0FFh 
0043F818 push offset $L111205 (00465099) 
0043F81D mov eax, fs:[00000000] 
0043F823 push eax 
0043F824 mov dword ptr fs:[0],esp 
0043F824 mov eax, 109DC8h 
0043F830 call $$$00001 (0045e840) //Breaks here and jumps to CHKSTK.ASM File 
0043F835 mov dword ptr [ebp-109DBCh], ecx 
0043F83B mov dword ptr [ebp-4], 0 

目前我没有CMyDllx的来源。只有标题和库。 但是我也从应用程序菜单中调用了相同的功能,它会在没有任何错误的情况下执行。只有当我使用树形控件调用它时,我才会面临错误。

@IIENSpectable对不起,但这是工作电脑,我不能在这台机器上安装任何软件。

+0

当它崩溃时,你可以看看调用堆栈吗? – immibis

+0

向我们展示'CreateFile'函数。问题很可能在那里。 –

+0

编辑并更新了问题 – Antony

回答

1
0043F824 mov eax, 109DC8h 
0043F830 call $$$00001 (0045e840) //Breaks here and jumps to CHKSTK.ASM File 

109DC8h讲述故事,传递给__chkstk()的参数是的那个的CreateFile()需要堆栈空间的量。 0x109dc8 == 1,088,968字节。不可以,这比堆栈中可用的整个空间(1兆字节)多。因此,__chkstk()正确地在程序碰到墙壁之前猛击紧急停止按钮,CreateFile()将始终失败。

你的代码片段直截了当地指责犯罪派对,它是CMyDllx太大的对象之一。或者更可能的是,所有这些都需要四分之一的兆字节。重写代码以使用new运算符在免费商店分配代码。

+0

谢谢。有效 – Antony