开发者

Get WebBrowserControl's AxIWebBrowser2 Handle for use in InternetSetOption, COM issues with System.__ComObject

开发者 https://www.devze.com 2023-01-26 16:20 出处:网络
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 t

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 开发者_StackOverflow社区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#?


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消