Board index » cppbuilder » EAccessViolation and Exception Occured Messages

EAccessViolation and Exception Occured Messages


2004-08-18 07:52:51 PM
cppbuilder49
Hi all,
I have been looking at this for several weeks now and have come to a
practival dead end and was wondering if any one knows how to solve this
issue, or even what is causing it. The functions below show how I implement
an event sink and fire it to my other clients, I call TransmitData and this
fires the method SendRemoteSerialData in the server (out of process exe),
this function in turn calls the function FireSendSerialData, this calls
Fire_SendSerialData which fires an event at each client. Simple enough, I
haven't shown the Sink code at the client end because it's not connected at
the moment and the fault happens whether its attached or not.
Basically I can call the TransmitData function hundreds(even thousands) of
times, I have had it auto firing in a 500 ms timer, it will function fine
for 5 mins, maybe 10 mins sometimes several hours (normally hours), then I
get the following:
The server gives an error "EAccessViolation", I would give you more
information but thats all I get, then the Clients give an error "Exception
Occured" (probably because the COM call failed) then the server throws
abnormal program termination and exits. I then run it in the de{*word*81}, when
the program halts it tells me an exception occured but no error information
is given, the de{*word*81} always halts at the same line which is in the file
utilcls.h at line 155 which is the following:
throw msg; // Hopefully we never get here: Need something much better to
throw!!
msg equates to the same error the de{*word*81} throws so no further information
can be derived from there, I don't understand how this function can work for
so long and the suddenly fail?, I also put a ShowMessage statement in the
catch block for the FireSendSerialData and found that this error may occur a
few times before the server terminates.
If any body knows anything I would sincerley appreciate some guidance, I
haven't searched google because i don't know exactly how to describe this
one in terms of a search :-). Any way Thanks in advance to any one who can
help.
Joe
//------------------------------------------------------
// Client Application
void __fastcall TMainForm::TransmitData(void)
{
String st;
st = "|" + String("CONCSERVER") + '|';
st = st + IntToStr(28) + '|' + "A" + '|';
OLECHECK(ServerConnection.SendRemoteSerialData(WideString(st)));
}
// COM implementation
STDMETHODIMP TSentServImpl::SendRemoteSerialData(BSTR sData)
{
try
{
String str = String(sData);
FireSendSerialData(str);
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_ISentServ);
}
return S_OK;
}
// Event Sink Event Wrapper function
STDMETHODIMP TSentServImpl::FireSendSerialData(String s)
{
TSentServImpl *pIntf;
try
{
if( AvailableClients )
{
TList *pList = AvailableClients->LockList();
try
{
for(int x = 0; x < pList->Count; ++x)
{
pIntf = static_cast<TSentServImpl*>(pList->Items[x]);
pIntf->Fire_SendSerialData(WideString(s));
}
}
__finally
{
AvailableClients->UnlockList();
}
}
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_ISentServ);
}
return S_OK;
}
// event sink auto generated code
template <class T>HRESULT
TEvents_SentServ<T>::Fire_SendSerialData(BSTR sData)
{
T * pT = (T*)this;
pT->Lock();
IUnknown ** pp = m_vec.begin();
while (pp < m_vec.end())
{
if (*pp != NULL)
{
m_EventIntfObj.Attach(*pp);
m_EventIntfObj.SendSerialData(sData);
m_EventIntfObj.Attach(0);
}
pp++;
}
pT->Unlock();
}
 
 

Re:EAccessViolation and Exception Occured Messages

JoeBlack schrieb:
Quote
Hi all,
The functions below show how I implement
an event sink and fire it to my other clients, I call TransmitData and this
fires the method SendRemoteSerialData in the server (out of process exe),
this function in turn calls the function FireSendSerialData, this calls
Fire_SendSerialData which fires an event at each client.

Basically I can call the TransmitData function hundreds(even thousands) of
times, I have had it auto firing in a 500 ms timer, it will function fine
for 5 mins, maybe 10 mins sometimes several hours (normally hours), then I
get the following:

The server gives an error "EAccessViolation",
Joe

