如何可靠地判断两个检查器引用指向同一个检查器实例?

发布于 2024-07-08 21:58:55 字数 1304 浏览 7 评论 0原文

[续有没有办法判断两个 COM 接口引用是否指向同一个实例?]

我引用了 < code>Inspector 对象来自两个不同的源,并且需要能够区分一个源中的哪个项目对应于另一个源中的哪个项目。 然而,到目前为止,我想出的方法都不起作用(可靠):

  • 我不能简单地比较 < code>IUnknown 接口,因为 Inspectors.Item() 方法似乎返回对动态创建的代理对象而不是检查器实例的引用本身。 尝试一下:两次访问相同的索引将返回两个截然不同的指针。

  • 比较 Inspector.CurrentItem.EntryID 也不好。 新的/未保存的项目的 EntryID 始终为空,并且一次可能会打开多个未保存的项目。

  • Inspector.CaptionInspector.CurrentItem.Subject 同样不明确。

  • 暂时将Inspector.CurrentItem.Subject(或任何其他项目属性)设置为明确的值,然后在其他列表中查找该值是可行的,但会产生恼人的标记副作用检查器中的项目为“脏”,即再次关闭检查器时,将要求用户保存该项目(即使他只是查看收到的邮件)。

还有其他想法吗?


上下文:

我正在尝试解决众所周知的错误/功能,即通过简单 MAPI 发起的新电子邮件(例如,资源管理器上下文菜单中的“发送到>邮件收件人”)不会生成 Inspectors.NewInspector 事件因此无法向这些检查器添加任何插件功能(例如添加工具栏按钮或在创建消息时执行代码)。 在我的 COM 插件中,我有一个包装器对象的内部列表来捕获 Inspector 事件。 通过监视 Inspectors.NewInspectorInspector.Close 事件,可以向此列表添加和删除项目。

作为另一种方法,我使用 shell 钩子:现在,每当创建或销毁新的检查器窗口时,我都能收到通知,因此这似乎是跳入并将包装器对象的内部列表与 < 进行匹配的好地方。 code>Application.Inspectors 集合并相应地添加或删除新的或孤立的包装对象。

[continued from Is there a way to tell whether two COM interface references point at the same instance?]

I've got references to Inspector objects from two different sources and need to be able to tell which item from one source corresponds to which item from the other source. However, none of the approaches I have been able to come up with so far worked (reliably):

  • I couldn't simply compare the IUnknown interfaces as it seems that the Inspectors.Item() method is returning a reference to a created-on-the-fly proxy object rather than the inspector instance itself. Try it: Accessing the same index twice will return two distinctly different pointers.

  • Comparing Inspector.CurrentItem.EntryID is no good either. A new/unsaved items' EntryID is always blank and there could potentially be more than one unsaved item open at a time.

  • Inspector.Caption or Inspector.CurrentItem.Subject is likewise ambiguous.

  • Temporarily setting Inspector.CurrentItem.Subject (or any other item property really) to an unambiguous value and then looking for that in the other list kind of works but has the annoying side-effect of marking the item in the inspector as "dirty", i.e. upon closing the inspector again the user will be asked to save the item (even if he was just viewing a received mail).

Any other ideas?


Context:

I'm trying to work around the well-known bug/feature that new email messages initiated via Simple MAPI (e.g. Send to>Mail recipient in Explorer context menu) do not generate an Inspectors.NewInspector event thus making it impossible to add any addin functionality to those inspectors (e.g. adding toolbar buttons or executing code on message creation). In my COM-addin I've got an internal list of wrapper objects to catch Inspector-events. Items are added and removed to this list by monitoring the Inspectors.NewInspector and Inspector.Close events.

As an alternative approach I'm using a shell hook: I am now able to get notified whenever a new inspector window is created or destroyed so that appears to be a good spot to jump in and match my internal list of wrapper objects with the Application.Inspectors collection and add or remove new or orphaned wrapper objects accordingly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扮仙女 2024-07-15 21:58:55

我现在发现比较 Inspector.CurrentItem.CreationTime 对我来说足够可靠。

I now found that comparing Inspector.CurrentItem.CreationTime was sufficiently reliable for me.

无可置疑 2024-07-15 21:58:55

您还可以使用Is运算符来查看两个对象引用是否引用同一个对象。

例如:

Debug.Print InspectorObj1 Is InspectorObj2

如果两个引用引用同一个检查器,这将在立即窗口中打印True

You could also use the Is operator to see if two object references are referring to the same object.

Ex:

Debug.Print InspectorObj1 Is InspectorObj2

This will print True to the Immediate Window if both references refer to the same Inspector.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文