我正在尝试修改 Chromium 嵌入式框架 ( https://bitbucket.org/chromiumembedded/cef/wiki/Tutorial ) 中的“cefsimple”示例,以便它使用单独的可执行文件在 Windows 上启动其子进程。
但是,这并没有按预期工作,并且每次在弹出任何窗口或启动任何子进程之前在主进程中调用 CefInitialize 时都会崩溃。调用堆栈:
chrome_elf.dll!00007ffaa7fc1cfd()
chrome_elf.dll!00007ffaa7fba5fc()
chrome_elf.dll!00007ffaa7fb9c9b()
libcef.dll!00007ffa88dae13c()
libcef.dll!00007ffa882fc146()
> cefsimple.exe!CefInitialize(const CefMainArgs & args, const CefStructBase<CefSettingsTraits> & settings, CefRefPtr<CefApp> * application, void * windows_sandbox_info) Line 201 + 0xb4 bytes C++
使用:CEF 版本 3.2883.1539、64 位、C++、VS 2015、Windows 10。
我的解决方案: 我在 CMakeLists 中添加了另一个目标(cefsimpleHelper.exe),并使用这些指令作为修改源代码的引用: https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-separate-sub-process-executable
cefsimple_win.cc: (主可执行文件的入口点)
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
CefEnableHighDPISupport();
CefMainArgs main_args(hInstance);
CefSettings settings;
settings.no_sandbox = true;
CefString(&settings.browser_subprocess_path).FromASCII("cefsimpleHelper.exe");
CefRefPtr<SimpleApp> app(new SimpleApp);
CefInitialize(main_args, settings, app.get(), NULL);
CefRunMessageLoop();
CefShutdown();
return 0;
}
process_helper_win.cc: (子流程启动器的入口点)
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
CefMainArgs main_args(hInstance);
CefRefPtr<SimpleApp> app(new SimpleApp);
return CefExecuteProcess(main_args, app.get(), nullptr);
}
知道可能是什么问题吗?
最佳答案
我想我找到了解决方案,主要是通过随机试验和错误:P
我刚刚在主可执行文件中的 CefInitialize 之前添加了对 CefExecuteProcess 的调用:
const auto exit_code = CefExecuteProcess(main_args, app.get(), nullptr);
if (exit_code >= 0)
return exit_code;
感谢您的所有评论,我希望这对其他人也有帮助。
关于c++ - 让 CEF 使用单独的可执行文件来启动子进程 (C++/Windows),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41223766/