Is it possible to use c++ as back-end for Electron.js?(是否可以使用 c++ 作为 Electron.js 的后端?)
问题描述
我的任务是制作简单的 c++ 应用程序,将信息存储到二进制文件中,然后需要对这些信息进行简单的操作,例如编辑、删除、读取.我想使用 Electron 创建桌面应用程序来设计 UI,并使用 c++ 来处理信息.
I have a task to make simple c++ app which stores information into binary files, then need to make simple manipulations with this info, like edit,delete,read. I wanted to create desktop app using Electron for designing UI and to use c++ for manipulation with information.
有可能吗,我如何将 c++ 包含到电子中,有教程吗?提前致谢.
Is it possible and how can i include c++ into electron, is there any tutorials? Thanks in advance.
推荐答案
Electron 使用的是 nodejs,所以你仍然可以将 cpp 代码打包为 node 模块,然后在你的电子应用程序中使用它作为依赖.
Electron is using nodejs, so you can still package cpp code as a node module and then use it as dependency in your electron app.
查看 Hello World 示例此处,它基本上是这样做的:
See the Hello World example here which basically does this:
module.exports.hello = () => 'world';
这是他们教程中的示例:
This is the example from their tutorial:
// hello.cc
#include <node.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(addon, init)
} // namespace demo
这篇关于是否可以使用 c++ 作为 Electron.js 的后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以使用 c++ 作为 Electron.js 的后端?


- 从python回调到c++的选项 2022-11-16
- 如何对自定义类的向量使用std::find()? 2022-11-07
- STL 中有 dereference_iterator 吗? 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01