garyflet wrote:
My MDI server has a CCmdTarget derived class: CAutoApp. I noted that CAutoApp gets created with every new client connection
Well, I consider this a strange behaviour because this means that there con be only one client per CAutoApp instance. The reference counting seems to be put aside. If you override OnFinalRelease in your CCmdTarget derived class and put a breakpoint there, I assume it will get hit when any of the clients "disconnects", but for different CAutoApp instances. I assume that the WM_CLOSE message will be sent from the same call chain. I suspect you're using the CCmdTarget derived class in a way it wasn't intended. When a new client "connects" the reference count should be increased for the same object, i.e. the m_dwRef member of your CAutoApp object should be increased by one. But this apparently does not happen, instead you're creating a new instance of the class which sounds strange.
garyflet wrote:
After any client calls ReleaseDispatch(), my server gets a WM_CLOSE message whether or not there are any clients left.
I would expect that since the reference count for the instance reaches zero. When the one and only client to the CAutoApp object "disconnects" the object will be destroyed.
garyflet wrote:
why do I get a WM_CLOSE message even when there are clients left?
That's the thing: there are no clients left for that CAutoApp instance. I suspect a design flaw here, but I cannot tell since I don't have enough information. It might require the complete source code and dig into it. It sounds like the CAutoApp class should be a singleton since it appears to control the lifetime of the entire application, but you've created multiple instances of it. When one of the instances reference count reaches zero it wants to close the application, hence the WM_CLOSE message. My best tip is to re-evaluate your design.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown