简体   繁体   English

COM:我可以查看是否存在对我的 COM 对象之一的进程外引用吗? 我可以释放它吗?

[英]COM: can I see if there is an out-of-process reference to one of my COM objects? Can I release it?

I have an application that makes a COM object accessible to external clients (by registering it in the ROT).我有一个应用程序使外部客户端可以访问 COM object(通过在 ROT 中注册它)。

The object is implemented in C++ using ATL. object 使用 ATL 在 C++ 中实现。

Question 1: Is it possible to determine whether one of the references held to my object originates from an out-of-process client?问题 1:是否可以确定对我的 object 持有的引用之一是否来自进程外客户端?

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.公开的接口是基于IDispatch的,因此不会发生自定义封送处理。

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"?问题 2:是否可以告诉 object(和/或所有对象)的进程外引用 object 不再“活动”? Forcing any call on the out-of-process interface to return, eg RPC_E_DISCONNECTED (in the same way as after terminating the server process, the client receives an RPC_E_SERVER_DIED for every call).强制返回进程外接口上的任何调用,例如RPC_E_DISCONNECTED (与终止服务器进程后的方式相同,客户端每次调用都会收到一个RPC_E_SERVER_DIED )。

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.谨慎的做法是提前通知他们通话没有成功。

External references can be monitored by implementing IExternalConnection , you get called when an external connection is added or removed.可以通过实现IExternalConnection来监视外部引用,当添加或删除外部连接时,您会被调用。

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). CoDisconnectObject允许您告诉外部连接“离开”(虽然看起来可能不会立即通知外部调用者,但可能需要激活消息循环)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM