0

I have an application that makes a COM object accessible to external clients (by registering it in the ROT).

The object is implemented in C++ using ATL.

Question 1: Is it possible to determine whether one of the references held to my object originates from an out-of-process client?

Motivation: I need to release some related objects (that block some operations) when external references are removed, even when the external reference dies unexpectedly. I also want to avoid requiring the caller to "say goodbye".

I am using the same interface internally, so I can't work with a separate reference count for the interface. The exposed interface is IDispatch-based, so no custom marshaling takes place.

Question 2: Is it possible to tell out-of-process references to an object (and/or all objects) that the object is no longer "alive"? Forcing any call on the out-of-process interface to return, e.g. RPC_E_DISCONNECTED (in the same way as after terminating the server process, the client receives an RPC_E_SERVER_DIED for every call).

Motivation: the shutdown process of the server may be initiated by the user, and may take a while. In that time, all calls from external clients block; it would be prudent to inform them earlier that the call does not succeed.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
peterchen
  • 40,917
  • 20
  • 104
  • 186
  • i think that you need implement [`IExternalConnection`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-iexternalconnection) interface on your object – RbMm Jun 29 '20 at 22:44
  • and [`CoDisconnectObject`](https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-codisconnectobject) for 2 – RbMm Jun 29 '20 at 23:02
  • @RbMm: thanks, works as expected. if you want to post it as an answer, I'm happy to accept. – peterchen Jun 30 '20 at 11:28

1 Answers1

0

External references can be monitored by implementing IExternalConnection, you get called when an external connection is added or removed.

CoDisconnectObject allows you to tell an external connection to "go away" (though it seems like the external caller may not be notified immediately, the messgae loop may need to be active).

peterchen
  • 40,917
  • 20
  • 104
  • 186