Hi
I think im dealing with a possible bug using vector objects.
Specificaly a vector of CComPtr(s) related objects that contain even sinks.
Lets say i got a ATL class that handles events from a COM object
using IDispEventImpl<,,,>
----------------------------------------------------------------------------
------
class CSomeClass : public IDispEventImpl<,,,>
{
public:
CSomeClass (){}
~CSomeClass (){}
CComPtr<ISomeComObject> m_pSome;
BOOL Create()
{
m_pSome.CoCreateInstance(,,,);
return TRUE;
}
BEGIN_SINK_MAP(CSomeClass )
SINK_ENTRY_EX(0, DIID__ISomeComObjectEvents , 0x01, OnLoad)
END_SINK_MAP()
VOID __stdcall OnLoad(){}
};
----------------------------------------------------------------------------
------
then if do this :
vector<CSomeClass> m_vSome;
m_vSome.resize(2);
m_vSome[0].Create();
m_vSome[0].DispEventAdvise(m_vSome[0].m_pSome);
m_vSome[1].Create();
m_vSome[1].DispEventAdvise(m_vSome[1].m_pSome);
m_vSome.clear();
No problem, everything is fine and dandy!
BUT if i do this >> ( 2 resize operations)
vector<CSomeClass> m_vSome;
m_vSome.resize(1);
m_vSome[0].Create();
m_vSome[0].DispEventAdvise(m_vSome[0].m_pSome);
m_vSome.resize(2);
m_vSome[1].Create();
m_vSome[1].DispEventAdvise(m_vSome[1].m_pSome);
m_vSome.clear();
CRASH BANG! , , the event connections are lost during the "second" resize
operation.
So i had to do this to get things to Work :
...
for(i=0; i<m_vSome.size(); i++)
HRESULT hr = m_vSome[i].DispEventUnadvise(m_vSome[i].m_pSome);
UINT size = m_vSome.size();
m_vSome.resize(size+1);
m_vSome[size].Create();
for(i=0; i<m_vSome.size(); i++)
HRESULT hr = m_vSome[i].DispEventAdvise(m_vSome[i].m_pSome);
...
And now everything works..
Anybody ever had this issue before ?