获取 WebBrowserControl 的 AxIWebBrowser2 句柄,用于 InternetSetOption、System.__ComObject 的 COM 问题

发布于 2024-10-04 13:49:30 字数 934 浏览 0 评论 0原文

我试图仅为 WebBrowserControl 的当前实例设置代理。该文档很糟糕,但我相信,如果我调用 wininet.dllInternetSetOption 将 IntPtr 句柄传递给 WebBrowserControl 使用的内部浏览器作为第一个参数,那么该方法只会影响当前实例(我可以使用此方法设置代理 http://msdn.microsoft.com/en-us/library/aa385114(v=VS.85).aspx)。但是,WebBrowserControl 不提供任何访问此句柄的方法。我花了几个小时在谷歌上搜索和搜索,这似乎对很多人很有帮助,但还没有人弄清楚!

WebBrowserControl 有一个名为 AxIWebBrowser2 的属性,它是我需要句柄的 COM 对象。 MS 为此使用的接口称为 UnsafeNativeMethods.IWebBrowser2 ,并且有一个名为 HWND 的属性,我认为这是我所需要的。但是,UnsafeNativeMethods.IWebBrowser2 被标记为内部。使用 WebBrowserControl 上的反射,我可以获得私有 AxIWebBrowser2 属性值,但其类型显示为 System.__ComObject。我无法将此 System.__ComObject 转换为 IWebBrowser2,因为它位于 Windows.Forms 程序集的内部。

有没有办法使用 C# 访问此 AxIWebBrowser2 对象的 HWND 属性?

I'm trying to set a proxy for only the current instance of a WebBrowserControl. The documentation is terrible but I believe that if I call wininet.dll's InternetSetOption passing the IntPtr handle to the internal browser used by the WebBrowserControl as the first parameter then the method will only affect the current instance (and I can set a proxy using this method http://msdn.microsoft.com/en-us/library/aa385114(v=VS.85).aspx). However, the WebBrowserControl does not provide any means to access this handle. I've spent hours googling and searching SO and it seems like this would be very helpful to a number of people but nobody has figured it out yet!

The WebBrowserControl has a property called AxIWebBrowser2 which is the COM object I need the handle for. The interface MS uses for this is called UnsafeNativeMethods.IWebBrowser2 and has a property called HWND which I think is what I need. However, UnsafeNativeMethods.IWebBrowser2 is marked internal. Using reflection on the WebBrowserControl, I can get the private AxIWebBrowser2 property value but the type on it comes up as System.__ComObject. I can't cast this System.__ComObject as an IWebBrowser2 because that's internal to the Windows.Forms assembly.

Is there any way to access the HWND property of this AxIWebBrowser2 object using C#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

佞臣 2024-10-11 13:49:31

Hwnd 不会给你你正在寻找的东西。它是浏览器控件的窗口句柄。我们正在寻找的是 WinInet HINTERNET 句柄。据我所知,没有办法以编程方式访问它。您是否尝试过在进程范围内设置该选项并将 IntPtr.Zero 作为 HINTERNET 句柄传递?

Hwnd won't give you what you are looking for. It's the window handle of the browser control. What are are looking for is the WinInet HINTERNET handle. There is no way to programmatically access that as far as I know. Have you tried setting the option on a process-wide basis and passing IntPtr.Zero in as the HINTERNET handle?

星星的軌跡 2024-10-11 13:49:31

尝试将 IE 配置为使用从代理池分配代理的代理自动配置脚本(或只需更改每个 Web 请求的 http 响应中的代理),并禁用自动代理缓存

Try configure IE to use an proxy automatic configuration script that allocates proxies from a proxy pool (or just change the proxy in the http response for each web request), and disable the automatic proxy caching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文