我在某一时钟触发事件中打开一文件,并以4096为一个BLOCK,读入文件内容,寻找其中时候有某一字串,如果有就关闭程序,SLEEP 5秒以后再重新启动程序。但是在重新启动程序的时候,系统弹出对话框说内存不能读,是否是CString读CFile 文件出错的原因?case ID_TIMER2:
{
CFile CurrentLogFile;
CFileException e; CurrentLogFile.Open("D:\\SDA\\Projects\\vos1.log", CFile::modeRead | CFile::shareDenyNone, &e);
CurrentLogFile.SeekToBegin(); BYTE buffer[4096];
DWORD dwRead; do
{
dwRead = CurrentLogFile.Read(buffer,4096);
CString CurrentBuffer = buffer;
int m = CurrentBuffer.Find("ATDX_TERMMSK(1[dxxxB1C1])=0x30");
int n = CurrentBuffer.Find("ATDX_TERMMSK(1[dxxxB1C2])=0x30");
if ((m >= 0)||(n >= 0))
{ if(isopen)
{
CWnd *ttt;
ttt = FindWindow(NULL,m_title);
ttt->SendMessage(WM_CLOSE,NULL,NULL);
isopen=false; Sleep(5000);
ShellExecute(NULL,NULL,m_path,NULL,NULL,SW_SHOW);
isopen=true;
}
else
{
ShellExecute(NULL,NULL,m_path,NULL,NULL,SW_SHOW);
isopen=true;
}
} //CurrentBuffer.Empty();
}
while (dwRead > 0);CurrentLogFile.Close();

解决方案 »

  1.   

    代码稍微有点多,其中主要是以下导致出错,但是在另外一个时钟触发函数里面一样的代码却不出错,请教大家了if(isopen)
    {
     CWnd *ttt;
     ttt = FindWindow(NULL,m_title);
     ttt->SendMessage(WM_CLOSE,NULL,NULL);
     isopen=false;
     sleep(5000);
     ShellExecute(NULL,NULL,m_path,NULL,NULL,SW_SHOW);
     isopen=true;
    }
    else
    {
     ShellExecute(NULL,NULL,m_path,NULL,NULL,SW_SHOW);
     isopen=true;
    }
      

  2.   

    主要是其中的以下代码导致的错误CWnd *ttt;
    ttt = FindWindow(NULL,m_title);
    ttt->SendMessage(WM_CLOSE,NULL,NULL);
    isopen=false;Sleep(5000);
    ShellExecute(NULL,NULL,m_path,NULL,NULL,SW_SHOW);
    isopen=true;