Trying to use cefclient as a DLL

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Trying to use cefclient as a DLL

Postby robinm2 » Fri Feb 12, 2021 12:51 pm

Hi,

I'm trying to run cefclient as a DLL from a Windows Desktop application.
The CEF version is 86.0.20+gf2039ae+chromium-86.0.4240.111, built for VS 2019 / Win32 platform / no sandbox.
The original cefclient executable project builds and runs fine. But when run as a DLL, an exception is thrown from libcef:

Code: Select all
>   libcef.dll!logging::LogMessage::~LogMessage() Line 867   C++
    libcef.dll!logging::LogMessage::~LogMessage() Line 537   C++
    libcef.dll!logging::CheckError::~CheckError() Line 105   C++
    libcef.dll!`anonymous namespace'::RegisterLocalizedFontPref(user_prefs::PrefRegistrySyncable * registry=0x076154e8, const char * path=0x178f516c, int default_message_id=143) Line 281   C++
    libcef.dll!PrefsTabHelper::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry=0x076154e8, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & locale={...}) Line 421   C++
    libcef.dll!renderer_prefs::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry=0x076154e8, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & locale={...}) Line 321   C++
    libcef.dll!browser_prefs::CreatePrefService(Profile * profile=0x07611630, const base::FilePath & cache_path={...}, bool persist_user_preferences) Line 240   C++
    libcef.dll!AlloyBrowserContext::Initialize() Line 123   C++
    libcef.dll!AlloyMainDelegate::CreateNewBrowserContext(const CefStructBase<CefRequestContextSettingsTraits> & settings={...}) Line 449   C++
    libcef.dll!CefRequestContextImpl::Initialize() Line 652   C++
    libcef.dll!CefRequestContextImpl::CreateGlobalRequestContext(const CefStructBase<CefRequestContextSettingsTraits> & settings={...}) Line 215   C++
    libcef.dll!AlloyBrowserMainParts::PreMainMessageLoopRun() Line 196   C++
    libcef.dll!content::BrowserMainLoop::PreMainMessageLoopRun() Line 983   C++
    libcef.dll!base::OnceCallback<int ()>::Run() Line 99   C++
    libcef.dll!content::StartupTaskRunner::RunAllTasksNow() Line 41   C++
    libcef.dll!content::BrowserMainLoop::CreateStartupTasks() Line 897   C++
    libcef.dll!content::BrowserMainRunnerImpl::Initialize(const content::MainFunctionParams & parameters={...}) Line 130   C++
    libcef.dll!CefMainRunner::RunMainProcess(const content::MainFunctionParams & main_function_params={...}) Line 449   C++
    libcef.dll!AlloyMainDelegate::RunProcess(const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & process_type={...}, const content::MainFunctionParams & main_function_params={...}) Line 407   C++
    libcef.dll!content::RunBrowserProcessMain(const content::MainFunctionParams & main_function_params={...}, content::ContentMainDelegate * delegate=0x00cdbf48) Line 523   C++
    libcef.dll!content::ContentMainRunnerImpl::RunServiceManager(content::MainFunctionParams & main_params={...}, bool start_service_manager_only) Line 998   C++
    libcef.dll!content::ContentMainRunnerImpl::Run(bool start_service_manager_only) Line 885   C++
    libcef.dll!content::ContentServiceManagerMainDelegate::RunEmbedderProcess() Line 60   C++
    libcef.dll!service_manager::MainRun(service_manager::MainParams & params={...}) Line 460   C++
    libcef.dll!CefMainRunner::ContentMainRun(bool * initialized=0x00d016e0, base::OnceCallback<void ()> context_initialized={...}) Line 419   C++
    libcef.dll!CefMainRunner::Initialize(CefStructBase<CefSettingsTraits> * settings=0x00d016e8, scoped_refptr<CefApp> application={...}, const CefMainArgs & args={...}, void * windows_sandbox_info=0x00000000, bool * initialized=0x00d016e0, base::OnceCallback<void ()> context_initialized={...}) Line 241   C++
    libcef.dll!CefContext::Initialize(const CefMainArgs & args={...}, const CefStructBase<CefSettingsTraits> & settings={...}, scoped_refptr<CefApp> application={...}, void * windows_sandbox_info=0x00000000) Line 356   C++
    libcef.dll!CefInitialize(const CefMainArgs & args={...}, const CefStructBase<CefSettingsTraits> & settings={...}, scoped_refptr<CefApp> application={...}, void * windows_sandbox_info=0x00000000) Line 214   C++
    libcef.dll!cef_initialize(const _cef_main_args_t * args=0x008dfad8, const _cef_settings_t * settings=0x008df9a8, _cef_app_t * application=0x00cdda50, void * windows_sandbox_info=0x00000000) Line 111   C++
    cefclient.dll!CefInitialize(const CefMainArgs & args={...}, const CefStructBase<CefSettingsTraits> & settings={...}, scoped_refptr<CefApp> application={...}, void * windows_sandbox_info=0x00000000) Line 105   C++
    cefclient.dll!client::MainContextImpl::Initialize(const CefMainArgs & args={...}, const CefStructBase<CefSettingsTraits> & settings={...}, scoped_refptr<CefApp> application={...}, void * windows_sandbox_info=0x00000000) Line 225   C++
    cefclient.dll!client::`anonymous namespace'::RunMain() Line 99   C++
    cefclient.dll!interface() Line 129   C++
    test_app.exe!wWinMain(HINSTANCE__ * hInstance=0x009a0000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00c937c8, int nCmdShow=10) Line 134   C++
    test_app.exe!invoke_main() Line 123   C++
    test_app.exe!__scrt_common_main_seh() Line 288   C++
    test_app.exe!__scrt_common_main() Line 331   C++
    test_app.exe!wWinMainCRTStartup() Line 17   C++
    kernel32.dll!7640fa29()   Unknown
    kernel32.dll![Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]   Unknown
    ntdll.dll!777575f4()   Unknown
    ntdll.dll!777575c4()   Unknown


