如何可靠地告知两个Inspector引用指向同一个检查器实例? [英] How do I reliably tell that two Inspector references point to the same inspector instance?

查看:192
本文介绍了如何可靠地告知两个Inspector引用指向同一个检查器实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[继续是否有方法可以判断两个COM介面参照是否指向同一个执行个体?]



我有来自两个不同来源的 Inspector 对象的引用,需要能够从一个来源中识别哪个项目对应于其他来源的项目。但是,我一直没有能够提出的方法,迄今为止工作(可靠):




  • 只需比较 IUnknown 接口,因为看起来 Inspectors.Item()方法返回对创建的即时代理对象的引用,而不是检查器实例本身。尝试:两次访问相同的索引会返回两个截然不同的指针。


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


  • Inspector.Caption Inspector.CurrentItem.Subject 同样含糊不清。

    / li>
  • 暂时将 Inspector.CurrentItem.Subject (或任何其他项属性)设置为一个明确的值,然后查找在其他列表类型的作品中,但是具有在检查器中将项目标记为脏的令人讨厌的副作用,即,在再次关闭检查器时,用户将被要求保存项目(即使他正在查看接收到的




任何其他想法?






上下文:



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

作为一种替代方法我使用shell钩子:我现在能够得到通知,当一个新的检查器窗口创建或销毁,这似乎是一个很好的地方跳转并且将 Application.Inspectors 集合中的包装器对象的内部列表匹配,并相应地添加或删除新的或孤立的包装器对象。

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


[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.

解决方案

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

这篇关于如何可靠地告知两个Inspector引用指向同一个检查器实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