为什么IHTMLDocument2不等于IHTMLDocument2.body.document

本文关键字:IHTMLDocument2 document body 不等于 为什么 | 更新日期: 2023-09-27 18:02:46

为什么下面的doc2不同于doc22?

IHTMLDocument2 doc2 = (pDisp as IWebBrowser2).Document as IHTMLDocument2;
IHTMLDocument2 doc22 = doc2.body.document as IHTMLDocument2;
bool isequal = Marshal.GetIUnknownForObject(doc2) == Marshal.GetIUnknownForObject(doc22);
//Here, isequal is false. Why?

为什么IHTMLDocument2不等于IHTMLDocument2.body.document

对我来说,最可能的解释是为同一事物创建了不同的包装器对象。谁知道MSHTML内部是如何管理这些的。只要((pDisp as IWebBrowser2).Document as IHTMLDocument3).documentElement as IUnknown == (((pDisp as IWebBrowser2).Document as IHTMLDocument2).body.document as IHTMLDocument3).documentElement as IUnknown世界是有序的;)