使用窗口句柄获取 IUnkown
我知道这可能不太可能,所以请原谅我,因为我对 COM 不太了解。
基本上我想做的是获取指向正在运行的应用程序的 IUnknown 接口的指针,问题是我对应用程序唯一了解的是它的主窗口句柄。
这可能吗?
I know this may be a long shot so forgive me as I don't really know that much about COM.
Basically what I am trying to do is get the pointer to the IUnknown interface for a running application, the problem is the only thing I know about the app is its main window handle.
Would this be possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行此操作的“标准”方法是使用 AccessibleObjectFromWindow Win32 API。也就是说,实际上支持这一点的东西并不多,所以你的里程可能会有所不同。您可以 PInvoke 访问 AccessibleObjectFromWindow,传递 HWND,然后在返回的 IntPtr 上使用 Marshal.GetObjectForIUnknown。
The "standard" way to do this is with the AccessibleObjectFromWindow Win32 API. That said, not many things actually support this, so your mileage may vary. You'd PInvoke to AccessibleObjectFromWindow, pass the HWND, then use Marshal.GetObjectForIUnknown on the IntPtr you get back.
有时是的,如果窗口位于您的进程中(否则另一个进程中的指针对您来说毫无意义)并且窗口的编写者明确告诉您它正在等待消息并返回接口。大多数情况下不会,人们通常不会在没有必要的情况下编写黑客代码,并且发送作者未知的消息会产生不可预测的行为。
Sometimes yes, if the window is in your process (otherwise a pointer in another process is meaningless to you) and the window's writer explicitly tell you that it is expecting a message and returning an interface. Mostly no, people usually do not write hacks when there is no need to and sending messages unknown to the writer would have unpredictable behavior.