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.

Cannot open file libcef.dll

Post Reply
yesha
Posts: 2
Joined: Tue Jun 09, 2020 7:14 am

Cannot open file libcef.dll

Post by yesha »

Hello.

I'm trying to bring into life the folowing scenario:
1.Creating browser form with TChromiumWindow on it by clicking the button.
(I'm creating TCefApplication in the button click event handler before creating the browser form)
2.After closing browser form i'm destroing it. And I'm calling DestroyGlobalCEFApp in OnDestroy method of the browser form.

My goal is to create chromium subprocesses only for a short period of time when i need them. And destroy them after that.

Scenario works fine for the first time. There is the problem at the second time. In debugger mode i'm getting error

Code: Select all

---------------------------
Debugger Exception Notification
---------------------------
Project SimpleBrowser.exe raised exception class EFOpenError with message 'Cannot open file "H:\projects\code\cef4delphi\bin\libcef.dll". The process cannot access the file because it is being used by another process'.
---------------------------
Break   Continue   Help   
---------------------------
What am doing wrong? Source code I used is in the attachment.
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4040
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Cannot open file libcef.dll

Post by salvadordf »

Hi,

CEF can only be initialized once per process. This is a CEF feature and there's no workaround.
You can create and destroy several browsers at runtime but you have to initialize CEF only once.

This is the reason the SubProcess demo calls CreateGlobalCEFApp and DestroyGlobalCEFApp in the initialization an finalization sections of uCEFLoader.pas

If you don't want to load CEF until it's necessary you can delay the CreateGlobalCEFApp call but you can call it only once.
yesha
Posts: 2
Joined: Tue Jun 09, 2020 7:14 am

Re: Cannot open file libcef.dll

Post by yesha »

I see. But still is there any way I can get rid of subprocesses after browser closing? I mean not main process.
User avatar
salvadordf
Posts: 4040
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Cannot open file libcef.dll

Post by salvadordf »

I'm afraid those subprocesses are used by Chromium while it's initialized and Chromium manages them internally.

Destroying GlobalCEFApp will free CEF and all those subprocesses will be closed but then you wouldn't be able to open a new browser in that process.

There's an exception to this rule with DLLs. Perhaps you can use it :
https://www.briskbard.com/forum/viewtop ... f=8&t=1315
Post Reply