C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[38422] [질문] 시리얼로 데이타 보내는 부분에서consecutive exceptions 에러
초보 [carl] 2375 읽음    2004-12-16 20:06
Project projectname raised too many consecutive exceptions :
access violation at 0xfffef88f : read of address 0xfffef87f :
Process Stopped.Use step or Run to continue;
에러가 뜹니다 디버깅도 안되고
예상되는 부분 모두 break point 잡아도 안됩니다.
어떻게 하면 좋을까여?

밑의 소스는 시리얼로 데이타를 보내는 소스입니다.
WriteData함수를 이용하여 1500바이트 정도의 데이타를 보냅니다.

void __fastcall TFileWriteThread::WriteData(BYTE* s)
{
  DWORD ErrCode;
  ::EnterCriticalSection(&CriticalSection);
  int len = 2048;
  memcpy(WriteString,&s,len);       -->WriteString에 데이타를 저장합니다.
  ::LeaveCriticalSection(&CriticalSection);
  SetEvent(osWrite.hEvent);
}
bool TFileWriteThread::WriteCommBlock(unsigned char *lpByte , int dwBytesToWrite)
{
  .....
   fWriteStat = ::WriteFile( hWrite, lpByte, dwBytesToWrite, &dwBytesWritten, &osWrite ) ;
   if(!fWriteStat) {
     if(::GetLastError() == ERROR_IO_PENDING) {
       while(!GetOverlappedResult(hWrite,&osWrite,&dwBytesWritten,TRUE)) {     ------1번 위치
         if(GetLastError() == ERROR_IO_INCOMPLETE) {
           dwBytesSent += dwBytesWritten;
           continue;
         }
         else {
           ::ClearCommError(hWrite,&dwError,&comstat);
           break;
         }
       }
       dwBytesSent += dwBytesWritten;
       if(dwBytesSent != dwBytesToWrite)
         wsprintf(szError,"Probable Write Timeout: Total of %ld bytes sent", dwBytesSent);
       else wsprintf(szError,"%ld bytes written", dwBytesSent);
     }
     else {
       ::ClearCommError(hWrite,&dwError,&comstat);
       return false;
     }
   }
   return true;
}

//Main loop
void __fastcall TFileWriteThread::Execute(void)    ///-->WriteThread를 시작합니다.
{
  DWORD BytesWritten, ErrCode;
  AnsiString a;
  while (!Terminated)
  {
    if (WriteString[0] != 0x00)
    {
      memset(Buffer, '\0', sizeof(Buffer));
      EnterCriticalSection(&CriticalSection);
      memcpy(Buffer, &WriteString, sizeof(char)*2048);
      WriteString[0] = 0x00;
      LeaveCriticalSection(&CriticalSection);

      int a = 1500;
      if (!WriteCommBlock(Buffer,  a))       //-->WriteCommBlock 함수를 호출합니다.
        if ((ErrCode = GetLastError()) != ERROR_IO_PENDING)
          ShowMessage("Error on write file " + IntToStr(ErrCode));

    }
    DWORD aaa = ::WaitForSingleObjectEx(osWrite.hEvent, INFINITE, TRUE);
  }

위의 1번 위치에서  처음 데이타를 보낼때는 잘 동작하지만
2번째 1500바이트를 보내면 CPU의 사용이 갑자기 커지면서
프로그램이 동작하지 않고 조금 더 있으면 맨위의 에러 메세지가 뜹니다.
어느 부분이 잘못됐는지 잘 모르겠습니다.
동작상에는 문제가 없어 보이는데..

+ -

관련 글 리스트
38422 [질문] 시리얼로 데이타 보내는 부분에서consecutive exceptions 에러 초보 2375 2004/12/16
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.