有没有方法来判断两个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.
推荐答案
您可以查询IUnknown接口并比较这些指针。所有其他界面指针不保证每次都返回相同的值。
You could query for the IUnknown interface and compare these pointers. All other interface pointers are not guaranteed to return the same value each time.
对象标识。要求对特定对象实例的任何接口对任何特定接口IUnknown的任何调用QueryInterface都必须返回相同的物理指针值。这使得能够在任何两个接口上调用QueryInterface(IID_IUnknown,...),并比较结果以确定它们是否指向同一个对象实例(相同的COM对象标识)。
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. 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).
这篇关于有没有方法来判断两个COM接口引用是否指向同一个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!