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 的后端?
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
