|
일단 소스를 보시고.....
========== 헤더 =============
#define MAX_DATA_SIZE 4096
class TBUFF{
public:
unsigned int size;
unsigned char Buff[MAX_DATA_SIZE];
void __fastcall InitBuff();
unsigned int __fastcall Size();
unsigned char * __fastcall c_str();
void __fastcall AddString(unsigned char *add);
};
============== 소스 ================
void __fastcall TBUFF::InitBuff(){ // 초기화
this->size = 0;
memset(&this->Buff,0,MAX_DATA_SIZE);
}
unsigned char * __fastcall TBUFF::c_str(){
unsigned char *p=this->Buff;
return p;
}
unsigned int __fastcall TBUFF::Size(){ // 크기 리턴
return this->size;
}
void __fastcall TBUFF::AddString(unsigned char *add){
memcpy(&this->Buff[this->size],add,strlen(add));
this->Buff[this->size+strlen(add)]=0x00; // 추가한뒤 끝에 0x00 을 붙힘
this->size =this->size+strlen(add)+1; // 크기 계산
}
=========== 사용 ============
void __fastcall Board::Button5Click(TObject *Sender){
TSocketBuff *bp=new TSocketBuff;
bp->InitBuff();
bp->AddString("11111");
bp->AddString("22222");
unsigned char *p=bp->c_str();
String a;
a.sprintf("%s",p[0]);
Memo1->Lines->Add(a);
}
폼에 메모장이랑 버튼 올려 놓고 시험한건데요..
엑세스 바이레션 인가;; 하는 오류가 납니다.
그리고 제가 알고 싶은거는 String 의 c_str 함수 처럼
포인터로 리턴해주게 만들고 싶은데요... 제게 맞는 방법인지;; 제가 초보라서
더 좋은 방법이 있으면 조언 부탁 드립니다.
|