Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

c# - SHDocVw works only with Win 10 x64 version

I have the following code written in C# WinForms:

...    
SHDocVw.WebBrowser_V1 axBrowser = (SHDocVw.WebBrowser_V1)webBrowser1.ActiveXInstance;
    
if (axBrowser != null)
{
     axBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, axBrowser, new object[] { true });
}
    
axBrowser.NewWindow += axBrowser_NewWindow;
...
if (!webBrowser1.IsDisposed && !webBrowser1.Url.Equals("about:blank")) //System.NullReferenceException: Object reference not set to an instance of an object.
{
     webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
}

I get a null reference error when running on x86 platform. When running on x64, everything is working fine. I suppose the problem is with the Interop.SHDocVw.

Edit: In the if condition, the webBrowser1.Url part becomes null. So i tried like this: (it gives me no error BUT the CONTROL is EMPTY)

private void contextMenuStrip1_Click(object sender, EventArgs e)
{
    try
    {
        if (!webBrowser1.IsDisposed && webBrowser1.Url !=null && !webBrowser1.Url.Equals("about:blank"))
        {
             webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
        }
        else if (webBrowser1.Url == null)
        {
            MessageBox.Show("webBrowser1.Url ");
            webBrowser1.AllowWebBrowserDrop = false;//MS bug?: {"Error HRESULT E_FAIL has been returned from a call to a COM component."}   System.Runtime.InteropServices.COMException
            webBrowser1.ScrollBarsEnabled = false;//false--MS bug?: {"Error HRESULT E_FAIL has been returned from a call to a COM component."}  System.Runtime.InteropServices.COMException
            webBrowser1.ScriptErrorsSuppressed = false;

            WinInetInterop.RestoreSystemProxy();

            SHDocVw.WebBrowser_V1 axBrowser = (SHDocVw.WebBrowser_V1)webBrowser1.ActiveXInstance;

            if (axBrowser != null)
            {
                axBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, axBrowser, new object[] { true });
            }

            axBrowser.NewWindow += axBrowser_NewWindow;

            webBrowser1.Url = new System.Uri("https://evidentacimitir.com/ProfitshareAds.html", System.UriKind.Absolute);
            webBrowser1.WebBrowserShortcutsEnabled = false;
            webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
            webBrowser1.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.webBrowser1_Navigated);
        }
    }
    catch (Exception ex)
    {
        ExceptionReportHelper.Exception(ex);
    }
}

How can I fix this problem to work also on x86 platforms?

Thanks

question from:https://stackoverflow.com/questions/65641290/shdocvw-works-only-with-win-10-x64-version

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...