1

我的应用程序在从 Visual Studio 内部运行时运行良好,但如果我使用 EXE 文件运行它会崩溃。[调试exe]

当应用程序到达这行代码时,问题就出现了:

            nmax=2*(nrows+rows);
            create_progrcntl(L"Processing please wait"); // Crashes here
            pgr->m_pgr.SetRange32(1,nmax);
            pgr->m_pgr.SetStep(1);

函数 create_progresscntl 是:

 void import::create_progrcntl(CString header)
{

 pgr = new CPgr;
 pgr->Create(IDD_PROGRESS,this);
 pgr->SetWindowTextW(header);
    pgr->ShowWindow(SW_SHOW);    
}

我在其他几个地方也使用了这个函数,它不会导致任何错误。它只是因为import::processENSAT_MasterSlave()它崩溃的功能。

它在 VS 内部运行良好,但如果我在外部运行 EXE 则会崩溃。

我将该进程附加到 VS 调试器。这是我的调用堆栈,就在崩溃之后:

   ntdll.dll!7729e3be()     
   [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]  
   ntdll.dll!7729e023()     
   kernel32.dll!751914dd()  
   msvcr100d.dll!_free_base(void * pBlock)  Line 50 + 0x13 bytes    
   msvcr100d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse)  Line 1431 + 0x9 bytes   C++
   msvcr100d.dll!_free_dbg(void * pUserData, int nBlockUse)  Line 1265 + 0xd bytes  C++
   mfc100ud.dll!operator delete(void * p)  Line 347 + 0xc bytes C++
   mfc100ud.dll!operator delete[](void * p)  Line 360 + 0x9 bytes   C++
   mfc100ud.dll!COccManager::PostCreateDialog(_AFX_OCC_DIALOG_INFO * pDlgInfo)  Line 239 + 0x12 bytes   C++
   mfc100ud.dll!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate, CWnd * pParentWnd, HINSTANCE__ * hInst)  Line 413 C++
   mfc100ud.dll!CDialog::CreateIndirect(const DLGTEMPLATE * lpDialogTemplate, CWnd * pParentWnd, void * lpDialogInit, HINSTANCE__ * hInst)  Line 263    C++
   mfc100ud.dll!CDialog::CreateIndirect(void * hDialogTemplate, CWnd * pParentWnd, HINSTANCE__ * hInst)  Line 240 + 0x16 bytes  C++
   mfc100ud.dll!CDialog::Create(const wchar_t * lpszTemplateName, CWnd * pParentWnd)  Line 222 + 0x14 bytes C++
   mfc100ud.dll!CDialog::Create(unsigned int nIDTemplate, CWnd * pParentWnd)  Line 673 + 0x1a bytes C++
   Sar_CCD.exe!import::create_progrcntl(ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > header)  Line 370 + 0x27 bytes  
   Sar_CCD.exe!import::processENSAT_MasterSlave()  Line 1760    
   Sar_CCD.exe!import::Select_process_func()  Line 2758 
   Sar_CCD.exe!import::OnBnClickedBtnProcess()  Line 340

完整代码: http ://sharetext.org/ZKKp


已解决: buf 被初始化为buf=new char[6];. 后来 21 个字节被读入其中。非常感谢@atzz

4

0 回答 0