OLE Automation server's knowledge of client(s)
-
Using Visual C++ Service Pack 6 on Windows 2000. When my automation client calls COleDispatchDriver::ReleaseDispatch(), thus releasing the server, the server receives a WM_CLOSE message. If there are other clients still connected, the server,if visible, is supposed to display a message to that effect and offer to close. If invisible, the server simly doesn't close. How does the server know which clients, if any, are still attached? Thanks, GF
-
Using Visual C++ Service Pack 6 on Windows 2000. When my automation client calls COleDispatchDriver::ReleaseDispatch(), thus releasing the server, the server receives a WM_CLOSE message. If there are other clients still connected, the server,if visible, is supposed to display a message to that effect and offer to close. If invisible, the server simly doesn't close. How does the server know which clients, if any, are still attached? Thanks, GF
garyflet wrote:
How does the server know which clients, if any, are still attached?
I may be misinterpreting your question, but this is done by reference counting. The server will in general not know anything about its clients, it only knows that it has one or more clients attached to it.
garyflet wrote:
When my automation client calls COleDispatchDriver::ReleaseDispatch(), thus releasing the server, the server receives a WM_CLOSE message. If there are other clients still connected, the server,if visible, is supposed to display a message to that effect and offer to close.
From your question I assume you're talking about an application that runs as an out-of-process COM server. I wouldn't expect the server to close, or even the WM_CLOSE message being sent, unless the reference count reaches zero. Popping a dialogue asking the user whether to shut down the server or not seems a bit odd since there shouldn't be any clients left.
garyflet wrote:
If invisible, the server simly doesn't close.
:confused: Don't quite get what you mean by this, but when a server shuts down and calls
::CoUninitialize
it tries to dispatch all pending COM calls in a message loop. A server may hang inside this loop if the server hasn't released all COM servers it may have created. Your problem may be related to this, or it may be popping an invisible dialogue box waiting for user input. I think you need to explain your problem a bit further and what you're trying to do."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
garyflet wrote:
How does the server know which clients, if any, are still attached?
I may be misinterpreting your question, but this is done by reference counting. The server will in general not know anything about its clients, it only knows that it has one or more clients attached to it.
garyflet wrote:
When my automation client calls COleDispatchDriver::ReleaseDispatch(), thus releasing the server, the server receives a WM_CLOSE message. If there are other clients still connected, the server,if visible, is supposed to display a message to that effect and offer to close.
From your question I assume you're talking about an application that runs as an out-of-process COM server. I wouldn't expect the server to close, or even the WM_CLOSE message being sent, unless the reference count reaches zero. Popping a dialogue asking the user whether to shut down the server or not seems a bit odd since there shouldn't be any clients left.
garyflet wrote:
If invisible, the server simly doesn't close.
:confused: Don't quite get what you mean by this, but when a server shuts down and calls
::CoUninitialize
it tries to dispatch all pending COM calls in a message loop. A server may hang inside this loop if the server hasn't released all COM servers it may have created. Your problem may be related to this, or it may be popping an invisible dialogue box waiting for user input. I think you need to explain your problem a bit further and what you're trying to do."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownThanks very much for your reply.
Roger Stoltz wrote:
I may be misinterpreting your question, but this is done by reference counting. The server will in general not know anything about its clients, it only knows that it has one or more clients attached to it.
That's exactly my question. I don't know how to do reference counting! My MDI server has a CCmdTarget derived class: CAutoApp. I noted that CAutoApp gets created with every new client connection, so I put in an array to capture the LPUNKNOWN return from GetInterface(&IID_IUnknown). However, I still don't know how to use that to tell me if the client has disconnected.
Roger Stoltz wrote:
From your question I assume you're talking about an application that runs as an out-of-process COM server. I wouldn't expect the server to close, or even the WM_CLOSE message being sent, unless the reference count reaches zero. Popping a dialogue asking the user whether to shut down the server or not seems a bit odd since there shouldn't be any clients left.
After any client calls ReleaseDispatch(), my server gets a WM_CLOSE message whether or not there are any clients left. I wouldn't even have to do a reference count if this were not the case. Maybe that's the real question, why do I get a WM_CLOSE message even when there are clients left? I'm not sure how to investigate that.
-
Thanks very much for your reply.
Roger Stoltz wrote:
I may be misinterpreting your question, but this is done by reference counting. The server will in general not know anything about its clients, it only knows that it has one or more clients attached to it.
That's exactly my question. I don't know how to do reference counting! My MDI server has a CCmdTarget derived class: CAutoApp. I noted that CAutoApp gets created with every new client connection, so I put in an array to capture the LPUNKNOWN return from GetInterface(&IID_IUnknown). However, I still don't know how to use that to tell me if the client has disconnected.
Roger Stoltz wrote:
From your question I assume you're talking about an application that runs as an out-of-process COM server. I wouldn't expect the server to close, or even the WM_CLOSE message being sent, unless the reference count reaches zero. Popping a dialogue asking the user whether to shut down the server or not seems a bit odd since there shouldn't be any clients left.
After any client calls ReleaseDispatch(), my server gets a WM_CLOSE message whether or not there are any clients left. I wouldn't even have to do a reference count if this were not the case. Maybe that's the real question, why do I get a WM_CLOSE message even when there are clients left? I'm not sure how to investigate that.
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 yourCCmdTarget
derived class and put a breakpoint there, I assume it will get hit when any of the clients "disconnects", but for differentCAutoApp
instances. I assume that theWM_CLOSE
message will be sent from the same call chain. I suspect you're using theCCmdTarget
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. them_dwRef
member of yourCAutoApp
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 theCAutoApp
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 theWM_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