How to Configure “Gecko” with Vb.NET Forms Application

我是研究僧i 提交于 2019-12-08 12:00:26

问题


I have been given a task to integrate Gecko browser component to a existing winform control, but the issue i m facing is how to configure dll, I am trying with different version as well, but no luck, at point it does not load dll and gives the error

Unable to find an entry point named 'NS_Alloc' in DLL 'xul'.

I have downloaded separately from given link. Xulrunner the latest and also the 29 but it says ,

An error occurred creating the form. See Exception.InnerException for details. The error is: Unable to load DLL 'xul': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Imports System.IO

Imports System.Xml Imports Gecko Imports Microsoft.Win32

Public Class Form1

Public Sub New()
    InitializeComponent()
    'D:\xulrunner\bin
    Xpcom.Initialize("D:\\xulrunner\\") 'xulrunner
    'Xpcom.Initialize("C:\Program Files (x86)\Mozilla Firefox\")
End Sub

End Class

please help me out if anybody has already done with that.


回答1:


Finally I managed to do so,

At the time of writing, I choose the latest version GeckoFX-33.0, and XULRunner 33.1. ,

  • Unpack the GeckoFX-330.zip, you will get below files:
  • GeckoFx Files

  • Add references to the dlls as shown above, click browse and select the Geckofx-Core.dll and Geckofx-Winforms.dll

  • In the toolbox, right click, and then select “Choose Item”, select Geckofx-Winforms.dll, and the Gecko winform control will be shown in the toolbox
  • Drag a GeckoWebBrowser control to the winform designer, and let’s call it “browse”
  • In the form1.cs file, add below code: AND FINALLY CODE:

                using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.Data;
            using System.Drawing;
            using System.Linq;
            using System.Text;
            using System.Windows.Forms;
            using System.Drawing.Printing;
    
            namespace GECKO_FORMS
            {
                public partial class Form1 : Form
                {
                    Bitmap bitmap;
                    Bitmap memoryImage;
                    public Form1()
                    {
                        InitializeComponent();
                        Gecko.Xpcom.Initialize(@"D:\\xulrunner\bin\\");
                    }              
                    private void cmdbrowse_Click(object sender, EventArgs e)
                    {
                        try
                        {
                            if (browse.IsBusy == false)
                            {
                                browse.Navigate(textBox1.Text);
                            }
                            else
                            {
                                lbox.Items.Add(browse.StatusText);
                                lbox.Items.Add(browse.History);
                            }               
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
    
                    private void cmdstop_Click(object sender, EventArgs e)
                    {
                        browse.Stop();
                    }
    
                                                                    private void browse_ProgressChanged(object sender, Gecko.GeckoProgressEventArgs e)
    {
        lbox.Items.Add(e.CurrentProgress + " of " + e.MaximumProgress);
    }
                                                                                                                                    private void CaptureScreen()
    {
        Graphics myGraphics = this.CreateGraphics();
        Size s = this.Size;
        memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
        Graphics memoryGraphics = Graphics.FromImage(memoryImage);
        memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
    }
    
                                                                                                                                                                                                                                                                                                                                                                                                                                    private void cmdprint_Click(object sender, EventArgs e)
    {
        try
        {
            CaptureScreen();
            pDoc.Print();
            ////Add a Panel control.
            //Panel panel = new Panel();
            //this.Controls.Add(panel);
            ////Create a Bitmap of size same as that of the Form.
            //Graphics grp = panel.CreateGraphics();
            //Size formSize = this.ClientSize;
            //bitmap = new Bitmap(formSize.Width, formSize.Height, grp);
            //grp = Graphics.FromImage(bitmap);
    
            ////Copy screen area that that the Panel covers.
            //Point panelLocation = PointToScreen(panel.Location);
            //grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize);
    
            ////Show the Print Preview Dialog.
            //ppd.Document = pDoc;
            //ppd.PrintPreviewControl.Zoom = 1;
            //ppd.ShowDialog();
        }
        catch (Exception ex)
        {
        }
    }        
    
                                                                    private void pDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(bitmap, 0, 0);
    }
                }
            }
    
  • Here is output:



来源:https://stackoverflow.com/questions/38539328/how-to-configure-gecko-with-vb-net-forms-application

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