如何从 Win32::OLE 中的 HWND 获取 COM 对象?
在 Perl 中,如果我有窗口对象的 HWND,如何使用该句柄访问该 COM 对象?我查看了 Win32::OLE,但我得到的最接近的是 GetActiveObject 方法,它需要一个类。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在 Perl 中,如果我有窗口对象的 HWND,如何使用该句柄访问该 COM 对象?我查看了 Win32::OLE,但我得到的最接近的是 GetActiveObject 方法,它需要一个类。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
没有标准方法可以从 HWND 获取 COM 接口指针,因为窗口不是 COM 对象。基本的 Windows API(包括窗口句柄)早于 OLE 和 COM 的发明。特定窗口的实现可以通过 COM 接口公开其部分或全部功能,但这些接口将是特定于应用程序的。
如果有记录表明您要控制的窗口公开了公共 COM 接口,则该窗口的文档还将告诉您如何在窗口中查询接口指针。最有可能的是,它需要发送特定于应用程序的 窗口消息。
There is no standard way to obtain a COM interface pointer from an HWND, because a window is not a COM object. The basic Windows API, including window handles, predates the invention of OLE and COM. The implementation of a particular window may expose some or all of its functionality through COM interfaces, but those interfaces will be application-specific.
If it is documented that the window you want to control exposes a public COM interface, the documentation for that window will also tell you how to query the window for an interface pointer. Most likely, it will require sending an application-specific window message.
从可访问对象获取 HWND 或位置并使用 Windows API 操作它:
使用 HWND
Get an HWND or location from an Accessible Object and manipulate it with the Windows API:
use a HWND
如果您希望从 HWND 获取 IAccessible 接口,可以尝试使用 WM_GETOBJECT(注意:我假设有某种方法可以在 Perl 中发送窗口消息 - 众所周知,我没有 Perl 知识)。
并不是每个人都这样做,所以请确保以某种方式处理失败。例如,Internet Explorer 公开 WM_HTML_GETOBJECT 来获取 IHTMLDocument2 指针。
If you're looking to get the IAccessible interface from an HWND, you can try using WM_GETOBJECT (note: I assume there is someway to send window messages in Perl—it is well established that I have no Perl knowledge).
Not everyone does it this way, so make sure you handle failure somehow. For example, Internet Explorer exposes WM_HTML_GETOBJECT to get the IHTMLDocument2 pointer.