Click to See Complete Forum and Search --> : problem with VC7 __event


verifier
November 17th, 2003, 07:26 AM
Hello

I got two classes:
CPabxWorker - handles diffrent connection interfaces.
CPhilipsOm - a interface two a pbx.

Im using events to notify CPabxWorker when something have happend in CPhilipsOm.

Everything works ok when I have only one CPhilipsOm, but If I have more than one I get the following error on __raise:

Unhandled exception at 0x004c0cbf in hvdserver.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.


event declaration:

__event void OnDone(int nId, bool bResult, int nExtension);


hooking the event:

bool CPabxWorker::AddOm(const char* pszHost, DWORD dwPort)
{
OM_CONTAINER* omCont = new OM_CONTAINER;
m_paOm.push_back(omCont);
omCont->bBusy = false;
omCont->bDisabled = false;
omCont->bInited = false;
omCont->nTimeout = 0;
try
{
printf("%d\n", __hook(&Philips::CPhilipsOm::OnDone, &omCont->Om, OnOmDone));
printf("%d\n", __hook(&Philips::CPhilipsOm::OnOmDisconnect, &omCont->Om, OnOmDisconnect));
omCont->Om.SetId(m_paOm.size()-1);
omCont->Om.InitTcpIp(pszHost, dwPort);
}
catch (Datatal::Exceptions::DtConnectError& ex)
{
WriteLog(Datatal::LP_HIGH, "OM", "OM init failed %s", ex.ToString());
return false;
}
WriteLog(Datatal::LP_NORMAL, "OM", "OM sucessfully inited: %s:%d", pszHost, dwPort);
omCont->bInited = true;
return true;
}


raising the event:

__raise OnDone(m_nId, true, m_nLastExt);

vicodin451
November 17th, 2003, 07:49 AM
Originally posted by verifier

Unhandled exception at 0x004c0cbf in hvdserver.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.



Looks like you're reading uninitialized memory...
MSDN, "Memory Management and the Debug Heap", "Debug Versions of Heap Functions":

New objects (0xCD)
New objects are filled with 0xCD when they are allocated.

verifier
November 17th, 2003, 08:56 AM
yes. I know. But i do not know why.

The program fails on "__raise OnDone(m_nId, true, m_nLastExt);"
If I remove that line everything works.

Also if I only run one CPhilipsOm everything works. Therefore It must be something with the event handling, but I do not know what.

vicodin451
November 17th, 2003, 09:01 AM
Potential threading issue?