简体   繁体   English

根据值比较两个COM接口实例

[英]Compare two instance of COM interface based on value

是否存在关于如何根据两个COM对象的值(即私有状态)而不是其标识(即指向IUnknown的指针)比较两个COM对象的模式?

Object equality is a heavy implementation detail, a detail that's well hidden in COM. 对象相等是一个沉重的实现细节,而这个细节在COM中已经很好地隐藏了。 COM is an interface based object model, the fact that an implementation is required of those interfaces is carefully hidden. COM是基于接口的对象模型,这些接口需要实现的事实已被仔细隐藏。 It comes up in just a few places, CoCreateInstance() being the obvious one. 它仅出现在几个地方,CoCreateInstance()是显而易见的地方。 Less obvious are the rules for IUnknown. IUnknown的规则不太明显。 Whose proper implementation requires that you'll get the same IUnknown interface pointer when you QI through any of the implemented interfaces. 谁的正确实现要求通过任何已实现的接口进行QI时,您将获得相同的IUnknown接口指针。 This provides object identity, not object equality. 这提供了对象身份,而不是对象相等性。

There is no standard COM interface type that is commonly used to test object equality. 没有通常用于测试对象相等性的标准COM接口类型。 You'll just have to make your own. 您只需要自己制作即可。 A simple one with an IsEqualTo() method gets the job done. 一个具有IsEqualTo()方法的简单方法即可完成工作。 Or you could just add that method to your default interface. 或者,您可以将该方法添加到默认界面中。

It depends on definition of "private state". 这取决于“私人国家”的定义。 A COM object does not have to have one. 一个COM对象不必具有一个。 If the objects implement IPersist* family of interfaces, esp. 如果对象实现IPersist*系列接口,尤其是。 IPersistStreamInit , then you can save both into persistent stream or property bag, and then compare storages directly, such as byte-by-byte comparison of the streams. IPersistStreamInit ,那么您可以它们保存到持久流或属性包中,然后直接比较存储,例如流的逐字节比较。

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

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