是否可以使用 c++ 作为 Electron.js 的后端? [英] Is it possible to use c++ as back-end for Electron.js?

查看:36
本文介绍了是否可以使用 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 的后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