Raising events quickly from DLL server crashes the client
Ok,
I don't know which is the cause, but I've noted that if I raise some
events quickly, my VB6 client crashes.
In the beginning I thought it was the "Firing events from a worker
thread" issue so I've changed my Proxy_ class with the code from
codeguru (http://www.codeguru.com/Cpp/COM-Tech/atl/atl/article.php/
c75) because I was not able to use the ATLCPImplMT.h from MS with
VC2008.
So, when I run my client app from the IDE attached to the VC debugger
all works....
When if I load the exe (always throught the debugger) and I fire
events quickly I get:
Unhandled exception at 0x73459a49 in EuroATLibTest.exe: 0xC0000005:
Access violation reading location 0x00000034.
on the line:
hr = pDispatch->Invoke(3, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL);
This is the line where I raise this event:
HRESULT Fire_OnStatusChanged( E_AT_DEV_STATE newStatus)
{
HRESULT hr = S_OK;
T * pThis = static_cast<T *>(this);
int cConnections = m_vec.GetSize();
for (int iConnection = 0; iConnection < cConnections; iConnection++)
{
pThis->Lock();
CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
pThis->Unlock();
CComQIPtr< IDispatch, &IID_IDispatch > pDispatch
( punkConnection.p );
if (pDispatch.p != NULL)
{
CComVariant avarParams[1];
avarParams[0] = newStatus;
CComVariant varResult;
DISPPARAMS params = { avarParams, NULL, 1, 0 };
hr = pDispatch->Invoke(3, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL);
}
}
return hr;
}
Could someone give me some suggestion on fix this problem?!
Thanks,
Daniele.