您当前的位置: 首页 > 

插件开发

暂无认证

  • 2浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

libcef-Vs2017-下载编译第一个libcef3项目

插件开发 发布时间:2022-03-18 08:08:10 ,浏览量:2

文章目录
    • 1.下载
    • 2.构建项目
    • 3.编译
    • 4.作者答疑
  libcef是一个非常优秀的嵌入式浏览开源库,可以在C++,Java,C#等常用语言中使用,在本文中,主要介绍在Vs2017环境下的编译使用。

1.下载

  第一步,需要下载libcef的版本,现今libcef的下载地址为:https://cef-builds.spotifycdn.com/index.html#windows64,本文默认已经安装好Vs2017和CMake。本文选择的版本为:cef_binary_79.0.10+ge866a07+chromium-79.0.3945.88,为至今日较新版本。

2.构建项目

  项目的构建文件CMakeLists.txt,位于根目录下,根据下图选择: 在这里插入图片描述

  然后选择Vs2017 Win64对应的编译器。

3.编译

  采用Vs2017打开解决方案cef.sln,如下图所示: 在这里插入图片描述   打开后项目解决方案如下: 在这里插入图片描述   编译时,可以先编译libcef_dll_wrapper项目,再编译其他项目。

范例代码如下:

#include 
#include "include/cef_sandbox_win.h"
#include "tests/cefsimple/simple_app.h"

#if defined(CEF_USE_SANDBOX)
// The cef_sandbox.lib static library may not link successfully with all VS
// versions.
#pragma comment(lib, "cef_sandbox.lib")
#endif

// 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;

#if defined(CEF_USE_SANDBOX)
  // Manage the life span of the sandbox information object. This is necessary
  // for sandbox support on Windows. See cef_sandbox_win.h for complete details.
  CefScopedSandboxInfo scoped_sandbox;
  sandbox_info = scoped_sandbox.sandbox_info();
#endif

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

  // 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, NULL, sandbox_info);
  if (exit_code >= 0) {
    // The sub-process has completed so return here.
    return exit_code;
  }

  // Specify CEF global settings here.
  CefSettings settings;

#if !defined(CEF_USE_SANDBOX)
  settings.no_sandbox = true;
#endif

  // SimpleApp implements application-level callbacks for the browser process.
  // It will create the first browser instance in OnContextInitialized() after
  // CEF has initialized.
  CefRefPtr app(new SimpleApp);

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

  // Run the CEF message loop. This will block until CefQuitMessageLoop() is
  // called.
  CefRunMessageLoop();

  // Shut down CEF.
  CefShutdown();

  return 0;
}
4.作者答疑

  如有疑问,请留言。

关注
打赏
1665481431
查看更多评论
立即登录/注册

微信扫码登录

0.0391s