The changes I've made to cefclient are minimal: set the project as a DLL, added a .def file, and modified cefclient_win.cc as follows:

Code: Select all
36c36
< int RunMain(HINSTANCE hInstance, int nCmdShow) {
---
>         int RunMain() {
40c40
<   CefMainArgs main_args(hInstance);
---
>             CefMainArgs main_args(GetModuleHandle(NULL));
127,134c127,128
< // Program entry point function.
< int APIENTRY wWinMain(HINSTANCE hInstance,
<                       HINSTANCE hPrevInstance,
<                       LPTSTR lpCmdLine,
<                       int nCmdShow) {
<   UNREFERENCED_PARAMETER(hPrevInstance);
<   UNREFERENCED_PARAMETER(lpCmdLine);
<   return client::RunMain(hInstance, nCmdShow);
---
> extern void interface() {
>     client::RunMain();


So in the main app I'm calling interface().

Note that I really have to use this DLL architecture: I'm working on upgrading a code that essentially does that but uses an old version of CEF (3.1750.1738).

Thank you in advance,
robinm2
Techie
 
Posts: 11
Joined: Mon Feb 08, 2021 12:14 pm

Re: Trying to use cefclient as a DLL

Postby magreenblatt » Fri Feb 12, 2021 1:09 pm

What console/log messages were reported? Where did you place the resource files (*.pak, *.bin) relative to your executable and libcef.dll?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Trying to use cefclient as a DLL

Postby robinm2 » Fri Feb 12, 2021 2:43 pm

The output is:

Code: Select all
[0212/201705.801:INFO:content_main_runner_impl.cc(994)] Chrome is running in full browser mode.
[0212/201705.935:FATAL:root_window_win.cc(371)] Check failed: hwnd_.


I've set the test_app output directory to be the same as cefclient: E:\CEF3\build\tests\cefclient\Debug\
So everything is sitting there, including libcef.dll:

Code: Select all
build/tests/cefclient/Debug:
cef.pak
cef_100_percent.pak
cef_200_percent.pak
cef_extensions.pak
cefclient.dll
cefclient.exe
cefclient.exp
cefclient.ilk
cefclient.lib
cefclient.pdb
chrome_elf.dll
d3dcompiler_47.dll
debug.log
devtools_resources.pak
icudtl.dat
libEGL.dll
libGLESv2.dll
libcef.dll
locales
snapshot_blob.bin
swiftshader
test_app.exe
test_app.ilk
test_app.pdb
v8_context_snapshot.bin

build/tests/cefclient/Debug/locales:
am.pak
ar.pak
bg.pak
bn.pak
ca.pak
cs.pak
da.pak
de.pak
el.pak
en-GB.pak
en-US.pak
es-419.pak
es.pak
et.pak
fa.pak
fi.pak
fil.pak
fr.pak
gu.pak
he.pak
hi.pak
hr.pak
hu.pak
id.pak
it.pak
ja.pak
kn.pak
ko.pak
lt.pak
lv.pak
ml.pak
mr.pak
ms.pak
nb.pak
nl.pak
pl.pak
pt-BR.pak
pt-PT.pak
ro.pak
ru.pak
sk.pak
sl.pak
sr.pak
sv.pak
sw.pak
ta.pak
te.pak
th.pak
tr.pak
uk.pak
vi.pak
zh-CN.pak
zh-TW.pak

build/tests/cefclient/Debug/swiftshader:
libEGL.dll
libGLESv2.dll
robinm2
Techie
 
Posts: 11
Joined: Mon Feb 08, 2021 12:14 pm

Re: Trying to use cefclient as a DLL

Postby robinm2 » Mon Feb 15, 2021 6:40 am

Okay the problem was that in test_app there was some code generated by VS to initialize a basic window, and this conflicted with the code in CEF.
Especially, in root_window_win.cc, the CreateWindowEx call at line 369 didn't initialize hwnd_ as expected, hence the failed check.

I think the exception I reported at first was due to a previous configuration with different output paths, and the .pak from locales couldn't be found.
When I fixed it and still got an exception I thought it was the same. Sorry about the mix up.
robinm2
Techie
 
Posts: 11
Joined: Mon Feb 08, 2021 12:14 pm

Re: Trying to use cefclient as a DLL

Postby robinm2 » Thu Feb 18, 2021 12:51 pm

Well, I'm stuck again. The CEF window is displayed, but the URL bar is empty (instead of the default google address) and it's unable to load webpages:

Image

The output is identical to the original cefclient project:

Code: Select all
[0218/184800.908:INFO:content_main_runner_impl.cc(994)] Chrome is running in full browser mode.
onecore\com\combase\dcomrem\resolver.cxx(2283)\combase.dll!752D3196: (caller: 752D5760) ReturnHr(1) tid(8410) 80040154 Classe non enregistrée
onecore\com\combase\dcomrem\resolver.cxx(2491)\combase.dll!752D5781: (caller: 752D3B3F) ReturnHr(2) tid(8410) 80040154 Classe non enregistrée


Those two errors don't seem to bother the original cefclient.exe so I guess they are not related to my issue.
robinm2
Techie
 
Posts: 11
Joined: Mon Feb 08, 2021 12:14 pm

Re: Trying to use cefclient as a DLL

Postby magreenblatt » Thu Feb 18, 2021 2:02 pm

What processes are currently running (use a tool like Process Explorer)? Did you specify a sub-process executable? This is required if you don't intend to relaunch the main executable for sub-processes.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Trying to use cefclient as a DLL

Postby robinm2 » Thu Feb 18, 2021 2:54 pm

I get the same results with or without a separate sub-process.

Process Explorer shows that the main process test_app.exe spawns a bunch of processes but they immediately exit, except for two of them:

Code: Select all
"E:\CEF3\build\tests\cefclient\Debug\test_app.exe" --type=utility --utility-sub-type=network.mojom.NetworkService --field-trial-handle=1664,12718472143885741694,5432087983011337636,131072 --enable-features=CastMediaRouteProvider --lang=en-US --service-sandbox-type=network --no-sandbox --log-file="E:\CEF3\build\tests\cefclient\Debug\debug.log" --lang=en-US --log-file="E:\CEF3\build\tests\cefclient\Debug\debug.log" --mojo-platform-channel-handle=2220 /prefetch:8

"E:\CEF3\build\tests\cefclient\Debug\test_app.exe" --type=gpu-process --field-trial-handle=1664,12718472143885741694,5432087983011337636,131072 --enable-features=CastMediaRouteProvider --no-sandbox --log-file="E:\CEF3\build\tests\cefclient\Debug\debug.log" --lang=en-US --gpu-preferences=MAAAAAAAAADgACAwAAAAAAAAAAAAAAAAAABgAAAAAAAQAAAAAAAAAAAAAAAAAAAAKAAAAAQAAAAgAAAAAAAAACgAAAAAAAAAMAAAAAAAAAA4AAAAAAAAABAAAAAAAAAAAAAAAAUAAAAQAAAAAAAAAAAAAAAGAAAAEAAAAAAAAAABAAAABQAAABAAAAAAAAAAAQAAAAYAAAA= --log-file="E:\CEF3\build\tests\cefclient\Debug\debug.log" --mojo-platform-channel-handle=1672 /prefetch:2


So, no renderer process left.
robinm2
Techie
 
Posts: 11
Joined: Mon Feb 08, 2021 12:14 pm

Re: Trying to use cefclient as a DLL

Postby magreenblatt » Thu Feb 18, 2021 4:14 pm

Run with a debugger and attach to the other processes to debug further (pass --wait-for-debugger-children=renderer). See also http://www.chromium.org/developers/how- ... on-windows
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Trying to use cefclient as a DLL

Postby robinm2 » Thu Feb 18, 2021 4:49 pm

Thank you, I'll try that.
robinm2
Techie
 
Posts: 11
Joined: Mon Feb 08, 2021 12:14 pm

Re: Trying to use cefclient as a DLL

Postby robinm2 » Fri Feb 19, 2021 10:46 am

Okay, it was the same issue as https://magpcss.org/ceforum/viewtopic.php?f=6&t=14721

So as suggested I copied src/tests/cefclient/resources/win/compatibility.manifest into the test_app source directory, then modified it to keep only the supportedOS entry for Windows 10.
Finally, added compatibility.manifest as additional manifest file in my test_app project properties > manifest tool > input and output.
It's working now.

Thank you for the guidance.
robinm2
Techie
 
Posts: 11
Joined: Mon Feb 08, 2021 12:14 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 102 guests