Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Chromium Browser in Exe and DLL

Post Reply
Schmulm
Posts: 1
Joined: Fri Jan 17, 2020 8:02 am

Chromium Browser in Exe and DLL

Post by Schmulm »

Hi,
I have an application that uses CEF4Delphi. A part of this application is a DLL containing some additional functions and Forms. The DLL is written in Delphi, too. The DLL interface is and must remain compatible with other applications written in other programming languages. The Exe contains some Form with Chromium browsers. This works fine.

Now, some of the forms in this DLL should also be extended with a chromium browser control. I don't know, how to get this work. I cannot create another instance of TCefApplication in the DLL, because it must be unique. If I try so, I get an exception (libcef.dll cannot be opened. The file is already in use by another process). I cannot use the instance of the TCefApplication from the Exe, because I cannot share the global TCefApplication instance between Exe and DLL (and even if I do so, I get lots of access violations).

Is there any way to achieve what I'm trying to do? Or is it impossible? The only workaround I see so far (but not yet tested), is to copy all the chromium libraries and additional files to a second folder and initialize another TCefApplication in the DLL. But having 150 MB of binaries twice on the hard disk, is not my favourite solution.

Thanks in advance
Matthias
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Chromium Browser in Exe and DLL

Post by salvadordf »

Hi,

The access violations you see when you copy the global TCefApplication are probably caused by uninitialized variables in the uCEFLibFunctions unit.

Those variables are the functions exported by the CEF binaries and they are initialized when you call GlobalCEFApp.StartMainProcess or GlobalCEFApp.StartSubProcess. Perhaps those issues could be fixed if you also copy the variables in uCEFLibFunctions.

There are other potential issues when you initialize CEF in a DLL. When you use those DLLs as plugins you have to consider that other DLLs might also initialize CEF and all of them are in the same process and this is not supported by CEF because you can only initialize it once per process.

Even if you manage to initialize CEF only once you could have problems because some other DLL plugin might use a different CEF version.

In those cases it's recommended to modify the DLL code to run another application with a CEF browser and communicate with that browser using IPC instead of creating the browsers in the DLL code. However, this solution would require to use another copy of the CEF binaries.

Maybe the best solution would be to move the form with the chromium browser from the EXE to the DLL in order to have all the browsers inside the DLL.
Post Reply