提问人:user2274060 提问时间:4/11/2018 更新时间:4/12/2018 访问量:1889
C# - 带有 Gecko 和 xul 的 Windows 窗体
C# - Windows forms with Gecko and xul
问:
我在将C#中的Gecko与XUL集成时遇到了一些问题。
1/我已经下载了geckofx45.45.0.34.nupkg。有了这个,我在“.zip”中重命名了它的扩展名并解压缩了这个文件夹。我有很多目录。
2/然后,我在 C# (.NET Framework 4.5.2) 中创建了一个 Windows 窗体应用程序。通过“解决方案资源管理器”,我添加了步骤 1 生成的两个库(Geckofx-Core.dll 和 Geckofx-Winforms.dll)
3/然后,在工具箱中,在“所有 Windows 窗体”折叠时,我右键单击并“选择项目”。然后,在“.NET Framework 组件”选项卡中,我添加了 Geckofx-Winforms.dll。
4/我已重新启动 Visual Studio 2015
5/然后,我再次打开我的项目,并将工具箱中的“GeckoBrowser”组件添加到我的窗口中。
6/然后,我编译了我的项目。没关系。但是,当我尝试执行我的应用程序时,我遇到了一个问题:
An unhandled exception of type 'System.DllNotFoundException' occurred in Geckofx-Core.dll
Additional information: Unable to load DLL 'xul': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
所以,我已经在 http://ftp.mozilla.org/pub/xulrunner/releases/latest/runtimes/xulrunner-41.0.2.en-US.win32.zip 上下载了 xulrunner 并解压缩了文件。结果:C:\xulrunner\xulrunner-41.0.2.en-US.win32\xulrunner\
7/ 然后,在我的项目属性的“引用路径”中,我添加了路径 C:\xulrunner\xulrunner-41.0.2.en-US.win32\xulrunner\
8/我再次启动了我的应用程序,但屏幕上总是出现相同的错误
我也尝试使用“TlbImp.exe”但没有成功。
你可以帮我吗?
答:
我使用的方法需要将 xulrunner 文件夹拖放到 app 文件夹中,然后使用此方法:
private void InitializeGeckoEngine()
{
try
{
if (!Directory.Exists(Paths.XulRunner))
{
MessageBox.Show($"Firefox folder not found at {Paths.XulRunner}!");
}
Xpcom.EnableProfileMonitoring = false;
Xpcom.Initialize(Paths.XulRunner);
}
catch (Exception ex)
{
MessageBox.Show($"Firefox engine not detected or was not loaded correctly. Loading path: {Paths.XulRunner}. Exception details:\n" + ex + ex.InnerException, "Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
关键部分当然是 Xpcom.Initialize() 调用。
评论
nupkg