//------------------------------------------------------
// Client Application
void __fastcall TMainForm::TransmitData(void)
{
String st;
st = "|" + String("CONCSERVER") + '|';
st = st + IntToStr(28) + '|' + "A" + '|';
OLECHECK(ServerConnection.SendRemoteSerialData(WideString(st)));
I had a - not really similar - problem with OLE and solved it by
passing copies of the strings to the function.
Try
OLECHECK(ServerConnection.SendRemoteSerialData(WideString(st).Copy()));
read
+++ Firing an Event in Method of ActiveX destroys memory +++
in the same newsgroup
Hope, this helps
Lutz
 

Re:EAccessViolation and Exception Occured Messages

What version of Builder? In BCB5, there was an issue with passing BSR
parameters to events; basically BCB5 used TVariantInParam which would
incorrectly take owsership of a BSTR passed to it and free the memory when
it went out of scope. Try changing your event to take a VARIANT parameter
and wrap you string in it. If you suffer from the above problem, then this
should do the trick.
Mark
"JoeBlack" < XXXX@XXXXX.COM >wrote in message
Quote
Hi all,

I have been looking at this for several weeks now and have come to a
practival dead end and was wondering if any one knows how to solve this
issue, or even what is causing it. The functions below show how I
implement
an event sink and fire it to my other clients, I call TransmitData and
this
fires the method SendRemoteSerialData in the server (out of process exe),
this function in turn calls the function FireSendSerialData, this calls
Fire_SendSerialData which fires an event at each client. Simple enough, I
haven't shown the Sink code at the client end because it's not connected
at
the moment and the fault happens whether its attached or not.

Basically I can call the TransmitData function hundreds(even thousands) of
times, I have had it auto firing in a 500 ms timer, it will function fine
for 5 mins, maybe 10 mins sometimes several hours (normally hours), then I
get the following:

The server gives an error "EAccessViolation", I would give you more
information but thats all I get, then the Clients give an error "Exception
Occured" (probably because the COM call failed) then the server throws
abnormal program termination and exits. I then run it in the de{*word*81},
when
the program halts it tells me an exception occured but no error
information
is given, the de{*word*81} always halts at the same line which is in the file
utilcls.h at line 155 which is the following:

throw msg; // Hopefully we never get here: Need something much better
to
throw!!

msg equates to the same error the de{*word*81} throws so no further
information
can be derived from there, I don't understand how this function can work
for
so long and the suddenly fail?, I also put a ShowMessage statement in the
catch block for the FireSendSerialData and found that this error may occur
a
few times before the server terminates.

If any body knows anything I would sincerley appreciate some guidance, I
haven't searched google because i don't know exactly how to describe this
one in terms of a search :-). Any way Thanks in advance to any one who can
help.

Joe

//------------------------------------------------------
// Client Application
void __fastcall TMainForm::TransmitData(void)
{
String st;
st = "|" + String("CONCSERVER") + '|';
st = st + IntToStr(28) + '|' + "A" + '|';
OLECHECK(ServerConnection.SendRemoteSerialData(WideString(st)));
}


// COM implementation
STDMETHODIMP TSentServImpl::SendRemoteSerialData(BSTR sData)
{
try
{
String str = String(sData);

FireSendSerialData(str);
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_ISentServ);
}
return S_OK;
}

// Event Sink Event Wrapper function
STDMETHODIMP TSentServImpl::FireSendSerialData(String s)
{
TSentServImpl *pIntf;
try
{
if( AvailableClients )
{
TList *pList = AvailableClients->LockList();
try
{
for(int x = 0; x < pList->Count; ++x)
{
pIntf = static_cast<TSentServImpl*>(pList->Items[x]);
pIntf->Fire_SendSerialData(WideString(s));
}
}
__finally
{
AvailableClients->UnlockList();
}
}
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_ISentServ);
}
return S_OK;
}

// event sink auto generated code
template <class T>HRESULT
TEvents_SentServ<T>::Fire_SendSerialData(BSTR sData)
{
T * pT = (T*)this;
pT->Lock();
IUnknown ** pp = m_vec.begin();
while (pp < m_vec.end())
{
if (*pp != NULL)
{
m_EventIntfObj.Attach(*pp);
m_EventIntfObj.SendSerialData(sData);
m_EventIntfObj.Attach(0);
}
pp++;
}
pT->Unlock();
}


 

{smallsort}

Re:EAccessViolation and Exception Occured Messages

Hi Mark,
I'm Using BCB6 with patch 4 and the linker update, I should have included
that with the post really, sorry. I will Give that a go and cheers for the
response.
Joe
"Mark Guerrieri" < XXXX@XXXXX.COM >wrote in message
Quote
What version of Builder? In BCB5, there was an issue with passing BSR
parameters to events; basically BCB5 used TVariantInParam which would
incorrectly take owsership of a BSTR passed to it and free the memory when
it went out of scope. Try changing your event to take a VARIANT parameter
and wrap you string in it. If you suffer from the above problem, then
this
should do the trick.

Mark