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

断了今生、忘了曾经 提交于 2019-12-11 00:48:04

问题


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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/323289/is-there-a-way-to-tell-whether-two-com-interface-references-point-at-the-same-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!