|
원인을 잘 몰라 속타고 있었는데 명쾌한 답변덕에 해결되었습니다.
감사드립니다....
아제나 님이 쓰신 글 :
: 윈도우 운영체제는 보호모드라서 프로그램이 할당된 메모리 공간만 사용해야 합니다.
: Access violation 에러는 할당되지 않은 메모리 공간을 사용하다보니
: 다른 프로그램이나 커널의 메모리 공간을 침범하여 발생하는 에러이며,
: 아래 소스에서는 할당되지 않은 변수인 packet을 쓰시다보니 발생하는 것 입니다.
:
: 해결하려면
:
: char packet[] = "";
:
: 코드를 아래와 같이 바꾸세요.
:
: char packet[65535]; // 65535 크기의 공간을 선언, 크기는 최대 입력 크기를 감안해서 조절 가능
: memset(packet,0,sizeof(packet)); // 공간을 0으로 초기화
:
:
: sunje 님이 쓰신 글 :
: : //---------------------------------------------------------------------------
: :
: : #include <vcl.h>
: : #pragma hdrstop
: :
: : #include <stdio.h>
: :
: : #include "Unit1.h"
: : //---------------------------------------------------------------------------
: : #pragma package(smart_init)
: : #pragma resource "*.dfm"
: : TForm1 *Form1;
: : //---------------------------------------------------------------------------
: : __fastcall TForm1::TForm1(TComponent* Owner)
: : : TForm(Owner)
: : {
: :
: : Cont=1;
: : Bar=1;
: : }
: : //---------------------------------------------------------------------------
: :
: : void __fastcall TForm1::Timer1Timer(TObject *Sender)
: : {
: : // int Cont; ->헤더파일
: : // int Bar; ->헤더파일
: : AnsiString str, str2, str3;
: :
: : if( Cont <=9 )
: : {
: : str.printf("C0""%d"",B3,REQ,""%d",Cont,Bar);
: :
: : char packet[] = "";
: : int i;
: : int size = 0;
: : char cksum = 0;
: :
: : sprintf(packet, "%s", str);
: :
: : while(packet[size] !='\0')
: : printf("%d",size++);
: :
: : printf("\n");
: :
: : for(i = 0 ; i < size ; i++)
: : {
: : if(i == 0)
: : cksum = packet[i];
: : else
: : cksum^= packet[i];
: : }
: :
: : str3.printf("%X",cksum);
: :
: : Edit4->Text = str3;
: :
: : str2.printf("$C0""%d"",B3,REQ,""%d""*""%x""\n ",Cont,Bar,cksum);
: :
: : Memo1->Lines->Add( str2 );
: :
: : Bar++;
: :
: : if (Bar>=9 )
: : {
: : Cont++;
: : Bar=1;
: : }
: : }
: : }
: : //---------------------------------------------------------------------------
: :
: : 들어온 데이터에 대해 체크섬을 만들려고 하는데요.
: : 위의 프로그램을 실행하면 아래 부분부터 메세지 창과 함께 프로그램이 멈추네요...
: :
: : Edit4->Text = str3;
: :
: : str2.printf("$C0""%d"",B3,REQ,""%d""*""%x""\n ",Cont,Bar,cksum);
: :
: : Memo1->Lines->Add( str2 );
: :
: : 이유를 잘 모르겠습니다.
: : 고수님들의 조언 부탁드립니다.......
|