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

不问归期 提交于 2019-12-23 02:54:11

问题


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#?


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/4251537/get-webbrowsercontrols-axiwebbrowser2-handle-for-use-in-internetsetoption-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!