CEF3 + MFC

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.

CEF3 + MFC

Postby p0lemic » Mon Jan 18, 2016 11:57 am

Hi!

I know this topic has been discused many times but I cannot find the problem I am getting. I am trying to add CEF3 in a project with MFC in a Shared DLL option.

In Debug, CefInitialize is always breaking at some LogMessage destruction:

Code: Select all
    libcef.dll!base::debug::BreakDebugger()  Line 21   C++
    libcef.dll!logging::LogMessage::~LogMessage()  Line 604   C++
    libcef.dll!base::i18n::InitializeICU()  Line 238   C++
    libcef.dll!content::ContentMainRunnerImpl::Initialize(const content::ContentMainParams & params)  Line 717 + 0x5 bytes   C++
    libcef.dll!CefContext::Initialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 268 + 0x2d bytes   C++
    libcef.dll!CefInitialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 130 + 0x23 bytes   C++
    libcef.dll!cef_initialize(const _cef_main_args_t * args, const _cef_settings_t * settings, _cef_app_t * application, void * windows_sandbox_info)  Line 178 + 0x24 bytes   C++
>   CEFMFC.exe!CefInitialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 170 + 0x6b bytes   C++
    CEFMFC.exe!CCEFMFCApp::InitInstance()  Line 112 + 0x3a bytes   C++


If I continue the break, another places break at the same place, like:

