Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EAccessViolation Exception help

Status
Not open for further replies.

StrikeTheCore

Programmer
Joined
May 26, 2006
Messages
5
Location
US
I have code running that constantly throws an Access Violation on Windows XP. This exception only occurs however after around 10 to 20 thousand times running this function. I can catch the exception but want to get rid of it completely, however cannot figure out where it is coming from. Code is below (str is a simple string parser). Any help is greatly appreciated.

//--------------------------------------------------------

unsigned char *inbuffer;
AnsiString tmp;
struct timeval current;
inbuffer = new unsigned char[Count+2];
myComPort->Read(inbuffer, Count);
str.reset();
try {
if(Form2->mode == TForm2::HEX_MODE && !Form2->BufferDisabled->Checked){
for(int i=0; i<Count; i++){
tmp.sprintf("%0x ", inbuffer);
if(tmp.Length() < 3)
tmp = AnsiString("0") + tmp;
str << tmp.c_str() << " ";
}
if(Form2->ReceiveBuffer.Length() + str.length() < Form2->MaxBufLen){
Form2->ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
}
else{
unsigned int n=0;
for(int count=0;n<=str.length();count++)
n += (*(Form2->Memo->Lines))[count].Length();
Form2->ReceiveBuffer.Delete(0, n);
Form2->ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
}
}
else if(Form2->mode == TForm2::ASCII_MODE && !Form2->BufferDisabled->Checked){
inbuffer[Count] = '\0';
if(Form2->ReceiveBuffer.Length() + strlen((char*)inbuffer) > Form2->MaxBufLen){
Form2->ReceiveBuffer.Delete(0, strlen((char*)inbuffer));
}
Form2->ReceiveBuffer += AnsiString((char*)inbuffer);
if(Form2->logdata){
std::ofstream outfile;
outfile.open(Form2->LogFileName.c_str(), std::ofstream::out | std::ofstream::app);
outfile << (char*)inbuffer;
outfile.close();
}
}
}
catch (const EAccessViolation & vae)
{
ShowMessage("Misread message");
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top