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

查看:572
本文介绍了可以将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代码打包为节点模块,然后将其用作电子应用程序中的依赖项。

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天全站免登陆