views:

49

answers:

2
A: 

I found the problem. The interface was being deleted when AppB disconnected even though the MFC document that implemented it was still alive. I had delved fairly deep in the MFC code and not found anything but it must be happening somewhere in there.

I AddRef'd the interface in the doc constructor and Release'd it in the destructor and the problem was solved.

Phil J Pearson
+2  A: 
 ::RegisterActiveObject(punk, CLSID_Interface, ACTIVEOBJECT_WEAK, &m_dwRegister);

ACTIVEOBJECT_WEAK is your problem here. From the RegisterActiveObject docs:

Weak registration keeps a pointer to the object in the running object table, but does not increment the reference count. Consequently, when the last external connection to a weakly registered object disappears, OLE releases the object's stub, and the object itself is no longer available.

Which is exactly what's happening in your program. Trivially solve the problem with ACTIVEOBJECT_STRONG.

Hans Passant
Duh! Why didn't I read that? Thanks - I've made the changes.
Phil J Pearson