Page 1 of 1

Cannot open file libcef.dll

Posted: Tue Jun 09, 2020 2:33 pm
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.

Re: Cannot open file libcef.dll

Posted: Tue Jun 09, 2020 5:11 pm
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.

Re: Cannot open file libcef.dll

Posted: Wed Jun 10, 2020 12:12 pm
by yesha
I see. But still is there any way I can get rid of subprocesses after browser closing? I mean not main process.

Re: Cannot open file libcef.dll

Posted: Wed Jun 10, 2020 1:29 pm
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