salvadordf / CEF4Delphi

CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
https://www.briskbard.com/forum/
Other
1.19k stars 363 forks source link

StartMainProcess: Error loading libcef.dll #506

Closed hafedh-trimeche closed 2 months ago

hafedh-trimeche commented 3 months ago

Hello,

CEF: 121.3.15 Chromium: 121.0.6167.184

Application raised this error:

StartMainProcess: Error loading libcef.dll

Error code : 0x00000057
The parameter is incorrect
hafedh-trimeche commented 3 months ago

Solved! dxil.dll not included inside the directory.

hafedh-trimeche commented 3 months ago

Now these errors are reported:

[0406/214708.185:ERROR:network_change_notifier_win.cc(267)] WSALookupServiceBegin failed with: 0
[0406/214708.189:ERROR:core_audio_util_win.cc(316)] Failed to create Core Audio device enumerator on thread with ID 16580
[0406/214709.525:ERROR:network_change_notifier_win.cc(267)] WSALookupServiceBegin failed with: 0
[0406/214711.463:ERROR:network_change_notifier_win.cc(267)] WSALookupServiceBegin failed with: 0
[0406/214711.466:ERROR:core_audio_util_win.cc(316)] Failed to create Core Audio device enumerator on thread with ID 27864
[0406/214712.941:ERROR:network_change_notifier_win.cc(267)] WSALookupServiceBegin failed with: 0
[0406/214729.026:ERROR:network_change_notifier_win.cc(267)] WSALookupServiceBegin failed with: 0
[0406/214729.030:ERROR:core_audio_util_win.cc(316)] Failed to create Core Audio device enumerator on thread with ID 13344
[0406/214730.395:ERROR:network_change_notifier_win.cc(267)] WSALookupServiceBegin failed with: 0
salvadordf commented 3 months ago

It seems Chromium can't use the Core Audio API https://source.chromium.org/chromium/chromium/src/+/main:media/audio/win/core_audio_util_win.cc;drc=f97f0d76be0b54403ef09d45f130c7aeec3798f9;l=352

And it doesn't know if the user is online https://source.chromium.org/chromium/chromium/src/+/main:net/base/network_change_notifier_win.cc;l=267;bpv=0;bpt=1

Check that all the contents of the Release and Resources directories were copied to the application directory or in the directories indicated by GlobalCEFApp.FrameworkDirPath, GlobalCEFApp.ResourcesDirPath and GlobalCEFApp.LocalesDirPath.

hafedh-trimeche commented 3 months ago

Hello,

Problem solved by setting DisableBackgroundNetworking to True and EnableMediaStream to False.

procedure CreateGlobalCEFApp;
begin
  GlobalCEFApp := TCefApplication.Create;
  with GlobalCEFApp do
  begin
    OnContextInitialized             := DoOnContextInitialized;

    AllowFileAccessFromFiles         := True;
    BlinkSettings                    := 'hideScrollbars=true,scrollAnimatorEnabled=false';
    DeleteCache                      := True;
    DeleteCookies                    := True;
    DisableBackForwardCache          := True;
    DisableBackgroundNetworking      := True;
    DisableComponentUpdate           := True;
    DisableImageLoading              := True;
    DisableJavascriptAccessClipboard := True;
    DisableJavascriptDomPaste        := True;
    DisableSpellChecking             := True;
    EnableGPU                        := False;
    EnableMediaStream                := False;
    EnableUsermediaScreenCapturing   := False;
    IgnoreCertificateErrors          := True;
    MultiThreadedMessageLoop         := False;
    MuteAudio                        := True;
    NoSandbox                        := True;
    PersistSessionCookies            := False;
    PersistUserPreferences           := False;
    SetCurrentDir                    := True;
    ShowMessageDlg                   := False;
    SmoothScrolling                  := STATE_DISABLED;
    TouchEvents                      := STATE_DISABLED;
    WindowlessRenderingEnabled       := True;

    if LogFile<>'' then
    begin
      ForceDirectories(ExtractFileDir(LogFile));
      LogFile     := LogFile;
      LogSeverity := LOGSEVERITY_ERROR;
    end;
  end;
end;

Would these parameters be tweaked to use this control only for converting HTML to PDF (Browser features not needed)?

Best regards.

salvadordf commented 3 months ago

The ConsoleBrowser2 demo uses a similar browser configuration to save the webpage as an image instead of a PDF but you can use similar GlobalCEFApp properties.

Setting GlobalCEFApp.MultiThreadedMessageLoop to False may require using a message pump (TCEFWorkScheduler or TFMXWorkScheduler) or using the "views" framework among other things. The default GlobalCEFApp.MultiThreadedMessageLoop value is the recommended setting for Windows applications.