我的应用程序在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