How to close a COM Server Process from Client? Thank you!
-
:-OHi, all experts: I tried to create a COM local server and a client using win32 console application winzard in VC++ 6. When the client started up, it active the server automatically. The client also connected to server and called interface functions successfully. :((But, how can I terminate the server from client, before the client ended itselt?:^) Thanks a lot!:):):-D:-D REMY
-
:-OHi, all experts: I tried to create a COM local server and a client using win32 console application winzard in VC++ 6. When the client started up, it active the server automatically. The client also connected to server and called interface functions successfully. :((But, how can I terminate the server from client, before the client ended itselt?:^) Thanks a lot!:):):-D:-D REMY
With COM objects you shouldn't need to take any explicit action to terminate the server beyond the normal reference counting calls to
AddRef
andRelease
you (and/or your smart pointers) do on the object's interfaces. Steve -
With COM objects you shouldn't need to take any explicit action to terminate the server beyond the normal reference counting calls to
AddRef
andRelease
you (and/or your smart pointers) do on the object's interfaces. SteveYes. I wrote the 'Release' member for COM SEVER just as following: ULONG CExeComServerConsole0_0::Release() { long nRefCount = InterlockedDecrement(&m_nRef) ; if (nRefCount == 0) delete this; return nRefCount; } But, How can I teminate the server process?:):):):)
-
Yes. I wrote the 'Release' member for COM SEVER just as following: ULONG CExeComServerConsole0_0::Release() { long nRefCount = InterlockedDecrement(&m_nRef) ; if (nRefCount == 0) delete this; return nRefCount; } But, How can I teminate the server process?:):):):)
Ok, you’re talking from the point of view of implementing the server, that wasn't clear in your post. Typically a global reference count is maintained which all implemented COM object increment when they're constructed and decrement when they're destructed.
IClassFactory::LockServer
also increments or decrements it based on its parameter - References on class factories should not influence this count. When the count transitions to zero the server typically wait for a timeout - If there is no activity and the timeout expiresCoSuspendClassObjects
is called and we arrange for the application to exit. In short it's complicated. Use ATL and you don't have to worry about any of this. Steve -
Ok, you’re talking from the point of view of implementing the server, that wasn't clear in your post. Typically a global reference count is maintained which all implemented COM object increment when they're constructed and decrement when they're destructed.
IClassFactory::LockServer
also increments or decrements it based on its parameter - References on class factories should not influence this count. When the count transitions to zero the server typically wait for a timeout - If there is no activity and the timeout expiresCoSuspendClassObjects
is called and we arrange for the application to exit. In short it's complicated. Use ATL and you don't have to worry about any of this. SteveThank you! Steve I wanted to know more about the auto-ending of Server. I created a ATL EXE COM SERVER and used a client to conneted and disconnected it. After a moment, in system process list, the ATL EXE process disappeared. But, I didn't know when the CoSuspendClassObjects was called. Could you tell me more details. I'm learning COM/ATL. Thank you very much! Sincerely REMY:)