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;
}
}
}
Cef.Initialize
a single time before creating aChromiumWebBrowser
instance, then you can create as many instances as required, then callCef.Shutdown
before your application exits. The default behaviour will be to hook the relevantWinForms
event to callCef.Shutdown
as it's important, you might need to disable this cefsharp.github.io/api/73.1.x/html/… - amaitlandVB6
is not a supported platform, so there are no guarantees any of this works. If you require further assistance you will need to provide more detail to your example. - amaitland