Can't seem to get FinalRelease() to get called
I assume I'm doing something stupid, but so far have been unable to figure
out what it is. I've got the following class which wants to be notified when
the last release happens:
#include <atlbase.h>
#include <atlcom.h>
#include <mapix.h>
#include "exchhndl.h"
#include "resource.h"
class DECLSPEC_UUID("9A0FCB24-18CA-4fa4-AAC4-F011BBC25D4E")
AgentProxy;
enum EventType
{
Invalid,
Folder_OnTimer,
Folder_OnMessageCreated,
Folder_OnMessageDeleted,
Message_OnChange,
Message_OnMove,
};
class ATL_NO_VTABLE AgentProxy :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<AgentProxy, &__uuidof(AgentProxy)>,
public IExchangeEventHandler
{
public:
AgentProxy();
void FinalRelease();
DECLARE_REGISTRY_RESOURCEID(IDR_AGENTPROXY)
BEGIN_COM_MAP(AgentProxy)
COM_INTERFACE_ENTRY(IExchangeEventHandler)
END_COM_MAP()
private:
STDMETHOD(ExecuteEvent)(IDispatch *source);
};
Unfortunately FinalRelease() does not get called. Instead when
~CComObject() is executing and it calls FinalRelease(), it specifically calls
CComObjectRootEx::FinalRelease() as shown in the disassembly below. Any idea
why?
// also catch mismatched Release in debug builds
virtual ~CComObject() throw()
{
1000AAB0 push ebp
1000AAB1 mov ebp,esp
1000AAB3 push ecx
1000AAB4 mov dword ptr [ebp-4],ecx
1000AAB7 mov eax,dword ptr [this]
1000AABA mov dword ptr [eax],offset
ATL::CComObject<AgentProxy>::`vftable' (10035480h)
m_dwRef = -(LONG_MAX/2);
1000AAC0 mov ecx,dword ptr [this]
1000AAC3 mov dword ptr [ecx+4],0C0000001h
FinalRelease();
1000AACA mov ecx,dword ptr [this]
1000AACD add ecx,4
1000AAD0 call ATL::CComObjectRootBase::FinalRelease (10001505h)
--
Thanks,
Nick
nicknospamdu@community.nospam
remove "nospam" change community. to msn.com