winapi - 了解在 COM 对象上查询哪些接口(interface)

标签 winapi interface com

我正在查看 Raymond Chen 的代码示例,可用 here 。据我了解,他使用IShellWindows接口(interface)获取了一个shell项。然后,使用该项目的 IDispatch 接口(interface)和对 QueryInterface 的调用,他跳转到该项目的 IWebBrowserApp 界面。几行之后,他似乎跳到了该项目的 IServiceProvider 界面。我的问题是,在使用 QueryInterface 之前,您如何知道 IShellWindows 项可能支持 IWebBrowserApp 和 IServiceProvider > 接口(interface)?例如,我没有看到任何文档列出 IShellWindows 项支持的所有接口(interface)。

最佳答案

MSDN 通常不会告诉您对象实现了哪些接口(interface),但是如果您环顾四周,您经常会发现一些可以 QI 的文档和相关接口(interface)。需要明确的是,接口(interface)只是一个契约,多个对象可以实现某个接口(interface),所以你不能真正责怪微软没有一个明确的列表。

让我们尝试分解您的具体示例。

实现 IShellWindows (CLSID_ShellWindows) 的对象实际上没有任何其他有趣的接口(interface),您只关心它的窗口列表。

IShellWindows -> (IDispatch ->) IWebBrowserApp:

IShellWindows 具有打开的 Internet Explorer 和资源管理器窗口的集合。无论出于何种原因,它只是为每个窗口提供一个 IDispatch,而不是让您请求特定的接口(interface)。可能只是因为 IShellWindows 也可以由 Windows Scripting Host/Visual Basic 编写脚本,并且 IDispatch 在那里发挥着重要作用。

The Shell windows collection includes file explorer windows and web browser windows Internet Explorer and 3rd-party web browsers). Normally each Shell window implements IDispatch; IShellWindows::Item and IShellWindows::FindWindowSW provide ways to access a Shell window's IDispatch interface.

..以及 IShellWindows 和 IWebBrowserApp/IWebBrowser2 之间的连接:

exdisp.h contains the following programming interfaces

  • IShellWindows
  • IWebBrowser2

IWebBrowserApp -> IShellBrowser:

Objects that have access to the site chain of the browser can get a reference to the browser on IShellBrowser using IServiceProvider::QueryService, with Service IDs such as SID_STopLevelBrowser and SID_SCommDlgBrowser. See the Knowledge Base article Retrieve the Top-Level IWebBrowser2 Interface from an ActiveX Control for more information on using service IDs.

对于在 Windows 98/IE 4 时间范围内对 Windows 感兴趣的人们来说,Web 浏览器和 shell 像这样连接这一事实应该不足为奇。 Internet Explorer 和文件资源管理器基本上是相同的东西; Explorer可以显示网页,IE可以显示“文件列表”(IShellView)。

IShellBrowser -> IShellView:

只需简单调用QueryActiveShellView

这里有一个关键点; IShellFolder/IShellView 可以通过第 3 方 shell 扩展来实现。 Explorer 实现了 IShellBrowser,IShellBrowser 承载了 IShellView,第 3 方 ISV 也可以创建实现 IShellBrowser 的文件浏览器。理论上,您可以拥有一个由一家公司创建的文件资源管理器应用程序,托管由另一家公司创建的 shell View ,而不涉及 Microsoft 代码。 IShellBrowser 和 IShellView 是它们如何看待彼此的。

IShellView -> IFolderView:

这里没有直接联系,但如果你环顾四周,你可以将这些点联系起来。

IShellFolderView is supported by the IShellView object that is returned from SHCreateShellFolderViewEx

[IShellFolderView is no longer available for use as of Windows 7. Instead, use IFolderView2 and IFolderView.]

在其他情况下,如果您找不到特定的文档,您只需尝试查询您感兴趣的接口(interface)。shell 还有大量未记录的接口(interface),如果您想尝试,调试器是您唯一的选择那些。

关于winapi - 了解在 COM 对象上查询哪些接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56469680/

相关文章:

c++ - OLE/COM 对象查看器报告 STG_E_FILENOTFOUND

C++(没有 MFC)禁用/灰色菜单项

multithreading - 在异步可插拔协议(protocol)线程中 - 如何将其关联/解析到实现::SetSite() 的特定 COM 对象?

c - 更新 WINAPI 中的文本框项目

java - 为什么不能继承Interface

java - 用相同的方法在一个类中实现两个接口(interface)。哪个接口(interface)方法被覆盖?

java - 实现并通过方法向 ArrayList 添加项目

iis - 经典的 ASP 和 COM 调试

winapi - ExtTextOut不显示下标字符

c++ - 逆向工程 C++ DLL