获取WebBrowserControl的AxIWebBrowser2句柄用于InternetSetOption,COM问题与System .__ ComObject [英] Get WebBrowserControl's AxIWebBrowser2 Handle for use in InternetSetOption, COM issues with System.__ComObject

查看:508
本文介绍了获取WebBrowserControl的AxIWebBrowser2句柄用于InternetSetOption,COM问题与System .__ ComObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试只为WebBrowserControl的当前实例设置代理。文档是可怕的,但我相信,如果我调用 wininet.dll ' InternetSetOption 将IntPtr句柄传递到内部浏览器使用的WebBrowserControl作为第一个参数,那么该方法将只影响当前实例(我可以设置一个代理使用此方法 http://msdn.microsoft.com/en-us/library/aa385114(v = VS.85).aspx )。但是,WebBrowserControl不提供任何方法来访问此句柄。我花了几个小时的谷歌和搜索SO,它似乎这将是非常有用的一些人,但没有人想出来了。

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!

WebBrowserControl有一个属性叫AxIWebBrowser2,这是COM对象我需要的句柄。接口MS为此使用称为 UnsafeNativeMethods.IWebBrowser2 并且有一个名为 HWND 的属性,我认为这是我需要的。但是, UnsafeNativeMethods.IWebBrowser2 标记为 internal 。使用WebBrowserControl上的反射,我可以获得私有 AxIWebBrowser2 属性值,但类型为 System .__ ComObject 。我不能将 System .__ ComObject 作为 IWebBrowser2 ,因为它位于 Windows .Forms

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.

是否有任何方法访问 HWND AxIWebBrowser2 使用C#的对象?

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

推荐答案

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?

这篇关于获取WebBrowserControl的AxIWebBrowser2句柄用于InternetSetOption,COM问题与System .__ ComObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