Code: Select all
    libcef.dll!base::debug::BreakDebugger()  Line 21   C++
    libcef.dll!logging::LogMessage::~LogMessage()  Line 604   C++
    libcef.dll!`anonymous namespace'::RegisterLocalizedFontPref(user_prefs::PrefRegistrySyncable * registry, const char * path, int default_message_id)  Line 318   C++
    libcef.dll!PrefsTabHelper::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)  Line 585 + 0x13 bytes   C++
    libcef.dll!renderer_prefs::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)  Line 341 + 0x9 bytes   C++
    libcef.dll!browser_prefs::CreatePrefService(const base::FilePath & pref_path)  Line 128 + 0xe bytes   C++
    libcef.dll!CefBrowserContextImpl::Initialize()  Line 183 + 0x13 bytes   C++
    libcef.dll!CefBrowserMainParts::PreMainMessageLoopRun()  Line 148 + 0x29 bytes   C++
    libcef.dll!content::BrowserMainLoop::PreMainMessageLoopRun()  Line 915 + 0x20 bytes   C++
    libcef.dll!base::internal::RunnableAdapter<int (__thiscall content::BrowserMainLoop::*)(void)>::Run(content::BrowserMainLoop * object)  Line 176 + 0xc bytes   C++
    libcef.dll!base::internal::InvokeHelper<0,int,base::internal::RunnableAdapter<int (__thiscall content::BrowserMainLoop::*)(void)>,base::internal::TypeList<content::BrowserMainLoop *> >::MakeItSo(base::internal::RunnableAdapter<int (__thiscall content::BrowserMainLoop::*)(void)> runnable)  Line 287   C++
    libcef.dll!base::internal::Invoker<base::IndexSequence<0>,base::internal::BindState<base::internal::RunnableAdapter<int (__thiscall content::BrowserMainLoop::*)(void)>,int __cdecl(content::BrowserMainLoop *),base::internal::TypeList<base::internal::UnretainedWrapper<content::BrowserMainLoop> > >,base::internal::TypeList<base::internal::UnwrapTraits<base::internal::UnretainedWrapper<content::BrowserMainLoop> > >,base::internal::InvokeHelper<0,int,base::internal::RunnableAdapter<int (__thiscall content::BrowserMainLoop::*)(void)>,base::internal::TypeList<content::BrowserMainLoop *> >,int __cdecl(void)>::Run(base::internal::BindStateBase * base)  Line 346 + 0x27 bytes   C++
    libcef.dll!base::Callback<int __cdecl(void)>::Run()  Line 396 + 0xe bytes   C++
    libcef.dll!content::StartupTaskRunner::RunAllTasksNow()  Line 45 + 0xf bytes   C++
    libcef.dll!content::BrowserMainLoop::CreateStartupTasks()  Line 806   C++
    libcef.dll!content::BrowserMainRunnerImpl::Initialize(const content::MainFunctionParams & parameters)  Line 221   C++
    libcef.dll!CefMainDelegate::RunProcess(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & process_type, const content::MainFunctionParams & main_function_params)  Line 604 + 0x2a bytes   C++
    libcef.dll!content::RunNamedProcessTypeMain(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & process_type, const content::MainFunctionParams & main_function_params, content::ContentMainDelegate * delegate)  Line 366 + 0x17 bytes   C++
    libcef.dll!content::ContentMainRunnerImpl::Run()  Line 804 + 0x14 bytes   C++
    libcef.dll!CefContext::Initialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 283 + 0x29 bytes   C++
    libcef.dll!CefInitialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 130 + 0x23 bytes   C++
    libcef.dll!cef_initialize(const _cef_main_args_t * args, const _cef_settings_t * settings, _cef_app_t * application, void * windows_sandbox_info)  Line 178 + 0x24 bytes   C++
>   CEFMFC.exe!CefInitialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 170 + 0x6b bytes   C++
    CEFMFC.exe!CCEFMFCApp::InitInstance()  Line 112 + 0x3a bytes   C++


After continue all breaks, nothing is rendered.

I use already compiled CEF3 TRUNK from cefbuilds.com. CEF3 branch 2272 has the same result. I use VS2010 SP1.

I could successfully add CEF1 to my project (although one break appears at the begining) and html is rendered correctly

In CEF3, using MFC as a static library has the same result. cefclient and cefsimple examples work correctly.

I compiled libcef_dll_wrapper consequently with MFC option selected.

Sample MFC CEF project used comes from https://code.google.com/p/cef-mfc/sourc ... g%2FCEFMFC

Any idea of what is going on?

Thanks!
p0lemic
Newbie
 
Posts: 5
Joined: Mon Jan 18, 2016 11:40 am

Re: CEF3 + MFC

Postby magreenblatt » Tue Jan 19, 2016 11:32 am

You're likely missing the ICU data file. See the README.txt included with the binary distribution for installation requirements.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 + MFC

Postby palaver » Tue Jan 19, 2016 11:40 am

Go to your project's
Properties -> Configuration Properties -> Build Events -> Post Build Events

And take a look at the Command Line options, you will notice that it only copies the *.dll and *.bak files. remove the extensions to allow it to copy the entire set of files in the Resource folder, as well as the *.bin files along with the dlls. Changing the post-build event to the following worked for me:

Code: Select all
xcopy /y /e /i C:\CEF\cef_binary\Resources\* $(OutputPath)
xcopy /y C:\CEF\cef_binary\$(Configuration)\* $(OutputPath)


Of course, you have to make sure that you point your command to the correct directory that contains your Resources folder and your dll's. As you can see, mine are in C:\CEF\cef_binary\
palaver
Techie
 
Posts: 36
Joined: Wed Nov 25, 2015 9:51 am

Re: CEF3 + MFC

Postby p0lemic » Tue Jan 19, 2016 2:47 pm

Thanks!! I missed the easiest part, really appreciate your help.

I could successfully use it in a dummy app but when I use in the final MFC app I have another problem during CefInitialize.

If I set multi_threaded_message_loop=TRUE, debugger says

Function marked as IO-only was called from a thread that disallows IO!

Code: Select all
>   libcef.dll!base::debug::BreakDebugger()  Line 21   C++
    libcef.dll!logging::LogMessage::~LogMessage()  Line 604   C++
    libcef.dll!base::ThreadRestrictions::AssertIOAllowed()  Line 45   C++
    libcef.dll!base::MakeAbsoluteFilePath(const base::FilePath & input)  Line 74   C++
    libcef.dll!base::PathService::Get(int key, base::FilePath * result)  Line 219 + 0xd bytes   C++
    libcef.dll!content::PathProvider(int key, base::FilePath * result)  Line 16 + 0xb bytes   C++
    libcef.dll!base::PathService::Get(int key, base::FilePath * result)  Line 208 + 0x11 bytes   C++
    libcef.dll!content::ChildProcessHost::GetChildPath(int flags)  Line 78 + 0xe bytes   C++
    libcef.dll!content::GpuProcessHost::LaunchGpuProcess(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & channel_id)  Line 983 + 0xd bytes   C++
    libcef.dll!content::GpuProcessHost::Init()  Line 565 + 0x19 bytes   C++
    libcef.dll!content::GpuProcessHost::Get(content::GpuProcessHost::GpuProcessKind kind, content::CauseForGpuLaunch cause)  Line 338 + 0x8 bytes   C++
    libcef.dll!content::BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO()  Line 130 + 0xe bytes   C++
    libcef.dll!base::internal::RunnableAdapter<void (__thiscall content::BrowserGpuChannelHostFactory::EstablishRequest::*)(void)>::Run(content::BrowserGpuChannelHostFactory::EstablishRequest * object)  Line 176 + 0xc bytes   C++
    libcef.dll!base::internal::InvokeHelper<0,void,base::internal::RunnableAdapter<void (__thiscall content::BrowserGpuChannelHostFactory::EstablishRequest::*)(void)>,base::internal::TypeList<content::BrowserGpuChannelHostFactory::EstablishRequest *> >::MakeItSo(base::internal::RunnableAdapter<void (__thiscall content::BrowserGpuChannelHostFactory::EstablishRequest::*)(void)> runnable)  Line 294   C++
    libcef.dll!base::internal::Invoker<base::IndexSequence<0>,base::internal::BindState<base::internal::RunnableAdapter<void (__thiscall content::BrowserGpuChannelHostFactory::EstablishRequest::*)(void)>,void __cdecl(content::BrowserGpuChannelHostFactory::EstablishRequest *),base::internal::TypeList<scoped_refptr<content::BrowserGpuChannelHostFactory::EstablishRequest> > >,base::internal::TypeList<base::internal::UnwrapTraits<scoped_refptr<content::BrowserGpuChannelHostFactory::EstablishRequest> > >,base::internal::InvokeHelper<0,void,base::internal::RunnableAdapter<void (__thiscall content::BrowserGpuChannelHostFactory::EstablishRequest::*)(void)>,base::internal::TypeList<content::BrowserGpuChannelHostFactory::EstablishRequest *> >,void __cdecl(void)>::Run(base::internal::BindStateBase * base)  Line 346 + 0x25 bytes   C++
    libcef.dll!base::Callback<void __cdecl(void)>::Run()  Line 396 + 0xe bytes   C++
    libcef.dll!base::debug::TaskAnnotator::RunTask(const char * queue_function, const base::PendingTask & pending_task)  Line 53   C++
    libcef.dll!base::MessageLoop::RunTask(const base::PendingTask & pending_task)  Line 477   C++
    libcef.dll!base::MessageLoop::DeferOrRunPendingTask(const base::PendingTask & pending_task)  Line 487   C++
    libcef.dll!base::MessageLoop::DoWork()  Line 596 + 0xc bytes   C++
    libcef.dll!base::MessagePumpForIO::DoRunLoop()  Line 496 + 0x19 bytes   C++
    libcef.dll!base::MessagePumpWin::RunWithDispatcher(base::MessagePump::Delegate * delegate, base::MessagePumpDispatcher * dispatcher)  Line 50 + 0xf bytes   C++
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate)  Line 57   C++
    libcef.dll!base::MessageLoop::RunHandler()  Line 439 + 0x2a bytes   C++
    libcef.dll!base::RunLoop::Run()  Line 56   C++
    libcef.dll!base::MessageLoop::Run()  Line 283   C++
    libcef.dll!base::Thread::Run(base::MessageLoop * message_loop)  Line 200   C++
    libcef.dll!content::BrowserThreadImpl::IOThreadRun(base::MessageLoop * message_loop)  Line 212   C++
    libcef.dll!content::BrowserThreadImpl::Run(base::MessageLoop * message_loop)  Line 246 + 0xc bytes   C++
    libcef.dll!base::Thread::ThreadMain()  Line 251 + 0x16 bytes   C++
    libcef.dll!base::`anonymous namespace'::ThreadFunc(void * params)  Line 82 + 0xe bytes   C++


