How to properly close CEF when the MFC dialog box program cr

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.

How to properly close CEF when the MFC dialog box program cr

Postby fanrongqi » Thu Dec 14, 2023 9:32 pm

I am using VS2019 to write code and the CEF version I am using is 101. I created a dialog box project for MFC and created a CEF browser window in the dialog box. When I close the dialog box, I cannot call the doclose() function of CEF, so I cannot close CEF properly. How should I write code?

BOOL CMFCAppApp::InitInstance() I initialize CEF
CefRefPtr<SimpleApp> app(new SimpleApp);

// Initialize CEF.
CefInitialize(main_args, settings, app.get(), sandbox_info);


BOOL CMFCAppDlg::OnInitDialog() I create the browser
info.SetAsChild(m_hWnd, cefRect);


CefBrowserHost::CreateBrowser(info, mCefHandler, "https://www.baidu.com",
browserSettings,
nullptr, nullptr);
fanrongqi
Newbie
 
Posts: 7
Joined: Tue Nov 21, 2023 8:31 am

Re: How to properly close CEF when the MFC dialog box progra

Postby KatrinaS » Thu Dec 14, 2023 10:01 pm

Maybe this https://learn.microsoft.com/en-us/cpp/m ... w=msvc-170 Document will help you muddle through :)
KatrinaS
Mentor
 
Posts: 83
Joined: Tue Jul 04, 2023 6:30 pm

Re: How to properly close CEF when the MFC dialog box progra

Postby fanrongqi » Thu Dec 14, 2023 10:08 pm

When I call CefShutdown() in void CMFCAppDlg:: OnDestroy() or void CMFCAppDlg:: OnClose(); Whenever there is an exception, I don't know how to trigger the handler's callback to close the cef sub window.

message is :

[1215/104724.735:FATAL:shutdown_checker.cc(30)] Check failed: !IsCefShutdown(). Object reference incorrectly held at CefShutdown
fanrongqi
Newbie
 
Posts: 7
Joined: Tue Nov 21, 2023 8:31 am

Re: How to properly close CEF when the MFC dialog box progra

Postby magreenblatt » Thu Dec 14, 2023 10:36 pm

See CefLifeSpanHandler::DoClose. CefInitialize/CefShutdown needs to be called a single time in your application. Move that out of your dialog class if you intend to display it multiple times.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to properly close CEF when the MFC dialog box progra

Postby magreenblatt » Thu Dec 14, 2023 11:11 pm

There are also many examples online if you google “cef mfc example”
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to properly close CEF when the MFC dialog box progra

Postby fanrongqi » Sat Dec 16, 2023 6:13 am

I can't find any code that can run, nor can I find a concise tutorial. I can't work well, my code can't close the browser, and sometimes the rendering process keeps running. Cannot be closed. Can someone help me, give me a connection, or a book. I can acquire the correct knowledge.
fanrongqi
Newbie
 
Posts: 7
Joined: Tue Nov 21, 2023 8:31 am

Re: How to properly close CEF when the MFC dialog box progra

Postby finder2 » Sat Dec 16, 2023 10:29 am

I also had issues with MFC and CEF because MFC uses different threads for different classes like Doc, App etc.
Finally, i solved all issues and run CefShutdown at ExitInstance()
Have a look at this example https://www.codeproject.com/Articles/11 ... pplication
finder2
Mentor
 
Posts: 51
Joined: Fri Jun 13, 2014 1:33 am


Return to Support Forum

Who is online

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