I'm updating a program in vb6 calling a Winform C# dll through COM interop. In this C# dll, the winform contain a webbrowser that instantiate Internet Explorer (.NET default browser). For compatibility issues, I need to embed Chromium. I've decided to go with CefSharp.
I've set up a test project in C# calling this dll & it's working fine. I've read CefSharp Wiki and they precise to initialize/shutdown Cef from the main UI thread. So I declare two methods in C# that I call directly in VB6. Issue is: the form is loading fine and browser with CefSharp is running. When I close the form and want to launch it again, application just shuts down. I've also tried to intialize/shutdown CefSharp in the C# dll with no success.
Any idea on how to correctly use CefSharp in this case? Thanks
Public gTest as boolean
Option Explicit
Public Function LaunchDLL() As Boolean
Dim oExtApp: Set oExtApp = CreateObject("TestCefSharp.Class2")
Dim test As Boolean
Dim bResult As Boolean
LaunchDLL = False
On Error GoTo Erreur
If gTest = False Then
oExtApp.InitializeChromium
gTest = True
End If
LaunchDLL = oExtApp.LaunchingForm
Set oExtApp = Nothing
Exit Function
Erreur:
MsgBox Err.Description
End Function
Public Sub LaunchBrowser_Click()
Dim test As Boolean
Dim Chrome As Boolean
test = LaunchDLL()
End Sub
namespace TestCefSharp
{
public interface IExternalApp
{
bool LaunchingForm();
bool InitializeChromium();
bool ShutdownChromium();
}
public abstract class CExternalApp : IExternalApp
{
public CExternalApp()
: base()
{
}
public bool LaunchingForm()
{
bool test = false;
MessageBox.Show("Starting");
Form1 form1 = new Form1();
DialogResult result = form1.ShowDialog();
if (result == DialogResult.OK)
{ test = true; }
else
{ test = false; }
return test ;
}
public bool InitializeChromium()
{
MessageBox.Show("Chromium initialized");
bool result = false;
try
{
CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
CefSharpSettings.ShutdownOnExit = false;
Cef.EnableHighDPISupport();
var settings = new CefSettings()
{ CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")};
Cef.Initialize(settings);
result = true;
}
catch
{ }
return result;
}
public bool ShutdownChromium()
{
MessageBox.Show("Chromium ended");
bool result = false;
try
{
Cef.Shutdown();
result = true;
}
catch
{ }
return result;
}
}
}
In fact, it's not working with the debug mode from VB6 editor... If I compile and launch directly the executable, all is working well.
I'll have to dig in a bit further but I think it comes from the fact that VB6 editor does not launch a separate thread in debug like VS2017 does in .NET.
Anyway, thanks for the help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.