CEF3 + Win32

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.

Re: CEF3 + Win32

Postby magreenblatt » Mon Jan 25, 2016 12:14 pm

You're creating the dialog before calling CefExecuteProcess. That's why you're getting multiple copies.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 + Win32

Postby bezbot » Tue Jan 26, 2016 8:52 am

Thanks, now I can really see just one dialog.

Now I have small problem with application shutdown. Do you know what the log below means?

Code: Select all
[0126/143727:FATAL:browser_main.cc(187)] Check failed: 0 == CefBrowserContext::DebugObjCt (0 vs. 1)
CefDlgTestX.exe has triggered a breakpoint
The thread 'CompositorTileWorker1/9208' (0x23f8) has exited with code 0 (0x0).
[0126/143731:WARNING:content_browser_client.cc(622)] No browser info matching frame process id 3 and routing id 1
The thread 'Chrome_IOThread' (0x12d4) has exited with code 0 (0x0).
The thread 'Chrome_CacheThread' (0x3ab8) has exited with code 0 (0x0).
The thread 'Chrome_ProcessLauncherThread' (0x3abc) has exited with code 0 (0x0).
The thread 'Chrome_FileUserBlockingThread' (0x39d4) has exited with code 0 (0x0).
The thread 'Chrome_FileThread' (0x2ab0) has exited with code 0 (0x0).
The thread 'Chrome_DBThread' (0x354c) has exited with code 0 (0x0).
The thread 'IndexedDB' (0x2e98) has exited with code 0 (0x0).
The thread 'BrowserBlockingWorker1/7868' (0x1ebc) has exited with code 0 (0x0).
[0126/143732:FATAL:browser_main.cc(201)] Check failed: 0 == CefURLRequestContext::DebugObjCt (0 vs. 1)
CefDlgTestX.exe has triggered a breakpoint
The thread 'VideoCaptureThread' (0x3a58) has exited with code 0 (0x0).
The thread 'AudioThread' (0x3a60) has exited with code 0 (0x0).
The thread 'DnsConfigService' (0x2c5c) has exited with code 0 (0x0).
[0126/143733:FATAL:keyed_service_factory.cc(19)] Check failed: mapping_.empty().
CefDlgTestX.exe has triggered a breakpoint
[0126/143734:FATAL:keyed_service_factory.cc(19)] Check failed: mapping_.empty().
CefDlgTestX.exe has triggered a breakpoint
First-chance exception at 0x00007ffc7058a1c8 in CefDlgTestX.exe: 0x0000071A: Remote procedure call was cancelled.
The thread 'handle-watcher-thread' (0x3834) has exited with code 0 (0x0).
[0126/143735:FATAL:browser_context_impl.cc(48)] Check failed: all_.empty().
CefDlgTestX.exe has triggered a breakpoint
[0126/143736:FATAL:keyed_service_factory.cc(19)] Check failed: mapping_.empty().
CefDlgTestX.exe has triggered a breakpoint
[0126/143737:FATAL:keyed_service_factory.cc(19)] Check failed: mapping_.empty().
CefDlgTestX.exe has triggered a breakpoint
[0126/143737:FATAL:keyed_service_factory.cc(19)] Check failed: mapping_.empty().
CefDlgTestX.exe has triggered a breakpoint
[0126/143738:FATAL:keyed_service_factory.cc(19)] Check failed: mapping_.empty().
CefDlgTestX.exe has triggered a breakpoint
The thread 'Win64 Thread' (0x3940) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x201c) has exited with code 0 (0x0).
The thread 'PacDhcpLookupWorker3/11396' (0x2c84) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x2ea4) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x37a4) has exited with code 0 (0x0).
The thread 'BrokerEvent' (0x3950) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x38b8) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x3acc) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x3884) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x2f28) has exited with code 0 (0x0).
The thread 'PacDhcpLookupWorker2/1652' (0x674) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x29fc) has exited with code 0 (0x0).
The thread 'PacDhcpLookupWorker1/4536' (0x11b8) has exited with code 0 (0x0).
The program '[0x2218] CefDlgTestX.exe: Native' has exited with code 0 (0x0).
bezbot
Techie
 
Posts: 11
Joined: Fri Jan 08, 2016 6:55 am

Re: CEF3 + Win32

Postby magreenblatt » Tue Jan 26, 2016 11:38 am

You're leaking some object references. Try calling CefDoMessageLoopWork() one last time before CefShutdown().
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 + Win32

Postby bezbot » Wed Jan 27, 2016 4:21 am

Now it works perfectly. Thanks a lot.

Here is the final version for those who are interrested:

Code: Select all
#include <windows.h>
#include <CommCtrl.h>
#include "MyCefApp.h"
#include "resource.h"

CefRefPtr<MyCefApp> pCefApp;

INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_COMMAND:

        if (HIWORD(wParam) == BN_CLICKED)
        {
            //button click event

            switch(LOWORD(wParam))
            {
                case IDC_BUTTON1:
                {
                    MessageBox(hDlg, L"Button1 Click",  L"Information", MB_OK|MB_ICONINFORMATION);
                }
                return TRUE;

                case IDC_BUTTON2:
                {
                    MessageBox(hDlg, L"Button2 Click", L"Information", MB_OK|MB_ICONINFORMATION);
                }
                return TRUE;

                case IDCANCEL:
                {
                    SendMessage(hDlg, WM_CLOSE, 0, 0);
                }                   
                return TRUE;
            }
        }

    case WM_CLOSE:
        if (pCefApp!=NULL)
        {
            if(pCefApp!=NULL)
            {
                if (pCefApp->GetCefClient()!=NULL)
                {
                    pCefApp->GetCefClient()->CloseAllBrowsers(false);
                }
            }           
        }
        if(MessageBox(hDlg, TEXT("Close the program?"), TEXT("Close"),
            MB_ICONQUESTION | MB_YESNO) == IDYES)
        {
            DestroyWindow(hDlg);
        }
        return TRUE;

    case WM_DESTROY:
        PostQuitMessage(0);
        return TRUE;
    }

    return FALSE;
}


// Entry point function for all processes.
int APIENTRY wWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPTSTR    lpCmdLine,
                      int       nCmdShow) {
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);
 
  // Enable High-DPI support on Windows 7 or newer.
  CefEnableHighDPISupport();
 
  void* sandbox_info = NULL;

  // Provide CEF with command-line arguments.
  CefMainArgs main_args(hInstance);

  // SimpleApp implements application-level callbacks. It will create the first
  // browser instance in OnContextInitialized() after CEF has initialized. 

  pCefApp = new MyCefApp();

  // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
  // that share the same executable. This function checks the command-line and,
  // if this is a sub-process, executes the appropriate logic.
 
  int exit_code = CefExecuteProcess(main_args, pCefApp.get(), sandbox_info);
  if (exit_code >= 0) {
    // The sub-process has completed so return here.
    return exit_code;
  }

  // Specify CEF global settings here.
  CefSettings settings;
  settings.multi_threaded_message_loop = false;

  InitCommonControls();
  HWND hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, DialogProc, 0); 
  if (hDlg==NULL) return -1;

  ShowWindow (hDlg,SW_SHOW);   
  UpdateWindow (hDlg);

  HWND hHTMLGroupBox = GetDlgItem(hDlg, IDC_GROUPBOX1);
  RECT htmlRect;
  WINDOWINFO wndInfo;
  GetWindowInfo(hDlg, &wndInfo);

  GetWindowRect(hHTMLGroupBox, &htmlRect);
  htmlRect.left-=wndInfo.rcClient.left;
  htmlRect.right-=wndInfo.rcClient.left;
  htmlRect.top-=wndInfo.rcClient.top;
  htmlRect.bottom-=wndInfo.rcClient.top;

  ShowWindow(hHTMLGroupBox, SW_HIDE);

  pCefApp->SetParentWindow(hDlg, htmlRect);

  // Initialize CEF.
  CefInitialize(main_args, settings, pCefApp.get(), sandbox_info);
 
  MSG Msg;
  while(GetMessage(&Msg, NULL, 0, 0))
  {         
      if(!IsDialogMessage (hDlg, &Msg))
      {
          TranslateMessage(&Msg);
          DispatchMessage(&Msg);         
      }     
      CefDoMessageLoopWork();
  }

  CefDoMessageLoopWork();
  CefDoMessageLoopWork();
  CefDoMessageLoopWork();
 
  // Shut down CEF.
  CefShutdown();

  return 0;
}
bezbot
Techie
 
Posts: 11
Joined: Fri Jan 08, 2016 6:55 am

Re: CEF3 + Win32

Postby magreenblatt » Wed Jan 27, 2016 12:44 pm

Was it necessary in your testing to call CefDoMessageLoopWork 3 times before CefShutdown?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 + Win32

Postby Plinker1961 » Fri Mar 11, 2016 11:34 am

I think the answer to that question is Yes. Of the various CEF integrations I've worked on, one of them (which has its own message loop) needed exactly what bezbot described. Without those 3 extra calls to CefDoMessageLoopWork() after the message pump completed, the debug version would report the same type of errors he reported.
Plinker1961
Mentor
 
Posts: 65
Joined: Thu Feb 26, 2015 5:14 pm

Re: CEF3 + Win32

Postby diablosbg » Tue Jun 18, 2019 2:16 am

Extremely helpful article - I successfully managed to compile bezbot's code sample and managed to get the CEF version cef_binary_3.3626.1894.g90eb8cc_windows64 to run in a dialog box in parallel with some other standard Win32 dialogs.

Only thing is I do not seem to be able to debug it properly - I keep getting the libcef.dll.pdb "no matching symbols found" error in Visual Studio 2019 CE.
Other than that the program runs correctly in Release mode - the only issue being is that it doesn't shut down properly - the threads don't seem to close.

Anyway, these are minor setbacks, taking into consideration that there's almost no other examples on-line of integrating CEF into Win32 API without using wrappers and preserving the standard message loop.

Thanks bezbot!
diablosbg
Newbie
 
Posts: 2
Joined: Tue Jun 18, 2019 1:48 am

Previous

Return to Support Forum

Who is online

Users browsing this forum: ElAndLivia, Majestic-12 [Bot] and 109 guests