If I continue the break, everything works like a charm. Outside vs seems to work correctly.

If I set multi_threaded_message_loop=FALSE, it fails saying

Invalid COM thread model change

Code: Select all
    libcef.dll!base::debug::BreakDebugger()  Line 21   C++
    libcef.dll!logging::LogMessage::~LogMessage()  Line 604   C++
    libcef.dll!ui::ScopedOleInitializer::ScopedOleInitializer()  Line 26   C++
    libcef.dll!content::BrowserMainRunnerImpl::Initialize(const content::MainFunctionParams & parameters)  Line 192 + 0x24 bytes   C++
>   libcef.dll!CefMainDelegate::RunProcess(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & process_type, const content::MainFunctionParams & main_function_params)  Line 604 + 0x2a bytes   C++
    libcef.dll!content::RunNamedProcessTypeMain(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & process_type, const content::MainFunctionParams & main_function_params, content::ContentMainDelegate * delegate)  Line 366 + 0x17 bytes   C++
    libcef.dll!content::ContentMainRunnerImpl::Run()  Line 804 + 0x14 bytes   C++
    libcef.dll!CefContext::Initialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 283 + 0x29 bytes   C++
    libcef.dll!CefInitialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 130 + 0x23 bytes   C++
    libcef.dll!cef_initialize(const _cef_main_args_t * args, const _cef_settings_t * settings, _cef_app_t * application, void * windows_sandbox_info)  Line 178 + 0x24 bytes   C++
    AlbaApp.exe!CefInitialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> application, void * windows_sandbox_info)  Line 170 + 0x6b bytes   C++


In our MFC application we already make a call to CoInitialize COINIT_MULTITHREADED. I imagine chromium is trying to call it in APARTMENT mode.

Am I missing something?

Thanks for your help!
p0lemic
Newbie
 
Posts: 5
Joined: Mon Jan 18, 2016 11:40 am

Re: CEF3 + MFC

Postby magreenblatt » Tue Jan 19, 2016 2:53 pm

See viewtopic.php?f=6&t=13678 for the MakeAbsoluteFilePath error.

The code for ScopedOleInitializer is here: https://code.google.com/p/chromium/code ... pe=cs&l=11. You shouldn't call OleInitialize() multiple times for the same thread (either use multi_threaded_message_loop or don't call OleInitialize() yourself).
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 + MFC

Postby p0lemic » Wed Jan 20, 2016 5:15 am

It works! Thanks for your patience with these newbie questions
p0lemic
Newbie
 
Posts: 5
Joined: Mon Jan 18, 2016 11:40 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 38 guests