简体   繁体   English

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

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

Given two interface references obtained from different sources. 给出从不同来源获得的两个接口引用。 Is there a programmatic way to tell whether they're implemented by the same instance? 是否有一种编程方式来判断它们是否由同一个实例实现?

A simple equality check of the interface references always fails. 对接口引用的简单相等检查总是失败。


EDIT: Large parts of the original question, which turned out to be an independent problem have now been moved to a new question . 编辑:原始问题的大部分,原来是一个独立的问题,现在已经转移到一个新的问题

You could query for the IUnknown interface and compare these pointers. 您可以查询IUnknown接口并比较这些指针。 All other interface pointers are not guaranteed to return the same value each time. 所有其他接口指针不保证每次都返回相同的值。

from The Rules of the Component Object Model : 来自组件对象模型的规则

Object identity. 对象标识。 It is required that any call to QueryInterface on any interface for a given object instance for the specific interface IUnknown must always return the same physical pointer value. 要求在特定接口IUnknown的给定对象实例的任何接口上对QueryInterface的任何调用都必须始终返回相同的物理指针值。 This enables calling QueryInterface(IID_IUnknown, ...) on any two interfaces and comparing the results to determine whether they point to the same instance of an object (the same COM object identity). 这样可以在任意两个接口上调用QueryInterface(IID_IUnknown,...)并比较结果以确定它们是否指向对象的同一实例(相同的COM对象标识)。

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

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